[ipxe-devel] [PATCH] [build] Make it deterministic when building from git.

Denis 'GNUtoo' Carikli GNUtoo at no-log.org
Sat Sep 10 21:03:40 UTC 2016


This is to permit deterministic builds, while
at the same time still permitting to identify
which binary is running.

Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo at no-log.org>
---
 src/Makefile.housekeeping | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/Makefile.housekeeping b/src/Makefile.housekeeping
index f09db37..a1863c0 100644
--- a/src/Makefile.housekeeping
+++ b/src/Makefile.housekeeping
@@ -1138,15 +1138,6 @@ $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
 	$(Q)$(RANLIB) $@
 blib : $(BLIB)
 
-# Command to generate build ID.  Must be unique for each $(BIN)/%.tmp,
-# even within the same build run.
-#
-BUILD_ID_CMD	:= perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
-
-# Build timestamp
-#
-BUILD_TIMESTAMP := $(shell date +%s)
-
 # Build version
 #
 GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
@@ -1159,13 +1150,20 @@ $(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
 		-DVERSION="\"$(VERSION)\"" \
 		-c $< -o $@
 
+# Build timestamp
+#
+BUILD_TIMESTAMP := $(if $(GIT_INDEX),$(shell git log --pretty=format:%ct -1),$(shell date +%s))
+
 # Build an intermediate object file from the objects required for the
 # specified target.
 #
+# The build ID must be unique for each $(BIN)/%.tmp, even within the same build run.
+#
+
 $(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
 	$(QM)$(ECHO) "  [LD] $@"
 	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
-		--defsym _build_id=`$(BUILD_ID_CMD)` \
+		--defsym _build_id=0x`cat $? | sha1sum | cut -c-8` \
 		--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
 		-Map $(BIN)/$*.tmp.map
 	$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
-- 
2.9.3




More information about the ipxe-devel mailing list