4 # Shell script to build Makefile in a build directory. It must be called
5 # from inside the directory. It does its own checking of when to rebuild; it
6 # just got too horrendous to get it right in "make", because of the optionally
7 # existing configuration files.
9 # Copyright (c) The Exim Maintainers 2017
12 # First off, get the OS type, and check that there is a make file for it.
14 ostype=`../scripts/os-type -generic` || exit 1
16 if [ ! -r ../OS/Makefile-$ostype ] ; then
18 echo "*** Sorry - operating system $ostype is not supported"
19 echo "*** See OS/Makefile-* for supported systems" 1>&2
24 # We also need the architecture type, in order to test for any architecture-
25 # specific configuration files.
27 archtype=`../scripts/arch-type` || exit 1
29 # Now test for either the non-existence of Makefile, or for any of its
30 # components being newer. Note that the "newer" script gives the right
31 # answer (for our purposes) when the first file is non-existent.
33 editme=../Local/Makefile
36 if [ -f Makefile ] ; then
38 if ../scripts/newer $editme Makefile || \
39 ../scripts/newer $editme-$ostype Makefile || \
40 ../scripts/newer $editme-$archtype Makefile || \
41 ../scripts/newer $editme-$ostype-$archtype Makefile || \
42 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
43 ../scripts/newer ../OS/Makefile-Base Makefile || \
44 ../scripts/newer ../OS/Makefile-Default Makefile
50 # If the "build" variable is set it means that a build name was explicitly
51 # given. Arrange to pick up a build-specific configuration file.
53 if [ "X$build" != "X" ] ; then
54 mfb=Local/Makefile-$build
55 if ../scripts/newer $editme-$build Makefile ; then
63 # If Makefile is up-to-date, no need to rebuild it.
65 if [ $rebuild = no ] ; then
66 echo "\`Makefile' is up to date."
71 # Makefile needs to be rebuilt in the current directory by joining
72 # the generic default makefile, the OS base makefile, and then local
73 # generic, OS-specific, architecture-specific, and OS+architecture-specific
74 # makefiles, if they exist. These files all contain macro definitions, with
75 # later definitions overriding earlier ones. Make a temporary file first, in
76 # case things go wrong. A second temporary is needed for sorting out the
77 # default Perl stuff. Use short macro names to save typing.
85 look_mf=lookups/Makefile
86 look_mf_pre=${look_mf}.predynamic
87 look_mf_post=${look_mf}.postdynamic
89 # Ensure the temporary does not exist and start the new one by setting
90 # the OSTYPE and ARCHTYPE variables.
92 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
93 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
95 # Now concatenate the files to the temporary file. Copy the files using sed to
96 # remove comments, blank lines, and trailing white space.
98 # BEWARE: a tab character is needed in the sed command below. It has had
99 # a nasty tendency to get lost in the past, causing a problem if a tab has
100 # actually been present in one of the files. Use a variable to hold a space
101 # and a tab to keep the tab in one place.
105 for f in OS/Makefile-Default \
106 OS/Makefile-$ostype \
108 Local/Makefile-$ostype \
109 Local/Makefile-$archtype \
110 Local/Makefile-$ostype-$archtype \
113 then echo "# From $f"
114 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
119 | sed 's/^TMPDIR=/EXIM_&/' \
122 # handle PKG_CONFIG_PATH because we need it in our env, and we want to handle
123 # wildcards; note that this logic means all setting _appends_ values, never
124 # replacing; if that's a problem, we can revisit.
125 sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
126 sed "s/[$st]*\$//" >> $mftepcp
127 if test -s ./$mftepcp
129 # expand any wildcards and strip spaces, to make it a real PATH-like variable
130 ( IFS=":${IFS-$st}"; for P in `cat ./$mftepcp`; do echo "$P"; done ) | xargs | sed "s/[$st]/:/g" >./$mftepcp2
131 sed "s/^/PKG_CONFIG_PATH='/" < ./$mftepcp2 | sed "s/\$/'/" > ./$mftepcp
133 export PKG_CONFIG_PATH
134 egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
137 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
138 sed "s/'//g" ./$mftepcp
139 echo "# End of collapsed PKG_CONFIG_PATH"
145 rm -f ./$mftepcp ./$mftepcp2
148 # beware portability of extended regexps with sed.
149 egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
150 sed "s/[$st]*=/='/" | \
151 sed "s/\$/'/" > $mftt
152 egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
153 sed "s/[$st]*=/='/" | \
154 sed "s/\$/'/" >> $mftt
158 echo "# pkg-config fixups"
160 for var in `cut -d = -f 1 < $mftt`; do
164 eval "pc_value=\"\$$var\""
167 if [ ".$SUPPORT_TLS" = "." ]; then
168 # no TLS, not referencing
170 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
172 need_core="gnutls-special"
173 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
177 if [ ".$need_this" != "." ]; then
178 tls_include=`pkg-config --cflags $pc_value`
179 if [ $? -ne 0 ]; then
180 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
183 tls_libs=`pkg-config --libs $pc_value`
184 echo "TLS_INCLUDE=$tls_include"
185 echo "TLS_LIBS=$tls_libs"
186 # With hash.h pulling crypto into the core, we need to also handle that
187 if [ ".$need_this" = ".t" ]; then
188 echo "CFLAGS += $tls_include"
189 echo "LDFLAGS += $tls_libs"
190 elif [ ".$need_this" = ".gnutls-special" ]; then
191 if pkg-config --atleast-version=2.10 gnutls ; then
192 echo "CFLAGS += $tls_include"
193 echo "LDFLAGS += $tls_libs"
195 echo "CFLAGS += `libgcrypt-config --cflags`"
196 echo "LDFLAGS += `libgcrypt-config --libs`"
203 eval "pc_value=\"\$$var\""
204 base=`echo $var | sed 's/_PC$//'`
205 eval "basevalue=\"\$$base\""
206 if [ ".$basevalue" = "." ]; then
207 # not pulling in this module, _PC defined as default? Ignore
209 elif [ $basevalue = 2 ]; then
210 # module; handled in scripts/lookups-Makefile
214 cflags=`pkg-config --cflags $pc_value`
215 if [ $? -ne 0 ]; then
216 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
219 libs=`pkg-config --libs $pc_value`
220 if [ "$var" != "${var#LOOKUP_}" ]; then
221 echo "LOOKUP_INCLUDE += $cflags"
222 echo "LOOKUP_LIBS += $libs"
223 elif [ "$var" != "${var#AUTH_}" ]; then
224 echo "CFLAGS += $cflags"
225 echo "AUTH_LIBS += $libs"
227 echo >&2 "Don't know how to handle pkg-config for $var"
235 cflags=`pcre-config --cflags`
236 if [ $? -ne 0 ]; then
237 echo >&2 "*** Missing pcre-config for regular expression support"
240 libs=`pcre-config --libs`
241 if [ ".$cflags" != "." ]; then
242 echo "INCLUDE += $cflags"
244 echo "PCRE_LIBS=$libs"
255 echo "# End of pkg-config fixups"
259 if [ $subexit -ne 0 ]; then
265 # make the lookups Makefile with the definitions
266 # the auxiliary script generates $look_mf_post from $look_mf_pre
268 cp ../src/lookups/Makefile $look_mf_pre
269 ../scripts/lookups-Makefile
271 # See if there is a definition of EXIM_PERL in what we have built so far.
272 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
273 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
274 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
275 # if it has been defined.
277 EXIM_PERL=`grep EXIM_PERL $mft`
279 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
280 if [ "${PERL_COMMAND}" = "" ] ; then
284 if [ "${EXIM_PERL}" != "" ] ; then
285 testperl=`$PERL_COMMAND --version`
286 if [ "$testperl" = "" ] ; then
287 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
291 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
292 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
293 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
298 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
299 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
300 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
306 # Record the build variable in the Makefile.
308 echo "build=$build" >>$mft
311 # Finally, join on the generic base make file, which contains the actual
314 echo "# From ../OS/Makefile-Base" >> $mft
315 cat ../OS/Makefile-Base >> $mft || exit 1
317 # If the new makefile is the same as the existing one, say so, and just
318 # update the timestamp. Otherwise remove the old and install the new.
320 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
321 then echo ">>> rebuilt $mf unchanged"
324 rm -f $mft $look_mf_pre $look_mf_post
325 elif rm -f $mf $look_mf $look_mf_pre
327 mv $look_mf_post $look_mf
328 then echo ">>> New $mf & $look_mf installed"
329 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
332 echo "*** Failed to install $mf - see $mft"
333 echo " (or $look_mft)"
339 # End of Configure-Makefile