[SeaBIOS] [PATCH] update version banner

Kevin O'Connor kevin at koconnor.net
Thu Mar 22 01:15:21 CET 2012


On Mon, Mar 19, 2012 at 01:56:01PM +0100, Gerd Hoffmann wrote:
> This patch changes the seabios version banner printed.  When building
> from a git repository 'git describe' is used to generate a version tag
> which includes the (short) commit hash and thus can be used to identify
> the commit used to build the binary.

I like the idea, but I'd rather not complicate the Makefile further.
How about the patch below?

-Kevin


diff --git a/Makefile b/Makefile
index abbac8c..a4d548d 100644
--- a/Makefile
+++ b/Makefile
@@ -4,9 +4,6 @@
 #
 # This file may be distributed under the terms of the GNU LGPLv3 license.
 
-# Program version
-VERSION=pre-1.6.4-$(shell date +"%Y%m%d_%H%M%S")-$(shell hostname)
-
 # Output directory
 OUT=out/
 
@@ -150,8 +147,8 @@ $(OUT)romlayout.o: romlayout.S $(OUT)asm-offsets.h
 	$(Q)$(CC) $(CFLAGS16) -c -D__ASSEMBLY__ $< -o $@
 
 $(OUT)romlayout16.lds: $(OUT)ccode32flat.o $(OUT)code32seg.o $(OUT)ccode16.o $(OUT)romlayout.o tools/layoutrom.py
-	@echo "  Building ld scripts (version \"$(VERSION)\")"
-	$(Q)echo 'const char VERSION[] = "$(VERSION)";' > $(OUT)version.c
+	@echo "  Building ld scripts"
+	$(Q)./tools/buildversion.sh $(OUT)version.c
 	$(Q)$(CC) $(CFLAGS32FLAT) -c $(OUT)version.c -o $(OUT)version.o
 	$(Q)$(LD) -melf_i386 -r $(OUT)ccode32flat.o $(OUT)version.o -o $(OUT)code32flat.o
 	$(Q)$(LD) -melf_i386 -r $(OUT)ccode16.o $(OUT)romlayout.o -o $(OUT)code16.o
@@ -206,8 +203,8 @@ $(OUT)vgaentry.o: vgaentry.S $(OUT)autoconf.h
 	$(Q)$(CC) $(CFLAGS16VGA) -c -D__ASSEMBLY__ $< -o $@
 
 $(OUT)vgarom.o: $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgalayout.lds
-	@echo "  Linking $@ (version \"$(VERSION)\")"
-	$(Q)printf '#include "types.h"\nchar VERSION[] VAR16 = "$(VERSION)";' > $(OUT)vgaversion.c
+	@echo "  Linking $@"
+	$(Q)./tools/buildversion.sh $(OUT)vgaversion.c VAR16
 	$(Q)$(CC) $(CFLAGS16VGA) -c $(OUT)vgaversion.c -o $(OUT)vgaversion.o
 	$(Q)$(LD) --gc-sections -T $(OUT)vgalayout.lds $(OUT)vgaccode16.o $(OUT)vgaentry.o $(OUT)vgaversion.o -o $@
 
diff --git a/tools/buildversion.sh b/tools/buildversion.sh
new file mode 100755
index 0000000..9b301e6
--- /dev/null
+++ b/tools/buildversion.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Script to generate a C file with version information.
+OUTFILE="$1"
+VAR16MODE="$2"
+
+# Extract version info
+if [ -d .git ]; then
+    VERSION="`git describe --tags --long --dirty`"
+elif [ -f .version ]; then
+    VERSION="`cat .version`"
+else
+    VERSION="?"
+fi
+VERSION="${VERSION}-`date +"%Y%m%d_%H%M%S"`-`hostname`"
+echo "Version: ${VERSION}"
+
+# Build header file
+if [ "$VAR16MODE" == "VAR16" ]; then
+    cat > ${OUTFILE} <<EOF
+#include "types.h"
+char VERSION[] VAR16 = "${VERSION}";
+EOF
+else
+    cat > ${OUTFILE} <<EOF
+char VERSION[] = "${VERSION}";
+EOF
+fi



More information about the SeaBIOS mailing list