From d9a840ff11d680e3b8801228e359b3a6d7e06182 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 16 May 2020 13:23:03 +0200 Subject: [PATCH] build: Create dependencies on the fly. This is faster since we run the compiler only once. It is more robust, too, because the build does not break if a random .h file is added to the working directory. Using $(wildcard) is almost always a mistake.. --- .gitignore | 2 +- Makefile | 15 +++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 907447f..8a57428 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -*.[oa] +*.[oad] foo bar* *lsg.[ch] diff --git a/Makefile b/Makefile index 7ce4493..c52eaea 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ mandir := $(PREFIX)/man/man1 objects := osl.o util.o rbtree.o sha1.o fsck_objects := fsck.o osl.o util.o rbtree.o sha1.o oslfsck.lsg.o +deps := $(sort $(objects:.o=.d) $(fsck_objects:.o=.d)) headers := osl.h executables := oslfsck man_pages := oslfsck.1 @@ -115,15 +116,13 @@ endif all: $(realname) $(executables) $(man_pages) shared: $(realname) -Makefile.deps: $(wildcard *.c *.h) - $(CC) -MM -MG *.c > $@ -osl.c fsck.c: - --include Makefile.deps - +ifeq ($(findstring clean, $(MAKECMDGOALS)),) +-include $(deps) +endif %.o: %.c Makefile errtab.h - $(CC) -c $(CPPFLAGS) $(CFLAGS) $(LIBCFLAGS) $< + $(CC) $(CPPFLAGS) -c -MMD -MF $(*F).d -MT $@ $(CFLAGS) $(LIBCFLAGS) $< +fsck.o: oslfsck.lsg.h oslfsck: $(fsck_objects) $(CC) -o $@ $(fsck_objects) -llopsub @@ -164,7 +163,7 @@ osl.h: osl.h.in osl_errors.h Makefile echo '#endif /* _OSL_H */' >> $@ clean: rm -f *.o $(realname) osl.h osl_errors.h errtab.h \ - oslfsck *.a *.ga *.sym *.lsg.* + oslfsck *.a *.ga *.sym *.lsg.* *.d distclean: clean rm -f web/index.html web/oslfsck.1.html web/osl.png -- 2.39.5