Update copyright year to 2018
[exim.git] / src / scripts / Configure-Makefile
1 #! /bin/sh
2 export LC_ALL=C
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.
8 #
9 # Copyright (c) The Exim Maintainers 1995 - 2018
10
11
12 # First off, get the OS type, and check that there is a make file for it.
13
14 ostype=`../scripts/os-type -generic` || exit 1
15
16 if [ ! -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
22 fi
23
24 # We also need the architecture type, in order to test for any architecture-
25 # specific configuration files.
26
27 archtype=`../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
33 editme=../Local/Makefile
34 rebuild=yes
35
36 if [ -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
48 fi
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
53 if [ "X$build" != "X" ] ; then
54 mfb=Local/Makefile-$build
55 if ../scripts/newer $editme-$build Makefile ; then
56 rebuild=yes
57 fi
58 else
59 mfb=
60 fi
61
62
63 # If Makefile is up-to-date, no need to rebuild it.
64
65 if [ $rebuild = no ] ; then
66 echo "\`Makefile' is up to date."
67 echo " "
68 exit
69 fi
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
79 mf=Makefile
80 mft=$mf-t
81 mftt=$mf-tt
82 mftepcp=$mf-tepcp
83 mftepcp2=$mf-tepcp2
84
85 look_mf=lookups/Makefile
86 look_mf_pre=${look_mf}.predynamic
87 look_mf_post=${look_mf}.postdynamic
88
89 # Ensure the temporary does not exist and start the new one by setting
90 # the OSTYPE and ARCHTYPE variables.
91
92 rm -f $mft $mftt $mftepcp $mftepcp2 $look_mf-t
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
103 st=' '
104
105 for 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
112 do 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
118 done \
119 | sed 's/^TMPDIR=/EXIM_&/' \
120 >> $mft || exit 1
121
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
128 then
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
144 fi
145 rm -f ./$mftepcp ./$mftepcp2
146
147 # handle pkg-config
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
155 if test -s $mftt
156 then
157 (
158 echo "# pkg-config fixups"
159 . ./$mftt
160 for var in `cut -d = -f 1 < $mftt`; do
161 case $var in
162
163 USE_*_PC)
164 eval "pc_value=\"\$$var\""
165 need_this=''
166 need_core=''
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
172 need_core="gnutls-special"
173 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
174 need_this=t
175 need_core=t
176 fi
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)"
181 exit 1
182 fi
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"
194 else
195 echo "CFLAGS += `libgcrypt-config --cflags`"
196 echo "LDFLAGS += `libgcrypt-config --libs`"
197 fi
198 fi
199 fi
200 ;;
201
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`
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
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 ;;
231
232 PCRE_CONFIG)
233 case $PCRE_CONFIG in
234 yes|YES|y|Y)
235 cflags=`pcre-config --cflags`
236 if [ $? -ne 0 ]; then
237 echo >&2 "*** Missing pcre-config for regular expression support"
238 exit 1
239 fi
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
249 AVOID_GNUTLS_PKCS11)
250 echo "$var=yes"
251 ;;
252
253 esac
254 done
255 echo "# End of pkg-config fixups"
256 echo
257 ) >> $mft
258 subexit=$?
259 if [ $subexit -ne 0 ]; then
260 exit $subexit
261 fi
262 fi
263 rm -f $mftt
264
265 # make the lookups Makefile with the definitions
266 # the auxiliary script generates $look_mf_post from $look_mf_pre
267
268 cp ../src/lookups/Makefile $look_mf_pre
269 ../scripts/lookups-Makefile
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
277 EXIM_PERL=`grep EXIM_PERL $mft`
278
279 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
280 if [ "${PERL_COMMAND}" = "" ] ; then
281 PERL_COMMAND='perl'
282 fi
283
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"
288 exit 1
289 fi
290
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
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
304 fi
305
306 # Record the build variable in the Makefile.
307
308 echo "build=$build" >>$mft
309 echo "" >>$mft
310
311 # Finally, join on the generic base make file, which contains the actual
312 # rules and stuff.
313
314 echo "# From ../OS/Makefile-Base" >> $mft
315 cat ../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
320 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
321 then echo ">>> rebuilt $mf unchanged"
322 echo " "
323 touch $mf || exit
324 rm -f $mft $look_mf_pre $look_mf_post
325 elif rm -f $mf $look_mf $look_mf_pre
326 mv $mft $mf
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'
330 echo " "
331 else echo " "
332 echo "*** Failed to install $mf - see $mft"
333 echo " (or $look_mft)"
334 echo " "
335 exit 1;
336 fi
337
338 # vim: set ft=sh :
339 # End of Configure-Makefile