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