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 echo 1 | grep -E 1 >/dev/null; 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)_[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"
240 echo >&2 "Don't know how to handle pkg-config for $var"
248 echo >&2 "pcre is no longer supported; migrate to pcre2"
251 # cflags=`pcre-config --cflags`
252 # if [ $? -ne 0 ]; then
253 # echo >&2 "*** Missing pcre-config for regular expression support"
256 # libs=`pcre-config --libs`
257 # if [ ".$cflags" != "." ]; then
258 # echo "INCLUDE += $cflags"
260 # echo "PCRE_LIBS=$libs"
266 case $PCRE2_CONFIG in
268 cflags=`pcre2-config --cflags`
269 if [ $? -ne 0 ]; then
270 echo >&2 "*** Missing pcre2-config for regular expression support"
273 libs=`pcre2-config --libs8`
274 if [ ".$cflags" != "." ]; then
275 echo "INCLUDE += $cflags"
277 echo "PCRE_LIBS=$libs"
288 echo "# End of pkg-config fixups"
292 if [ $subexit -ne 0 ]; then
298 # make the lookups Makefile with the definitions
299 # the auxiliary script generates $look_mf_post from $look_mf_pre
301 cp ../src/lookups/Makefile $look_mf_pre
302 ../scripts/lookups-Makefile
304 while read class classdef names
306 cp ../src/$class/Makefile $class/Makefile.predynamic
307 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" ../scripts/drivers-Makefile
308 mv $class/Makefile.postdynamic $class/Makefile
309 rm $class/Makefile.predynamic
311 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
312 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
313 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
317 # See if there is a definition of EXIM_PERL in what we have built so far.
318 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
319 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
320 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
321 # if it has been defined.
323 EXIM_PERL=`grep EXIM_PERL $mft`
325 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
326 if [ "${PERL_COMMAND}" = "" ] ; then
330 if [ "${EXIM_PERL}" != "" ] ; then
331 testperl=`$PERL_COMMAND --version`
332 if [ "$testperl" = "" ] ; then
333 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
337 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
338 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
339 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
344 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
345 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
346 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
352 # Record the build variable in the Makefile.
354 echo "build=$build" >>$mft
357 # Finally, join on the generic base make file, which contains the actual
360 echo "# From ../OS/Makefile-Base" >> $mft
361 cat ../OS/Makefile-Base >> $mft || exit 1
363 # If the new makefile is the same as the existing one, say so, and just
364 # update the timestamp. Otherwise remove the old and install the new.
366 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
367 then echo ">>> rebuilt $mf unchanged"
370 rm -f $mft $look_mf_pre $look_mf_post
371 elif rm -f $mf $look_mf $look_mf_pre
373 mv $look_mf_post $look_mf
374 then echo ">>> New $mf & $look_mf installed"
375 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
378 echo "*** Failed to install $mf - see $mft"
379 echo " (or $look_mft)"
385 # End of Configure-Makefile