From 8d52323ea8fd2f2ca70fcb57bcdaeb422a931c8b Mon Sep 17 00:00:00 2001 From: Milan Skocic Date: Thu, 21 Nov 2024 05:47:43 +0100 Subject: [PATCH] Clean up and improve C Makefiles. --- C/Makefile | 22 +++++++++++++++++++--- C/src/Makefile | 19 +++---------------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/C/Makefile b/C/Makefile index 3487e09..815bc9f 100644 --- a/C/Makefile +++ b/C/Makefile @@ -1,9 +1,11 @@ +C_SRC=$(wildcard src/*.c) +C_OBJ=$(patsubst src/%.c, $(BUILD_DIR)/%.o, $(C_SRC)) +SLIB=$(BUILD_DIR)/$(LIBNAME).a +.PHONY: headers sources build static shared clean -.PHONY: headers sources build clean - -all: headers sources build +all: headers sources build static shared headers: @@ -19,6 +21,20 @@ build: headers sources example: sources headers build make -C example +static: build + ar -crs $(SLIB) $(C_OBJ) + +shared: build static shared_$(PLATFORM) + +shared_linux: + $(CC) -shared -o $(BUILD_DIR)/$(LIBNAME).so -Wl,--whole-archive $(BUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive + +shared_darwin: + $(CC) -dynamiclib -install_name @rpath/$(LIBNAME).dylib $(FPM_LDFLAGS) -o $(BUILD_DIR)/$(LIBNAME).dylib -Wl,-all_load $(BUILD_DIR)/$(LIBNAME).a + +shared_windows: + $(CC) -shared $(FPM_LDFLAGS) -o $(BUILD_DIR)/$(LIBNAME).dll -Wl,--out-implib=$(BUILD_DIR)/$(LIBNAME).dll.a,--export-all-symbols,--enable-auto-import,--whole-archive $(BUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive + clean: rm -rf ./build/* make -C include clean diff --git a/C/src/Makefile b/C/src/Makefile index 2390095..a2e8de7 100644 --- a/C/src/Makefile +++ b/C/src/Makefile @@ -7,15 +7,15 @@ CBUILD_DIR = ../build AST_SRC=$(wildcard $(AST_DIR)/*.toml) C_SRC = codata_constants_2010.c codata_constants_2014.c codata_constants_2018.c codata_constants_2022.c codata_version.c C_OBJ=$(patsubst %.c, $(CBUILD_DIR)/%.o, $(C_SRC)) -DLIB=$(CBUILD_DIR)/$(LIBNAME).a + .PHONY: clean -all: sources build shared +all: sources build sources: $(C_SRC) -build: $(C_OBJ) $(DLIB) +build: $(C_OBJ) codata_constants_2010.c: $(AST_DIR)/codata_2010.toml $(PY) $(GEN) $< $@ @@ -32,19 +32,6 @@ codata_constants_2022.c: $(AST_DIR)/codata_2022.toml $(CBUILD_DIR)/%.o: %.c gcc -c -I../include $(CFLAGS_RELEASE) $(FPM_CFLAGS) $< -o $@ -$(CBUILD_DIR)/$(LIBNAME).a: $(C_OBJ) - ar -crs $@ $^ - -shared: build shared_$(PLATFORM) - -shared_linux: - $(CC) -shared -o $(CBUILD_DIR)/$(LIBNAME).so -Wl,--whole-archive $(CBUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive - -shared_darwin: - $(CC) -dynamiclib -install_name @rpath/$(LIBNAME).dylib $(FPM_LDFLAGS) -o $(CBUILD_DIR)/$(LIBNAME).dylib -Wl,-all_load $(CBUILD_DIR)/$(LIBNAME).a - -shared_windows: - $(CC) -shared $(FPM_LDFLAGS) -o $(CBUILD_DIR)/$(LIBNAME).dll -Wl,--out-implib=$(CBUILD_DIR)/$(LIBNAME).dll.a,--export-all-symbols,--enable-auto-import,--whole-archive $(CBUILD_DIR)/$(LIBNAME).a -Wl,--no-whole-archive clean: rm -rf $(C_SRC) \ No newline at end of file