From 9f1107cf041d44e79f566f41fc117321fb42881f Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 17 Apr 2024 12:32:22 -0400 Subject: build: Directly generate version.c --- Makefile | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'Makefile') 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 -- cgit v1.2.3