Copyright year bumps for substantive changes 2017
[exim.git] / src / scripts / Configure-Makefile
CommitLineData
61ec970d 1#! /bin/sh
47d00458 2export LC_ALL=C
61ec970d
PH
3
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.
80fea873 8#
9242a7e8 9# Copyright (c) The Exim Maintainers 2017
61ec970d
PH
10
11
12# First off, get the OS type, and check that there is a make file for it.
13
14ostype=`../scripts/os-type -generic` || exit 1
15
16if [ ! -r ../OS/Makefile-$ostype ] ; then
17 echo ""
18 echo "*** Sorry - operating system $ostype is not supported"
19 echo "*** See OS/Makefile-* for supported systems" 1>&2
20 echo ""
21 exit 1
22fi
23
24# We also need the architecture type, in order to test for any architecture-
25# specific configuration files.
26
27archtype=`../scripts/arch-type` || exit 1
28
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.
32
33editme=../Local/Makefile
34rebuild=yes
35
36if [ -f Makefile ] ; then
37 rebuild=no
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
45 then
46 rebuild=yes
47 fi
48fi
49
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.
52
53if [ "X$build" != "X" ] ; then
54 mfb=Local/Makefile-$build
55 if ../scripts/newer $editme-$build Makefile ; then
56 rebuild=yes
57 fi
58else
59 mfb=
60fi
61
62
63# If Makefile is up-to-date, no need to rebuild it.
64
65if [ $rebuild = no ] ; then
66 echo "\`Makefile' is up to date."
67 echo " "
68 exit
69fi
70
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.
78
79mf=Makefile
80mft=$mf-t
81mftt=$mf-tt
856d1e16
PP
82mftepcp=$mf-tepcp
83mftepcp2=$mf-tepcp2
61ec970d 84
58ee1eb6
TF
85look_mf=lookups/Makefile
86look_mf_pre=${look_mf}.predynamic
87look_mf_post=${look_mf}.postdynamic
0a349494 88
61ec970d
PH
89# Ensure the temporary does not exist and start the new one by setting
90# the OSTYPE and ARCHTYPE variables.
91
856d1e16 92rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
61ec970d
PH
93(echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
94
95# Now concatenate the files to the temporary file. Copy the files using sed to
96# remove comments, blank lines, and trailing white space.
97
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.
102
103st=' '
104
105for f in OS/Makefile-Default \
106 OS/Makefile-$ostype \
107 Local/Makefile \
108 Local/Makefile-$ostype \
109 Local/Makefile-$archtype \
110 Local/Makefile-$ostype-$archtype \
111 $mfb
112do if test -r ../$f
113 then echo "# From $f"
114 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
115 echo "# End of $f"
116 echo ""
117 fi
8f3bfb82
HSHR
118done \
119 | sed 's/^TMPDIR=/EXIM_&/' \
120 >> $mft || exit 1
0a349494 121
856d1e16
PP
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.
125sed -n "s/^[$st]*PKG_CONFIG_PATH[$st]*[+]*=[$st]*//p" $mft | \
126 sed "s/[$st]*\$//" >> $mftepcp
127if test -s ./$mftepcp
128then
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
132 . ./$mftepcp
133 export PKG_CONFIG_PATH
134 egrep -v "^[$st]*PKG_CONFIG_PATH[$st]*=" ./$mft > ./$mftt
135 rm -f ./$mft
136 (
137 echo "# Collapsed PKG_CONFIG_PATH in build-prep:"
138 sed "s/'//g" ./$mftepcp
139 echo "# End of collapsed PKG_CONFIG_PATH"
140 echo ""
141 cat ./$mftt
142 ) > ./$mft
143 rm -f ./$mftt
144fi
145rm -f ./$mftepcp ./$mftepcp2
146
dde3daac
PP
147# handle pkg-config
148# beware portability of extended regexps with sed.
dde3daac
PP
149egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
150 sed "s/[$st]*=/='/" | \
151 sed "s/\$/'/" > $mftt
2519e60d 152egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
f4b00a2d
PP
153 sed "s/[$st]*=/='/" | \
154 sed "s/\$/'/" >> $mftt
dde3daac
PP
155if test -s $mftt
156then
157 (
158 echo "# pkg-config fixups"
159 . ./$mftt
160 for var in `cut -d = -f 1 < $mftt`; do
161 case $var in
f4b00a2d
PP
162
163 USE_*_PC)
164 eval "pc_value=\"\$$var\""
165 need_this=''
8b0fb68e 166 need_core=''
f4b00a2d
PP
167 if [ ".$SUPPORT_TLS" = "." ]; then
168 # no TLS, not referencing
169 true
170 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
171 need_this=t
8b0fb68e 172 need_core="gnutls-special"
f4b00a2d
PP
173 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
174 need_this=t
8b0fb68e 175 need_core=t
f4b00a2d
PP
176 fi
177 if [ ".$need_this" != "." ]; then
178 tls_include=`pkg-config --cflags $pc_value`
14ea0bea
PP
179 if [ $? -ne 0 ]; then
180 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
181 exit 1
182 fi
f4b00a2d
PP
183 tls_libs=`pkg-config --libs $pc_value`
184 echo "TLS_INCLUDE=$tls_include"
185 echo "TLS_LIBS=$tls_libs"
8b0fb68e
PP
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"
194 else
856d1e16
PP
195 echo "CFLAGS += `libgcrypt-config --cflags`"
196 echo "LDFLAGS += `libgcrypt-config --libs`"
8b0fb68e
PP
197 fi
198 fi
f4b00a2d
PP
199 fi
200 ;;
201
dde3daac
PP
202 *_PC)
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
208 true
209 elif [ $basevalue = 2 ]; then
210 # module; handled in scripts/lookups-Makefile
211 true
212 else
213 # main binary
214 cflags=`pkg-config --cflags $pc_value`
14ea0bea
PP
215 if [ $? -ne 0 ]; then
216 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
217 exit 1
218 fi
dde3daac
PP
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"
226 else
227 echo >&2 "Don't know how to handle pkg-config for $var"
228 fi
229 fi
230 ;;
f4b00a2d 231
6a6084f8
PP
232 PCRE_CONFIG)
233 case $PCRE_CONFIG in
234 yes|YES|y|Y)
235 cflags=`pcre-config --cflags`
14ea0bea
PP
236 if [ $? -ne 0 ]; then
237 echo >&2 "*** Missing pcre-config for regular expression support"
238 exit 1
239 fi
6a6084f8
PP
240 libs=`pcre-config --libs`
241 if [ ".$cflags" != "." ]; then
242 echo "INCLUDE += $cflags"
243 fi
244 echo "PCRE_LIBS=$libs"
245 ;;
246 esac
247 ;;
248
2519e60d
TL
249 AVOID_GNUTLS_PKCS11)
250 echo "$var=yes"
251 ;;
252
dde3daac
PP
253 esac
254 done
255 echo "# End of pkg-config fixups"
256 echo
257 ) >> $mft
14ea0bea
PP
258 subexit=$?
259 if [ $subexit -ne 0 ]; then
260 exit $subexit
261 fi
dde3daac
PP
262fi
263rm -f $mftt
264
0a349494 265# make the lookups Makefile with the definitions
58ee1eb6 266# the auxiliary script generates $look_mf_post from $look_mf_pre
0a349494 267
58ee1eb6
TF
268cp ../src/lookups/Makefile $look_mf_pre
269../scripts/lookups-Makefile
61ec970d
PH
270
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.
276
277EXIM_PERL=`grep EXIM_PERL $mft`
278
279PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
280if [ "${PERL_COMMAND}" = "" ] ; then
281 PERL_COMMAND='perl'
282fi
283
284if [ "${EXIM_PERL}" != "" ] ; then
285 testperl=`$PERL_COMMAND --version`
286 if [ "$testperl" = "" ] ; then
287 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
288 exit 1
289 fi
290
177ebd9b
NM
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"
294 exit 1;
295 fi
296
61ec970d
PH
297 mv $mft $mftt
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
301 echo "" >>$mft
302 cat $mftt >> $mft
303 rm -f $mftt
304fi
305
306# Record the build variable in the Makefile.
307
308echo "build=$build" >>$mft
309echo "" >>$mft
310
311# Finally, join on the generic base make file, which contains the actual
312# rules and stuff.
313
76ea0716 314echo "# From ../OS/Makefile-Base" >> $mft
61ec970d
PH
315cat ../OS/Makefile-Base >> $mft || exit 1
316
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.
319
58ee1eb6 320if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
61ec970d
PH
321then echo ">>> rebuilt $mf unchanged"
322 echo " "
323 touch $mf || exit
58ee1eb6
TF
324 rm -f $mft $look_mf_pre $look_mf_post
325elif rm -f $mf $look_mf $look_mf_pre
61ec970d 326 mv $mft $mf
58ee1eb6 327 mv $look_mf_post $look_mf
0a349494 328then echo ">>> New $mf & $look_mf installed"
61ec970d
PH
329 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
330 echo " "
331else echo " "
332 echo "*** Failed to install $mf - see $mft"
0a349494 333 echo " (or $look_mft)"
61ec970d
PH
334 echo " "
335 exit 1;
336fi
337
dde3daac 338# vim: set ft=sh :
61ec970d 339# End of Configure-Makefile