Solaris/Irix portability hacks for reversion
[exim.git] / src / scripts / reversion
1 #!/bin/sh
2
3 # Update Exim's version header file.
4
5 # Compatibility gross-ness for non-POSIX systems
6 if [ -z "$EXIM_REVERSION_ADJUSTED" ]
7 then
8   SHELL=/bin/sh
9   EXIM_REVERSION_ADJUSTED=yes
10   export SHELL EXIM_REVERSION_ADJUSTED
11   # Solaris:
12   if [ -x /usr/xpg4/bin/sh ]
13   then
14     PATH="/usr/xpg4/bin:$PATH"
15     SHELL=/usr/xpg4/bin/sh
16     export PATH SHELL
17   fi
18   # Irix:
19   _XPG=1 ; export _XPG
20   #
21   exec "$SHELL" "$0" "$@"
22 fi
23
24 # Read version information that was generated by a previous run of
25 # this script, or during the release process.
26
27 if   [ -f ./version.sh ]
28 then .    ./version.sh
29 elif [ -f ../src/version.sh ]
30 then .    ../src/version.sh
31 fi
32
33 # If this tree is a git working directory, use that to get version information.
34
35 if [ -e ../../.git ] || [ "$1" = "release" ]
36 then
37         # Modify the output of git describe into separate parts for
38         # the name "exim" and the release and variant versions.
39         # Put a dot in the version number and remove a spurious g.
40         set $(git describe --dirty=-XX --match 'exim-4*' |
41                 sed 's|-| |;s|_|.|;s|[-_]| _|;s|-g|-|')
42         # Only update if we need to
43         if [ "$2 $3" != "$EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION" ]
44         then
45                 EXIM_RELEASE_VERSION="$2"
46                 EXIM_VARIANT_VERSION="$3"
47                 rm -f version.h
48         fi
49 fi
50
51 # If you are maintaining a patched version of Exim, you can either
52 # create your own version.sh as part of your release process, or you
53 # can modify EXIM_VARIANT_VERSION at this point in this script.
54
55 case $EXIM_RELEASE_VERSION in
56 '')     echo "*** Your copy of Exim lacks any version information."
57         exit 1
58 esac
59
60 EXIM_COMPILE_NUMBER=$(expr "${EXIM_COMPILE_NUMBER:-0}" + 1)
61
62 echo "$EXIM_COMPILE_NUMBER" >cnumber.h
63
64 ( echo '# automatically generated file - see ../scripts/reversion'
65   echo EXIM_RELEASE_VERSION='"'"$EXIM_RELEASE_VERSION"'"'
66   echo EXIM_VARIANT_VERSION='"'"$EXIM_VARIANT_VERSION"'"'
67   echo EXIM_COMPILE_NUMBER='"'"$EXIM_COMPILE_NUMBER"'"'
68 ) >version.sh
69
70 if [ ! -f version.h ]
71 then
72 ( echo '/* automatically generated file - see ../scripts/reversion */'
73   echo '#define EXIM_RELEASE_VERSION "'"$EXIM_RELEASE_VERSION"'"'
74   echo '#define EXIM_VARIANT_VERSION "'"$EXIM_VARIANT_VERSION"'"'
75   echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION EXIM_VARIANT_VERSION'
76 ) >version.h
77 fi
78
79 echo ">>> version $EXIM_RELEASE_VERSION$EXIM_VARIANT_VERSION #$EXIM_COMPILE_NUMBER"
80 echo