root/buildtools/mkversion.sh

Revision 520106c37dca8dd9921431f0385fa4a74fecf4d5, 1.2 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 3 years ago)

support versioning from git

  • Property mode set to 100755
Line 
1 #!/bin/sh
2
3 STATUS=`git status 2>&1`
4 if [ $? == 0 ]; then
5   echo "Building version info from git"
6   HASH=`git show --format=%H | head -1`
7   echo "    * version -> $HASH"
8   SYM=`git name-rev $HASH | awk '{print $2;}' | sed -e 's/\^.*//'`
9   if [ -z "`echo $SYM | grep '^tags/'`" ]; then
10     SYM="branches/$SYM"
11   fi
12   echo "    * symbolic -> $SYM"
13   BRANCH=$SYM
14   if [ -n "`echo $STATUS | grep 'Changed but not updated'`" ]; then
15     HASH="$HASH.modified"
16   fi
17 else
18   BRANCH=exported
19   echo "    * exported"
20 fi
21
22 if [ -r "$1" ]; then
23   eval `cat noit_version.h | awk '/^#define/ { print $2"="$3;}'`
24   if [ "$NOIT_BRANCH" == "$BRANCH" -a "$NOIT_VERSION" == "$HASH" ]; then
25     echo "    * version unchanged"
26     exit
27   fi
28 fi
29
30 cat > $1 <<EOF
31 #ifndef NOIT_VERSION_H
32 #ifndef NOIT_BRANCH
33 #define NOIT_BRANCH "$BRANCH"
34 #endif
35 #ifndef NOIT_VERSION
36 #define NOIT_VERSION "$HASH"
37 #endif
38
39 #include <stdio.h>
40
41 static inline int noit_build_version(char *buff, int len) {
42   const char *start = NOIT_BRANCH;
43   if(!strncmp(start, "branches/", 9))
44     return snprintf(buff, len, "%s.%s", start+9, NOIT_VERSION);
45   if(!strncmp(start, "tags/", 5))
46     return snprintf(buff, len, "%s.%s", start+5, NOIT_VERSION);
47   return snprintf(buff, len, "%s.%s", NOIT_BRANCH, NOIT_VERSION);
48 }
49
50 #endif
51 EOF
Note: See TracBrowser for help on using the browser.