Fix build for HP-UX and older Solaris: (un)setenv. Bug 1578
[exim.git] / src / scripts / Configure-Makefile
CommitLineData
61ec970d 1#! /bin/sh
61ec970d
PH
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
58ee1eb6
TF
80look_mf=lookups/Makefile
81look_mf_pre=${look_mf}.predynamic
82look_mf_post=${look_mf}.postdynamic
0a349494 83
61ec970d
PH
84# Ensure the temporary does not exist and start the new one by setting
85# the OSTYPE and ARCHTYPE variables.
86
0a349494 87rm -f $mft $mftt $look_mf-t
61ec970d
PH
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
8f3bfb82
HSHR
113done \
114 | sed 's/^TMPDIR=/EXIM_&/' \
115 >> $mft || exit 1
0a349494 116
dde3daac
PP
117# handle pkg-config
118# beware portability of extended regexps with sed.
119
120egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
121 sed "s/[$st]*=/='/" | \
122 sed "s/\$/'/" > $mftt
2519e60d 123egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG|AVOID_GNUTLS_PKCS11)[$st]*=[$st]*" $mft | \
f4b00a2d
PP
124 sed "s/[$st]*=/='/" | \
125 sed "s/\$/'/" >> $mftt
dde3daac
PP
126if test -s $mftt
127then
128 (
129 echo "# pkg-config fixups"
130 . ./$mftt
131 for var in `cut -d = -f 1 < $mftt`; do
132 case $var in
f4b00a2d
PP
133
134 USE_*_PC)
135 eval "pc_value=\"\$$var\""
136 need_this=''
137 if [ ".$SUPPORT_TLS" = "." ]; then
138 # no TLS, not referencing
139 true
140 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
141 need_this=t
142 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
143 need_this=t
144 fi
145 if [ ".$need_this" != "." ]; then
146 tls_include=`pkg-config --cflags $pc_value`
14ea0bea
PP
147 if [ $? -ne 0 ]; then
148 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
149 exit 1
150 fi
f4b00a2d
PP
151 tls_libs=`pkg-config --libs $pc_value`
152 echo "TLS_INCLUDE=$tls_include"
153 echo "TLS_LIBS=$tls_libs"
154 fi
155 ;;
156
dde3daac
PP
157 *_PC)
158 eval "pc_value=\"\$$var\""
159 base=`echo $var | sed 's/_PC$//'`
160 eval "basevalue=\"\$$base\""
161 if [ ".$basevalue" = "." ]; then
162 # not pulling in this module, _PC defined as default? Ignore
163 true
164 elif [ $basevalue = 2 ]; then
165 # module; handled in scripts/lookups-Makefile
166 true
167 else
168 # main binary
169 cflags=`pkg-config --cflags $pc_value`
14ea0bea
PP
170 if [ $? -ne 0 ]; then
171 echo >&2 "*** Missing pkg-config for package $pc_value (for Exim $var build option)"
172 exit 1
173 fi
dde3daac
PP
174 libs=`pkg-config --libs $pc_value`
175 if [ "$var" != "${var#LOOKUP_}" ]; then
176 echo "LOOKUP_INCLUDE += $cflags"
177 echo "LOOKUP_LIBS += $libs"
178 elif [ "$var" != "${var#AUTH_}" ]; then
179 echo "CFLAGS += $cflags"
180 echo "AUTH_LIBS += $libs"
181 else
182 echo >&2 "Don't know how to handle pkg-config for $var"
183 fi
184 fi
185 ;;
f4b00a2d 186
6a6084f8
PP
187 PCRE_CONFIG)
188 case $PCRE_CONFIG in
189 yes|YES|y|Y)
190 cflags=`pcre-config --cflags`
14ea0bea
PP
191 if [ $? -ne 0 ]; then
192 echo >&2 "*** Missing pcre-config for regular expression support"
193 exit 1
194 fi
6a6084f8
PP
195 libs=`pcre-config --libs`
196 if [ ".$cflags" != "." ]; then
197 echo "INCLUDE += $cflags"
198 fi
199 echo "PCRE_LIBS=$libs"
200 ;;
201 esac
202 ;;
203
2519e60d
TL
204 AVOID_GNUTLS_PKCS11)
205 echo "$var=yes"
206 ;;
207
dde3daac
PP
208 esac
209 done
210 echo "# End of pkg-config fixups"
211 echo
212 ) >> $mft
14ea0bea
PP
213 subexit=$?
214 if [ $subexit -ne 0 ]; then
215 exit $subexit
216 fi
dde3daac
PP
217fi
218rm -f $mftt
219
0a349494 220# make the lookups Makefile with the definitions
58ee1eb6 221# the auxiliary script generates $look_mf_post from $look_mf_pre
0a349494 222
58ee1eb6
TF
223cp ../src/lookups/Makefile $look_mf_pre
224../scripts/lookups-Makefile
61ec970d
PH
225
226# See if there is a definition of EXIM_PERL in what we have built so far.
227# If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
228# and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
229# what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
230# if it has been defined.
231
232EXIM_PERL=`grep EXIM_PERL $mft`
233
234PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
235if [ "${PERL_COMMAND}" = "" ] ; then
236 PERL_COMMAND='perl'
237fi
238
239if [ "${EXIM_PERL}" != "" ] ; then
240 testperl=`$PERL_COMMAND --version`
241 if [ "$testperl" = "" ] ; then
242 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
243 exit 1
244 fi
245
177ebd9b
NM
246 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
247 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
248 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
249 exit 1;
250 fi
251
61ec970d
PH
252 mv $mft $mftt
253 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
254 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
255 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
256 echo "" >>$mft
257 cat $mftt >> $mft
258 rm -f $mftt
259fi
260
261# Record the build variable in the Makefile.
262
263echo "build=$build" >>$mft
264echo "" >>$mft
265
266# Finally, join on the generic base make file, which contains the actual
267# rules and stuff.
268
76ea0716 269echo "# From ../OS/Makefile-Base" >> $mft
61ec970d
PH
270cat ../OS/Makefile-Base >> $mft || exit 1
271
272# If the new makefile is the same as the existing one, say so, and just
273# update the timestamp. Otherwise remove the old and install the new.
274
58ee1eb6 275if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mf_post $look_mf
61ec970d
PH
276then echo ">>> rebuilt $mf unchanged"
277 echo " "
278 touch $mf || exit
58ee1eb6
TF
279 rm -f $mft $look_mf_pre $look_mf_post
280elif rm -f $mf $look_mf $look_mf_pre
61ec970d 281 mv $mft $mf
58ee1eb6 282 mv $look_mf_post $look_mf
0a349494 283then echo ">>> New $mf & $look_mf installed"
61ec970d
PH
284 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
285 echo " "
286else echo " "
287 echo "*** Failed to install $mf - see $mft"
0a349494 288 echo " (or $look_mft)"
61ec970d
PH
289 echo " "
290 exit 1;
291fi
292
dde3daac 293# vim: set ft=sh :
61ec970d 294# End of Configure-Makefile