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 # Linux now whines about egrep, saying "use grep -E".
33 # Solarix doesn't support -E on grep. Thanks so much for
34 # going non-back-compatible, Linux.
35 if echo 1 | grep -E 1 >/dev/null; then
42 # Now test for either the non-existence of Makefile, or for any of its
43 # components being newer. Note that the "newer" script gives the right
44 # answer (for our purposes) when the first file is non-existent.
46 editme=../Local/Makefile
49 if [ -f Makefile ] ; then
51 if ../scripts/newer $editme Makefile || \
52 ../scripts/newer $editme-$ostype Makefile || \
53 ../scripts/newer $editme-$archtype Makefile || \
54 ../scripts/newer $editme-$ostype-$archtype Makefile || \
55 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
56 ../scripts/newer ../OS/Makefile-Base Makefile || \
57 ../scripts/newer ../OS/Makefile-Default Makefile
63 # If the "build" variable is set it means that a build name was explicitly
64 # given. Arrange to pick up a build-specific configuration file.
66 if [ "X$build" != "X" ] ; then
67 mfb=Local/Makefile-$build
68 if ../scripts/newer $editme-$build Makefile ; then
76 # Linux now whines about egrep, saying "use grep -E".
77 # Solarix doesn't support -E on grep. Thanks so much for
78 # going non-back-compatible, Linux.
79 if echo 1 | grep -E 1 >/dev/null; then
86 # If Makefile is up-to-date, no need to rebuild it.
88 if [ $rebuild = no ] ; then
89 echo "\`Makefile' is up to date."
94 # Makefile needs to be rebuilt in the current directory by joining
95 # the generic default makefile, the OS base makefile, and then local
96 # generic, OS-specific, architecture-specific, and OS+architecture-specific
97 # makefiles, if they exist. These files all contain macro definitions, with
98 # later definitions overriding earlier ones. Make a temporary file first, in
99 # case things go wrong. A second temporary is needed for sorting out the
100 # default Perl stuff. Use short macro names to save typing.
108 look_mf=lookups/Makefile
109 look_mf_pre=${look_mf}.predynamic
110 look_mf_post=${look_mf}.postdynamic
112 # Ensure the temporary does not exist and start the new one by setting
113 # the OSTYPE and ARCHTYPE variables.
115 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
116 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
118 # Now concatenate the files to the temporary file. Copy the files using sed to
119 # remove comments, blank lines, and trailing white space.
121 # BEWARE: a tab character is needed in the sed command below. It has had
122 # a nasty tendency to get lost in the past, causing a problem if a tab has
123 # actually been present in one of the files. Use a variable to hold a space
124 # and a tab to keep the tab in one place.
128 for f in OS/Makefile-Default \
129 OS/Makefile-$ostype \
131 Local/Makefile-$ostype \
132 Local/Makefile-$archtype \
133 Local/Makefile-$ostype-$archtype \
136 then echo "# From $f"
137 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
142 | sed 's/^TMPDIR=/EXIM_&/' \
145 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
146 # wildcards; note that this logic means all setting _appends_ values, never
147 # replacing; if that's a problem, we can revisit.
148 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
149 sed "s/[$st]*\$//" >> $mftepcp
150 if test -s ./$mftepcp
152 # expand any wildcards and strip spaces, to make it a real PATH-like variable
153 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
154 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
156 export PKG_CONFIG_PATH
157 $egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
160 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
161 sed "s/'//g" ./$mftepcp
162 echo "# End of collapsed PKG_CONFIG_PATH"
168 rm -f ./$mftepcp ./$mftepcp2
171 # beware portability of extended regexps with sed.
172 $egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
173 sed "s/[$st]*=/='/" | \
174 sed "s/\$/'/" > $mftt
175 $egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE2?_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
176 sed "s/[$st]*=/='/" | \
177 sed "s/\$/'/" >> $mftt
181 echo "# pkg-config fixups"
183 for var in `cut -d = -f 1 < $mftt`; do
187 eval "pc_value=\"\$$var\""
190 if [ ".$DISABLE_TLS" = .yes ]; then
191 # no TLS, not referencing
193 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
195 need_core="gnutls-special"
196 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
200 if [ ".$need_this" != "." ]; then
201 tls_include=`pkg-config --cflags $pc_value`
202 if [ $? -ne 0 ]; then
203 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
206 tls_libs=`pkg-config --libs $pc_value`
207 echo "TLS_INCLUDE=$tls_include"
208 echo "TLS_LIBS=$tls_libs"
209 # With hash.h pulling crypto into the core, we need to also handle that
210 if [ ".$need_this" = ".t" ]; then
211 echo "CFLAGS += $tls_include"
212 echo "LDFLAGS += $tls_libs"
213 elif [ ".$need_this" = ".gnutls-special" ]; then
214 if pkg-config --atleast-version=2.10 gnutls ; then
215 echo "CFLAGS += $tls_include"
216 echo "LDFLAGS += $tls_libs"
218 echo "CFLAGS += `libgcrypt-config --cflags`"
219 echo "LDFLAGS += `libgcrypt-config --libs`"
226 eval "pc_value=\"\$$var\""
227 base=`echo $var | sed 's/_PC$//'`
228 eval "basevalue=\"\$$base\""
229 if [ ".$basevalue" = "." ]; then
230 # not pulling in this module, _PC defined as default? Ignore
232 elif [ $basevalue = 2 ]; then
233 # module; handled in scripts/lookups-Makefile
237 cflags=`pkg-config --cflags $pc_value`
238 if [ $? -ne 0 ]; then
239 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
242 libs=`pkg-config --libs $pc_value`
243 if [ "$var" != "${var#LOOKUP_}" ]; then
244 echo "LOOKUP_INCLUDE += $cflags"
245 echo "LOOKUP_LIBS += $libs"
246 elif [ "$var" != "${var#AUTH_}" ]; then
247 echo "CFLAGS += $cflags"
248 echo "AUTH_LIBS += $libs"
250 echo >&2 "Don't know how to handle pkg-config for $var"
258 echo >&2 "pcre is no longer supported; migrate to pcre2"
261 # cflags=`pcre-config --cflags`
262 # if [ $? -ne 0 ]; then
263 # echo >&2 "*** Missing pcre-config for regular expression support"
266 # libs=`pcre-config --libs`
267 # if [ ".$cflags" != "." ]; then
268 # echo "INCLUDE += $cflags"
270 # echo "PCRE_LIBS=$libs"
276 case $PCRE2_CONFIG in
278 cflags=`pcre2-config --cflags`
279 if [ $? -ne 0 ]; then
280 echo >&2 "*** Missing pcre2-config for regular expression support"
283 libs=`pcre2-config --libs8`
284 if [ ".$cflags" != "." ]; then
285 echo "INCLUDE += $cflags"
287 echo "PCRE_LIBS=$libs"
298 echo "# End of pkg-config fixups"
302 if [ $subexit -ne 0 ]; then
308 # make the lookups Makefile with the definitions
309 # the auxiliary script generates $look_mf_post from $look_mf_pre
311 cp ../src/lookups/Makefile $look_mf_pre
312 ../scripts/lookups-Makefile
314 while read class classdef names
316 cp ../src/$class/Makefile $class/Makefile.predynamic
317 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" ../scripts/drivers-Makefile
318 mv $class/Makefile.postdynamic $class/Makefile
319 rm $class/Makefile.predynamic
321 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
322 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
323 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
324 miscmods SUPPORT SPF DMARC
327 # See if there is a definition of EXIM_PERL in what we have built so far.
328 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
329 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
330 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
331 # if it has been defined.
333 EXIM_PERL=`grep EXIM_PERL $mft`
335 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
336 if [ "${PERL_COMMAND}" = "" ] ; then
340 if [ "${EXIM_PERL}" != "" ] ; then
341 testperl=`$PERL_COMMAND --version`
342 if [ "$testperl" = "" ] ; then
343 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
347 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
348 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
349 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
354 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
355 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
356 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
362 # Record the build variable in the Makefile.
364 echo "build=$build" >>$mft
367 # Finally, join on the generic base make file, which contains the actual
370 echo "# From ../OS/Makefile-Base" >> $mft
371 cat ../OS/Makefile-Base >> $mft || exit 1
373 # If the new makefile is the same as the existing one, say so, and just
374 # update the timestamp. Otherwise remove the old and install the new.
376 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
377 then echo ">>> rebuilt $mf unchanged"
380 rm -f $mft $look_mf_pre $look_mf_post
381 elif rm -f $mf $look_mf $look_mf_pre
383 mv $look_mf_post $look_mf
384 then echo ">>> New $mf & $look_mf installed"
385 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
388 echo "*** Failed to install $mf - see $mft"
389 echo " (or $look_mft)"
395 # End of Configure-Makefile