Merge branch 'debian' into hcoop_489
[hcoop/debian/exim4.git] / scripts / Configure-Makefile
CommitLineData
420a0d19
CE
1#! /bin/sh
2
3# Shell script to build Makefile in a build directory. It must be called
4# from inside the directory. It does its own checking of when to rebuild; it
5# just got too horrendous to get it right in "make", because of the optionally
6# existing configuration files.
2813c06e
CE
7#
8# Copyright (c) The Exim Maintainers 2016
420a0d19
CE
9
10
11# First off, get the OS type, and check that there is a make file for it.
12
13ostype=`../scripts/os-type -generic` || exit 1
14
15if [ ! -r ../OS/Makefile-$ostype ] ; then
16 echo ""
17 echo "*** Sorry - operating system $ostype is not supported"
18 echo "*** See OS/Makefile-* for supported systems" 1>&2
19 echo ""
20 exit 1
21fi
22
23# We also need the architecture type, in order to test for any architecture-
24# specific configuration files.
25
26archtype=`../scripts/arch-type` || exit 1
27
28# Now test for either the non-existence of Makefile, or for any of its
29# components being newer. Note that the "newer" script gives the right
30# answer (for our purposes) when the first file is non-existent.
31
32editme=../Local/Makefile
33rebuild=yes
34
35if [ -f Makefile ] ; then
36 rebuild=no
37 if ../scripts/newer $editme Makefile || \
38 ../scripts/newer $editme-$ostype Makefile || \
39 ../scripts/newer $editme-$archtype Makefile || \
40 ../scripts/newer $editme-$ostype-$archtype Makefile || \
41 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
42 ../scripts/newer ../OS/Makefile-Base Makefile || \
43 ../scripts/newer ../OS/Makefile-Default Makefile
44 then
45 rebuild=yes
46 fi
47fi
48
49# If the "build" variable is set it means that a build name was explicitly
50# given. Arrange to pick up a build-specific configuration file.
51
52if [ "X$build" != "X" ] ; then
53 mfb=Local/Makefile-$build
54 if ../scripts/newer $editme-$build Makefile ; then
55 rebuild=yes
56 fi
57else
58 mfb=
59fi
60
61
62# If Makefile is up-to-date, no need to rebuild it.
63
64if [ $rebuild = no ] ; then
65 echo "\`Makefile' is up to date."
66 echo " "
67 exit
68fi
69
70# Makefile needs to be rebuilt in the current directory by joining
71# the generic default makefile, the OS base makefile, and then local
72# generic, OS-specific, architecture-specific, and OS+architecture-specific
73# makefiles, if they exist. These files all contain macro definitions, with
74# later definitions overriding earlier ones. Make a temporary file first, in
75# case things go wrong. A second temporary is needed for sorting out the
76# default Perl stuff. Use short macro names to save typing.
77
78mf=Makefile
79mft=$mf-t
80mftt=$mf-tt
81
82look_mf=lookups/Makefile
83look_mf_pre=${look_mf}.predynamic
84look_mf_post=${look_mf}.postdynamic
85
86# Ensure the temporary does not exist and start the new one by setting
87# the OSTYPE and ARCHTYPE variables.
88
89rm -f $mft $mftt $look_mf-t
90(echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
91
92# Now concatenate the files to the temporary file. Copy the files using sed to
93# remove comments, blank lines, and trailing white space.
94
95# BEWARE: a tab character is needed in the sed command below. It has had
96# a nasty tendency to get lost in the past, causing a problem if a tab has
97# actually been present in one of the files. Use a variable to hold a space
98# and a tab to keep the tab in one place.
99
100st=' '
101
102for f in OS/Makefile-Default \
103 OS/Makefile-$ostype \
104 Local/Makefile \
105 Local/Makefile-$ostype \
106 Local/Makefile-$archtype \
107 Local/Makefile-$ostype-$archtype \
108 $mfb
109do if test -r ../$f
110 then echo "# From $f"
111 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
112 echo "# End of $f"
113 echo ""
114 fi
2813c06e
CE
115done \
116 | sed 's/^TMPDIR=/EXIM_&/' \
117 >> $mft || exit 1
420a0d19
CE
118
119# handle pkg-config
120# beware portability of extended regexps with sed.
121
122egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
123 sed "s/[$st]*=/='/" | \
124 sed "s/\$/'/" > $mftt
125egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
126 sed "s/[$st]*=/='/" | \
127 sed "s/\$/'/" >> $mftt
128if test -s $mftt
129then
130 (
131 echo "# pkg-config fixups"
132 . ./$mftt
133 for var in `cut -d = -f 1 < $mftt`; do
134 case $var in
135
136 USE_*_PC)
137 eval "pc_value=\"\$$var\""
138 need_this=''
2813c06e 139 need_core=''
420a0d19
CE
140 if [ ".$SUPPORT_TLS" = "." ]; then
141 # no TLS, not referencing
142 true
143 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
144 need_this=t
2813c06e 145 need_core="gnutls-special"
420a0d19
CE
146 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
147 need_this=t
2813c06e 148 need_core=t
420a0d19
CE
149 fi
150 if [ ".$need_this" != "." ]; then
151 tls_include=`pkg-config --cflags $pc_value`
152 if [ $? -ne 0 ]; then
153 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
154 exit 1
155 fi
156 tls_libs=`pkg-config --libs $pc_value`
157 echo "TLS_INCLUDE=$tls_include"
158 echo "TLS_LIBS=$tls_libs"
2813c06e
CE
159 # With hash.h pulling crypto into the core, we need to also handle that
160 if [ ".$need_this" = ".t" ]; then
161 echo "CFLAGS += $tls_include"
162 echo "LDFLAGS += $tls_libs"
163 elif [ ".$need_this" = ".gnutls-special" ]; then
164 if pkg-config --atleast-version=2.10 gnutls ; then
165 echo "CFLAGS += $tls_include"
166 echo "LDFLAGS += $tls_libs"
167 else
168 echo "CFLAGS += $(libgcrypt-config --cflags)"
169 echo "LDFLAGS += $(libgcrypt-config --libs)"
170 fi
171 fi
420a0d19
CE
172 fi
173 ;;
174
175 *_PC)
176 eval "pc_value=\"\$$var\""
177 base=`echo $var | sed 's/_PC$//'`
178 eval "basevalue=\"\$$base\""
179 if [ ".$basevalue" = "." ]; then
180 # not pulling in this module, _PC defined as default? Ignore
181 true
182 elif [ $basevalue = 2 ]; then
183 # module; handled in scripts/lookups-Makefile
184 true
185 else
186 # main binary
187 cflags=`pkg-config --cflags $pc_value`
188 if [ $? -ne 0 ]; then
189 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
190 exit 1
191 fi
192 libs=`pkg-config --libs $pc_value`
193 if [ "$var" != "${var#LOOKUP_}" ]; then
194 echo "LOOKUP_INCLUDE += $cflags"
195 echo "LOOKUP_LIBS += $libs"
196 elif [ "$var" != "${var#AUTH_}" ]; then
197 echo "CFLAGS += $cflags"
198 echo "AUTH_LIBS += $libs"
199 else
200 echo >&2 "Don't know how to handle pkg-config for $var"
201 fi
202 fi
203 ;;
204
205 PCRE_CONFIG)
206 case $PCRE_CONFIG in
207 yes|YES|y|Y)
208 cflags=`pcre-config --cflags`
209 if [ $? -ne 0 ]; then
210 echo >&2 "*** Missing pcre-config for regular expression support"
211 exit 1
212 fi
213 libs=`pcre-config --libs`
214 if [ ".$cflags" != "." ]; then
215 echo "INCLUDE += $cflags"
216 fi
217 echo "PCRE_LIBS=$libs"
218 ;;
219 esac
220 ;;
221
222 AVOID_GNUTLS_PKCS11)
223 echo "$var=yes"
224 ;;
225
226 esac
227 done
228 echo "# End of pkg-config fixups"
229 echo
230 ) >> $mft
231 subexit=$?
232 if [ $subexit -ne 0 ]; then
233 exit $subexit
234 fi
235fi
236rm -f $mftt
237
238# make the lookups Makefile with the definitions
239# the auxiliary script generates $look_mf_post from $look_mf_pre
240
241cp ../src/lookups/Makefile $look_mf_pre
242../scripts/lookups-Makefile
243
244# See if there is a definition of EXIM_PERL in what we have built so far.
245# If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
246# and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
247# what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
248# if it has been defined.
249
250EXIM_PERL=`grep EXIM_PERL $mft`
251
252PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
253if [ "${PERL_COMMAND}" = "" ] ; then
254 PERL_COMMAND='perl'
255fi
256
257if [ "${EXIM_PERL}" != "" ] ; then
258 testperl=`$PERL_COMMAND --version`
259 if [ "$testperl" = "" ] ; then
260 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
261 exit 1
262 fi
263
264 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
265 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
266 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
267 exit 1;
268 fi
269
270 mv $mft $mftt
271 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
272 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
273 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
274 echo "" >>$mft
275 cat $mftt >> $mft
276 rm -f $mftt
277fi
278
279# Record the build variable in the Makefile.
280
281echo "build=$build" >>$mft
282echo "" >>$mft
283
284# Finally, join on the generic base make file, which contains the actual
285# rules and stuff.
286
287echo "# From ../OS/Makefile-Base" >> $mft
288cat ../OS/Makefile-Base >> $mft || exit 1
289
290# If the new makefile is the same as the existing one, say so, and just
291# update the timestamp. Otherwise remove the old and install the new.
292
293if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
294then echo ">>> rebuilt $mf unchanged"
295 echo " "
296 touch $mf || exit
297 rm -f $mft $look_mf_pre $look_mf_post
298elif rm -f $mf $look_mf $look_mf_pre
299 mv $mft $mf
300 mv $look_mf_post $look_mf
301then echo ">>> New $mf & $look_mf installed"
302 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
303 echo " "
304else echo " "
305 echo "*** Failed to install $mf - see $mft"
306 echo " (or $look_mft)"
307 echo " "
308 exit 1;
309fi
310
311# vim: set ft=sh :
312# End of Configure-Makefile