Debian Codegraph @

scripts/Configure-Makefile

raw symbols SCIP
1 #! /bin/sh
2 # Shell script to build Makefile in a build directory. It must be called
3 # from inside the directory. It does its own checking of when to rebuild; it
4 # just got too horrendous to get it right in "make", because of the optionally
5 # existing configuration files.
6 #
7 # Copyright (c) The Exim Maintainers 1995 - 2026
8 # SPDX-License-Identifier: GPL-2.0-or-later
9
10
11 LC_ALL=C
12 export LC_ALL
13
14
15 # First off, get the OS type, and check that there is a make file for it.
16
17 ostype=`../scripts/os-type -generic` || exit 1
18
19 if [ ! -r ../OS/Makefile-$ostype ] ; then
20 echo ""
21 echo "*** Sorry - operating system $ostype is not supported"
22 echo "*** See OS/Makefile-* for supported systems" 1>&2
23 echo ""
24 exit 1
25 fi
26
27 # We also need the architecture type, in order to test for any architecture-
28 # specific configuration files.
29
30 archtype=`../scripts/arch-type` || exit 1
31
32 # Now test for either the non-existence of Makefile, or for any of its
33 # components being newer. Note that the "newer" script gives the right
34 # answer (for our purposes) when the first file is non-existent.
35
36 editme=../Local/Makefile
37 rebuild=yes
38
39 if [ -f Makefile ] ; then
40 rebuild=no
41 if ../scripts/newer $editme Makefile \
42 || ../scripts/newer $editme-$ostype Makefile \
43 || ../scripts/newer $editme-$archtype Makefile \
44 || ../scripts/newer $editme-$ostype-$archtype Makefile \
45 || ../scripts/newer ../scripts/Configure-Makefile Makefile \
46 || ../scripts/newer ../scripts/lookups-Makefile Makefile \
47 || ../scripts/newer ../scripts/drivers-Makefile Makefile \
48 || ../scripts/newer ../OS/Makefile-Base Makefile \
49 || ../scripts/newer ../OS/Makefile-Default Makefile \
50 || ../scripts/newer ../src/auths/Makefile Makefile \
51 || ../scripts/newer ../src/lookups/Makefile Makefile \
52 || ../scripts/newer ../src/miscmods/Makefile Makefile \
53 || ../scripts/newer ../src/routers/Makefile Makefile \
54 || ../scripts/newer ../src/transports/Makefile Makefile
55 then
56 rebuild=yes
57 fi
58 fi
59
60 # If the "build" variable is set it means that a build name was explicitly
61 # given. Arrange to pick up a build-specific configuration file.
62
63 if [ "X$build" != "X" ] ; then
64 mfb=Local/Makefile-$build
65 if ../scripts/newer $editme-$build Makefile ; then
66 rebuild=yes
67 fi
68 else
69 mfb=
70 fi
71
72
73 # Linux now whines about egrep, saying "use grep -E".
74 # Solarix doesn't support -E on grep. Thanks so much for
75 # going non-back-compatible, Linux.
76 if [ "$ostype" != "SunOS5" ] ; then
77 egrep="grep -E"
78 else
79 egrep="egrep"
80 fi
81
82
83 # If Makefile is up-to-date, no need to rebuild it.
84
85 if [ $rebuild = no ] ; then
86 # echo "\`Makefile' is up to date."
87 # echo " "
88 exit
89 fi
90
91 # Makefile needs to be rebuilt in the current directory by joining
92 # the generic default makefile, the OS base makefile, and then local
93 # generic, OS-specific, architecture-specific, and OS+architecture-specific
94 # makefiles, if they exist. These files all contain macro definitions, with
95 # later definitions overriding earlier ones. Make a temporary file first, in
96 # case things go wrong. A second temporary is needed for sorting out the
97 # default Perl stuff. Use short macro names to save typing.
98
99 mf=Makefile
100 mft=$mf-t
101 mftt=$mf-tt
102 mftepcp=$mf-tepcp
103 mftepcp2=$mf-tepcp2
104
105 look_mf=lookups/Makefile
106 look_mf_pre=${look_mf}.predynamic
107 look_mf_post=${look_mf}.postdynamic
108
109 # Ensure the temporary does not exist and start the new one by setting
110 # the OSTYPE and ARCHTYPE variables.
111
112 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
113 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
114
115 # Now concatenate the files to the temporary file. Copy the files using sed to
116 # remove comments, blank lines, and trailing white space.
117
118 # BEWARE: a tab character is needed in the sed command below. It has had
119 # a nasty tendency to get lost in the past, causing a problem if a tab has
120 # actually been present in one of the files. Use a variable to hold a space
121 # and a tab to keep the tab in one place.
122
123 st=' '
124
125 for f in OS/Makefile-Default \
126 OS/Makefile-$ostype \
127 Local/Makefile \
128 Local/Makefile-$ostype \
129 Local/Makefile-$archtype \
130 Local/Makefile-$ostype-$archtype \
131 $mfb
132 do if test -r ../$f
133 then echo "# From $f"
134 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
135 echo "# End of $f"
136 echo ""
137 fi
138 done \
139 | sed 's/^TMPDIR=/EXIM_&/' \
140 >> $mft || exit 1
141
142 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
143 # wildcards; note that this logic means all setting _appends_ values, never
144 # replacing; if that's a problem, we can revisit.
145 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
146 sed "s/[$st]*\$//" >> $mftepcp
147 if test -s ./$mftepcp
148 then
149 # expand any wildcards and strip spaces, to make it a real PATH-like variable
150 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
151 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
152 . ./$mftepcp
153 export PKG_CONFIG_PATH
154 $egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
155 rm -f ./$mft
156 (
157 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
158 sed "s/'//g" ./$mftepcp
159 echo "# End of collapsed PKG_CONFIG_PATH"
160 echo ""
161 cat ./$mftt
162 ) > ./$mft
163 rm -f ./$mftt
164 fi
165 rm -f ./$mftepcp ./$mftepcp2
166
167 # handle pkg-config
168 # beware portability of extended regexps with sed.
169 $egrep "^[$st]*(AUTH|LOOKUP|SUPPORT)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
170 sed "s/[$st]*=/='/" | \
171 sed "s/\$/'/" > $mftt
172 $egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE2?_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
173 sed "s/[$st]*=/='/" | \
174 sed "s/\$/'/" >> $mftt
175 if test -s $mftt
176 then
177 (
178 echo "# pkg-config fixups"
179 . ./$mftt
180 for var in `cut -d = -f 1 < $mftt`; do
181 case $var in
182
183 USE_*_PC)
184 eval "pc_value=\"\$$var\""
185 need_this=''
186 need_core=''
187 if [ ".$DISABLE_TLS" = .yes ]; then
188 # no TLS, not referencing
189 true
190 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
191 need_this=t
192 need_core="gnutls-special"
193 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
194 need_this=t
195 need_core=t
196 fi
197 if [ ".$need_this" != "." ]; then
198 tls_include=`pkg-config --cflags $pc_value`
199 if [ $? -ne 0 ]; then
200 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
201 exit 1
202 fi
203 tls_libs=`pkg-config --libs $pc_value`
204 echo "TLS_INCLUDE=$tls_include"
205 echo "TLS_LIBS += $tls_libs"
206 # With hash.h pulling crypto into the core, we need to also handle that
207 if [ ".$need_this" = ".t" ]; then
208 echo "CFLAGS += $tls_include"
209 echo "LDFLAGS += $tls_libs"
210 elif [ ".$need_this" = ".gnutls-special" ]; then
211 if pkg-config --atleast-version=2.10 gnutls ; then
212 echo "CFLAGS += $tls_include"
213 echo "LDFLAGS += $tls_libs"
214 else
215 echo "CFLAGS += `libgcrypt-config --cflags`"
216 echo "LDFLAGS += `libgcrypt-config --libs`"
217 fi
218 fi
219 fi
220 ;;
221
222 *_PC)
223 eval "pc_value=\"\$$var\""
224 base=`echo $var | sed 's/_PC$//'`
225 eval "basevalue=\"\$$base\""
226 if [ ".$basevalue" = "." ]; then
227 # not pulling in this module, _PC defined as default? Ignore
228 true
229 elif [ $basevalue = 2 ]; then
230 # module; handled in scripts/lookups-Makefile
231 true
232 else
233 # main binary
234 cflags=`pkg-config --cflags $pc_value`
235 if [ $? -ne 0 ]; then
236 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
237 exit 1
238 fi
239 libs=`pkg-config --libs $pc_value`
240 if [ "$var" != "${var#LOOKUP_}" ]; then
241 echo "LOOKUP_INCLUDE += $cflags"
242 echo "LOOKUP_LIBS += $libs"
243 elif [ "$var" != "${var#AUTH_}" ]; then
244 echo "CFLAGS += $cflags"
245 echo "AUTH_LIBS += $libs"
246 elif [ "$var" != "${var#SUPPORT_}" ]; then
247 echo "CFLAGS += $cflags"
248 echo "LIBS += $libs"
249 else
250 echo >&2 "Don't know how to handle pkg-config for $var"
251 fi
252 fi
253 ;;
254
255 PCRE_CONFIG)
256 case $PCRE_CONFIG in
257 yes|YES|y|Y)
258 echo >&2 "pcre is no longer supported; migrate to pcre2"
259 exit 1
260 ;;
261 esac
262 ;;
263
264 PCRE2_CONFIG)
265 case $PCRE2_CONFIG in
266 yes|YES|y|Y)
267 cflags=`pcre2-config --cflags`
268 if [ $? -ne 0 ]; then
269 echo >&2 "*** Missing pcre2-config for regular expression support"
270 exit 1
271 fi
272 libs=`pcre2-config --libs8`
273 if [ ".$cflags" != "." ]; then
274 echo "INCLUDE += $cflags"
275 fi
276 echo "PCRE_LIBS=$libs"
277 ;;
278 esac
279 ;;
280
281 AVOID_GNUTLS_PKCS11)
282 echo "$var=yes"
283 ;;
284
285 esac
286 done
287 echo "# End of pkg-config fixups"
288 echo
289 ) >> $mft
290 subexit=$?
291 if [ $subexit -ne 0 ]; then
292 exit $subexit
293 fi
294 fi
295 rm -f $mftt
296
297
298 # look for RADIUS in $mft; add a SUPPORT_
299 if $egrep -q "^RADIUS_CONFIG_FILE" $mft; then
300 echo "# radius fixup"
301 $egrep -q "^SUPPORT_RADIUS" $mft || echo "SUPPORT_RADIUS=yes" >> $mft
302 fi
303 # also PERL
304 if $egrep -q "^EXIM_PERL" $mft; then
305 echo "# perl fixup"
306 $egrep -q "^SUPPORT_PERL" $mft || echo "SUPPORT_PERL=yes" >> $mft
307 fi
308
309
310 # make the lookups Makefile with the definitions
311 # the auxiliary script generates $look_mf_post from $look_mf_pre
312
313 cp ../src/lookups/Makefile $look_mf_pre
314 EGREP="$egrep" ../scripts/lookups-Makefile
315
316 # Make the Makefiles for routers, transports, auths and miscmods
317 #
318 # Columns in the here-file:
319 # 1 "class" the subdir name to work in
320 # 2 "classdef" is a prefix on the driver name, used for pulling
321 # construction data from Local/Makefile
322 # (remainder) "names" a list of driver names, in caps
323 # An _ prefix on a name means the control in Local/Makefile is DISABLED_<name>
324 #
325 while read class classdef names
326 do
327 cp ../src/$class/Makefile $class/Makefile.predynamic
328 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" EGREP="$egrep" ../scripts/drivers-Makefile
329 mv $class/Makefile.postdynamic $class/Makefile
330 rm $class/Makefile.predynamic
331 done <<-END
332 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
333 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
334 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
335 miscmods SUPPORT ARC _DKIM DMARC DMARC_NATIVE DSCP _EXIM_FILTER PAM PERL PROXY RADIUS _SIEVE_FILTER SOCKS SPF SPF_PERL XCLIENT
336 END
337
338 # See if there is a definition of EXIM_PERL in what we have built so far.
339 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
340 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
341 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
342 # if it has been defined.
343
344 EXIM_PERL=`grep EXIM_PERL $mft`
345
346 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
347 if [ "${PERL_COMMAND}" = "" ] ; then
348 PERL_COMMAND='perl'
349 fi
350
351 if [ "${EXIM_PERL}" != "" ] ; then
352 testperl=`$PERL_COMMAND --version`
353 if [ "$testperl" = "" ] ; then
354 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
355 exit 1
356 fi
357
358 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
359 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
360 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
361 exit 1;
362 fi
363
364 perl_cc="`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`"
365 perl_ccopts="`$PERL_COMMAND -MExtUtils::Embed -e ccopts`"
366 perl_libs="`$PERL_COMMAND -MExtUtils::Embed -e ldopts`"
367
368 # For the dynamic-module build, pull out all the -D & -I into another var,
369 # and -L (maybe & -l?) to another, both for feed to miscmods
370 # ending up as SUPPORT_PERL_INCLUDE & SUPPORT_PERL_LIB respectively
371
372 perl_cflags=`PERL_CCOPTS="$perl_ccopts" $PERL_COMMAND \
373 -e 'my @list = split(" ", $ENV{PERL_CCOPTS});' \
374 -e 'foreach (@list) {print "$_ " if (/^-[DI]/)}'`
375 perl_lflags=`PERL_LIBS="$perl_libs" $PERL_COMMAND \
376 -e 'my @list = split(" ", $ENV{PERL_LIBS});' \
377 -e 'foreach (@list) {print "$_ " if (/^-L/)}'`
378
379 mv $mft $mftt
380 echo "PERL_CC=${perl_cc}" >>$mft
381 echo "PERL_CCOPTS=${perl_ccopts}" >>$mft
382 echo "PERL_LIBS=${perl_libs}" >>$mft
383 echo "PERL_CFLAGS=${perl_cflags}" >>$mft
384 echo "PERL_LFLAGS=${perl_lflags}" >>$mft
385 echo "" >>$mft
386 cat $mftt >> $mft
387 rm -f $mftt
388 fi
389
390 # Record the build variable in the Makefile.
391
392 echo "build=$build" >>$mft
393 echo "" >>$mft
394
395 # Finally, join on the generic base make file, which contains the actual
396 # rules and stuff.
397
398 echo "# From ../OS/Makefile-Base" >> $mft
399 cat ../OS/Makefile-Base >> $mft || exit 1
400
401 # If the new makefile is the same as the existing one, say so, and just
402 # update the timestamp. Otherwise remove the old and install the new.
403
404 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
405 then echo ">>> rebuilt $mf unchanged"
406 echo " "
407 touch $mf || exit
408 rm -f $mft $look_mf_pre $look_mf_post
409 elif rm -f $mf $look_mf $look_mf_pre
410 mv $mft $mf
411 mv $look_mf_post $look_mf
412 then echo ">>> New $mf & $look_mf installed"
413 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
414 echo " "
415 else echo " "
416 echo "*** Failed to install $mf - see $mft"
417 echo " (or $look_mft)"
418 echo " "
419 exit 1;
420 fi
421
422 # vim: set ft=sh :
423 # End of Configure-Makefile