Import Upstream version 4.92
[hcoop/debian/exim4.git] / scripts / reversion
CommitLineData
420a0d19 1#!/bin/sh
2ea97746
CE
2# Copyright (c) The Exim Maintainers 1995 - 2018
3
4set -e
5LC_ALL=C
6export LC_ALL
420a0d19
CE
7
8# Update Exim's version header file.
9
10# Compatibility gross-ness for non-POSIX systems
11if [ -z "$EXIM_REVERSION_ADJUSTED" ]
12then
13 SHELL=/bin/sh
14 EXIM_REVERSION_ADJUSTED=yes
15 export SHELL EXIM_REVERSION_ADJUSTED
16 # Solaris:
17 if [ -x /usr/xpg4/bin/sh ]
18 then
19 PATH="/usr/xpg4/bin:$PATH"
20 SHELL=/usr/xpg4/bin/sh
21 export PATH SHELL
22 fi
23 # Irix:
24 _XPG=1 ; export _XPG
25 #
26 exec "$SHELL" "$0" "$@"
27fi
28
29# Read version information that was generated by a previous run of
30# this script, or during the release process.
31
2ea97746
CE
32if [ -f ./version.sh ]; then
33 . ./version.sh
34elif [ -f ../src/version.sh ]; then
35 . ../src/version.sh
36elif [ -d ../../.git ] || [ -f ../../.git ] || [ "$1" = release ]; 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 if [ "$2" ]
41 then
42 description=$(git describe "$2")
43 else
44 description=$(git describe --dirty=-XX --match 'exim-4*')
45 fi
46 set $(echo "$description" | sed 's/-/ /; s/-g/-/')
47 # Only update if we need to
48 if [ "$2 $3" != "$EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION" ]
49 then
50 EXIM_RELEASE_VERSION="$2"
51 EXIM_VARIANT_VERSION="$3"
52 rm -f version.h
53 fi
54else
55 echo "Cannot determine the release number" >&2
56 exit
420a0d19
CE
57fi
58
59# If you are maintaining a patched version of Exim, you can either
60# create your own version.sh as part of your release process, or you
61# can modify EXIM_VARIANT_VERSION at this point in this script.
62
2ea97746
CE
63if test -z "$EXIM_RELEASE_VERSION"; then
64 echo "$0: Your copy of Exim lacks any version information." >&2
65 exit 1
66fi
420a0d19
CE
67
68EXIM_COMPILE_NUMBER=$(expr "${EXIM_COMPILE_NUMBER:-0}" + 1)
69
70echo "$EXIM_COMPILE_NUMBER" >cnumber.h
71
2ea97746
CE
72# Reproducible builds, accept a build timestamp override from environ per
73# <https://reproducible-builds.org/specs/source-date-epoch/>.
74# We require a fairly modern date(1) command here, which is not portable
75# to some of the systems Exim is built on. That's okay, because the scenarios
76# are:
77# 1) Local postmaster building, not using $SOURCE_DATE_EPOCH, doesn't matter
78# 2) Packaging folks who don't care about reproducible builds
79# 3) Packaging folks who care but are using systems where date Just Works
80# 3) Packaging folks who care and can put a modern date(1) in $PATH
81# 4) Packaging folks who care and can supply us with a clean patch to support
82# their requirements
83# 5) Packaging folks who care but won't do any work to support their strange
84# old systems and want us to do the work for them. We don't care either,
85# they're SOL and have to live without reproducible builds.
86#
87exim_build_date_override=''
88if [ ".${SOURCE_DATE_EPOCH:-}" != "." ]; then
89 fmt='+%d-%b-%Y %H:%M:%S'
90 # Non-reproducible, we use __DATE__ and __TIME__ in C, which respect timezone
91 # (think localtime, not gmtime); for reproduction between systems, UTC makes
92 # more sense and the examples available use UTC without explicitly mandating
93 # it. I think that we can switch behavior and use UTC for reproducible
94 # builds without it causing any problems: nothing really cares about timezone.
95 # GNU date: "date -d @TS"
96 # BSD date: "date -r TS"
97 exim_build_date_override="$(date -u -d "@${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null || date -u -r "${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null)"
98fi
99
420a0d19
CE
100( echo '# automatically generated file - see ../scripts/reversion'
101 echo EXIM_RELEASE_VERSION='"'"$EXIM_RELEASE_VERSION"'"'
2ea97746 102 test -n "$EXIM_VARIANT_VERSION" && \
420a0d19
CE
103 echo EXIM_VARIANT_VERSION='"'"$EXIM_VARIANT_VERSION"'"'
104 echo EXIM_COMPILE_NUMBER='"'"$EXIM_COMPILE_NUMBER"'"'
2ea97746
CE
105 if [ ".${exim_build_date_override:-}" != "." ]; then
106 echo EXIM_BUILD_DATE_OVERRIDE='"'"${exim_build_date_override}"'"'
107 fi
420a0d19
CE
108) >version.sh
109
110if [ ! -f version.h ]
111then
112( echo '/* automatically generated file - see ../scripts/reversion */'
113 echo '#define EXIM_RELEASE_VERSION "'"$EXIM_RELEASE_VERSION"'"'
2ea97746 114 test -n "$EXIM_VARIANT_VERSION" && \
420a0d19 115 echo '#define EXIM_VARIANT_VERSION "'"$EXIM_VARIANT_VERSION"'"'
2ea97746
CE
116 echo '#ifdef EXIM_VARIANT_VERSION'
117 echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION "-" EXIM_VARIANT_VERSION'
118 echo '#else'
119 echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION'
120 echo '#endif'
121 if [ ".${exim_build_date_override:-}" != "." ]; then
122 echo '#define EXIM_BUILD_DATE_OVERRIDE "'"${exim_build_date_override}"'"'
123 fi
420a0d19
CE
124) >version.h
125fi
126
2ea97746 127echo ">>> version $EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION #$EXIM_COMPILE_NUMBER"
420a0d19 128echo