From 25054935344b2a901be93f55ccb3cd4a1ab84366 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 22 Jun 2024 16:49:02 +0200 Subject: [PATCH] Added support for building the shared library (DLL) via Makefile. --- Makefile | 48 +++++++++++++++++++++++++------ etc/build/freebsd/mk-release.sh | 2 -- etc/build/gnuhurd/mk-release.sh | 2 -- etc/build/haiku/mk-release.sh | 2 -- etc/build/linux/mk-release-gnu.sh | 2 -- etc/build/linux/mk-release.sh | 2 -- etc/build/macosx/mk-release.sh | 2 -- etc/build/netbsd/mk-release.sh | 2 -- etc/build/openbsd/mk-release.sh | 2 -- etc/build/solaris/mk-release.sh | 2 -- etc/build/win32/mk-release.sh | 2 -- 11 files changed, 39 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index e90eea6..720f0ff 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,20 @@ DEBUG ?= 0 NALYZE ?= 0 ASAN ?= 0 STATIC ?= 0 +SHARED ?= 0 FLTO ?= 0 FPGO ?= 0 STRIP ?= 0 CPU ?= 0 THREAD ?= 1 -$(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD)) +$(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), SHARED=$(SHARED), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD)) + +ifneq ($(SHARED),0) + ifneq ($(STATIC),0) + $(error Options SHARED=1 and STATIC=1 are mutually exclusive!) + endif +endif # --------------------------------------------------------------------------- # Directories @@ -72,6 +79,9 @@ endif ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)))) EXE_SUFFIX := .exe + LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),dll,lib) +else + LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),$(if $(findstring -apple-darwin,$(MACHINE)),dylib,so),a) endif ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))) @@ -96,12 +106,26 @@ ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE)))) LDFLGS += -lbsd endif +APP_CFLAGS = $(CFLAGS) +APP_LDFLGS = $(LDFLGS) -L$(SUBDIR_LIB)/lib -l$(VERSION_LIB) +LIB_CFLAGS = $(CFLAGS) +LIB_LDFLGS = $(LDFLGS) + +ifneq ($(SHARED),0) + LIB_CFLAGS += -fPIC + ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))) + LIB_LDFLGS = -Wl,--out-implib,"$@.a" $(LDFLGS) + endif +endif + # --------------------------------------------------------------------------- # File names # --------------------------------------------------------------------------- +VERSION_LIB := slunkcrypt$(CONFIG)-1 + OUTNAME_APP := slunkcrypt$(CONFIG)$(EXE_SUFFIX) -OUTNAME_LIB := libslunkcrypt$(CONFIG)-1.a +OUTNAME_LIB := lib$(VERSION_LIB)$(LIB_SUFFIX) OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP) OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB) @@ -121,21 +145,27 @@ endif # Targets # --------------------------------------------------------------------------- -.PHONY: all clean +.PHONY: all build clean -all: $(OUTPATH_APP) +all: clean build + +build: $(OUTPATH_APP) $(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB) @mkdir -p $(@D) - $(CC) $(CFLAGS) $^ -o $@ $(LDFLGS) + $(CC) $(APP_CFLAGS) $(OBJECTS_APP) -o $@ $(APP_LDFLGS) $(OUTPATH_LIB): $(OBJECTS_LIB) @mkdir -p $(@D) +ifneq ($(SHARED),0) + $(CC) $(LIB_CFLAGS) $^ -shared -o $@ $(LIB_LDFLGS) +else $(AR) rcs $@ $^ +endif $(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c @mkdir -p $(@D) - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(APP_CFLAGS) -c $< -o $@ $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc @mkdir -p $(@D) @@ -143,8 +173,8 @@ $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c @mkdir -p $(@D) - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(LIB_CFLAGS) -c $< -o $@ clean: - $(RM) $(SUBDIR_APP)/obj/*.o $(SUBDIR_APP)/obj/*.gcda $(SUBDIR_APP)/lib/*.a $(SUBDIR_APP)/bin/*$(EXE_SUFFIX) - $(RM) $(SUBDIR_LIB)/obj/*.o $(SUBDIR_LIB)/obj/*.gcda $(SUBDIR_LIB)/lib/*.a $(SUBDIR_LIB)/bin/*$(EXE_SUFFIX) + $(RM) $(SUBDIR_APP)/obj/* $(SUBDIR_APP)/lib/* $(SUBDIR_APP)/bin/* + $(RM) $(SUBDIR_LIB)/obj/* $(SUBDIR_LIB)/lib/* $(SUBDIR_LIB)/bin/* diff --git a/etc/build/freebsd/mk-release.sh b/etc/build/freebsd/mk-release.sh index bcd2bdc..c900999 100755 --- a/etc/build/freebsd/mk-release.sh +++ b/etc/build/freebsd/mk-release.sh @@ -18,8 +18,6 @@ fi rm -rf "out" && mkdir -p "out" -gmake CC="${cc_path}" clean - mk_slunk 32 "i686" "pentiumpro" "pentium3" mk_slunk 64 "x86_64" "x86-64" "nocona" diff --git a/etc/build/gnuhurd/mk-release.sh b/etc/build/gnuhurd/mk-release.sh index 0711993..b804da2 100755 --- a/etc/build/gnuhurd/mk-release.sh +++ b/etc/build/gnuhurd/mk-release.sh @@ -15,8 +15,6 @@ fi rm -rf "out" && mkdir -p "out" -$BASH -x -c "make clean" - mk_slunk "i686" "i686-gnu" "MARCH=pentiumpro MTUNE=pentium3" ./etc/build/build_info.sh "gcc" > "out/.build_info" diff --git a/etc/build/haiku/mk-release.sh b/etc/build/haiku/mk-release.sh index 29fb496..466791a 100755 --- a/etc/build/haiku/mk-release.sh +++ b/etc/build/haiku/mk-release.sh @@ -14,8 +14,6 @@ fi rm -rf "out" && mkdir -p "out" -make clean - case "${BE_HOST_CPU}" in x86_64) mk_slunk "gcc" "x86_64" "x86-64" "nocona" diff --git a/etc/build/linux/mk-release-gnu.sh b/etc/build/linux/mk-release-gnu.sh index 0e2947f..47c9be3 100755 --- a/etc/build/linux/mk-release-gnu.sh +++ b/etc/build/linux/mk-release-gnu.sh @@ -19,8 +19,6 @@ fi rm -rf "out" && mkdir -p "out" -$BASH -x -c "make clean" - mk_slunk "x86_64" "x86_64-linux-gnu" "MARCH=x86-64 MTUNE=nocona" mk_slunk "i686" "i686-linux-gnu" "MARCH=pentiumpro MTUNE=pentium3" diff --git a/etc/build/linux/mk-release.sh b/etc/build/linux/mk-release.sh index d94d561..9fc400c 100755 --- a/etc/build/linux/mk-release.sh +++ b/etc/build/linux/mk-release.sh @@ -20,8 +20,6 @@ fi rm -rf "out" && mkdir -p "out" -$BASH -x -c "make clean" - mk_slunk "x86_64" "MARCH=x86-64 MTUNE=nocona" mk_slunk "i686" "MARCH=pentiumpro MTUNE=pentium3" diff --git a/etc/build/macosx/mk-release.sh b/etc/build/macosx/mk-release.sh index 42edf7d..44c11ba 100755 --- a/etc/build/macosx/mk-release.sh +++ b/etc/build/macosx/mk-release.sh @@ -13,8 +13,6 @@ mk_slunk() { rm -rf "out" && mkdir -p "out" -make CC="${cc_path}" clean - mk_slunk "x86_64" mk_slunk "arm64" diff --git a/etc/build/netbsd/mk-release.sh b/etc/build/netbsd/mk-release.sh index 06fdbe1..0351098 100755 --- a/etc/build/netbsd/mk-release.sh +++ b/etc/build/netbsd/mk-release.sh @@ -18,8 +18,6 @@ fi rm -rf "out" && mkdir -p "out" -gmake CC="${cc_path}" clean - case "$(uname -m)" in amd64) mk_slunk "x86_64" "x86-64" "nocona" diff --git a/etc/build/openbsd/mk-release.sh b/etc/build/openbsd/mk-release.sh index c5d8973..77774eb 100755 --- a/etc/build/openbsd/mk-release.sh +++ b/etc/build/openbsd/mk-release.sh @@ -18,8 +18,6 @@ fi rm -rf "out" && mkdir -p "out" -gmake CC="${cc_path}" clean - case "$(uname -m)" in amd64) mk_slunk "x86_64" "x86-64" "nocona" diff --git a/etc/build/solaris/mk-release.sh b/etc/build/solaris/mk-release.sh index dae9e44..5efdb69 100755 --- a/etc/build/solaris/mk-release.sh +++ b/etc/build/solaris/mk-release.sh @@ -18,8 +18,6 @@ fi rm -rf "out" && mkdir -p "out" -gmake CC="${cc_path}" clean - mk_slunk 32 "i686" "pentiumpro" "pentium3" mk_slunk 64 "x86_64" "x86-64" "nocona" diff --git a/etc/build/win32/mk-release.sh b/etc/build/win32/mk-release.sh index 6842318..1b5de02 100755 --- a/etc/build/win32/mk-release.sh +++ b/etc/build/win32/mk-release.sh @@ -28,8 +28,6 @@ mk_slunk() { mkdir -p "out/_next_" -make -B CC="${cc_path}" clean - case "${machine}" in x86_64*) mk_slunk "x86_64" "x86-64" "nocona"