summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-04-19 15:42:34 -0400
committerTavian Barnes <tavianator@tavianator.com>2022-04-19 15:54:46 -0400
commita41df19413f8e1b45b25fc4bd6a4434ad38be057 (patch)
treee0ab96b916a5796bb41e9318b8d22e75596ff6f5
parent13cd21d9f1b62456f84aa995a9b4e5b203bf657c (diff)
downloadbfs-a41df19413f8e1b45b25fc4bd6a4434ad38be057.tar.xz
Makefile: Move .flags to build/FLAGS
-rw-r--r--.gitignore1
-rw-r--r--Makefile12
-rwxr-xr-xflags.sh13
3 files changed, 14 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 76b7428..faa1ff5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,2 @@
-.flags
/build/
/bfs
diff --git a/Makefile b/Makefile
index a6e7363..acc5cbf 100644
--- a/Makefile
+++ b/Makefile
@@ -235,18 +235,18 @@ $(BIN_GOALS):
build build/tests:
$(MKDIR) $@
-build/%.o: src/%.c .flags | build
+build/%.o: src/%.c build/FLAGS
$(CC) $(ALL_CFLAGS) -c $< -o $@
-build/tests/%.o: tests/%.c .flags | build/tests
+build/tests/%.o: tests/%.c build/FLAGS | build/tests
$(CC) $(ALL_CFLAGS) -c $< -o $@
# Save the full set of flags to rebuild everything when they change
-.flags: FORCE
- @./flags.sh $(CC) : $(ALL_CFLAGS) : $(ALL_LDFLAGS) : $(ALL_LDLIBS)
+build/FLAGS: FORCE | build
+ @./flags.sh $@ $(CC) : $(ALL_CFLAGS) : $(ALL_LDFLAGS) : $(ALL_LDLIBS)
.PHONY: FORCE
-# Make sure that "make release" builds everything, but "make release main.o" doesn't
+# Make sure that "make release" builds everything, but "make release build/main.o" doesn't
$(FLAG_GOALS): $(FLAG_PREREQS)
@:
.PHONY: $(FLAG_GOALS)
@@ -273,7 +273,7 @@ endif
.PHONY: distcheck
clean:
- $(RM) -r bfs .flags build
+ $(RM) -r bfs build
.PHONY: clean
install:
diff --git a/flags.sh b/flags.sh
index 15a3a77..5711a18 100755
--- a/flags.sh
+++ b/flags.sh
@@ -1,11 +1,14 @@
#!/usr/bin/env bash
-set -e
+set -eu
-echo "$@" >.newflags
+OUT="$1"
+shift
-if [ -e .flags ] && cmp -s .flags .newflags; then
- rm .newflags
+echo "$@" >"$OUT.tmp"
+
+if [ -e "$OUT" ] && cmp -s "$OUT" "$OUT.tmp"; then
+ rm "$OUT.tmp"
else
- mv .newflags .flags
+ mv "$OUT.tmp" "$OUT"
fi