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)_[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"
255 case $PCRE2_CONFIG in
257 cflags=`pcre2-config --cflags`
258 if [ $? -ne 0 ]; then
259 echo >&2 "*** Missing pcre2-config for regular expression support"
262 libs=`pcre2-config --libs8`
263 if [ ".$cflags" != "." ]; then
264 echo "INCLUDE += $cflags"
266 echo "PCRE_LIBS=$libs"
277 echo "# End of pkg-config fixups"
281 if [ $subexit -ne 0 ]; then
287 #XXX look for RADIUS in $mft; add a SUPPORT_
288 if $egrep -q "^RADIUS_CONFIG_FILE" $mft; then
289 echo "# radius fixup"
290 $egrep -q "^SUPPORT_RADIUS" $mft || echo "SUPPORT_RADIUS=yes" >> $mft
294 # make the lookups Makefile with the definitions
295 # the auxiliary script generates $look_mf_post from $look_mf_pre
297 cp ../src/lookups/Makefile $look_mf_pre
298 ../scripts/lookups-Makefile
300 # make the Makefiles for routers, transports, auths and miscmods
302 while read class classdef names
304 cp ../src/$class/Makefile $class/Makefile.predynamic
305 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" EGREP="$egrep" ../scripts/drivers-Makefile
306 mv $class/Makefile.postdynamic $class/Makefile
307 rm $class/Makefile.predynamic
309 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
310 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
311 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
312 miscmods SUPPORT ARC _DKIM DMARC PAM RADIUS SPF
315 # See if there is a definition of EXIM_PERL in what we have built so far.
316 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
317 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
318 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
319 # if it has been defined.
321 EXIM_PERL=`grep EXIM_PERL $mft`
323 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
324 if [ "${PERL_COMMAND}" = "" ] ; then
328 if [ "${EXIM_PERL}" != "" ] ; then
329 testperl=`$PERL_COMMAND --version`
330 if [ "$testperl" = "" ] ; then
331 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
335 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
336 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
337 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
342 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
343 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
344 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
350 # Record the build variable in the Makefile.
352 echo "build=$build" >>$mft
355 # Finally, join on the generic base make file, which contains the actual
358 echo "# From ../OS/Makefile-Base" >> $mft
359 cat ../OS/Makefile-Base >> $mft || exit 1
361 # If the new makefile is the same as the existing one, say so, and just
362 # update the timestamp. Otherwise remove the old and install the new.
364 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
365 then echo ">>> rebuilt $mf unchanged"
368 rm -f $mft $look_mf_pre $look_mf_post
369 elif rm -f $mf $look_mf $look_mf_pre
371 mv $look_mf_post $look_mf
372 then echo ">>> New $mf & $look_mf installed"
373 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
376 echo "*** Failed to install $mf - see $mft"
377 echo " (or $look_mft)"
383 # End of Configure-Makefile