From: Andre Noll Date: Sat, 16 May 2020 11:23:03 +0000 (+0200) Subject: build: Create dependencies on the fly. X-Git-Tag: v0.2.0~8^2~8 X-Git-Url: http://git.tuebingen.mpg.de/versions/paraslash-0.3.1.tar.bz2.asc?a=commitdiff_plain;h=d9a840ff11d680e3b8801228e359b3a6d7e06182;p=osl.git 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.. --- 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