[klibc] [PATCH] klibc: enable reproducible builds

Maciej Żenczykowski zenczykowski at gmail.com
Mon Oct 25 14:09:16 PDT 2010


From: Maciej Żenczykowski <maze at google.com>

This adds a new setting: KBUILD_REPRODUCIBLE
If it is non-empty, ar and ranlib will be called in such
a way that timestamps do not affect the build output.
This allows one to get perfectly reproducible builds.

Signed-off-by: Maciej Żenczykowski <maze at google.com>
---
 scripts/Kbuild.klibc |   15 ++++++++++-----
 usr/klibc/Kbuild     |    2 +-
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc
index 79d196f..fb399f5 100644
--- a/scripts/Kbuild.klibc
+++ b/scripts/Kbuild.klibc
@@ -93,11 +93,16 @@ KLIBCMINOR        := $(shell cut -d. -f2 $(srctree)/usr/klibc/version)
 KLIBCLD          := $(LD)
 KLIBCCC          := $(CC)
 KLIBCAR          := $(AR)
-KLIBCRANLIB      := $(RANLIB)
+
+# klibc-ar is a macro that invokes KLIBCAR and takes 2 arguments of ar commands.
+# The second will be used for reproducible builds, the first otherwise.
+klibc-ar = $(KLIBCAR) $(if $(KBUILD_REPRODUCIBLE),$(2),$(1))
+
+KLIBCRANLIB      := $(call klibc-ar,s,Ds)
 KLIBCSTRIP       := $(STRIP)
 KLIBCNM          := $(NM)
-KLIBCOBJCOPY	 := $(OBJCOPY)
-KLIBCOBJDUMP	 := $(OBJDUMP)
+KLIBCOBJCOPY     := $(OBJCOPY)
+KLIBCOBJDUMP     := $(OBJDUMP)
 
 # klibc include paths
 KLIBCCPPFLAGS    := -nostdinc -iwithprefix include \
@@ -265,8 +270,8 @@ ifdef lib-target
 quiet_cmd_link_o_target = LD      $@
 # If the list of objects to link is empty, just create an empty lib.a
 cmd_link_o_target = $(if $(strip $(lib-y)),\
-                    rm -f $@; $(KLIBCAR) cru $@ $(filter $(lib-y), $^),\
-                    rm -f $@; $(KLIBCAR) crs $@)
+                    rm -f $@; $(call klibc-ar,cru,Dcr) $@ $(filter $(lib-y), $^),\
+                    rm -f $@; $(call klibc-ar,crs,Dcrs) $@)
 
 $(lib-target): $(lib-y) FORCE
 	$(call if_changed,link_o_target)
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index ab5212b..af40367 100644
--- a/usr/klibc/Kbuild
+++ b/usr/klibc/Kbuild
@@ -109,7 +109,7 @@ klib-o-files = $(shell cat $(obj)/klib.list \
 targets += libc.a __static_init.o
 quiet_cmd_libc = KLIBCAR $@
       cmd_libc = rm -f $@;						\
-                 $(KLIBCAR) cq $@					\
+                 $(call klibc-ar,cq,Dcq) $@				\
 		 $(call objectify,__static_init.o) $(klib-o-files);	\
                  $(KLIBCRANLIB) $@
 
-- 
1.7.1



More information about the klibc mailing list