testsuite: don't break on '+' in trusted-config-list path
[exim.git] / src / scripts / Configure-Makefile
CommitLineData
61ec970d 1#! /bin/sh
61ec970d
PH
2
3# Shell script to build Makefile in a build directory. It must be called
4# from inside the directory. It does its own checking of when to rebuild; it
5# just got too horrendous to get it right in "make", because of the optionally
6# existing configuration files.
80fea873
JH
7#
8# Copyright (c) The Exim Maintainers 2016
61ec970d
PH
9
10
11# First off, get the OS type, and check that there is a make file for it.
12
13ostype=`../scripts/os-type -generic` || exit 1
14
15if [ ! -r ../OS/Makefile-$ostype ] ; then
16 echo ""
17 echo "*** Sorry - operating system $ostype is not supported"
18 echo "*** See OS/Makefile-* for supported systems" 1>&2
19 echo ""
20 exit 1
21fi
22
23# We also need the architecture type, in order to test for any architecture-
24# specific configuration files.
25
26archtype=`../scripts/arch-type` || exit 1
27
28# Now test for either the non-existence of Makefile, or for any of its
29# components being newer. Note that the "newer" script gives the right
30# answer (for our purposes) when the first file is non-existent.
31
32editme=../Local/Makefile
33rebuild=yes
34
35if [ -f Makefile ] ; then
36 rebuild=no
37 if ../scripts/newer $editme Makefile || \
38 ../scripts/newer $editme-$ostype Makefile || \
39 ../scripts/newer $editme-$archtype Makefile || \
40 ../scripts/newer $editme-$ostype-$archtype Makefile || \
41 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
42 ../scripts/newer ../OS/Makefile-Base Makefile || \
43 ../scripts/newer ../OS/Makefile-Default Makefile
44 then
45 rebuild=yes
46 fi
47fi
48
49# If the "build" variable is set it means that a build name was explicitly
50# given. Arrange to pick up a build-specific configuration file.
51
52if [ "X$build" != "X" ] ; then
53 mfb=Local/Makefile-$build
54 if ../scripts/newer $editme-$build Makefile ; then
55 rebuild=yes
56 fi
57else
58 mfb=
59fi
60
61
62# If Makefile is up-to-date, no need to rebuild it.
63
64if [ $rebuild = no ] ; then
65 echo "\`Makefile' is up to date."
66 echo " "
67 exit
68fi
69
70# Makefile needs to be rebuilt in the current directory by joining
71# the generic default makefile, the OS base makefile, and then local
72# generic, OS-specific, architecture-specific, and OS+architecture-specific
73# makefiles, if they exist. These files all contain macro definitions, with
74# later definitions overriding earlier ones. Make a temporary file first, in
75# case things go wrong. A second temporary is needed for sorting out the
76# default Perl stuff. Use short macro names to save typing.
77
78mf=Makefile
79mft=$mf-t
80mftt=$mf-tt
856d1e16
PP
81mftepcp=$mf-tepcp
82mftepcp2=$mf-tepcp2
61ec970d 83
58ee1eb6
TF
84look_mf=lookups/Makefile
85look_mf_pre=${look_mf}.predynamic
86look_mf_post=${look_mf}.postdynamic
0a349494 87
61ec970d
PH
88# Ensure the temporary does not exist and start the new one by setting
89# the OSTYPE and ARCHTYPE variables.
90
856d1e16 91rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
61ec970d
PH
92(echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
93
94# Now concatenate the files to the temporary file. Copy the files using sed to
95# remove comments, blank lines, and trailing white space.
96
97# BEWARE: a tab character is needed in the sed command below. It has had
98# a nasty tendency to get lost in the past, causing a problem if a tab has
99# actually been present in one of the files. Use a variable to hold a space
100# and a tab to keep the tab in one place.
101
102st=' '
103
104for f in OS/Makefile-Default \
105 OS/Makefile-$ostype \
106 Local/Makefile \
107 Local/Makefile-$ostype \
108 Local/Makefile-$archtype \
109 Local/Makefile-$ostype-$archtype \
110 $mfb
111do if test -r ../$f
112 then echo "# From $f"
113 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
114 echo "# End of $f"
115 echo ""
116 fi
8f3bfb82
HSHR
117done \
118 | sed 's/^TMPDIR=/EXIM_&/' \
119 >> $mft || exit 1
0a349494 120
856d1e16
PP
121# handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
122# wildcards; note that this logic means all setting _appends_ values, never
123# replacing; if that's a problem, we can revisit.
124sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
125 sed "s/[$st]*\$//" >> $mftepcp
126if test -s ./$mftepcp
127then
128 # expand any wildcards and strip spaces, to make it a real PATH-like variable
129 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
130 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
131 . ./$mftepcp
132 export PKG_CONFIG_PATH
133 egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
134 rm -f ./$mft
135 (
136 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
137 sed "s/'//g" ./$mftepcp
138 echo "# End of collapsed PKG_CONFIG_PATH"
139 echo ""
140 cat ./$mftt
141 ) > ./$mft
142 rm -f ./$mftt
143fi
144rm -f ./$mftepcp ./$mftepcp2
145
dde3daac
PP
146# handle pkg-config
147# beware portability of extended regexps with sed.
dde3daac
PP
148egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
149 sed "s/[$st]*=/='/" | \
150 sed "s/\$/'/" > $mftt
2519e60d 151egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
f4b00a2d
PP
152 sed "s/[$st]*=/='/" | \
153 sed "s/\$/'/" >> $mftt
dde3daac
PP
154if test -s $mftt
155then
156 (
157 echo "# pkg-config fixups"
158 . ./$mftt
159 for var in `cut -d = -f 1 < $mftt`; do
160 case $var in
f4b00a2d
PP
161
162 USE_*_PC)
163 eval "pc_value=\"\$$var\""
164 need_this=''
8b0fb68e 165 need_core=''
f4b00a2d
PP
166 if [ ".$SUPPORT_TLS" = "." ]; then
167 # no TLS, not referencing
168 true
169 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
170 need_this=t
8b0fb68e 171 need_core="gnutls-special"
f4b00a2d
PP
172 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
173 need_this=t
8b0fb68e 174 need_core=t
f4b00a2d
PP
175 fi
176 if [ ".$need_this" != "." ]; then
177 tls_include=`pkg-config --cflags $pc_value`
14ea0bea
PP
178 if [ $? -ne 0 ]; then
179 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
180 exit 1
181 fi
f4b00a2d
PP
182 tls_libs=`pkg-config --libs $pc_value`
183 echo "TLS_INCLUDE=$tls_include"
184 echo "TLS_LIBS=$tls_libs"
8b0fb68e
PP
185 # With hash.h pulling crypto into the core, we need to also handle that
186 if [ ".$need_this" = ".t" ]; then
187 echo "CFLAGS += $tls_include"
188 echo "LDFLAGS += $tls_libs"
189 elif [ ".$need_this" = ".gnutls-special" ]; then
190 if pkg-config --atleast-version=2.10 gnutls ; then
191 echo "CFLAGS += $tls_include"
192 echo "LDFLAGS += $tls_libs"
193 else
856d1e16
PP
194 echo "CFLAGS += `libgcrypt-config --cflags`"
195 echo "LDFLAGS += `libgcrypt-config --libs`"
8b0fb68e
PP
196 fi
197 fi
f4b00a2d
PP
198 fi
199 ;;
200
dde3daac
PP
201 *_PC)
202 eval "pc_value=\"\$$var\""
203 base=`echo $var | sed 's/_PC$//'`
204 eval "basevalue=\"\$$base\""
205 if [ ".$basevalue" = "." ]; then
206 # not pulling in this module, _PC defined as default? Ignore
207 true
208 elif [ $basevalue = 2 ]; then
209 # module; handled in scripts/lookups-Makefile
210 true
211 else
212 # main binary
213 cflags=`pkg-config --cflags $pc_value`
14ea0bea
PP
214 if [ $? -ne 0 ]; then
215 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
216 exit 1
217 fi
dde3daac
PP
218 libs=`pkg-config --libs $pc_value`
219 if [ "$var" != "${var#LOOKUP_}" ]; then
220 echo "LOOKUP_INCLUDE += $cflags"
221 echo "LOOKUP_LIBS += $libs"
222 elif [ "$var" != "${var#AUTH_}" ]; then
223 echo "CFLAGS += $cflags"
224 echo "AUTH_LIBS += $libs"
225 else
226 echo >&2 "Don't know how to handle pkg-config for $var"
227 fi
228 fi
229 ;;
f4b00a2d 230
6a6084f8
PP
231 PCRE_CONFIG)
232 case $PCRE_CONFIG in
233 yes|YES|y|Y)
234 cflags=`pcre-config --cflags`
14ea0bea
PP
235 if [ $? -ne 0 ]; then
236 echo >&2 "*** Missing pcre-config for regular expression support"
237 exit 1
238 fi
6a6084f8
PP
239 libs=`pcre-config --libs`
240 if [ ".$cflags" != "." ]; then
241 echo "INCLUDE += $cflags"
242 fi
243 echo "PCRE_LIBS=$libs"
244 ;;
245 esac
246 ;;
247
2519e60d
TL
248 AVOID_GNUTLS_PKCS11)
249 echo "$var=yes"
250 ;;
251
dde3daac
PP
252 esac
253 done
254 echo "# End of pkg-config fixups"
255 echo
256 ) >> $mft
14ea0bea
PP
257 subexit=$?
258 if [ $subexit -ne 0 ]; then
259 exit $subexit
260 fi
dde3daac
PP
261fi
262rm -f $mftt
263
0a349494 264# make the lookups Makefile with the definitions
58ee1eb6 265# the auxiliary script generates $look_mf_post from $look_mf_pre
0a349494 266
58ee1eb6
TF
267cp ../src/lookups/Makefile $look_mf_pre
268../scripts/lookups-Makefile
61ec970d
PH
269
270# See if there is a definition of EXIM_PERL in what we have built so far.
271# If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
272# and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
273# what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
274# if it has been defined.
275
276EXIM_PERL=`grep EXIM_PERL $mft`
277
278PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
279if [ "${PERL_COMMAND}" = "" ] ; then
280 PERL_COMMAND='perl'
281fi
282
283if [ "${EXIM_PERL}" != "" ] ; then
284 testperl=`$PERL_COMMAND --version`
285 if [ "$testperl" = "" ] ; then
286 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
287 exit 1
288 fi
289
177ebd9b
NM
290 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
291 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
292 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
293 exit 1;
294 fi
295
61ec970d
PH
296 mv $mft $mftt
297 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
298 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
299 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
300 echo "" >>$mft
301 cat $mftt >> $mft
302 rm -f $mftt
303fi
304
305# Record the build variable in the Makefile.
306
307echo "build=$build" >>$mft
308echo "" >>$mft
309
310# Finally, join on the generic base make file, which contains the actual
311# rules and stuff.
312
76ea0716 313echo "# From ../OS/Makefile-Base" >> $mft
61ec970d
PH
314cat ../OS/Makefile-Base >> $mft || exit 1
315
316# If the new makefile is the same as the existing one, say so, and just
317# update the timestamp. Otherwise remove the old and install the new.
318
58ee1eb6 319if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
61ec970d
PH
320then echo ">>> rebuilt $mf unchanged"
321 echo " "
322 touch $mf || exit
58ee1eb6
TF
323 rm -f $mft $look_mf_pre $look_mf_post
324elif rm -f $mf $look_mf $look_mf_pre
61ec970d 325 mv $mft $mf
58ee1eb6 326 mv $look_mf_post $look_mf
0a349494 327then echo ">>> New $mf & $look_mf installed"
61ec970d
PH
328 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
329 echo " "
330else echo " "
331 echo "*** Failed to install $mf - see $mft"
0a349494 332 echo " (or $look_mft)"
61ec970d
PH
333 echo " "
334 exit 1;
335fi
336
dde3daac 337# vim: set ft=sh :
61ec970d 338# End of Configure-Makefile