root/buildtools/mkversion.sh

Revision d3e7ae2b8283e5d05460c2b3b6d365a6562216b8, 1.3 kB (checked in by Brandon Philips <brandon.philips@rackspace.com>, 3 years ago)

buildtools: fix == bashism in mkversion.sh

With a branch named bpdev I was getting an error at compile time:

[: 1: branches/bpdev: unexpected operator

This was because /bin/sh on my distro is dash which doesn't know what ==
is. Fix this by using a single =.

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