From 18811c585d5ff1285446d3eee301e2139dc1a60b Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Thu, 17 Apr 2025 18:53:36 -0500 Subject: Improve makefile slightly --- src/Makefile | 13 +++++++++---- src/depend.sh | 14 -------------- 2 files changed, 9 insertions(+), 18 deletions(-) delete mode 100755 src/depend.sh 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 CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyzer-too-complex -ggdb -g3 -O0 $$(pkg-config --cflags libsodium) LDLIBS += $$(pkg-config --libs-only-l libsodium) LDFLAGS += $$(pkg-config --libs-only-L libsodium) +DEPFLAGS = -MT $@ -MMD -MP -MF $*.d SOURCES := $(wildcard *.c) OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) DEPS := $(patsubst %.c,%.d,$(SOURCES)) +COMPILE.c = $(CC) $(DEPFLAGS) $(CFLAGS) -c + .PHONY: all c clean val .DELETE_ON_ERROR: .ONESHELL: @@ -21,10 +24,12 @@ DEPS := $(patsubst %.c,%.d,$(SOURCES)) all: main main: $(OBJECTS) -$(OBJECTS): %.o: %.d -include $(DEPS) # Make sure the dependencies are actually included -%.d: %.c - ./depend.sh $$(dirname $*) $(CFLAGS) $*.c > $@ +%.o: %.c %.d + $(COMPILE.c) $< + +$(DEPS): +include $(wildcard $(DEPS)) +# Adopted from https://make.mad-scientist.net/papers/advanced-auto-dependency-generation/ c clean: @-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 @@ -#!/usr/bin/env -S bash -DIR="$1" -shift 1 -case "$DIR" in - "" | ".") - gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@\1.d \1.o:@" - ;; - *) - gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@$DIR/\1.d $DIR/\1.o:@" - ;; -esac - -# Shamelessly stolen from Peter Miller's "Recursive Make Considered Harmful" - # https://web.archive.org/web/20250404190928/https://aegis.sourceforge.net/auug97.pdf \ No newline at end of file -- cgit v1.2.3