Skip to contentSkip to conversation

Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

PATCH New Jean-Baptiste Trédez 3 participants 5 messages Dec 6, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

Fix kernel reproducible build if LANG=fr_FR.UTF-8 in host system.

when building linux kernel, scripts/gen_initramfs_list.sh do 'date -d"$KBUILD_BUILD_TIMESTAMP" +%s' In buildroot makefile, KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))" if LANG=fr_FR.UTF-8 in host system, it does not work :
- LANG=C date -d"$(LANG=C date)" : ok
- LANG=C date -d"$(LANG=fr_FR.UTF-8 date)" : error

---
 linux/linux.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux/linux.mk +1 -1
index a63d1f3..554c5f1 100644
@@ -99,7 +99,7 @@ LINUX_MAKE_ENV += \
 	KBUILD_BUILD_VERSION=1 \
 	KBUILD_BUILD_USER=buildroot \
 	KBUILD_BUILD_HOST=buildroot \
-	KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))"
+	KBUILD_BUILD_TIMESTAMP="$(shell LANG=C date -d @$(SOURCE_DATE_EPOCH))"
 endif
 
 # Get the real Linux version, which tells us where kernel modules are
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

Hello,

Quoted 9 lines · Jean-Baptiste Tr?dez

Fix kernel reproducible build if LANG=fr_FR.UTF-8 in host system.

when building linux kernel, scripts/gen_initramfs_list.sh do 'date -d"$KBUILD_BUILD_TIMESTAMP" +%s' In buildroot makefile, KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))" if LANG=fr_FR.UTF-8 in host system, it does not work :
- LANG=C date -d"$(LANG=C date)" : ok
- LANG=C date -d"$(LANG=fr_FR.UTF-8 date)" : error

Indeed, seems like the LANG/LC_ALL variables exported in the main Makefile are not used in the $(shell ...) sub-shells.

However, are you sure it works with LANG=C ? It seems like LC_ALL=C is needed instead:

thomas at skate:/tmp$ LANG=C date
mardi 6 d?cembre 2016, 11:31:52 (UTC+0100)
thomas at skate:/tmp$ LC_ALL=C date
Tue Dec 6 11:31:59 CET 2016

I also tested with the following test makefile:

====

export LC_ALL=C

foo = $(shell LC_ALL=C date)

all:

	date
	echo "$(foo)"

====

And indeed, the "export LC_ALL" is enough for the direct "date" call to work. But for the date call whose output is stored in the "foo" variable, passing again LC_ALL in the sub-shell is necessary.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

Le 06/12/2016 ? 11:33, Thomas Petazzoni a ?crit :

Quoted 15 lines

Hello,

Quoted 9 lines · Jean-Baptiste Tr?dez

Fix kernel reproducible build if LANG=fr_FR.UTF-8 in host system.

when building linux kernel, scripts/gen_initramfs_list.sh do 'date -d"$KBUILD_BUILD_TIMESTAMP" +%s' In buildroot makefile, KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))" if LANG=fr_FR.UTF-8 in host system, it does not work :
- LANG=C date -d"$(LANG=C date)" : ok
- LANG=C date -d"$(LANG=fr_FR.UTF-8 date)" : error

Indeed, seems like the LANG/LC_ALL variables exported in the main Makefile are not used in the $(shell ...) sub-shells.

Quoted 7 lines

However, are you sure it works with LANG=C ? It seems like LC_ALL=C is needed instead:

thomas at skate:/tmp$ LANG=C date
mardi 6 d?cembre 2016, 11:31:52 (UTC+0100)
thomas at skate:/tmp$ LC_ALL=C date
Tue Dec 6 11:31:59 CET 2016

$ date
mardi 6 d?cembre 2016, 11:36:21 (UTC+0100)
$ LANG=C date
Tue Dec  6 11:36:49 CET 2016
$ LC_ALL=C date
Tue Dec  6 11:36:57 CET 2016

It works fine on my machine with LANG=C. I will change to LC_ALL=C.

Quoted 20 lines

I also tested with the following test makefile:

====

export LC_ALL=C

foo = $(shell LC_ALL=C date)

all:

	date
	echo "$(foo)"

====

And indeed, the "export LC_ALL" is enough for the direct "date" call to work. But for the date call whose output is stored in the "foo" variable, passing again LC_ALL in the sub-shell is necessary.

Thomas

#3 lore raw

PATCH 1/1 Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

In reply to Jean-Baptiste Trédez

Hello Jean-Baptiste,

Quoted 7 lines · On Tuesday 06 December 2016 11:10:01 Jean-Baptiste Tr?dez wrote:

Fix kernel reproducible build if LANG=fr_FR.UTF-8 in host system.

when building linux kernel, scripts/gen_initramfs_list.sh do 'date -d"$KBUILD_BUILD_TIMESTAMP" +%s' In buildroot makefile, KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))" if LANG=fr_FR.UTF-8 in host system, it does not work :
- LANG=C date -d"$(LANG=C date)" : ok
- LANG=C date -d"$(LANG=fr_FR.UTF-8 date)" : error

Good catch.

Quoted 9 lines
---
 linux/linux.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux/linux.mk +0 -0
index a63d1f3..554c5f1 100644

linux/linux.mk LINUX_MAKE_ENV += \ · line 102

Quoted 5 lines
linux/linux.mk +1 -1
@@ -99,7 +99,7 @@ LINUX_MAKE_ENV += \
 	KBUILD_BUILD_VERSION=1 \
 	KBUILD_BUILD_USER=buildroot \
 	KBUILD_BUILD_HOST=buildroot \
-	KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))"
+	KBUILD_BUILD_TIMESTAMP="$(shell LANG=C date -d @$(SOURCE_DATE_EPOCH))"

It should also possible to fix problem using backquotes:

  KBUILD_BUILD_TIMESTAMP="`date -d @$(SOURCE_DATE_EPOCH)`"

I find it lighter.

BR,

Signature · 3 lines
J?r?me Pouiller, Sysmic
Embedded Linux specialist
http://www.sysmic.fr
#4 lore raw

PATCH 1/1 Makefile: generate KBUILD_BUILD_TIMESTAMP date whith LANG=C

Hello,

Le 06/12/2016 ? 14:02, J?r?me Pouiller a ?crit :

Quoted 28 lines

Hello Jean-Baptiste,

Quoted 7 lines · On Tuesday 06 December 2016 11:10:01 Jean-Baptiste Tr?dez wrote:

Fix kernel reproducible build if LANG=fr_FR.UTF-8 in host system.

when building linux kernel, scripts/gen_initramfs_list.sh do 'date -d"$KBUILD_BUILD_TIMESTAMP" +%s' In buildroot makefile, KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))" if LANG=fr_FR.UTF-8 in host system, it does not work :
- LANG=C date -d"$(LANG=C date)" : ok
- LANG=C date -d"$(LANG=fr_FR.UTF-8 date)" : error

Good catch.

Quoted 9 lines
---
  linux/linux.mk | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux/linux.mk +0 -0
index a63d1f3..554c5f1 100644

linux/linux.mk LINUX_MAKE_ENV += \ · line 102

Quoted 5 lines
linux/linux.mk +1 -1
@@ -99,7 +99,7 @@ LINUX_MAKE_ENV += \
  	KBUILD_BUILD_VERSION=1 \
  	KBUILD_BUILD_USER=buildroot \
  	KBUILD_BUILD_HOST=buildroot \
-	KBUILD_BUILD_TIMESTAMP="$(shell date -d @$(SOURCE_DATE_EPOCH))"
+	KBUILD_BUILD_TIMESTAMP="$(shell LANG=C date -d @$(SOURCE_DATE_EPOCH))"

It should also possible to fix problem using backquotes:

Quoted 3 lines
   KBUILD_BUILD_TIMESTAMP="`date -d @$(SOURCE_DATE_EPOCH)`"

I find it lighter.

It should work but may require a comment. One may not see the importance of the backquotes and it is hard to track (since the compilation do not fail in case of error only a binary compare on vmlinux will show the issue).

Quoted 4 lines

BR,