git » libjio » commit 17409b8

Rebuild when the build flags have changed

author Alberto Bertogli
2009-07-26 14:52:05 UTC
committer Alberto Bertogli
2009-07-26 14:52:05 UTC
parent a41528419a2944cee9393bf023f2fe073d126dfb

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 +1 -0
libjio/Makefile +17 -6

diff --git a/.gitignore b/.gitignore
index 09f00d4..fbb6f00 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,4 +15,5 @@ tests/performance/random
 *.pyo
 libjio/doxygen/doc.internal
 libjio/doxygen/doc.public
+libjio/build-flags
 
diff --git a/libjio/Makefile b/libjio/Makefile
index c78e4a8..be15dab 100644
--- a/libjio/Makefile
+++ b/libjio/Makefile
@@ -61,23 +61,23 @@ default: all
 
 all: libjio.so libjio.a libjio.pc jiofsck
 
-libjio.so: $(OBJS)
+libjio.so: build-flags $(OBJS)
 	$(NICE_CC) -shared $(ALL_LDFLAGS) \
 		-Wl,-soname,libjio.so.$(LIB_SO_VER) \
 		$(LIBS) $(OBJS) -o libjio.so.$(LIB_VER)
 	ln -fs libjio.so.$(LIB_VER) libjio.so
 
-libjio.a: $(OBJS)
+libjio.a: build-flags $(OBJS)
 	$(NICE_AR) cr libjio.a $(OBJS)
 
-libjio.pc: libjio.skel.pc
+libjio.pc: build-flags libjio.skel.pc
 	@echo "generating libjio.pc"
 	@cat libjio.skel.pc | \
 		sed 's@++PREFIX++@$(DESTDIR)@g' | \
 		sed 's@++CFLAGS++@$(MANDATORY_CFLAGS)@g' \
 		> libjio.pc
 
-jiofsck: jiofsck.o libjio.a
+jiofsck: build-flags jiofsck.o libjio.a
 	$(NICE_CC) $(ALL_LDFLAGS) jiofsck.o libjio.a $(LIBS) -o jiofsck
 
 install: all
@@ -98,6 +98,17 @@ install: all
 	@echo "Please run ldconfig to update your library cache"
 	@echo
 
+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 $@
 
@@ -107,9 +118,9 @@ doxygen:
 clean:
 	rm -f libjio.a libjio.so libjio.so.$(LIB_VER) libjio.pc
 	rm -f $(OBJS) jiofsck.o jiofsck
-	rm -f *.bb *.bbg *.da *.gcov *.gcno *.gcda gmon.out
+	rm -f *.bb *.bbg *.da *.gcov *.gcno *.gcda gmon.out build-flags
 	$(MAKE) -C doxygen $@
 
 
-.PHONY: default all install clean doxygen
+.PHONY: default all install clean doxygen .force-build-flags