summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile13
-rwxr-xr-xsrc/depend.sh14
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
9CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 $$(pkg-config --cflags libsodium) 9CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 $$(pkg-config --cflags libsodium)
10LDLIBS += $$(pkg-config --libs-only-l libsodium) 10LDLIBS += $$(pkg-config --libs-only-l libsodium)
11LDFLAGS += $$(pkg-config --libs-only-L libsodium) 11LDFLAGS += $$(pkg-config --libs-only-L libsodium)
12DEPFLAGS = -MT $@ -MMD -MP -MF $*.d
12 13
13SOURCES := $(wildcard *.c) 14SOURCES := $(wildcard *.c)
14OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) 15OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
15DEPS := $(patsubst %.c,%.d,$(SOURCES)) 16DEPS := $(patsubst %.c,%.d,$(SOURCES))
16 17
18COMPILE.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))
21all: main 24all: main
22main: $(OBJECTS) 25main: $(OBJECTS)
23 26
24$(OBJECTS): %.o: %.d 27%.o: %.c %.d
25include $(DEPS) # Make sure the dependencies are actually included 28 $(COMPILE.c) $<
26%.d: %.c 29
27 ./depend.sh $$(dirname $*) $(CFLAGS) $*.c > $@ 30$(DEPS):
31include $(wildcard $(DEPS))
32# Adopted from https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
28 33
29c clean: 34c 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
2DIR="$1"
3shift 1
4case "$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 ;;
11esac
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