File: gen-versionh.sh

package info (click to toggle)
trinity 1.9%2Bgit20200331.4d2343bd18c7b-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,080 kB
  • sloc: ansic: 32,746; sh: 536; makefile: 164
file content (52 lines) | stat: -rwxr-xr-x 1,044 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

HEADER="include/version.h"

hdr()
{
 echo "#pragma once" > $HEADER
 echo "/* This file is auto-generated */" >> $HEADER
}

if [ -f $HEADER ]; then
  OLD=$(grep VERSION $HEADER | head -n1 | sed 's/"//g' | awk '{ print $3 }')
else
  OLD=""
fi

DEVEL=$(grep VERSION Makefile | head -n1 | grep pre | wc -l)

# if we don't have git installed, or we're a release version
# get the version number from the makefile.
makefilever()
{
  VER=$(grep VERSION= Makefile | sed -re '1 s/.*=.*"(.*)".*/\1/')
  if [ "$OLD" != "$VER" ]; then
    hdr
    echo "#define VERSION \""$VER\" >> $HEADER
  fi
}

GIT=`which git 2>/dev/null`
if [ "$DEVEL" == "1" ]; then
  if [ ! -z ${GIT} ]; then
    if [ -f ${GIT} -a -d ${0%/*}/../.git ]; then
      VER=$(${GIT} describe --always)
      if [ "$OLD" != "$VER" ]; then
	hdr
	echo "#define VERSION \""$VER\" >> $HEADER
      fi
    else
      # can't find .git
      makefilever
    fi
  else
    # No git installed.
    makefilever
  fi
else
  # devel=0 : release version.
  makefilever
fi

touch ${HEADER}