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
16 # First off, get the OS type, and check that there is a make file for it.
18 ostype=`../scripts/os-type -generic` || exit 1
20 if [ ! -r ../OS/Makefile-$ostype ] ; then
22 echo "*** Sorry - operating system $ostype is not supported"
23 echo "*** See OS/Makefile-* for supported systems" 1>&2
28 # We also need the architecture type, in order to test for any architecture-
29 # specific configuration files.
31 archtype=`../scripts/arch-type` || exit 1
33 # Now test for either the non-existence of Makefile, or for any of its
34 # components being newer. Note that the "newer" script gives the right
35 # answer (for our purposes) when the first file is non-existent.
37 editme=../Local/Makefile
40 if [ -f Makefile ] ; then
42 if ../scripts/newer $editme Makefile || \
43 ../scripts/newer $editme-$ostype Makefile || \
44 ../scripts/newer $editme-$archtype Makefile || \
45 ../scripts/newer $editme-$ostype-$archtype Makefile || \
46 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
47 ../scripts/newer ../OS/Makefile-Base Makefile || \
48 ../scripts/newer ../OS/Makefile-Default Makefile
54 # If the "build" variable is set it means that a build name was explicitly
55 # given. Arrange to pick up a build-specific configuration file.
57 if [ "X$build" != "X" ] ; then
58 mfb=Local/Makefile-$build
59 if ../scripts/newer $editme-$build Makefile ; then
67 # If Makefile is up-to-date, no need to rebuild it.
69 if [ $rebuild = no ] ; then
70 echo "\`Makefile' is up to date."
75 # Makefile needs to be rebuilt in the current directory by joining
76 # the generic default makefile, the OS base makefile, and then local
77 # generic, OS-specific, architecture-specific, and OS+architecture-specific
78 # makefiles, if they exist. These files all contain macro definitions, with
79 # later definitions overriding earlier ones. Make a temporary file first, in
80 # case things go wrong. A second temporary is needed for sorting out the
81 # default Perl stuff. Use short macro names to save typing.
89 look_mf=lookups/Makefile
90 look_mf_pre=${look_mf}.predynamic
91 look_mf_post=${look_mf}.postdynamic
93 # Ensure the temporary does not exist and start the new one by setting
94 # the OSTYPE and ARCHTYPE variables.
96 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
97 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
99 # Now concatenate the files to the temporary file. Copy the files using sed to
100 # remove comments, blank lines, and trailing white space.
102 # BEWARE: a tab character is needed in the sed command below. It has had
103 # a nasty tendency to get lost in the past, causing a problem if a tab has
104 # actually been present in one of the files. Use a variable to hold a space
105 # and a tab to keep the tab in one place.
109 for f in OS/Makefile-Default \
110 OS/Makefile-$ostype \
112 Local/Makefile-$ostype \
113 Local/Makefile-$archtype \
114 Local/Makefile-$ostype-$archtype \
117 then echo "# From $f"
118 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
123 | sed 's/^TMPDIR=/EXIM_&/' \
126 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
127 # wildcards; note that this logic means all setting _appends_ values, never
128 # replacing; if that's a problem, we can revisit.
129 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
130 sed "s/[$st]*\$//" >> $mftepcp
131 if test -s ./$mftepcp
133 # expand any wildcards and strip spaces, to make it a real PATH-like variable
134 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
135 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
137 export PKG_CONFIG_PATH
138 grep -E -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
141 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
142 sed "s/'//g" ./$mftepcp
143 echo "# End of collapsed PKG_CONFIG_PATH"
149 rm -f ./$mftepcp ./$mftepcp2
152 # beware portability of extended regexps with sed.
153 grep -E "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
154 sed "s/[$st]*=/='/" | \
155 sed "s/\$/'/" > $mftt
156 grep -E "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE2?_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
157 sed "s/[$st]*=/='/" | \
158 sed "s/\$/'/" >> $mftt
162 echo "# pkg-config fixups"
164 for var in `cut -d = -f 1 < $mftt`; do
168 eval "pc_value=\"\$$var\""
171 if [ ".$DISABLE_TLS" = .yes ]; then
172 # no TLS, not referencing
174 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
176 need_core="gnutls-special"
177 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
181 if [ ".$need_this" != "." ]; then
182 tls_include=`pkg-config --cflags $pc_value`
183 if [ $? -ne 0 ]; then
184 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
187 tls_libs=`pkg-config --libs $pc_value`
188 echo "TLS_INCLUDE=$tls_include"
189 echo "TLS_LIBS=$tls_libs"
190 # With hash.h pulling crypto into the core, we need to also handle that
191 if [ ".$need_this" = ".t" ]; then
192 echo "CFLAGS += $tls_include"
193 echo "LDFLAGS += $tls_libs"
194 elif [ ".$need_this" = ".gnutls-special" ]; then
195 if pkg-config --atleast-version=2.10 gnutls ; then
196 echo "CFLAGS += $tls_include"
197 echo "LDFLAGS += $tls_libs"
199 echo "CFLAGS += `libgcrypt-config --cflags`"
200 echo "LDFLAGS += `libgcrypt-config --libs`"
207 eval "pc_value=\"\$$var\""
208 base=`echo $var | sed 's/_PC$//'`
209 eval "basevalue=\"\$$base\""
210 if [ ".$basevalue" = "." ]; then
211 # not pulling in this module, _PC defined as default? Ignore
213 elif [ $basevalue = 2 ]; then
214 # module; handled in scripts/lookups-Makefile
218 cflags=`pkg-config --cflags $pc_value`
219 if [ $? -ne 0 ]; then
220 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
223 libs=`pkg-config --libs $pc_value`
224 if [ "$var" != "${var#LOOKUP_}" ]; then
225 echo "LOOKUP_INCLUDE += $cflags"
226 echo "LOOKUP_LIBS += $libs"
227 elif [ "$var" != "${var#AUTH_}" ]; then
228 echo "CFLAGS += $cflags"
229 echo "AUTH_LIBS += $libs"
231 echo >&2 "Don't know how to handle pkg-config for $var"
239 echo >&2 "pcre is no longer supported; migrate to pcre2"
242 # cflags=`pcre-config --cflags`
243 # if [ $? -ne 0 ]; then
244 # echo >&2 "*** Missing pcre-config for regular expression support"
247 # libs=`pcre-config --libs`
248 # if [ ".$cflags" != "." ]; then
249 # echo "INCLUDE += $cflags"
251 # echo "PCRE_LIBS=$libs"
257 case $PCRE2_CONFIG in
259 cflags=`pcre2-config --cflags`
260 if [ $? -ne 0 ]; then
261 echo >&2 "*** Missing pcre2-config for regular expression support"
264 libs=`pcre2-config --libs8`
265 if [ ".$cflags" != "." ]; then
266 echo "INCLUDE += $cflags"
268 echo "PCRE_LIBS=$libs"
279 echo "# End of pkg-config fixups"
283 if [ $subexit -ne 0 ]; then
289 # make the lookups Makefile with the definitions
290 # the auxiliary script generates $look_mf_post from $look_mf_pre
292 cp ../src/lookups/Makefile $look_mf_pre
293 ../scripts/lookups-Makefile
295 while read class classdef names
297 cp ../src/$class/Makefile $class/Makefile.predynamic
298 CLASS=$class CLASSDEF=$classdef DRNAMES="$names" ../scripts/drivers-Makefile
299 mv $class/Makefile.postdynamic $class/Makefile
300 rm $class/Makefile.predynamic
302 routers ROUTER ACCEPT DNSLOOKUP IPLITERAL IPLOOKUP MANUALROUTE QUERYPROGRAM REDIRECT
303 transports TRANSPORT APPENDFILE AUTOREPLY LMTP PIPE QUEUEFILE SMTP
306 # See if there is a definition of EXIM_PERL in what we have built so far.
307 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
308 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
309 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
310 # if it has been defined.
312 EXIM_PERL=`grep EXIM_PERL $mft`
314 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
315 if [ "${PERL_COMMAND}" = "" ] ; then
319 if [ "${EXIM_PERL}" != "" ] ; then
320 testperl=`$PERL_COMMAND --version`
321 if [ "$testperl" = "" ] ; then
322 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
326 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
327 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
328 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
333 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
334 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
335 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
341 # Record the build variable in the Makefile.
343 echo "build=$build" >>$mft
346 # Finally, join on the generic base make file, which contains the actual
349 echo "# From ../OS/Makefile-Base" >> $mft
350 cat ../OS/Makefile-Base >> $mft || exit 1
352 # If the new makefile is the same as the existing one, say so, and just
353 # update the timestamp. Otherwise remove the old and install the new.
355 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
356 then echo ">>> rebuilt $mf unchanged"
359 rm -f $mft $look_mf_pre $look_mf_post
360 elif rm -f $mf $look_mf $look_mf_pre
362 mv $look_mf_post $look_mf
363 then echo ">>> New $mf & $look_mf installed"
364 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
367 echo "*** Failed to install $mf - see $mft"
368 echo " (or $look_mft)"
374 # End of Configure-Makefile