]> git.tuebingen.mpg.de Git - osl.git/commitdiff
build: Create dependencies on the fly.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 16 May 2020 11:23:03 +0000 (13:23 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 7 Jun 2020 19:49:42 +0000 (21:49 +0200)
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
Makefile

index 907447f62d75046b0aa40ee12217642297fc1cbd..8a57428668a6d42b262bb1e5c930149fcfeed246 100644 (file)
@@ -1,4 +1,4 @@
-*.[oa]
+*.[oad]
 foo
 bar*
 *lsg.[ch]
index 7ce449390d1eb9ef7bac35857984c4d45722aaa8..c52eaea2477e7fb76b32d5638ddb59b39234f5a5 100644 (file)
--- 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