Debian Codegraph @

scripts/Configure-Makefile

raw symbols SCIP
1 #! /bin/shscip-shell filesystem . . `/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 [scip-shell system . . `[`. ! -r ../OS/Makefile-$ostype ] ; then
20 echoscip-shell system . . echo. ""
21 echoscip-shell system . . echo. "*** Sorry - operating system $ostype is not supported"
22 echoscip-shell system . . echo. "*** See OS/Makefile-* for supported systems" 1>&2
23 echoscip-shell system . . 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 [scip-shell system . . `[`. -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 [scip-shell system . . `[`. "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 [scip-shell system . . `[`. "$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 [scip-shell system . . `[`. $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 rmscip-shell system . . rm. -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
113 (echoscip-shell system . . echo. "OSTYPE=$ostype"; echoscip-shell system . . echo. "ARCHTYPE=$archtype"; echoscip-shell system . . 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 testscip-shell system . . test. -r ../$f
133 then echoscip-shell system . . echo. "# From $f"
134 sedscip-shell system . . sed. "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
135 echoscip-shell system . . echo. "# End of $f"
136 echoscip-shell system . . echo. ""
137 fi
138 done \
139 | sedscip-shell system . . 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 sedscip-shell system . . sed. -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
146 sed "s/[$st]*\$//" >> $mftepcp
147 if testscip-shell system . . 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 `catscip-shell system . . cat. ./$mftepcp`; do echoscip-shell system . . echo. "$P"; done ) | xargsscip-shell system . . xargs. | sedscip-shell system . . sed. "s/[$st]/:/g" >./$mftepcp2
151 sedscip-shell system . . sed. "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sedscip-shell system . . sed. "s/\$/'/" > ./$mftepcp
152 . ./$mftepcp
153 export PKG_CONFIG_PATH
154 $egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
155 rmscip-shell system . . rm. -f ./$mft
156 (
157 echoscip-shell system . . echo. "# Collapsed PKG_CONFIG_PATH in build-prep:"
158 sedscip-shell system . . sed. "s/'//g" ./$mftepcp
159 echoscip-shell system . . echo. "# End of collapsed PKG_CONFIG_PATH"
160 echoscip-shell system . . echo. ""
161 catscip-shell system . . cat. ./$mftt
162 ) > ./$mft
163 rmscip-shell system . . rm. -f ./$mftt
164 fi
165 rmscip-shell system . . 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 testscip-shell system . . test. -s $mftt
176 then
177 (
178 echoscip-shell system . . echo. "# pkg-config fixups"
179 . ./$mftt
180 for var in `cutscip-shell system . . 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 [scip-shell system . . `[`. ".$DISABLE_TLS" = .yes ]; then
188 # no TLS, not referencing
189 truescip-shell system . . true.
190 elif [scip-shell system . . `[`. ".$var" = ".USE_GNUTLS_PC" ] && [scip-shell system . . `[`. ".$USE_GNUTLS" != "." ]; then
191 need_this=t
192 need_core="gnutls-special"
193 elif [scip-shell system . . `[`. ".$var" = ".USE_OPENSSL_PC" ] && [scip-shell system . . `[`. ".$USE_GNUTLS" = "." ]; then
194 need_this=t
195 need_core=t
196 fi
197 if [scip-shell system . . `[`. ".$need_this" != "." ]; then
198 tls_include=`pkg-config --cflags $pc_value`
199 if [scip-shell system . . `[`. $? -ne 0 ]; then
200 echoscip-shell system . . 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 echoscip-shell system . . echo. "TLS_INCLUDE=$tls_include"
205 echoscip-shell system . . echo. "TLS_LIBS += $tls_libs"
206 # With hash.h pulling crypto into the core, we need to also handle that
207 if [scip-shell system . . `[`. ".$need_this" = ".t" ]; then
208 echoscip-shell system . . echo. "CFLAGS += $tls_include"
209 echoscip-shell system . . echo. "LDFLAGS += $tls_libs"
210 elif [scip-shell system . . `[`. ".$need_this" = ".gnutls-special" ]; then
211 if pkg-config --atleast-version=2.10 gnutls ; then
212 echoscip-shell system . . echo. "CFLAGS += $tls_include"
213 echoscip-shell system . . echo. "LDFLAGS += $tls_libs"
214 else
215 echoscip-shell system . . echo. "CFLAGS += `libgcrypt-config --cflags`"
216 echoscip-shell system . . echo. "LDFLAGS += `libgcrypt-config --libs`"
217 fi
218 fi
219 fi
220 ;;
221
222 *_PC)
223 eval "pc_value=\"\$$var\""
224 base=`echoscip-shell system . . echo. $var | sedscip-shell system . . sed. 's/_PC$//'`
225 eval "basevalue=\"\$$base\""
226 if [scip-shell system . . `[`. ".$basevalue" = "." ]; then
227 # not pulling in this module, _PC defined as default? Ignore
228 truescip-shell system . . true.
229 elif [scip-shell system . . `[`. $basevalue = 2 ]; then
230 # module; handled in scripts/lookups-Makefile
231 truescip-shell system . . true.
232 else
233 # main binary
234 cflags=`pkg-config --cflags $pc_value`
235 if [scip-shell system . . `[`. $? -ne 0 ]; then
236 echoscip-shell system . . 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 [scip-shell system . . `[`. "$var" != "${var#LOOKUP_}" ]; then
241 echoscip-shell system . . echo. "LOOKUP_INCLUDE += $cflags"
242 echoscip-shell system . . echo. "LOOKUP_LIBS += $libs"
243 elif [scip-shell system . . `[`. "$var" != "${var#AUTH_}" ]; then
244 echoscip-shell system . . echo. "CFLAGS += $cflags"
245 echoscip-shell system . . echo. "AUTH_LIBS += $libs"
246 elif [scip-shell system . . `[`. "$var" != "${var#SUPPORT_}" ]; then
247 echoscip-shell system . . echo. "CFLAGS += $cflags"
248 echoscip-shell system . . echo. "LIBS += $libs"
249 else
250 echoscip-shell system . . 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 echoscip-shell system . . 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 [scip-shell system . . `[`. $? -ne 0 ]; then
269 echoscip-shell system . . echo. >&2 "*** Missing pcre2-config for regular expression support"
270 exit 1
271 fi
272 libs=`pcre2-config --libs8`
273 if [scip-shell system . . `[`. ".$cflags" != "." ]; then
274 echoscip-shell system . . echo. "INCLUDE += $cflags"
275 fi
276 echoscip-shell system . . echo. "PCRE_LIBS=$libs"
277 ;;
278 esac
279 ;;
280
281 AVOID_GNUTLS_PKCS11)
282 echoscip-shell system . . echo. "$var=yes"
283 ;;
284
285 esac
286 done
287 echoscip-shell system . . echo. "# End of pkg-config fixups"
288 echoscip-shell system . . echo.
289 ) >> $mft
290 subexit=$?
291 if [scip-shell system . . `[`. $subexit -ne 0 ]; then
292 exit $subexit
293 fi
294 fi
295 rmscip-shell system . . rm. -f $mftt
296
297
298 # look for RADIUS in $mft; add a SUPPORT_
299 if $egrep -q "^RADIUS_CONFIG_FILE" $mft; then
300 echoscip-shell system . . echo. "# radius fixup"
301 $egrep -q "^SUPPORT_RADIUS" $mft || echoscip-shell system . . echo. "SUPPORT_RADIUS=yes" >> $mft
302 fi
303 # also PERL
304 if $egrep -q "^EXIM_PERL" $mft; then
305 echoscip-shell system . . echo. "# perl fixup"
306 $egrep -q "^SUPPORT_PERL" $mft || echoscip-shell system . . 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 cpscip-shell system . . 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 cpscip-shell system . . cp. ../src/$class/Makefile $class/Makefile.predynamic
328 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" EGREP="$egrep" ../scripts/drivers-Makefile
329 mvscip-shell system . . mv. $class/Makefile.postdynamic $class/Makefile
330 rmscip-shell system . . 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=`grepscip-shell system . . grep. EXIM_PERL $mft`
345
346 PERL_COMMAND=`grepscip-shell system . . grep. PERL_COMMAND $mft | sedscip-shell system . . sed. -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
347 if [scip-shell system . . `[`. "${PERL_COMMAND}" = "" ] ; then
348 PERL_COMMAND='perl'
349 fi
350
351 if [scip-shell system . . `[`. "${EXIM_PERL}" != "" ] ; then
352 testperl=`$PERL_COMMAND --version`
353 if [scip-shell system . . `[`. "$testperl" = "" ] ; then
354 echoscip-shell system . . 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 [scip-shell system . . `[`. "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
360 echoscip-shell system . . 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 mvscip-shell system . . mv. $mft $mftt
380 echoscip-shell system . . echo. "PERL_CC=${perl_cc}" >>$mft
381 echoscip-shell system . . echo. "PERL_CCOPTS=${perl_ccopts}" >>$mft
382 echoscip-shell system . . echo. "PERL_LIBS=${perl_libs}" >>$mft
383 echoscip-shell system . . echo. "PERL_CFLAGS=${perl_cflags}" >>$mft
384 echoscip-shell system . . echo. "PERL_LFLAGS=${perl_lflags}" >>$mft
385 echoscip-shell system . . echo. "" >>$mft
386 catscip-shell system . . cat. $mftt >> $mft
387 rmscip-shell system . . rm. -f $mftt
388 fi
389
390 # Record the build variable in the Makefile.
391
392 echoscip-shell system . . echo. "build=$build" >>$mft
393 echoscip-shell system . . echo. "" >>$mft
394
395 # Finally, join on the generic base make file, which contains the actual
396 # rules and stuff.
397
398 echoscip-shell system . . echo. "# From ../OS/Makefile-Base" >> $mft
399 catscip-shell system . . 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 [scip-shell system . . `[`. -s $mf ] && cmpscip-shell system . . cmp. -s $mft $mf && [scip-shell system . . `[`. -s $look_mf ] && cmpscip-shell system . . cmp. -s $look_mf_post $look_mf
405 then echoscip-shell system . . echo. ">>> rebuilt $mf unchanged"
406 echoscip-shell system . . echo. " "
407 touchscip-shell system . . touch. $mf || exit
408 rmscip-shell system . . rm. -f $mft $look_mf_pre $look_mf_post
409 elif rmscip-shell system . . rm. -f $mf $look_mf $look_mf_pre
410 mvscip-shell system . . mv. $mft $mf
411 mvscip-shell system . . mv. $look_mf_post $look_mf
412 then echoscip-shell system . . echo. ">>> New $mf & $look_mf installed"
413 echoscip-shell system . . echo. '>>> Use "make makefile" if you need to force rebuilding of the makefile'
414 echoscip-shell system . . echo. " "
415 else echoscip-shell system . . echo. " "
416 echoscip-shell system . . echo. "*** Failed to install $mf - see $mft"
417 echoscip-shell system . . echo. " (or $look_mft)"
418 echoscip-shell system . . echo. " "
419 exit 1;
420 fi
421
422 # vim: set ft=sh :
423 # End of Configure-Makefile