diff options
| author | @syxhe <https://t.me/syxhe> | 2025-04-17 18:53:36 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2025-04-17 18:53:36 -0500 |
| commit | 18811c585d5ff1285446d3eee301e2139dc1a60b (patch) | |
| tree | c121ce7f27909e9a22cdbaedb6e241fa37fd30fe /src | |
| parent | ed4a91bcc1d68c26cd533c4432f93c799b1771c2 (diff) | |
Improve makefile slightly
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 13 | ||||
| -rwxr-xr-x | src/depend.sh | 14 |
2 files changed, 9 insertions, 18 deletions
diff --git a/src/Makefile b/src/Makefile index e32f72b..b045807 100644 --- a/src/Makefile +++ b/src/Makefile | |||
| @@ -9,11 +9,14 @@ SHELL := /usr/bin/env | |||
| 9 | CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 $$(pkg-config --cflags libsodium) | 9 | CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 $$(pkg-config --cflags libsodium) |
| 10 | LDLIBS += $$(pkg-config --libs-only-l libsodium) | 10 | LDLIBS += $$(pkg-config --libs-only-l libsodium) |
| 11 | LDFLAGS += $$(pkg-config --libs-only-L libsodium) | 11 | LDFLAGS += $$(pkg-config --libs-only-L libsodium) |
| 12 | DEPFLAGS = -MT $@ -MMD -MP -MF $*.d | ||
| 12 | 13 | ||
| 13 | SOURCES := $(wildcard *.c) | 14 | SOURCES := $(wildcard *.c) |
| 14 | OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) | 15 | OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) |
| 15 | DEPS := $(patsubst %.c,%.d,$(SOURCES)) | 16 | DEPS := $(patsubst %.c,%.d,$(SOURCES)) |
| 16 | 17 | ||
| 18 | COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) -c | ||
| 19 | |||
| 17 | .PHONY: all c clean val | 20 | .PHONY: all c clean val |
| 18 | .DELETE_ON_ERROR: | 21 | .DELETE_ON_ERROR: |
| 19 | .ONESHELL: | 22 | .ONESHELL: |
| @@ -21,10 +24,12 @@ DEPS := $(patsubst %.c,%.d,$(SOURCES)) | |||
| 21 | all: main | 24 | all: main |
| 22 | main: $(OBJECTS) | 25 | main: $(OBJECTS) |
| 23 | 26 | ||
| 24 | $(OBJECTS): %.o: %.d | 27 | %.o: %.c %.d |
| 25 | include $(DEPS) # Make sure the dependencies are actually included | 28 | $(COMPILE.c) $< |
| 26 | %.d: %.c | 29 | |
| 27 | ./depend.sh $$(dirname $*) $(CFLAGS) $*.c > $@ | 30 | $(DEPS): |
| 31 | include $(wildcard $(DEPS)) | ||
| 32 | # Adopted from https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ | ||
| 28 | 33 | ||
| 29 | c clean: | 34 | c clean: |
| 30 | @-rm -rv main $(OBJECTS) $(DEPS) $(wildcard *.test*) $(wildcard *.enc) | 35 | @-rm -rv main $(OBJECTS) $(DEPS) $(wildcard *.test*) $(wildcard *.enc) |
diff --git a/src/depend.sh b/src/depend.sh deleted file mode 100755 index 7b3caa7..0000000 --- a/src/depend.sh +++ /dev/null | |||
| @@ -1,14 +0,0 @@ | |||
| 1 | #!/usr/bin/env -S bash | ||
| 2 | DIR="$1" | ||
| 3 | shift 1 | ||
| 4 | case "$DIR" in | ||
| 5 | "" | ".") | ||
| 6 | gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@\1.d \1.o:@" | ||
| 7 | ;; | ||
| 8 | *) | ||
| 9 | gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@$DIR/\1.d $DIR/\1.o:@" | ||
| 10 | ;; | ||
| 11 | esac | ||
| 12 | |||
| 13 | # Shamelessly stolen from Peter Miller's "Recursive Make Considered Harmful" | ||
| 14 | # https://web.archive.org/web/20250404190928/https://aegis.sourceforge.net/auug97.pdf \ No newline at end of file | ||
