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 # If Makefile is up-to-date, no need to rebuild it.
68 if [ $rebuild = no ] ; then
69 echo "\`Makefile' is up to date."
74 # Makefile needs to be rebuilt in the current directory by joining
75 # the generic default makefile, the OS base makefile, and then local
76 # generic, OS-specific, architecture-specific, and OS+architecture-specific
77 # makefiles, if they exist. These files all contain macro definitions, with
78 # later definitions overriding earlier ones. Make a temporary file first, in
79 # case things go wrong. A second temporary is needed for sorting out the
80 # default Perl stuff. Use short macro names to save typing.
88 look_mf=lookups/Makefile
89 look_mf_pre=${look_mf}.predynamic
90 look_mf_post=${look_mf}.postdynamic
92 # Ensure the temporary does not exist and start the new one by setting
93 # the OSTYPE and ARCHTYPE variables.
95 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
96 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
98 # Now concatenate the files to the temporary file. Copy the files using sed to
99 # remove comments, blank lines, and trailing white space.
101 # BEWARE: a tab character is needed in the sed command below. It has had
102 # a nasty tendency to get lost in the past, causing a problem if a tab has
103 # actually been present in one of the files. Use a variable to hold a space
104 # and a tab to keep the tab in one place.
108 for f in OS/Makefile-Default \
109 OS/Makefile-$ostype \
111 Local/Makefile-$ostype \
112 Local/Makefile-$archtype \
113 Local/Makefile-$ostype-$archtype \
116 then echo "# From $f"
117 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
122 | sed 's/^TMPDIR=/EXIM_&/' \
125 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
126 # wildcards; note that this logic means all setting _appends_ values, never
127 # replacing; if that's a problem, we can revisit.
128 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
129 sed "s/[$st]*\$//" >> $mftepcp
130 if test -s ./$mftepcp
132 # expand any wildcards and strip spaces, to make it a real PATH-like variable
133 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
134 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
136 export PKG_CONFIG_PATH
137 grep -E -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
140 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
141 sed "s/'//g" ./$mftepcp
142 echo "# End of collapsed PKG_CONFIG_PATH"
148 rm -f ./$mftepcp ./$mftepcp2
151 # beware portability of extended regexps with sed.
152 grep -E "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
153 sed "s/[$st]*=/='/" | \
154 sed "s/\$/'/" > $mftt
155 grep -E "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE2?_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
156 sed "s/[$st]*=/='/" | \
157 sed "s/\$/'/" >> $mftt
161 echo "# pkg-config fixups"
163 for var in `cut -d = -f 1 < $mftt`; do
167 eval "pc_value=\"\$$var\""
170 if [ ".$DISABLE_TLS" = .yes ]; then
171 # no TLS, not referencing
173 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
175 need_core="gnutls-special"
176 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
180 if [ ".$need_this" != "." ]; then
181 tls_include=`pkg-config --cflags $pc_value`
182 if [ $? -ne 0 ]; then
183 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
186 tls_libs=`pkg-config --libs $pc_value`
187 echo "TLS_INCLUDE=$tls_include"
188 echo "TLS_LIBS=$tls_libs"
189 # With hash.h pulling crypto into the core, we need to also handle that
190 if [ ".$need_this" = ".t" ]; then
191 echo "CFLAGS += $tls_include"
192 echo "LDFLAGS += $tls_libs"
193 elif [ ".$need_this" = ".gnutls-special" ]; then
194 if pkg-config --atleast-version=2.10 gnutls ; then
195 echo "CFLAGS += $tls_include"
196 echo "LDFLAGS += $tls_libs"
198 echo "CFLAGS += `libgcrypt-config --cflags`"
199 echo "LDFLAGS += `libgcrypt-config --libs`"
206 eval "pc_value=\"\$$var\""
207 base=`echo $var | sed 's/_PC$//'`
208 eval "basevalue=\"\$$base\""
209 if [ ".$basevalue" = "." ]; then
210 # not pulling in this module, _PC defined as default? Ignore
212 elif [ $basevalue = 2 ]; then
213 # module; handled in scripts/lookups-Makefile
217 cflags=`pkg-config --cflags $pc_value`
218 if [ $? -ne 0 ]; then
219 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
222 libs=`pkg-config --libs $pc_value`
223 if [ "$var" != "${var#LOOKUP_}" ]; then
224 echo "LOOKUP_INCLUDE += $cflags"
225 echo "LOOKUP_LIBS += $libs"
226 elif [ "$var" != "${var#AUTH_}" ]; then
227 echo "CFLAGS += $cflags"
228 echo "AUTH_LIBS += $libs"
230 echo >&2 "Don't know how to handle pkg-config for $var"
238 echo >&2 "pcre is no longer supported; migrate to pcre2"
241 # cflags=`pcre-config --cflags`
242 # if [ $? -ne 0 ]; then
243 # echo >&2 "*** Missing pcre-config for regular expression support"
246 # libs=`pcre-config --libs`
247 # if [ ".$cflags" != "." ]; then
248 # echo "INCLUDE += $cflags"
250 # echo "PCRE_LIBS=$libs"
256 case $PCRE2_CONFIG in
258 cflags=`pcre2-config --cflags`
259 if [ $? -ne 0 ]; then
260 echo >&2 "*** Missing pcre2-config for regular expression support"
263 libs=`pcre2-config --libs8`
264 if [ ".$cflags" != "." ]; then
265 echo "INCLUDE += $cflags"
267 echo "PCRE_LIBS=$libs"
278 echo "# End of pkg-config fixups"
282 if [ $subexit -ne 0 ]; then
288 # make the lookups Makefile with the definitions
289 # the auxiliary script generates $look_mf_post from $look_mf_pre
291 cp ../src/lookups/Makefile $look_mf_pre
292 ../scripts/lookups-Makefile
294 while read class classdef names
296 cp ../src/$class/Makefile $class/Makefile.predynamic
297 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" ../scripts/drivers-Makefile
298 mv $class/Makefile.postdynamic $class/Makefile
299 rm $class/Makefile.predynamic
301 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
302 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
303 auths AUTH CRAM_MD5 CYRUS_SASL DOVECOT EXTERNAL GSASL HEIMDAL_GSSAPI PLAINTEXT SPA TLS
307 # See if there is a definition of EXIM_PERL in what we have built so far.
308 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
309 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
310 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
311 # if it has been defined.
313 EXIM_PERL=`grep EXIM_PERL $mft`
315 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
316 if [ "${PERL_COMMAND}" = "" ] ; then
320 if [ "${EXIM_PERL}" != "" ] ; then
321 testperl=`$PERL_COMMAND --version`
322 if [ "$testperl" = "" ] ; then
323 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
327 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
328 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
329 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
334 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
335 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
336 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
342 # Record the build variable in the Makefile.
344 echo "build=$build" >>$mft
347 # Finally, join on the generic base make file, which contains the actual
350 echo "# From ../OS/Makefile-Base" >> $mft
351 cat ../OS/Makefile-Base >> $mft || exit 1
353 # If the new makefile is the same as the existing one, say so, and just
354 # update the timestamp. Otherwise remove the old and install the new.
356 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
357 then echo ">>> rebuilt $mf unchanged"
360 rm -f $mft $look_mf_pre $look_mf_post
361 elif rm -f $mf $look_mf $look_mf_pre
363 mv $look_mf_post $look_mf
364 then echo ">>> New $mf & $look_mf installed"
365 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
368 echo "*** Failed to install $mf - see $mft"
369 echo " (or $look_mft)"
375 # End of Configure-Makefile