Skip to content

Commit

Permalink
Clean up and improve C Makefiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Nov 21, 2024
1 parent 0f5ef0f commit 8d52323
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
22 changes: 19 additions & 3 deletions C/Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
19 changes: 3 additions & 16 deletions C/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) $< $@
Expand All @@ -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)

0 comments on commit 8d52323

Please sign in to comment.