From c8787fecd2eb18a1d27fd1a594994450ab84b476 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:00:46 +0100 Subject: [PATCH 01/10] Makefile: depends.mk is not an optional include We really need depends.mk in the following Makefile reorganization. Signed-off-by: Kai Krakow --- lib/Makefile | 2 +- src/Makefile | 2 +- test/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 9ca53af..8ee4b7e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -29,7 +29,7 @@ depends.mk: *.cc echo "namespace crucible { const char *VERSION = \"$(TAG)\"; }" > .version.new.cc mv -f .version.new.cc .version.cc --include depends.mk +include depends.mk %.o: %.cc ../include/crucible/%.h $(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< diff --git a/src/Makefile b/src/Makefile index 3a69c9a..c720c6a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,7 +18,7 @@ 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 +include depends.mk %.o: %.cc %.h $(CXX) $(CXXFLAGS) -o "$@" -c "$<" diff --git a/test/Makefile b/test/Makefile index c0091e1..532f617 100644 --- a/test/Makefile +++ b/test/Makefile @@ -21,7 +21,7 @@ depends.mk: *.cc for x in *.cc; do $(CXX) $(CXXFLAGS) -M "$$x"; done > depends.mk.new mv -fv depends.mk.new depends.mk --include depends.mk +include depends.mk %.o: %.cc %.h ../makeflags -echo "Implicit rule %.o: %.cc" >&2 From 4789445d7b14cb8f6655c84ad5de671d2692d399 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:03:05 +0100 Subject: [PATCH 02/10] Makefile: .o already depends on its .h file We can remove the explicit depend on the .h file because that is covered by depends.mk. Let's instead depend on makeflags which makes more sense. Signed-off-by: Kai Krakow --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile b/lib/Makefile index 8ee4b7e..aedcdc9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -31,7 +31,7 @@ depends.mk: *.cc include depends.mk -%.o: %.cc ../include/crucible/%.h +%.o: %.cc ../makeflags $(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< libcrucible.so: $(OBJS) Makefile From 4cfd5b43dab83d5e99b0ce50a69c4d60cd0be388 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:06:06 +0100 Subject: [PATCH 03/10] Makefile: generalize .so target We can generalize the .so target by moving its depends into rules without build instructions. Signed-off-by: Kai Krakow --- lib/Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index aedcdc9..9ac78bc 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,6 +1,7 @@ TAG := $(shell git describe --always --dirty || echo UNKNOWN) default: libcrucible.so +%.so: Makefile OBJS = \ chatter.o \ @@ -19,6 +20,8 @@ OBJS = \ uuid.o \ .version.o \ +libcrucible.so: $(OBJS) + include ../makeflags depends.mk: *.cc @@ -34,5 +37,5 @@ include depends.mk %.o: %.cc ../makeflags $(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< -libcrucible.so: $(OBJS) Makefile - $(CXX) $(LDFLAGS) -fPIC -o $@ $(OBJS) -shared -Wl,-soname,$@ -luuid +%.so: + $(CXX) $(LDFLAGS) -fPIC -o $@ $^ -shared -Wl,-soname,$@ -luuid From bc1b67fde1c9313902dcd7e65eea509f4c35da78 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:07:48 +0100 Subject: [PATCH 04/10] Makefile: rename OBJS to CRUCIBLE_OBJS This paves the way for building different .so libs. Signed-off-by: Kai Krakow --- lib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 9ac78bc..e466ada 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -3,7 +3,7 @@ TAG := $(shell git describe --always --dirty || echo UNKNOWN) default: libcrucible.so %.so: Makefile -OBJS = \ +CRUCIBLE_OBJS = \ chatter.o \ cleanup.o \ crc64.o \ @@ -20,7 +20,7 @@ OBJS = \ uuid.o \ .version.o \ -libcrucible.so: $(OBJS) +libcrucible.so: $(CRUCIBLE_OBJS) include ../makeflags From fdf434e8ebdd31725cea7c0569371aad652d324f Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:12:24 +0100 Subject: [PATCH 05/10] Makefile: fix dependency generation Let's generalize the depends.mk target so we can easily move files around later. While doing it, let's also fix the "gcc -M" call to use explicit target names and not clobber it with preprocessor output. Signed-off-by: Kai Krakow --- lib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index e466ada..227dc6d 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,8 +25,8 @@ libcrucible.so: $(CRUCIBLE_OBJS) include ../makeflags depends.mk: *.cc - for x in *.cc; do $(CXX) $(CXXFLAGS) -M "$$x"; done > depends.mk.new - mv -fv depends.mk.new depends.mk + for x in $^; do $(CXX) $(CXXFLAGS) -M -MG -MT "$${x/%.cc/.o}" "$$x"; done > $@.new + mv -fv $@.new $@ .version.cc: Makefile ../makeflags *.cc ../include/crucible/*.h echo "namespace crucible { const char *VERSION = \"$(TAG)\"; }" > .version.new.cc From 27b12821eed1ae9edc5cbcf7acfd7f5f6a0d8f55 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:13:37 +0100 Subject: [PATCH 06/10] Makefile: Generalize the .version.cc target This enables us to move the file around later. Signed-off-by: Kai Krakow --- lib/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 227dc6d..ae2f4c9 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -29,8 +29,8 @@ depends.mk: *.cc mv -fv $@.new $@ .version.cc: Makefile ../makeflags *.cc ../include/crucible/*.h - echo "namespace crucible { const char *VERSION = \"$(TAG)\"; }" > .version.new.cc - mv -f .version.new.cc .version.cc + echo "namespace crucible { const char *VERSION = \"$(TAG)\"; }" > $@.new + mv -f $@.new $@ include depends.mk From b8f933d360b977b38bfd04533d2e7d5f9644d007 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 00:32:22 +0100 Subject: [PATCH 07/10] Makefile: do not be verbose about mv A small left-over from me fixing the same problem as Zygo did in his merged branch. Signed-off-by: Kai Krakow --- lib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Makefile b/lib/Makefile index ae2f4c9..6db5122 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -26,7 +26,7 @@ include ../makeflags depends.mk: *.cc for x in $^; do $(CXX) $(CXXFLAGS) -M -MG -MT "$${x/%.cc/.o}" "$$x"; done > $@.new - mv -fv $@.new $@ + mv -f $@.new $@ .version.cc: Makefile ../makeflags *.cc ../include/crucible/*.h echo "namespace crucible { const char *VERSION = \"$(TAG)\"; }" > $@.new From d6b847db0d41202104db6e218a0addd794a6097c Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Tue, 16 Jan 2018 01:02:57 +0100 Subject: [PATCH 08/10] 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 From 8a5f790a03098597e17ffe60b72587f5a07c99d4 Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Thu, 18 Jan 2018 21:59:22 +0100 Subject: [PATCH 09/10] Makefile: Some cleanups Reorder and reformat some arguments so it looks more streamlined during the build process. Signed-off-by: Kai Krakow --- Makefile | 2 +- lib/Makefile | 4 ++-- src/Makefile | 9 ++++----- test/Makefile | 10 +++++----- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index ea2a2da..9931a3e 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ test: lib src $(MAKE) -C test scripts/%: scripts/%.in - sed -e's#@LIBEXEC_PREFIX@#$(LIBEXEC_PREFIX)#' -e's#@PREFIX@#$(PREFIX)#' "$<" >"$@" + sed -e's#@LIBEXEC_PREFIX@#$(LIBEXEC_PREFIX)#' -e's#@PREFIX@#$(PREFIX)#' $< >$@ scripts: scripts/beesd scripts/beesd@.service diff --git a/lib/Makefile b/lib/Makefile index ae8392f..21460f7 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ CRUCIBLE_OBJS = \ uuid.o \ .version.o \ -libcrucible.so: $(CRUCIBLE_OBJS) +libcrucible.so: $(CRUCIBLE_OBJS) -luuid include ../makeflags @@ -42,4 +42,4 @@ include depends.mk $(CXX) $(CXXFLAGS) -fPIC -o $@ -c $< %.so: - $(CXX) $(LDFLAGS) -fPIC -o $@ $^ -shared -Wl,-soname,$@ -luuid + $(CXX) $(LDFLAGS) -fPIC -shared -Wl,-soname,$@ -o $@ $^ diff --git a/src/Makefile b/src/Makefile index d6ccb25..058e921 100644 --- a/src/Makefile +++ b/src/Makefile @@ -34,15 +34,14 @@ depends.mk: $(BEES_OBJS:%.o=.depends/%.dep) include depends.mk %.o: %.cc %.h - $(CXX) $(CXXFLAGS) -o "$@" -c "$<" + $(CXX) $(CXXFLAGS) -o $@ -c $< ../bin/%: %.o @echo Implicit bin rule "$<" '->' "$@" - $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ $< + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $< $(LIBS) ../bin/bees: $(BEES_OBJS) bees-version.o - $(CXX) $(CXXFLAGS) -o "$@" $^ $(LDFLAGS) $(LIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) clean: - -rm -fv bees-version.h - -rm -fv *.o bees-version.c + rm -fv *.o bees-version.c diff --git a/test/Makefile b/test/Makefile index 13e6f21..533c6c8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -28,12 +28,12 @@ depends.mk: $(PROGRAMS:%=.depends/%.dep) include depends.mk %.o: %.cc %.h ../makeflags - -echo "Implicit rule %.o: %.cc" >&2 - $(CXX) $(CXXFLAGS) -o "$@" -c "$<" + @echo "Implicit rule %.o: %.cc" + $(CXX) $(CXXFLAGS) -o $@ -c $< %: %.o ../makeflags - -echo "Implicit rule %: %.o" >&2 - $(CXX) $(CXXFLAGS) -o "$@" "$<" $(LDFLAGS) $(LIBS) + @echo "Implicit rule %: %.o" + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ $< clean: - -rm -fv *.o + rm -fv *.o From 826b27fde2b3d58e8bbd17c741dea51c4d4abd3a Mon Sep 17 00:00:00 2001 From: Kai Krakow Date: Thu, 18 Jan 2018 22:25:32 +0100 Subject: [PATCH 10/10] Makefile: Fix some dependencies Some deps are already referenced by depends.mk, some where actually missing. Signed-off-by: Kai Krakow --- src/Makefile | 2 +- test/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile b/src/Makefile index 058e921..a820b6a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ PROGRAMS = \ ../bin/fiemap \ ../bin/fiewalk \ -all: $(PROGRAMS) depends.mk +all: $(PROGRAMS) include ../makeflags diff --git a/test/Makefile b/test/Makefile index 533c6c8..e1ea18b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -17,7 +17,7 @@ include ../makeflags LIBS = -lcrucible -lpthread LDFLAGS = -L../lib -Wl,-rpath=$(shell realpath ../lib) -.depends/%.dep: %.cc +.depends/%.dep: %.cc tests.h Makefile @mkdir -p .depends $(CXX) $(CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $<