From d6b847db0d41202104db6e218a0addd794a6097c Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 01:02:57 +0100 Subject: [PATCH] Makefile: speedup dependency generation Dependencies can be generated in parallel which can be much faster. It also puts away the problem that for may fail multiple times in a row and leaving behind a broken intermediate file which would be picked up by successive runs. Signed-off-by: Kai Krakow --- .gitignore | 1 + lib/Makefile | 8 ++++++-- src/Makefile | 43 +++++++++++++++++++++++-------------------- test/Makefile | 10 +++++++--- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/.gitignore b/.gitignore index e00f61d..72e65cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ *.[ao] *.bak *.new +*.dep *.so* Doxyfile README.html diff --git a/lib/Makefile b/lib/Makefile index 6db5122..ae8392f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -24,8 +24,12 @@ libcrucible.so: $(CRUCIBLE_OBJS) include ../makeflags -depends.mk: *.cc - for x in $^; do $(CXX) $(CXXFLAGS) -M -MG -MT "$${x/%.cc/.o}" "$$x"; done > $@.new +.depends/%.dep: %.cc Makefile + @mkdir -p .depends + $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + +depends.mk: $(CRUCIBLE_OBJS:%.o=.depends/%.dep) + cat $^ > $@.new mv -f $@.new $@ .version.cc: Makefile ../makeflags *.cc ../include/crucible/*.h diff --git a/src/Makefile b/src/Makefile index c720c6a..d6ccb25 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,23 +10,6 @@ include ../makeflags LIBS = -lcrucible -lpthread LDFLAGS = -L../lib -depends.mk: Makefile *.cc - for x in *.cc; do $(CXX) $(CXXFLAGS) -M "$$x"; done > depends.mk.new - mv -fv depends.mk.new depends.mk - -bees-version.c: Makefile *.cc *.h - echo "const char *BEES_VERSION = \"$(shell git describe --always --dirty || echo UNKNOWN)\";" > bees-version.new.c - mv -f bees-version.new.c bees-version.c - -include depends.mk - -%.o: %.cc %.h - $(CXX) $(CXXFLAGS) -o "$@" -c "$<" - -../bin/%: %.o - @echo Implicit bin rule "$<" '->' "$@" - $(CXX) $(CXXFLAGS) -o "$@" "$<" $(LDFLAGS) $(LIBS) - BEES_OBJS = \ bees.o \ bees-context.o \ @@ -35,10 +18,30 @@ BEES_OBJS = \ bees-roots.o \ bees-thread.o \ bees-types.o \ - bees-version.o \ -../bin/bees: $(BEES_OBJS) - $(CXX) $(CXXFLAGS) -o "$@" $(BEES_OBJS) $(LDFLAGS) $(LIBS) +bees-version.c: bees.h $(BEES_OBJS:.o=.cc) Makefile + echo "const char *BEES_VERSION = \"$(shell git describe --always --dirty || echo UNKNOWN)\";" > bees-version.new.c + mv -f bees-version.new.c bees-version.c + +.depends/%.dep: %.cc Makefile + @mkdir -p .depends + $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + +depends.mk: $(BEES_OBJS:%.o=.depends/%.dep) + cat $^ > $@.new + mv -f $@.new $@ + +include depends.mk + +%.o: %.cc %.h + $(CXX) $(CXXFLAGS) -o "$@" -c "$<" + +../bin/%: %.o + @echo Implicit bin rule "$<" '->' "$@" + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ $< + +../bin/bees: $(BEES_OBJS) bees-version.o + $(CXX) $(CXXFLAGS) -o "$@" $^ $(LDFLAGS) $(LIBS) clean: -rm -fv bees-version.h diff --git a/test/Makefile b/test/Makefile index 532f617..13e6f21 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,9 +17,13 @@ include ../makeflags LIBS = -lcrucible -lpthread LDFLAGS = -L../lib -Wl,-rpath=$(shell realpath ../lib) -depends.mk: *.cc - for x in *.cc; do $(CXX) $(CXXFLAGS) -M "$$x"; done > depends.mk.new - mv -fv depends.mk.new depends.mk +.depends/%.dep: %.cc + @mkdir -p .depends + $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $< + +depends.mk: $(PROGRAMS:%=.depends/%.dep) + cat $^ > $@.new + mv -f $@.new $@ include depends.mk