Skip to contentSkip to conversation

configure: Generate BUILD_STAMP at configure time

PATCH In review Phil Sutter 3 participants 5 messages Jan 28

Subsystems (2)
lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 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

Fixes 64c07e38f049 ("table: Embed creating nft version into userdata")
Cc Jeremy Sowden <[email protected]>
---
 Makefile.am  |  2 --
 configure.ac | 16 ++++++++--------
 2 files changed, 8 insertions(+), 10 deletions(-)
Makefile.am +0 -2
index 5c7c197f43ca7..c60c2e63d5aff 100644
@@ -159,8 +159,6 @@ AM_CFLAGS = \
 	\
 	$(GCC_FVISIBILITY_HIDDEN) \
 	\
-	-DMAKE_STAMP=$(MAKE_STAMP) \
-	\
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
configure.ac +8 -8
index dd172e88ca581..ff1d86213eb80 100644
@@ -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
maintainer Acked-by on v1 1/1
#1 lore raw
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_STAMP make variable caused changing values upon each gcc call
- Partial recompiling could also lead to changing BUILD_STAMP values 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.

#2 lore raw
In reply to Phil Sutter
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_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

Fixes 64c07e38f049 ("table: Embed creating nft version into userdata")
Cc Jeremy Sowden <[email protected]>

---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------

2 files changed, 8 insertions(+), 10 deletions(-)
Makefile.am +0 -2
index 5c7c197f43ca7..c60c2e63d5aff 100644
@@ -159,8 +159,6 @@ AM_CFLAGS = \
 	\
 	$(GCC_FVISIBILITY_HIDDEN) \
 	\
-	-DMAKE_STAMP=$(MAKE_STAMP) \
-	\
 	$(NULL)
 

AM_YFLAGS = -d -Wno-yacc

configure.ac +0 -0
index dd172e88ca581..ff1d86213eb80 100644
@@ -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 generating
nftversion.h like this. How about the attached?

J.

Makefile.am +0 -2
index b134330d5ca2..ceb222578f93 100644
@@ -159,8 +159,6 @@ AM_CFLAGS = \
 	\
 	$(GCC_FVISIBILITY_HIDDEN) \
 	\
-	-DMAKE_STAMP=$(MAKE_STAMP) \
-	\
 	$(NULL)
 
 AM_YFLAGS = -d -Wno-yacc
configure.ac +4 -19
index dd172e88ca58..ba936a42febd 100644
@@ -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
new file mode 100644
index 000000000000..92e8ca1d53cf
@@ -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) */
author reviewer
#3 lore raw
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_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

Fixes 64c07e38f049 ("table: Embed creating nft version into userdata")
Cc Jeremy Sowden <[email protected]>

---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------

2 files changed, 8 insertions(+), 10 deletions(-)
Makefile.am +0 -2
index 5c7c197f43ca7..c60c2e63d5aff 100644
@@ -159,8 +159,6 @@ AM_CFLAGS = \
 	\
 	$(GCC_FVISIBILITY_HIDDEN) \
 	\
-	-DMAKE_STAMP=$(MAKE_STAMP) \
-	\
 	$(NULL)
 

AM_YFLAGS = -d -Wno-yacc

configure.ac +0 -0
index dd172e88ca581..ff1d86213eb80 100644
@@ -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.h like 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

#4 lore raw
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_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

Fixes 64c07e38f049 ("table: Embed creating nft version into userdata")
Cc Jeremy Sowden <[email protected]>

---
Makefile.am | 2 --
configure.ac | 16 ++++++++--------

2 files changed, 8 insertions(+), 10 deletions(-)
Makefile.am +0 -2
index 5c7c197f43ca7..c60c2e63d5aff 100644
@@ -159,8 +159,6 @@ AM_CFLAGS = \
 	\
 	$(GCC_FVISIBILITY_HIDDEN) \
 	\
-	-DMAKE_STAMP=$(MAKE_STAMP) \
-	\
 	$(NULL)
 

AM_YFLAGS = -d -Wno-yacc

configure.ac +0 -0
index dd172e88ca581..ff1d86213eb80 100644
@@ -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.h like 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.