summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2020-10-28 10:01:30 -0400
committerTavian Barnes <tavianator@tavianator.com>2020-12-10 15:37:15 -0500
commit986a206965da3f5bf6fd11d3285b5e19b6e066d1 (patch)
tree031c2521994218ebd2f9a2b52e7b37fdfba4f320
parent5920a1b5e19e529ab3a3972348a6d53bcd90acfc (diff)
downloadbfs-986a206965da3f5bf6fd11d3285b5e19b6e066d1.tar.xz
Makefile: Rebuild whenever the build flags change
This removes the need to do make clean before rebuilding with a new build type.
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--README.md1
-rwxr-xr-xflags.sh11
4 files changed, 17 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 3356bfa..1424907 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.flags
*.o
*.d
*.gcda
diff --git a/Makefile b/Makefile
index 3dd263f..77fad91 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,10 @@ ALL_CFLAGS = $(ALL_CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(DEPFLAGS)
ALL_LDFLAGS = $(ALL_CFLAGS) $(LOCAL_LDFLAGS) $(LDFLAGS)
ALL_LDLIBS = $(LOCAL_LDLIBS) $(LDLIBS)
+# Save the full set of flags to rebuild everything when they change
+ALL_FLAGS := $(CC) : $(ALL_CFLAGS) : $(ALL_LDFLAGS) : $(ALL_LDLIBS)
+$(shell ./flags.sh $(ALL_FLAGS))
+
default: bfs
all: bfs tests/mksock tests/trie tests/xtimegm
@@ -154,7 +158,7 @@ tests/trie: trie.o tests/trie.o
tests/xtimegm: time.o tests/xtimegm.o
$(CC) $(ALL_LDFLAGS) $^ -o $@
-%.o: %.c
+%.o: %.c .flags
$(CC) $(ALL_CFLAGS) -c $< -o $@
check: check-trie check-xtimegm check-bfs check-dfs check-ids check-eds
diff --git a/README.md b/README.md
index bf38169..c33b02c 100644
--- a/README.md
+++ b/README.md
@@ -145,7 +145,6 @@ You can test it out:
If you're interested in speed, you may want to build the release version instead:
- $ make clean
$ make release
Finally, if you want to install it globally, run
diff --git a/flags.sh b/flags.sh
new file mode 100755
index 0000000..8180eb4
--- /dev/null
+++ b/flags.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+set -e
+
+echo "$@" >.newflags
+
+if [ -e .flags ] && cmp -s .flags .newflags; then
+ rm .newflags
+else
+ mv .newflags .flags
+fi