Fix build warning. Bug 2181
[exim.git] / src / scripts / reversion
CommitLineData
5901f0ab 1#!/bin/sh
9242a7e8 2# Copyright (c) The Exim Maintainers 2017
5901f0ab 3
9677df8a 4set -e
be92b80c
HSHR
5LC_ALL=C
6export LC_ALL
9677df8a 7
5901f0ab
TF
8# Update Exim's version header file.
9
28c60590
PP
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
5901f0ab
TF
29# Read version information that was generated by a previous run of
30# this script, or during the release process.
31
c6554334
PP
32if [ -f ./version.sh ]
33then . ./version.sh
5901f0ab
TF
34elif [ -f ../src/version.sh ]
35then . ../src/version.sh
36fi
37
38# If this tree is a git working directory, use that to get version information.
39
1abf359c 40if [ -d ../../.git ] || [ "$1" = "release" ]
5901f0ab
TF
41then
42 # Modify the output of git describe into separate parts for
43 # the name "exim" and the release and variant versions.
44 # Put a dot in the version number and remove a spurious g.
9677df8a
HSHR
45 if [ "$2" ]
46 then
47 description=$(git describe "$2")
48 else
49 description=$(git describe --dirty=-XX --match 'exim-4*')
50 fi
51 set $(echo "$description" | sed 's|-| |;s|_|.|;s|[-_]| _|;s|-g|-|')
5901f0ab
TF
52 # Only update if we need to
53 if [ "$2 $3" != "$EXIM_RELEASE_VERSION $EXIM_VARIANT_VERSION" ]
54 then
55 EXIM_RELEASE_VERSION="$2"
56 EXIM_VARIANT_VERSION="$3"
57 rm -f version.h
58 fi
59fi
60
61# If you are maintaining a patched version of Exim, you can either
62# create your own version.sh as part of your release process, or you
63# can modify EXIM_VARIANT_VERSION at this point in this script.
64
19cbdd27 65case "$EXIM_RELEASE_VERSION" in
5901f0ab
TF
66'') echo "*** Your copy of Exim lacks any version information."
67 exit 1
68esac
69
70EXIM_COMPILE_NUMBER=$(expr "${EXIM_COMPILE_NUMBER:-0}" + 1)
71
72echo "$EXIM_COMPILE_NUMBER" >cnumber.h
73
6e411084
PP
74# Reproducible builds, accept a build timestamp override from environ per
75# <https://reproducible-builds.org/specs/source-date-epoch/>.
76# We require a fairly modern date(1) command here, which is not portable
77# to some of the systems Exim is built on. That's okay, because the scenarios
78# are:
79# 1) Local postmaster building, not using $SOURCE_DATE_EPOCH, doesn't matter
80# 2) Packaging folks who don't care about reproducible builds
81# 3) Packaging folks who care but are using systems where date Just Works
82# 3) Packaging folks who care and can put a modern date(1) in $PATH
83# 4) Packaging folks who care and can supply us with a clean patch to support
84# their requirements
85# 5) Packaging folks who care but won't do any work to support their strange
86# old systems and want us to do the work for them. We don't care either,
87# they're SOL and have to live without reproducible builds.
88#
89exim_build_date_override=''
90if [ ".${SOURCE_DATE_EPOCH:-}" != "." ]; then
91 fmt='+%d-%b-%Y %H:%M:%S'
92 # Non-reproducible, we use __DATE__ and __TIME__ in C, which respect timezone
93 # (think localtime, not gmtime); for reproduction between systems, UTC makes
94 # more sense and the examples available use UTC without explicitly mandating
95 # it. I think that we can switch behavior and use UTC for reproducible
96 # builds without it causing any problems: nothing really cares about timezone.
97 # GNU date: "date -d @TS"
98 # BSD date: "date -r TS"
99 exim_build_date_override="$(date -u -d "@${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null | date -u -r "${SOURCE_DATE_EPOCH}" "$fmt" 2>/dev/null)"
100fi
101
5901f0ab
TF
102( echo '# automatically generated file - see ../scripts/reversion'
103 echo EXIM_RELEASE_VERSION='"'"$EXIM_RELEASE_VERSION"'"'
104 echo EXIM_VARIANT_VERSION='"'"$EXIM_VARIANT_VERSION"'"'
105 echo EXIM_COMPILE_NUMBER='"'"$EXIM_COMPILE_NUMBER"'"'
6e411084
PP
106 if [ ".${exim_build_date_override:-}" != "." ]; then
107 echo EXIM_BUILD_DATE_OVERRIDE='"'"${exim_build_date_override}"'"'
108 fi
5901f0ab
TF
109) >version.sh
110
111if [ ! -f version.h ]
112then
113( echo '/* automatically generated file - see ../scripts/reversion */'
114 echo '#define EXIM_RELEASE_VERSION "'"$EXIM_RELEASE_VERSION"'"'
115 echo '#define EXIM_VARIANT_VERSION "'"$EXIM_VARIANT_VERSION"'"'
116 echo '#define EXIM_VERSION_STR EXIM_RELEASE_VERSION EXIM_VARIANT_VERSION'
6e411084
PP
117 if [ ".${exim_build_date_override:-}" != "." ]; then
118 echo '#define EXIM_BUILD_DATE_OVERRIDE "'"${exim_build_date_override}"'"'
119 fi
5901f0ab
TF
120) >version.h
121fi
122
123echo ">>> version $EXIM_RELEASE_VERSION$EXIM_VARIANT_VERSION #$EXIM_COMPILE_NUMBER"
124echo