build: simplify the instantation of nftversion.h
PATCH 1/3 build: simplify the instantation of nftversion.h
Add an nftversion.h.in autoconf input file which configure uses to instantiate nftversion.h in the usual way.
--- configure.ac | 19 +++---------------- nftversion.h.in | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 nftversion.h.in
configure.ac +3 -16
@@ -147,22 +147,8 @@ AM_CONDITIONAL([BUILD_SERVICE], [test "x$unitdir" != x]) AC_ARG_WITH([stable-release], [AS_HELP_STRING([--with-stable-release], [Stable release number])], [], [with_stable_release=0]) -AC_CONFIG_COMMANDS([stable_release], - [STABLE_RELEASE=$stable_release], - [stable_release=$with_stable_release]) -AC_CONFIG_COMMANDS([nftversion.h], [ -( - echo "static char nftversion[[]] = {" - echo " ${VERSION}," | tr '.' ',' - echo " ${STABLE_RELEASE}" - echo "};" - echo "static char nftbuildstamp[[]] = {" - for i in `seq 56 -8 0`; do - echo " ((uint64_t)MAKE_STAMP >> $i) & 0xff," - done - echo "};" -) >nftversion.h -]) +AC_SUBST([STABLE_RELEASE],[$with_stable_release]) +AC_SUBST([NFT_VERSION], [$(echo "${VERSION}" | tr '.' ',')]) # Current date should be fetched exactly once per build, # so have 'make' call date and pass the value to every 'gcc' call AC_SUBST([MAKE_STAMP], ["\$(shell date +%s)"])
@@ -175,6 +161,7 @@ AM_CONDITIONAL([BUILD_DISTCHECK], [test "x$enable_distcheck" = "xyes"]) AC_CONFIG_FILES([ \ Makefile \ libnftables.pc \ + nftversion.h \ ]) AC_OUTPUT
nftversion.h.in new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef NFTABLES_NFTVERSION_H +#define NFTABLES_NFTVERSION_H + +static char nftversion[] = { + @NFT_VERSION@, + @STABLE_RELEASE@ +}; +static char nftbuildstamp[] = { + ((uint64_t)MAKE_STAMP >> 56) & 0xff, + ((uint64_t)MAKE_STAMP >> 48) & 0xff, + ((uint64_t)MAKE_STAMP >> 40) & 0xff, + ((uint64_t)MAKE_STAMP >> 32) & 0xff, + ((uint64_t)MAKE_STAMP >> 24) & 0xff, + ((uint64_t)MAKE_STAMP >> 16) & 0xff, + ((uint64_t)MAKE_STAMP >> 8) & 0xff, + ((uint64_t)MAKE_STAMP >> 0) & 0xff, +}; + +#endif /* !defined(NFTABLES_NFTVERSION_H) */
Signature · 1 line
2.51.0
PATCH 2/3 build: generate build time-stamp once at configure
The existing implementation tries to generate a time-stamp once when make is run. However, it doesn't work and generates one for every compilation. Getting this right portably in automake is not straightforward. Instead, do it when configure is run.
Rename the time-stamp variable since it is no longer generated by make.
--- Makefile.am | 2 -- configure.ac | 4 +--- nftversion.h.in | 18 ++++++++++-------- 3 files changed, 11 insertions(+), 13 deletions(-)
Makefile.am +0 -2
@@ -159,8 +159,6 @@ AM_CFLAGS = \ \ $(GCC_FVISIBILITY_HIDDEN) \ \ - -DMAKE_STAMP=$(MAKE_STAMP) \ - \ $(NULL) AM_YFLAGS = -d -Wno-yacc
configure.ac +1 -3
@@ -149,9 +149,7 @@ AC_ARG_WITH([stable-release], [AS_HELP_STRING([--with-stable-release], [], [with_stable_release=0]) AC_SUBST([STABLE_RELEASE],[$with_stable_release]) AC_SUBST([NFT_VERSION], [$(echo "${VERSION}" | tr '.' ',')]) -# Current date should be fetched exactly once per build, -# so have 'make' call date and pass the value to every 'gcc' call -AC_SUBST([MAKE_STAMP], ["\$(shell date +%s)"]) +AC_SUBST([BUILD_STAMP], [$(date +%s)]) AC_ARG_ENABLE([distcheck], AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),
nftversion.h.in +10 -8
@@ -1,19 +1,21 @@ #ifndef NFTABLES_NFTVERSION_H #define NFTABLES_NFTVERSION_H +#define BUILD_STAMP @BUILD_STAMP@ + static char nftversion[] = { @NFT_VERSION@, @STABLE_RELEASE@ }; static char nftbuildstamp[] = { - ((uint64_t)MAKE_STAMP >> 56) & 0xff, - ((uint64_t)MAKE_STAMP >> 48) & 0xff, - ((uint64_t)MAKE_STAMP >> 40) & 0xff, - ((uint64_t)MAKE_STAMP >> 32) & 0xff, - ((uint64_t)MAKE_STAMP >> 24) & 0xff, - ((uint64_t)MAKE_STAMP >> 16) & 0xff, - ((uint64_t)MAKE_STAMP >> 8) & 0xff, - ((uint64_t)MAKE_STAMP >> 0) & 0xff, + ((uint64_t)BUILD_STAMP >> 56) & 0xff, + ((uint64_t)BUILD_STAMP >> 48) & 0xff, + ((uint64_t)BUILD_STAMP >> 40) & 0xff, + ((uint64_t)BUILD_STAMP >> 32) & 0xff, + ((uint64_t)BUILD_STAMP >> 24) & 0xff, + ((uint64_t)BUILD_STAMP >> 16) & 0xff, + ((uint64_t)BUILD_STAMP >> 8) & 0xff, + ((uint64_t)BUILD_STAMP >> 0) & 0xff, }; #endif /* !defined(NFTABLES_NFTVERSION_H) */
Signature · 1 line
2.51.0
PATCH 3/3 build: support `SOURCE_DATE_EPOCH` for build time-stamp
In reply to Jeremy SowdenIn order to support reproducible builds, set the build time-stamp to the value of the environment variable, SOURCE_DATE_EPOCH, if set, and fall back to calling date, otherwise.
--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
@@ -149,7 +149,7 @@ AC_ARG_WITH([stable-release], [AS_HELP_STRING([--with-stable-release], [], [with_stable_release=0]) AC_SUBST([STABLE_RELEASE],[$with_stable_release]) AC_SUBST([NFT_VERSION], [$(echo "${VERSION}" | tr '.' ',')]) -AC_SUBST([BUILD_STAMP], [$(date +%s)]) +AC_SUBST([BUILD_STAMP], [${SOURCE_DATE_EPOCH:-$(date +%s)}]) AC_ARG_ENABLE([distcheck], AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),
Signature · 1 line
2.51.0
Phil Sutter
reviewerQuoted 4 lines · Jeremy Sowden
Add an nftversion.h.in autoconf input file which configure uses to instantiate
nftversion.hin the usual way.Signed-off-by Jeremy Sowden <[email protected]>
Series applied, thanks!