SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / scripts / Configure-config.h
1 #! /bin/sh
2 # Copyright (c) The Exim Maintainters 2022
3 # SPDX-License-Identifier: GPL-2.0-or-later
4
5 # Build the config.h file, using the buildconfig program, first ensuring that
6 # it exists.
7
8 # 22-May-1996: remove the use of the "-a" flag for /bin/sh because it is not
9 # implemented in the FreeBSD shell. Sigh.
10
11 # 12-Mar-1997: add s/#.*$// to the sed script to allow for comments on the
12 # ends of settings - someone got caught.
13
14 # 18-Apr-1997: put the tab character into a variable to stop it getting
15 # lost by accident (which has happened a couple of times).
16
17 # 19-Jan-1998: indented settings in the makefile weren't being handled
18 # correctly; added [$st]* before \\([A-Z] in the pattern, to ignore leading
19 # space. Oddly, the pattern previously read ^\([A-Z which didn't seem to
20 # cause a problem (but did when the new bit was put in).
21
22 # 04-May-2005: if $1 is set, copy it into $MAKE, and then use $MAKE, if set,
23 # instead of "make" so that if gmake is used, it is used consistently.
24
25 if [ "$1" != "" ] ; then MAKE=$1 ; fi
26 if [ "$MAKE" = "" ] ; then MAKE=make ; fi
27
28 $MAKE buildconfig || exit 1
29
30 # BEWARE: tab characters needed in the following sed command. They have had
31 # a nasty tendency to get lost in the past, causing a problem if a tab has
32 # actually been present in makefile. Use a variable to hold a space and a
33 # tab to keep the tab in one place. This makes the sed option horrendous to
34 # read, but the whole script is safer.
35
36 st='     '
37
38 (sed -n \
39   "/\\\$/d;s/#.*\$//;s/^[$st]*\\([A-Z][^:!+$st]*\\)[$st]*=[$st]*\\([^$st]*\\)[$st]*\$/\\1=\\2 export \\1/p" \
40   < Makefile ; echo "./buildconfig") | /bin/sh
41
42 # If buildconfig ends with an error code, it will have output an error
43 # message. Ensure that a broken config.h gets deleted.
44
45 if [ $? != 0 ] ; then
46   rm -f config.h
47   exit 1
48 fi
49
50 # Double-check that config.h is complete.
51
52 if [ "`tail -1 config.h`" != "/* End of config.h */" ] ; then
53   echo "*** config.h appears to be incomplete"
54   echo "*** unexpected failure in buildconfig program"
55   exit 1
56 fi
57
58 echo ">>> config.h built"
59 echo ""
60
61 # vim: set ft=sh :
62 # End of Configure-config.h