Added support for building the shared library (DLL) via Makefile.

This commit is contained in:
LoRd_MuldeR 2024-06-22 16:49:02 +02:00
parent aaecd43e2d
commit 2505493534
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
11 changed files with 39 additions and 29 deletions

View File

@ -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/*

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -13,8 +13,6 @@ mk_slunk() {
rm -rf "out" && mkdir -p "out"
make CC="${cc_path}" clean
mk_slunk "x86_64"
mk_slunk "arm64"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"