git » libfiu » commit f5f470c

Rebuild when the build flags have changed

author Alberto Bertogli
2009-07-13 17:04:13 UTC
committer Alberto Bertogli
2009-07-13 17:04:13 UTC
parent 86357af6dc2d03c195621b1a49caea9e13c5aec6

Rebuild when the build flags have changed

This patch causes "make" to rebuild the target when the build flags
(either CFLAGS or PREFIX) have changed.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

.gitignore +3 -0
libfiu/Makefile +16 -5
preload/posix/Makefile +14 -3
preload/run/Makefile +15 -4

diff --git a/.gitignore b/.gitignore
index 68ac8d0..1011ae1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,8 +5,10 @@ libfiu/*.o
 libfiu/libfiu.a
 libfiu/libfiu.pc
 libfiu/libfiu.so
+libfiu/build-flags
 preload/posix/*.o
 preload/posix/*.so
+preload/posix/build-flags
 preload/posix/function_list
 preload/posix/modules/*.o
 preload/posix/modules/*.mod.c
@@ -14,4 +16,5 @@ preload/posix/modules/*.mod.fl
 preload/run/*.o
 preload/run/*.so
 preload/run/fiu-run
+preload/run/build-flags
 
diff --git a/libfiu/Makefile b/libfiu/Makefile
index 901fa4b..e312976 100644
--- a/libfiu/Makefile
+++ b/libfiu/Makefile
@@ -32,7 +32,7 @@ default: all
 
 all: libs libfiu.pc
 
-libfiu.pc: libfiu.pc.in
+libfiu.pc: build-flags libfiu.pc.in
 	@echo "generating libfiu.pc"
 	@cat libfiu.pc.in | \
 		sed 's@++PREFIX++@$(PREFIX)@g' \
@@ -40,10 +40,10 @@ libfiu.pc: libfiu.pc.in
 
 libs: libfiu.so libfiu.a
 
-libfiu.so: fiu.h $(OBJS)
+libfiu.so: build-flags fiu.h $(OBJS)
 	$(NICE_CC) $(ALL_CFLAGS) -shared -fPIC $(OBJS) -lpthread -o libfiu.so
 
-libfiu.a: fiu.h $(OBJS)
+libfiu.a: build-flags fiu.h $(OBJS)
 	$(AR) cr libfiu.a $(OBJS)
 
 
@@ -67,14 +67,25 @@ install-man:
 
 install: install-lib install-man
 
+BF = $(ALL_CFLAGS) ~ $(PREFIX)
+build-flags: .force-build-flags
+	@if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \
+		if [ -f build-flags ]; then \
+			echo "build flags changed, rebuilding"; \
+		fi; \
+		echo "$(BF)" > build-flags; \
+	fi
+
+$(OBJS): build-flags
 
 .c.o:
 	$(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
 
 clean:
-	rm -f libfiu.pc $(OBJS) libfiu.so libfiu.a
+	rm -f libfiu.pc $(OBJS) libfiu.so libfiu.a build-flags
 	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
-.PHONY: default all libs install-lib install-man install clean
+.PHONY: default all libs install-lib install-man install clean \
+	.force-build-flags
 
 
diff --git a/preload/posix/Makefile b/preload/posix/Makefile
index 359c997..ce0be4e 100644
--- a/preload/posix/Makefile
+++ b/preload/posix/Makefile
@@ -41,8 +41,19 @@ default: all
 	
 all: fiu_posix_preload.so function_list
 
+BF = $(ALL_CFLAGS) ~ $(PREFIX)
+build-flags: .force-build-flags
+	@if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \
+		if [ -f build-flags ]; then \
+			echo "build flags changed, rebuilding"; \
+		fi; \
+		echo "$(BF)" > build-flags; \
+	fi
+
 $(GEN_OBJS): $(GEN_C)
 
+$(OBJS): build-flags
+
 %.mod.c: %.mod
 	$(NICE_GEN) $< $@ $<.fl
 
@@ -53,7 +64,7 @@ $(GEN_OBJS): $(GEN_C)
 NEED_LIBDL := $(shell ld -o dlcheck.so -shared -ldl 2>/dev/null && echo -ldl; \
 	rm -f dlcheck.so)
 
-fiu_posix_preload.so: $(OBJS)
+fiu_posix_preload.so: build-flags $(OBJS)
 	$(NICE_CC) $(ALL_CFLAGS) -shared -fPIC $(OBJS) -lfiu $(NEED_LIBDL) \
 		-o fiu_posix_preload.so
 
@@ -72,10 +83,10 @@ install: fiu_posix_preload.so
 	$(INSTALL) -m 0755 fiu_posix_preload.so $(PREFIX)/lib
 
 clean:
-	rm -f $(OBJS) $(GEN_OBJS:.o=.c) $(GEN_FL)
+	rm -f $(OBJS) $(GEN_OBJS:.o=.c) $(GEN_FL) build-flags
 	rm -f function_list fiu_posix_preload.so
 	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
-.PHONY: default install clean
+.PHONY: default install clean .force-build-flags
 
 
diff --git a/preload/run/Makefile b/preload/run/Makefile
index 4ccc905..4328548 100644
--- a/preload/run/Makefile
+++ b/preload/run/Makefile
@@ -32,6 +32,17 @@ default: all
 	
 all: fiu_run_preload.so fiu-run
 
+BF = $(ALL_CFLAGS) ~ $(PREFIX)
+build-flags: .force-build-flags
+	@if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \
+		if [ -f build-flags ]; then \
+			echo "build flags changed, rebuilding"; \
+		fi; \
+		echo "$(BF)" > build-flags; \
+	fi
+
+$(OBJS): build-flags
+
 .c.o:
 	$(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
 
@@ -39,11 +50,11 @@ all: fiu_run_preload.so fiu-run
 NEED_LIBDL := $(shell ld -o dlcheck.so -shared -ldl 2>/dev/null && echo -ldl; \
 	rm -f dlcheck.so)
 
-fiu_run_preload.so: $(OBJS)
+fiu_run_preload.so: build-flags $(OBJS)
 	$(NICE_CC) $(ALL_CFLAGS) -shared -fPIC $(OBJS) -lfiu $(NEED_LIBDL) \
 		-o fiu_run_preload.so
 
-fiu-run: fiu-run.in
+fiu-run: build-flags fiu-run.in
 	cat fiu-run.in | sed "s+@@PREFIX@@+$(PREFIX)+g" > fiu-run
 	chmod +x fiu-run
 
@@ -56,9 +67,9 @@ install: fiu_run_preload.so fiu-run
 	$(INSTALL) -m 0644 fiu-run.1 $(PREFIX)/man/man1/
 
 clean:
-	rm -f $(OBJS) fiu_run_preload.so fiu-run
+	rm -f $(OBJS) fiu_run_preload.so fiu-run build-flags
 	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
 
-.PHONY: default install clean
+.PHONY: default install clean .force-build-flags