OSDN Git Service

Make toybox --version use the "git describe" info if it's available.
authorRob Landley <rob@landley.net>
Fri, 17 Apr 2015 07:46:11 +0000 (02:46 -0500)
committerRob Landley <rob@landley.net>
Fri, 17 Apr 2015 07:46:11 +0000 (02:46 -0500)
main.c
scripts/make.sh

diff --git a/main.c b/main.c
index a800dee..5702244 100644 (file)
--- a/main.c
+++ b/main.c
@@ -5,7 +5,9 @@
 
 #include "toys.h"
 
+#ifndef TOYBOX_VERSION
 #define TOYBOX_VERSION "0.5.2"
+#endif
 
 // Populate toy_list[].
 
index 4cb1927..3d9eed3 100755 (executable)
@@ -58,9 +58,11 @@ fi
 # Extract a list of toys/*/*.c files to compile from the data in $KCONFIG_CONFIG
 # (First command names, then filenames with relevant {NEW,OLD}TOY() macro.)
 
+GITHASH="$(git describe --tags --abbrev=12 2>/dev/null)"
+[ ! -z "$GITHASH" ] && GITHASH="-DTOYBOX_VERSION=\"$GITHASH\""
 TOYFILES="$(sed -n 's/^CONFIG_\([^=]*\)=.*/\1/p' "$KCONFIG_CONFIG" | xargs | tr ' [A-Z]' '|[a-z]')"
 TOYFILES="$(egrep -l "TOY[(]($TOYFILES)[ ,]" toys/*/*.c)"
-BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE)"
+BUILD="$(echo ${CROSS_COMPILE}${CC} $CFLAGS -I . $OPTIMIZE $GITHASH)"
 FILES="$(echo lib/*.c main.c $TOYFILES)"
 
 genbuildsh()