configure: Generate BUILD_STAMP at configure time
Phil Sutter
reviewerPATCH 1/1 configure: Generate BUILD_STAMP at configure time
Several flaws were identified with the previous approach at generating the build timestamp during compilation:
- Recursive expansion of the BUILD_STAMP make variable caused changing values upon each gcc call
- Partial recompiling could also lead to changing BUILD_STAMP values in objects
While it is possible to work around the above issues using simple expansion and a mandatorily recompiled source file holding the values, generating the stamp at configure time is a much simpler solution and deemed sufficient enough for the purpose.
While at it:
- Respect SOURCE_DATE_EPOCH environment variable to support reproducible builds, suggested by Philipp Bartsch
- Guard the header against multiple inclusion, just in case
--- Makefile.am | 2 -- configure.ac | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 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 +8 -8
@@ -152,20 +152,20 @@ AC_CONFIG_COMMANDS([stable_release], [stable_release=$with_stable_release]) AC_CONFIG_COMMANDS([nftversion.h], [ ( + echo "#ifndef NFTABLES_NFTVERSION_H" + echo "#define NFTABLES_NFTVERSION_H" + echo "" 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 "};" + printf "static char nftbuildstamp[[]] = { " + printf "%.16x" "$(printenv SOURCE_DATE_EPOCH || date '+%s')" | \ + sed -e 's/\(..\)/0x\1, /g' -e 's/, $/ };\n/' + echo "" + echo "#endif /* NFTABLES_NFTVERSION_H */" ) >nftversion.h ]) -# 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_ARG_ENABLE([distcheck], AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),
Signature · 1 line
2.51.0
Quoted 8 lines · Phil Sutter
Several flaws were identified with the previous approach at generating the build timestamp during compilation:
- Recursive expansion of the
BUILD_STAMPmake variable caused changing values upon each gcc call
- Partial recompiling could also lead to changingBUILD_STAMPvalues in objects
Quoted 4 lines
While it is possible to work around the above issues using simple expansion and a mandatorily recompiled source file holding the values, generating the stamp at configure time is a much simpler solution and deemed sufficient enough for the purpose.
Quoted 74 lines · Phil Sutter
Several flaws were identified with the previous approach at generating the build timestamp during compilation:
- Recursive expansion of the
BUILD_STAMPmake variable caused changing values upon each gcc call
- Partial recompiling could also lead to changingBUILD_STAMPvalues in objectsWhile it is possible to work around the above issues using simple expansion and a mandatorily recompiled source file holding the values, generating the stamp at configure time is a much simpler solution and deemed sufficient enough for the purpose.
While at it:
- Respect
SOURCE_DATE_EPOCHenvironment variable to support reproducible builds, suggested by Philipp Bartsch
- Guard the header against multiple inclusion, just in caseFixes 64c07e38f049 ("table: Embed creating nft version into userdata")Reported-by Arnout Engelen <[email protected]>Sugested-by Philipp Bartsch <[email protected]>Cc Jeremy Sowden <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------2 files changed, 8 insertions(+), 10 deletions(-)Makefile.am +0
-2@@ -159,8 +159,6 @@ AM_CFLAGS = \ \ $(GCC_FVISIBILITY_HIDDEN) \ \ - -DMAKE_STAMP=$(MAKE_STAMP) \ - \ $(NULL)
AM_YFLAGS= -d -Wno-yaccconfigure.ac +0
-0@@ -152,20 +152,20 @@ AC_CONFIG_COMMANDS([stable_release], [stable_release=$with_stable_release])AC_CONFIG_COMMANDS([nftversion.h], [
(configure.ac +3
-0+ echo "#ifndef NFTABLES_NFTVERSION_H" + echo "#define NFTABLES_NFTVERSION_H" + echo ""echo "static char nftversion[[]] = {" echo " ${VERSION}," | tr '.' ',' echo " ${STABLE_RELEASE}" echo "};"configure.ac +5
-5- echo "static char nftbuildstamp[[]] = {" - for i in `seq 56 -8 0`; do - echo " ((uint64_t)MAKE_STAMP >> $i) & 0xff," - done - echo "};" + printf "static char nftbuildstamp[[]] = { " + printf "%.16x" "$(printenv SOURCE_DATE_EPOCH || date '+%s')" | \ + sed -e 's/\(..\)/0x\1, /g' -e 's/, $/ };\n/' + echo "" + echo "#endif /* NFTABLES_NFTVERSION_H */") >nftversion.h
])configure.ac +0
-3-# 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)"])
Quoted 2 lines
AC_ARG_ENABLE([distcheck],
AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),
One other thing that I wondered about is why we are generatingnftversion.h like this. How about the attached?
J.
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 +4 -19
@@ -147,25 +147,9 @@ 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 -]) -# 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([STABLE_RELEASE],[$with_stable_release]) +AC_SUBST([NFT_VERSION], [$(echo "${VERSION}" | tr '.' ',')]) +AC_SUBST([MAKE_STAMP], [${SOURCE_DATE_EPOCH:-$(date +%s)}]) AC_ARG_ENABLE([distcheck], AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),
@@ -175,6 +159,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 +21 -0
@@ -0,0 +1,21 @@ +#ifndef NFTVERSION_H_INCLUDED +#define NFTVERSION_H_INCLUDED + +#define MAKE_STAMP @MAKE_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, +}; + +#endif /* !defined(NFTVERSION_H_INCLUDED) */
Phil Sutter
reviewerQuoted 75 lines · Jeremy Sowden
Quoted 74 lines · Phil Sutter
Several flaws were identified with the previous approach at generating the build timestamp during compilation:
- Recursive expansion of the
BUILD_STAMPmake variable caused changing values upon each gcc call
- Partial recompiling could also lead to changingBUILD_STAMPvalues in objectsWhile it is possible to work around the above issues using simple expansion and a mandatorily recompiled source file holding the values, generating the stamp at configure time is a much simpler solution and deemed sufficient enough for the purpose.
While at it:
- Respect
SOURCE_DATE_EPOCHenvironment variable to support reproducible builds, suggested by Philipp Bartsch
- Guard the header against multiple inclusion, just in caseFixes 64c07e38f049 ("table: Embed creating nft version into userdata")Reported-by Arnout Engelen <[email protected]>Sugested-by Philipp Bartsch <[email protected]>Cc Jeremy Sowden <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------2 files changed, 8 insertions(+), 10 deletions(-)Makefile.am +0
-2@@ -159,8 +159,6 @@ AM_CFLAGS = \ \ $(GCC_FVISIBILITY_HIDDEN) \ \ - -DMAKE_STAMP=$(MAKE_STAMP) \ - \ $(NULL)
AM_YFLAGS= -d -Wno-yaccconfigure.ac +0
-0@@ -152,20 +152,20 @@ AC_CONFIG_COMMANDS([stable_release], [stable_release=$with_stable_release])AC_CONFIG_COMMANDS([nftversion.h], [
(configure.ac +3
-0+ echo "#ifndef NFTABLES_NFTVERSION_H" + echo "#define NFTABLES_NFTVERSION_H" + echo ""echo "static char nftversion[[]] = {" echo " ${VERSION}," | tr '.' ',' echo " ${STABLE_RELEASE}" echo "};"configure.ac +5
-5- echo "static char nftbuildstamp[[]] = {" - for i in `seq 56 -8 0`; do - echo " ((uint64_t)MAKE_STAMP >> $i) & 0xff," - done - echo "};" + printf "static char nftbuildstamp[[]] = { " + printf "%.16x" "$(printenv SOURCE_DATE_EPOCH || date '+%s')" | \ + sed -e 's/\(..\)/0x\1, /g' -e 's/, $/ };\n/' + echo "" + echo "#endif /* NFTABLES_NFTVERSION_H */") >nftversion.h
])configure.ac +0
-3-# 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)"])
Quoted 5 lines
Quoted 2 lines
AC_ARG_ENABLE([distcheck],
AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),One other thing that I wondered about is why we are generating
nftversion.hlike this. How about the attached?
Oh, much simpler. You wonder why I apparently reimplemented parts of autotools? The obvious answer is incompetence! ;)
Will you formally submit a patch?
Thanks, Phil
Quoted 76 lines · Phil Sutter
Quoted 75 lines · Jeremy Sowden
Quoted 74 lines · Phil Sutter
Several flaws were identified with the previous approach at generating the build timestamp during compilation:
- Recursive expansion of the
BUILD_STAMPmake variable caused changing values upon each gcc call
- Partial recompiling could also lead to changingBUILD_STAMPvalues in objectsWhile it is possible to work around the above issues using simple expansion and a mandatorily recompiled source file holding the values, generating the stamp at configure time is a much simpler solution and deemed sufficient enough for the purpose.
While at it:
- Respect
SOURCE_DATE_EPOCHenvironment variable to support reproducible builds, suggested by Philipp Bartsch
- Guard the header against multiple inclusion, just in caseFixes 64c07e38f049 ("table: Embed creating nft version into userdata")Reported-by Arnout Engelen <[email protected]>Sugested-by Philipp Bartsch <[email protected]>Cc Jeremy Sowden <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------2 files changed, 8 insertions(+), 10 deletions(-)Makefile.am +0
-2@@ -159,8 +159,6 @@ AM_CFLAGS = \ \ $(GCC_FVISIBILITY_HIDDEN) \ \ - -DMAKE_STAMP=$(MAKE_STAMP) \ - \ $(NULL)
AM_YFLAGS= -d -Wno-yaccconfigure.ac +0
-0@@ -152,20 +152,20 @@ AC_CONFIG_COMMANDS([stable_release], [stable_release=$with_stable_release])AC_CONFIG_COMMANDS([nftversion.h], [
(configure.ac +3
-0+ echo "#ifndef NFTABLES_NFTVERSION_H" + echo "#define NFTABLES_NFTVERSION_H" + echo ""echo "static char nftversion[[]] = {" echo " ${VERSION}," | tr '.' ',' echo " ${STABLE_RELEASE}" echo "};"configure.ac +5
-5- echo "static char nftbuildstamp[[]] = {" - for i in `seq 56 -8 0`; do - echo " ((uint64_t)MAKE_STAMP >> $i) & 0xff," - done - echo "};" + printf "static char nftbuildstamp[[]] = { " + printf "%.16x" "$(printenv SOURCE_DATE_EPOCH || date '+%s')" | \ + sed -e 's/\(..\)/0x\1, /g' -e 's/, $/ };\n/' + echo "" + echo "#endif /* NFTABLES_NFTVERSION_H */") >nftversion.h
])configure.ac +0
-3-# 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)"])
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
AC_ARG_ENABLE([distcheck],
AS_HELP_STRING([--enable-distcheck], [Build for distcheck]),One other thing that I wondered about is why we are generating
nftversion.hlike this. How about the attached?Oh, much simpler. You wonder why I apparently reimplemented parts of autotools? The obvious answer is incompetence! ;)
:)
Quoted 1 line
Will you formally submit a patch?
Sure.
J.