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