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.
7 # Copyright (c) The Exim Maintainers 1995 - 2024
8 # SPDX-License-Identifier: GPL-2.0-or-later
15 # First off, get the OS type, and check that there is a make file for it.
17 ostype=`../scripts/os-type -generic` || exit 1
19 if [ ! -r ../OS/Makefile-$ostype ] ; then
21 echo "*** Sorry - operating system $ostype is not supported"
22 echo "*** See OS/Makefile-* for supported systems" 1>&2
27 # We also need the architecture type, in order to test for any architecture-
28 # specific configuration files.
30 archtype=`../scripts/arch-type` || exit 1
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.
36 editme=../Local/Makefile
39 if [ -f Makefile ] ; then
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 ../OS/Makefile-Base Makefile || \
47 ../scripts/newer ../OS/Makefile-Default Makefile
53 # If the "build" variable is set it means that a build name was explicitly
54 # given. Arrange to pick up a build-specific configuration file.
56 if [ "X$build" != "X" ] ; then
57 mfb=Local/Makefile-$build
58 if ../scripts/newer $editme-$build Makefile ; then
66 # Linux now whines about egrep, saying "use grep -E".
67 # Solarix doesn't support -E on grep. Thanks so much for
68 # going non-back-compatible, Linux.
69 if [ "$ostype" != "SunOS5" ] ; then
76 # If Makefile is up-to-date, no need to rebuild it.
78 if [ $rebuild = no ] ; then
79 echo "\`Makefile' is up to date."
84 # Makefile needs to be rebuilt in the current directory by joining
85 # the generic default makefile, the OS base makefile, and then local
86 # generic, OS-specific, architecture-specific, and OS+architecture-specific
87 # makefiles, if they exist. These files all contain macro definitions, with
88 # later definitions overriding earlier ones. Make a temporary file first, in
89 # case things go wrong. A second temporary is needed for sorting out the
90 # default Perl stuff. Use short macro names to save typing.
98 look_mf=lookups/Makefile
99 look_mf_pre=${look_mf}.predynamic
100 look_mf_post=${look_mf}.postdynamic
102 # Ensure the temporary does not exist and start the new one by setting
103 # the OSTYPE and ARCHTYPE variables.
105 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
106 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
108 # Now concatenate the files to the temporary file. Copy the files using sed to
109 # remove comments, blank lines, and trailing white space.
111 # BEWARE: a tab character is needed in the sed command below. It has had
112 # a nasty tendency to get lost in the past, causing a problem if a tab has
113 # actually been present in one of the files. Use a variable to hold a space
114 # and a tab to keep the tab in one place.
118 for f in OS/Makefile-Default \
119 OS/Makefile-$ostype \
121 Local/Makefile-$ostype \
122 Local/Makefile-$archtype \
123 Local/Makefile-$ostype-$archtype \
126 then echo "# From $f"
127 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
132 | sed 's/^TMPDIR=/EXIM_&/' \
135 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
136 # wildcards; note that this logic means all setting _appends_ values, never
137 # replacing; if that's a problem, we can revisit.
138 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
139 sed "s/[$st]*\$//" >> $mftepcp
140 if test -s ./$mftepcp
142 # expand any wildcards and strip spaces, to make it a real PATH-like variable
143 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
144 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
146 export PKG_CONFIG_PATH
147 $egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
150 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
151 sed "s/'//g" ./$mftepcp
152 echo "# End of collapsed PKG_CONFIG_PATH"
158 rm -f ./$mftepcp ./$mftepcp2
161 # beware portability of extended regexps with sed.
162 $egrep "^[$st]*(AUTH|LOOKUP|SUPPORT)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
163 sed "s/[$st]*=/='/" | \
164 sed "s/\$/'/" > $mftt
165 $egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE2?_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
166 sed "s/[$st]*=/='/" | \
167 sed "s/\$/'/" >> $mftt
171 echo "# pkg-config fixups"
173 for var in `cut -d = -f 1 < $mftt`; do
177 eval "pc_value=\"\$$var\""
180 if [ ".$DISABLE_TLS" = .yes ]; then
181 # no TLS, not referencing
183 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
185 need_core="gnutls-special"
186 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
190 if [ ".$need_this" != "." ]; then
191 tls_include=`pkg-config --cflags $pc_value`
192 if [ $? -ne 0 ]; then
193 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
196 tls_libs=`pkg-config --libs $pc_value`
197 echo "TLS_INCLUDE=$tls_include"
198 echo "TLS_LIBS=$tls_libs"
199 # With hash.h pulling crypto into the core, we need to also handle that
200 if [ ".$need_this" = ".t" ]; then
201 echo "CFLAGS += $tls_include"
202 echo "LDFLAGS += $tls_libs"
203 elif [ ".$need_this" = ".gnutls-special" ]; then
204 if pkg-config --atleast-version=2.10 gnutls ; then
205 echo "CFLAGS += $tls_include"
206 echo "LDFLAGS += $tls_libs"
208 echo "CFLAGS += `libgcrypt-config --cflags`"
209 echo "LDFLAGS += `libgcrypt-config --libs`"
216 eval "pc_value=\"\$$var\""
217 base=`echo $var | sed 's/_PC$//'`
218 eval "basevalue=\"\$$base\""
219 if [ ".$basevalue" = "." ]; then
220 # not pulling in this module, _PC defined as default? Ignore
222 elif [ $basevalue = 2 ]; then
223 # module; handled in scripts/lookups-Makefile
227 cflags=`pkg-config --cflags $pc_value`
228 if [ $? -ne 0 ]; then
229 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
232 libs=`pkg-config --libs $pc_value`
233 if [ "$var" != "${var#LOOKUP_}" ]; then
234 echo "LOOKUP_INCLUDE += $cflags"
235 echo "LOOKUP_LIBS += $libs"
236 elif [ "$var" != "${var#AUTH_}" ]; then
237 echo "CFLAGS += $cflags"
238 echo "AUTH_LIBS += $libs"
239 elif [ "$var" != "${var#SUPPORT_}" ]; then
240 echo "CFLAGS += $cflags"
243 echo >&2 "Don't know how to handle pkg-config for $var"
251 echo >&2 "pcre is no longer supported; migrate to pcre2"
258 case $PCRE2_CONFIG in
260 cflags=`pcre2-config --cflags`
261 if [ $? -ne 0 ]; then
262 echo >&2 "*** Missing pcre2-config for regular expression support"
265 libs=`pcre2-config --libs8`
266 if [ ".$cflags" != "." ]; then
267 echo "INCLUDE += $cflags"
269 echo "PCRE_LIBS=$libs"
280 echo "# End of pkg-config fixups"
284 if [ $subexit -ne 0 ]; then
291 # look for RADIUS in $mft; add a SUPPORT_
292 if $egrep -q "^RADIUS_CONFIG_FILE" $mft; then
293 echo "# radius fixup"
294 $egrep -q "^SUPPORT_RADIUS" $mft || echo "SUPPORT_RADIUS=yes" >> $mft
297 if $egrep -q "^EXIM_PERL" $mft; then
299 $egrep -q "^SUPPORT_PERL" $mft || echo "SUPPORT_PERL=yes" >> $mft
303 # make the lookups Makefile with the definitions
304 # the auxiliary script generates $look_mf_post from $look_mf_pre
306 cp ../src/lookups/Makefile $look_mf_pre
307 ../scripts/lookups-Makefile
309 # make the Makefiles for routers, transports, auths and miscmods
311 while read class classdef names
313 cp ../src/$class/Makefile $class/Makefile.predynamic
314 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" EGREP="$egrep" ../scripts/drivers-Makefile
315 mv $class/Makefile.postdynamic $class/Makefile
316 rm $class/Makefile.predynamic
318 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
319 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
320 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
321 miscmods SUPPORT ARC _DKIM DMARC _EXIM_FILTER PAM PERL RADIUS _SIEVE_FILTER SPF
324 # See if there is a definition of EXIM_PERL in what we have built so far.
325 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
326 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
327 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
328 # if it has been defined.
330 EXIM_PERL=`grep EXIM_PERL $mft`
332 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
333 if [ "${PERL_COMMAND}" = "" ] ; then
337 if [ "${EXIM_PERL}" != "" ] ; then
338 testperl=`$PERL_COMMAND --version`
339 if [ "$testperl" = "" ] ; then
340 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
344 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
345 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
346 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
350 perl_cc="`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`"
351 perl_ccopts="`$PERL_COMMAND -MExtUtils::Embed -e ccopts`"
352 perl_libs="`$PERL_COMMAND -MExtUtils::Embed -e ldopts`"
354 # For the dynamic-module build, pull out all the -D & -I into another var,
355 # and -L (maybe & -l?) to another, both for feed to miscmods
356 # ending up as SUPPORT_PERL_INCLUDE & SUPPORT_PERL_LIB respectively
358 perl_cflags=`PERL_CCOPTS="$perl_ccopts" $PERL_COMMAND \
359 -e 'my @list = split(" ", $ENV{PERL_CCOPTS});' \
360 -e 'foreach (@list) {print "$_ " if (/^-[DI]/)}'`
361 perl_lflags=`PERL_LIBS="$perl_libs" $PERL_COMMAND \
362 -e 'my @list = split(" ", $ENV{PERL_LIBS});' \
363 -e 'foreach (@list) {print "$_ " if (/^-L/)}'`
366 echo "PERL_CC=${perl_cc}" >>$mft
367 echo "PERL_CCOPTS=${perl_ccopts}" >>$mft
368 echo "PERL_LIBS=${perl_libs}" >>$mft
369 echo "PERL_CFLAGS=${perl_cflags}" >>$mft
370 echo "PERL_LFLAGS=${perl_lflags}" >>$mft
376 # Record the build variable in the Makefile.
378 echo "build=$build" >>$mft
381 # Finally, join on the generic base make file, which contains the actual
384 echo "# From ../OS/Makefile-Base" >> $mft
385 cat ../OS/Makefile-Base >> $mft || exit 1
387 # If the new makefile is the same as the existing one, say so, and just
388 # update the timestamp. Otherwise remove the old and install the new.
390 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
391 then echo ">>> rebuilt $mf unchanged"
394 rm -f $mft $look_mf_pre $look_mf_post
395 elif rm -f $mf $look_mf $look_mf_pre
397 mv $look_mf_post $look_mf
398 then echo ">>> New $mf & $look_mf installed"
399 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
402 echo "*** Failed to install $mf - see $mft"
403 echo " (or $look_mft)"
409 # End of Configure-Makefile