summaryrefslogtreecommitdiffstats
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
parent94f26cec62be7f0d766f80f7376ea5e0040948ae (diff)
downloadbfs-9f1107cf041d44e79f566f41fc117321fb42881f.tar.xz
build: Directly generate version.c
-rw-r--r--Makefile21
-rw-r--r--config/config.mk12
-rw-r--r--config/deps.mk2
-rw-r--r--config/flags.mk2
-rw-r--r--config/pkg.mk2
-rw-r--r--config/prelude.mk4
-rw-r--r--src/main.c1
-rw-r--r--src/version.c6
8 files changed, 22 insertions, 28 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
diff --git a/config/config.mk b/config/config.mk
index 9d64eec..4771a5e 100644
--- a/config/config.mk
+++ b/config/config.mk
@@ -17,7 +17,7 @@ MKS := \
# The main configuration file, which includes the others
${CONFIG}: ${MKS}
${MSG} "[ GEN] ${TGT}"
- @printf '# %s\n' "$@" >$@
+ @printf '# %s\n' "${TGT}" >$@
@printf 'include $${GEN}/%s\n' ${.ALLSRC:${GEN}/%=%} >>$@
${VCAT} ${CONFIG}
.PHONY: ${CONFIG}
@@ -26,7 +26,7 @@ ${CONFIG}: ${MKS}
${GEN}/vars.mk::
@${MKDIR} ${@D}
${MSG} "[ GEN] ${TGT}"
- @printf '# %s\n' "$@" >$@
+ @printf '# %s\n' "${TGT}" >$@
@printf 'PREFIX := %s\n' "$$XPREFIX" >>$@
@printf 'MANDIR := %s\n' "$$XMANDIR" >>$@
@printf 'OS := %s\n' "$${OS:-$$(uname)}" >>$@
@@ -54,8 +54,10 @@ ${GEN}/deps.mk: ${GEN}/flags.mk
${GEN}/objs.mk::
@${MKDIR} ${@D}
${MSG} "[ GEN] ${TGT}"
- @printf '# %s\n' "$@" >$@
- @for obj in ${OBJS:${OBJ}/%.o=%}; do printf '$${OBJ}/%s.o: %s.c\n' "$$obj" "$$obj"; done >>$@
+ @printf '# %s\n' "${TGT}" >$@
+ @for obj in ${OBJS:${OBJ}/%.o=%}; do \
+ printf '$${OBJ}/%s.o: %s.c\n' "$$obj" "$$obj"; \
+ done | sed 's|: gen/|: $${GEN}/|' >>$@
# External dependencies
PKG_MKS := \
@@ -67,7 +69,7 @@ PKG_MKS := \
# Auto-detect dependencies and their build flags
${GEN}/pkgs.mk: ${PKG_MKS}
- @printf '# %s\n' "$@" >$@
+ @printf '# %s\n' "${TGT}" >$@
@printf 'include $${GEN}/%s\n' ${.ALLSRC:${GEN}/%=%} >>$@
@+${MAKE} -sf config/pkgs.mk
.PHONY: ${GEN}/pkgs.mk
diff --git a/config/deps.mk b/config/deps.mk
index ca178de..e963b6e 100644
--- a/config/deps.mk
+++ b/config/deps.mk
@@ -10,7 +10,7 @@ include config/exports.mk
${GEN}/deps.mk::
${MSG} "[ GEN] ${TGT}"
- printf '# %s\n' "$@" >$@
+ printf '# %s\n' "${TGT}" >$@
if config/cc.sh -MD -MP -MF /dev/null config/empty.c; then \
printf 'DEPFLAGS = -MD -MP -MF $${@:.o=.d}\n'; \
fi >>$@ 2>$@.log
diff --git a/config/flags.mk b/config/flags.mk
index c9d7913..48f1a08 100644
--- a/config/flags.mk
+++ b/config/flags.mk
@@ -105,7 +105,7 @@ APPEND = append() { test -z "$$2" || printf '%s += %s\n' "$$1" "$$2" >>$@; }; ap
${GEN}/flags.mk::
${MSG} "[ GEN] ${TGT}"
- printf '# %s\n' "$@" >$@
+ printf '# %s\n' "${TGT}" >$@
${SETVAR} CPPFLAGS "$$BFS_CPPFLAGS"
${APPEND} CPPFLAGS "$$TSAN_CPPFLAGS"
${APPEND} CPPFLAGS "$$LINT_CPPFLAGS"
diff --git a/config/pkg.mk b/config/pkg.mk
index 482ca17..d2d77b0 100644
--- a/config/pkg.mk
+++ b/config/pkg.mk
@@ -12,7 +12,7 @@ include config/exports.mk
SHORT = ${TARGET:${BUILDDIR}/%=%}
default::
- @printf '# %s\n' "${TARGET}" >${TARGET}
+ @printf '# %s\n' "${SHORT}" >${TARGET}
config/pkg.sh ${TARGET:${GEN}/%.mk=%} >>${TARGET} 2>${TARGET}.log
@if [ "${IS_V}" ]; then \
cat ${TARGET}; \
diff --git a/config/prelude.mk b/config/prelude.mk
index 2bcb208..dbc6875 100644
--- a/config/prelude.mk
+++ b/config/prelude.mk
@@ -141,10 +141,10 @@ LIBBFS := \
${OBJ}/src/thread.o \
${OBJ}/src/trie.o \
${OBJ}/src/typo.o \
- ${OBJ}/src/version.o \
${OBJ}/src/xregex.o \
${OBJ}/src/xspawn.o \
- ${OBJ}/src/xtime.o
+ ${OBJ}/src/xtime.o \
+ ${OBJ}/gen/version.o
# Unit test objects
UNIT_OBJS := \
diff --git a/src/main.c b/src/main.c
index b4d65ce..e120f03 100644
--- a/src/main.c
+++ b/src/main.c
@@ -40,7 +40,6 @@
* - thread.h (multi-threading)
* - trie.[ch] (a trie set/map implementation)
* - typo.[ch] (fuzzy matching for typos)
- * - version.c (defines the version number)
* - xregex.[ch] (regular expression support)
* - xspawn.[ch] (spawns processes)
* - xtime.[ch] (date/time handling utilities)
diff --git a/src/version.c b/src/version.c
deleted file mode 100644
index 736f3d5..0000000
--- a/src/version.c
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright © Tavian Barnes <tavianator@tavianator.com>
-// SPDX-License-Identifier: 0BSD
-
-#include "config.h"
-
-const char bfs_version[] = BFS_VERSION;