Skip to content

Commit

Permalink
Refractor and simplify Makefile in C code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MilanSkocic committed Nov 21, 2024
1 parent 8d52323 commit b1aab13
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
25 changes: 20 additions & 5 deletions C/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
C_SRC=$(wildcard src/*.c)
C_OBJ=$(patsubst src/%.c, $(BUILD_DIR)/%.o, $(C_SRC))
C_OBJ=$(patsubst src/%.c, build/%.o, $(C_SRC))

SLIB=$(BUILD_DIR)/$(LIBNAME).a

.PHONY: headers sources build static shared clean
.PHONY: headers sources build static shared clean ostype

all: headers sources build static shared
all: build static shared


# ---------------------------------------------------------------------
# SOURCES
headers:
make -C include

sources: headers
make -C src sources
# ---------------------------------------------------------------------

build: headers sources

# ---------------------------------------------------------------------
# COMPILATION
build: $(C_OBJ)
mkdir -p $(BUILD_DIR)
make -C src

example: sources headers build
make -C example

build/%.o: src/%.c
gcc -c -I./include $(CFLAGS_RELEASE) $(FPM_CFLAGS) $< -o $@
# ---------------------------------------------------------------------


# ---------------------------------------------------------------------
# LINKING - STATIC and DYNAMIC LIBS
static: build
ar -crs $(SLIB) $(C_OBJ)

Expand All @@ -34,6 +46,9 @@ shared_darwin:

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/*
Expand Down
4 changes: 0 additions & 4 deletions C/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,5 @@ codata_constants_2018.c: $(AST_DIR)/codata_2018.toml
codata_constants_2022.c: $(AST_DIR)/codata_2022.toml
$(PY) $(GEN) $< $@

$(CBUILD_DIR)/%.o: %.c
gcc -c -I../include $(CFLAGS_RELEASE) $(FPM_CFLAGS) $< -o $@


clean:
rm -rf $(C_SRC)

0 comments on commit b1aab13

Please sign in to comment.