[klibc] [PATCH] klibc: reproducible builds

Maciej Żenczykowski zenczykowski at gmail.com
Tue Oct 19 17:07:11 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 |   14 +++++++++-----
 usr/klibc/Kbuild     |    2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/scripts/Kbuild.klibc b/scripts/Kbuild.klibc
index 79d196f..6427be0 100644
--- a/scripts/Kbuild.klibc
+++ b/scripts/Kbuild.klibc
@@ -93,11 +93,15 @@ KLIBCMINOR        := $(shell cut -d. -f2 $(srctree)/usr/klibc/version)
 KLIBCLD          := $(LD)
 KLIBCCC          := $(CC)
 KLIBCAR          := $(AR)
-KLIBCRANLIB      := $(RANLIB)
+KLIBCAR_cq       := $(KLIBCAR) $(if $(KBUILD_REPRODUCIBLE),Dcq,cq)
+KLIBCAR_crs      := $(KLIBCAR) $(if $(KBUILD_REPRODUCIBLE),Dcrs,crs)
+KLIBCAR_cru      := $(KLIBCAR) $(if $(KBUILD_REPRODUCIBLE),Dcr,cru)
+KLIBCAR_s        := $(KLIBCAR) $(if $(KBUILD_REPRODUCIBLE),Ds,s)
+KLIBCRANLIB      := $(KLIBCAR_s)
 KLIBCSTRIP       := $(STRIP)
 KLIBCNM          := $(NM)
-KLIBCOBJCOPY	 := $(OBJCOPY)
-KLIBCOBJDUMP	 := $(OBJDUMP)
+KLIBCOBJCOPY     := $(OBJCOPY)
+KLIBCOBJDUMP     := $(OBJDUMP)
 
 # klibc include paths
 KLIBCCPPFLAGS    := -nostdinc -iwithprefix include \
@@ -265,8 +269,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 $@; $(KLIBCAR_cru) $@ $(filter $(lib-y), $^),\
+                    rm -f $@; $(KLIBCAR_crs) $@)
 
 $(lib-target): $(lib-y) FORCE
 	$(call if_changed,link_o_target)
diff --git a/usr/klibc/Kbuild b/usr/klibc/Kbuild
index ab5212b..f64785e 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 $@					\
+                 $(KLIBCAR_cq) $@					\
 		 $(call objectify,__static_init.o) $(klib-o-files);	\
                  $(KLIBCRANLIB) $@
 
-- 
1.7.1



More information about the klibc mailing list