summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-04-17 12:32:22 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-04-17 12:32:22 -0400
commit9f1107cf041d44e79f566f41fc117321fb42881f (patch)
tree6dc927bfaf1a2b79fcf259d02a059599dba5447a /Makefile
parent94f26cec62be7f0d766f80f7376ea5e0040948ae (diff)
downloadbfs-9f1107cf041d44e79f566f41fc117321fb42881f.tar.xz
build: Directly generate version.c
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile21
1 files changed, 10 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 52f3aee..1d26d12 100644
--- a/Makefile
+++ b/Makefile
@@ -68,32 +68,31 @@ ${BINS}:
${POSTLINK}
# Get the .c file for a .o file
-CSRC = ${@:${OBJ}/%.o=%.c}
+_CSRC = ${@:${OBJ}/%.o=%.c}
+CSRC = ${_CSRC:gen/%=${GEN}/%}
# Depend on ${CONFIG} to make sure `make config` runs first, and to rebuild when
# the configuration changes
${OBJS}: ${CONFIG}
@${MKDIR} ${@D}
- ${MSG} "[ CC ] ${CSRC}" ${CC} ${ALL_CFLAGS} -c ${CSRC} -o $@
+ ${MSG} "[ CC ] ${_CSRC}" ${CC} ${ALL_CFLAGS} -c ${CSRC} -o $@
-# Save the version number to this file, but only update VERSION if it changes
-${GEN}/NEWVERSION::
+# Save the version number to this file, but only update version.c if it changes
+${GEN}/version.c.new::
@${MKDIR} ${@D}
+ @printf 'const char bfs_version[] = "' >$@
@if [ "$$VERSION" ]; then \
- printf '%s\n' "$$VERSION"; \
+ printf '%s' "$$VERSION"; \
elif test -d .git && command -v git >/dev/null 2>&1; then \
git describe --always --dirty; \
else \
echo "3.1.3"; \
- fi >$@
+ fi | tr -d '\n' >>$@
+ @printf '";\n' >>$@
-${GEN}/VERSION: ${GEN}/NEWVERSION
+${GEN}/version.c: ${GEN}/version.c.new
@test -e $@ && cmp -s $@ ${.ALLSRC} && rm ${.ALLSRC} || mv ${.ALLSRC} $@
-# Rebuild version.c whenever the version number changes
-${OBJ}/src/version.o: ${GEN}/VERSION
-${OBJ}/src/version.o: CPPFLAGS := ${CPPFLAGS} -DBFS_VERSION='"$$(cat ${GEN}/VERSION)"'
-
## Test phase (`make check`)
# Unit test binaries