Logging: connection_reject log selector should apply also to the connect acl
[exim.git] / src / scripts / Configure-Makefile
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.
7 #
8 # Copyright (c) The Exim Maintainers 2016
9
10
11 # First off, get the OS type, and check that there is a make file for it.
12
13 ostype=`../scripts/os-type -generic` || exit 1
14
15 if [ ! -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
21 fi
22
23 # We also need the architecture type, in order to test for any architecture-
24 # specific configuration files.
25
26 archtype=`../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
32 editme=../Local/Makefile
33 rebuild=yes
34
35 if [ -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
47 fi
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
52 if [ "X$build" != "X" ] ; then
53 mfb=Local/Makefile-$build
54 if ../scripts/newer $editme-$build Makefile ; then
55 rebuild=yes
56 fi
57 else
58 mfb=
59 fi
60
61
62 # If Makefile is up-to-date, no need to rebuild it.
63
64 if [ $rebuild = no ] ; then
65 echo "\`Makefile' is up to date."
66 echo " "
67 exit
68 fi
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
78 mf=Makefile
79 mft=$mf-t
80 mftt=$mf-tt
81
82 look_mf=lookups/Makefile
83 look_mf_pre=${look_mf}.predynamic
84 look_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
89 rm -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
100 st=' '
101
102 for 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
109 do 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
115 done \
116 | sed 's/^TMPDIR=/EXIM_&/' \
117 >> $mft || exit 1
118
119 # handle pkg-config
120 # beware portability of extended regexps with sed.
121
122 egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
123 sed "s/[$st]*=/='/" | \
124 sed "s/\$/'/" > $mftt
125 egrep "^[$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
128 if test -s $mftt
129 then
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=''
139 if [ ".$SUPPORT_TLS" = "." ]; then
140 # no TLS, not referencing
141 true
142 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
143 need_this=t
144 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
145 need_this=t
146 fi
147 if [ ".$need_this" != "." ]; then
148 tls_include=`pkg-config --cflags $pc_value`
149 if [ $? -ne 0 ]; then
150 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
151 exit 1
152 fi
153 tls_libs=`pkg-config --libs $pc_value`
154 echo "TLS_INCLUDE=$tls_include"
155 echo "TLS_LIBS=$tls_libs"
156 fi
157 ;;
158
159 *_PC)
160 eval "pc_value=\"\$$var\""
161 base=`echo $var | sed 's/_PC$//'`
162 eval "basevalue=\"\$$base\""
163 if [ ".$basevalue" = "." ]; then
164 # not pulling in this module, _PC defined as default? Ignore
165 true
166 elif [ $basevalue = 2 ]; then
167 # module; handled in scripts/lookups-Makefile
168 true
169 else
170 # main binary
171 cflags=`pkg-config --cflags $pc_value`
172 if [ $? -ne 0 ]; then
173 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
174 exit 1
175 fi
176 libs=`pkg-config --libs $pc_value`
177 if [ "$var" != "${var#LOOKUP_}" ]; then
178 echo "LOOKUP_INCLUDE += $cflags"
179 echo "LOOKUP_LIBS += $libs"
180 elif [ "$var" != "${var#AUTH_}" ]; then
181 echo "CFLAGS += $cflags"
182 echo "AUTH_LIBS += $libs"
183 else
184 echo >&2 "Don't know how to handle pkg-config for $var"
185 fi
186 fi
187 ;;
188
189 PCRE_CONFIG)
190 case $PCRE_CONFIG in
191 yes|YES|y|Y)
192 cflags=`pcre-config --cflags`
193 if [ $? -ne 0 ]; then
194 echo >&2 "*** Missing pcre-config for regular expression support"
195 exit 1
196 fi
197 libs=`pcre-config --libs`
198 if [ ".$cflags" != "." ]; then
199 echo "INCLUDE += $cflags"
200 fi
201 echo "PCRE_LIBS=$libs"
202 ;;
203 esac
204 ;;
205
206 AVOID_GNUTLS_PKCS11)
207 echo "$var=yes"
208 ;;
209
210 esac
211 done
212 echo "# End of pkg-config fixups"
213 echo
214 ) >> $mft
215 subexit=$?
216 if [ $subexit -ne 0 ]; then
217 exit $subexit
218 fi
219 fi
220 rm -f $mftt
221
222 # make the lookups Makefile with the definitions
223 # the auxiliary script generates $look_mf_post from $look_mf_pre
224
225 cp ../src/lookups/Makefile $look_mf_pre
226 ../scripts/lookups-Makefile
227
228 # See if there is a definition of EXIM_PERL in what we have built so far.
229 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
230 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
231 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
232 # if it has been defined.
233
234 EXIM_PERL=`grep EXIM_PERL $mft`
235
236 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
237 if [ "${PERL_COMMAND}" = "" ] ; then
238 PERL_COMMAND='perl'
239 fi
240
241 if [ "${EXIM_PERL}" != "" ] ; then
242 testperl=`$PERL_COMMAND --version`
243 if [ "$testperl" = "" ] ; then
244 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
245 exit 1
246 fi
247
248 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
249 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
250 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
251 exit 1;
252 fi
253
254 mv $mft $mftt
255 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
256 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
257 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
258 echo "" >>$mft
259 cat $mftt >> $mft
260 rm -f $mftt
261 fi
262
263 # Record the build variable in the Makefile.
264
265 echo "build=$build" >>$mft
266 echo "" >>$mft
267
268 # Finally, join on the generic base make file, which contains the actual
269 # rules and stuff.
270
271 echo "# From ../OS/Makefile-Base" >> $mft
272 cat ../OS/Makefile-Base >> $mft || exit 1
273
274 # If the new makefile is the same as the existing one, say so, and just
275 # update the timestamp. Otherwise remove the old and install the new.
276
277 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
278 then echo ">>> rebuilt $mf unchanged"
279 echo " "
280 touch $mf || exit
281 rm -f $mft $look_mf_pre $look_mf_post
282 elif rm -f $mf $look_mf $look_mf_pre
283 mv $mft $mf
284 mv $look_mf_post $look_mf
285 then echo ">>> New $mf & $look_mf installed"
286 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
287 echo " "
288 else echo " "
289 echo "*** Failed to install $mf - see $mft"
290 echo " (or $look_mft)"
291 echo " "
292 exit 1;
293 fi
294
295 # vim: set ft=sh :
296 # End of Configure-Makefile