Fix tests 5401 and 5410 when not run under a user named eximtest.
[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
0a349494
PP
80look_mf=lookups/Makefile.predynamic
81look_mft=${look_mf}-t
82
61ec970d
PH
83# Ensure the temporary does not exist and start the new one by setting
84# the OSTYPE and ARCHTYPE variables.
85
0a349494 86rm -f $mft $mftt $look_mf-t
61ec970d
PH
87(echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
88
89# Now concatenate the files to the temporary file. Copy the files using sed to
90# remove comments, blank lines, and trailing white space.
91
92# BEWARE: a tab character is needed in the sed command below. It has had
93# a nasty tendency to get lost in the past, causing a problem if a tab has
94# actually been present in one of the files. Use a variable to hold a space
95# and a tab to keep the tab in one place.
96
97st=' '
98
99for f in OS/Makefile-Default \
100 OS/Makefile-$ostype \
101 Local/Makefile \
102 Local/Makefile-$ostype \
103 Local/Makefile-$archtype \
104 Local/Makefile-$ostype-$archtype \
105 $mfb
106do if test -r ../$f
107 then echo "# From $f"
108 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
109 echo "# End of $f"
110 echo ""
111 fi
0a349494
PP
112done >> $mft || exit 1
113
dde3daac
PP
114# handle pkg-config
115# beware portability of extended regexps with sed.
116
117egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
118 sed "s/[$st]*=/='/" | \
119 sed "s/\$/'/" > $mftt
6a6084f8 120egrep "^[$st]*((USE_(OPENSSL|GNUTLS)_PC)|SUPPORT_TLS|USE_GNUTLS|PCRE_CONFIG)[$st]*=[$st]*" $mft | \
f4b00a2d
PP
121 sed "s/[$st]*=/='/" | \
122 sed "s/\$/'/" >> $mftt
dde3daac
PP
123if test -s $mftt
124then
125 (
126 echo "# pkg-config fixups"
127 . ./$mftt
128 for var in `cut -d = -f 1 < $mftt`; do
129 case $var in
f4b00a2d
PP
130
131 USE_*_PC)
132 eval "pc_value=\"\$$var\""
133 need_this=''
134 if [ ".$SUPPORT_TLS" = "." ]; then
135 # no TLS, not referencing
136 true
137 elif [ ".$var" = ".USE_GNUTLS_PC" ] && [ ".$USE_GNUTLS" != "." ]; then
138 need_this=t
139 elif [ ".$var" = ".USE_OPENSSL_PC" ] && [ ".$USE_GNUTLS" = "." ]; then
140 need_this=t
141 fi
142 if [ ".$need_this" != "." ]; then
143 tls_include=`pkg-config --cflags $pc_value`
144 tls_libs=`pkg-config --libs $pc_value`
145 echo "TLS_INCLUDE=$tls_include"
146 echo "TLS_LIBS=$tls_libs"
147 fi
148 ;;
149
dde3daac
PP
150 *_PC)
151 eval "pc_value=\"\$$var\""
152 base=`echo $var | sed 's/_PC$//'`
153 eval "basevalue=\"\$$base\""
154 if [ ".$basevalue" = "." ]; then
155 # not pulling in this module, _PC defined as default? Ignore
156 true
157 elif [ $basevalue = 2 ]; then
158 # module; handled in scripts/lookups-Makefile
159 true
160 else
161 # main binary
162 cflags=`pkg-config --cflags $pc_value`
163 libs=`pkg-config --libs $pc_value`
164 if [ "$var" != "${var#LOOKUP_}" ]; then
165 echo "LOOKUP_INCLUDE += $cflags"
166 echo "LOOKUP_LIBS += $libs"
167 elif [ "$var" != "${var#AUTH_}" ]; then
168 echo "CFLAGS += $cflags"
169 echo "AUTH_LIBS += $libs"
170 else
171 echo >&2 "Don't know how to handle pkg-config for $var"
172 fi
173 fi
174 ;;
f4b00a2d 175
6a6084f8
PP
176 PCRE_CONFIG)
177 case $PCRE_CONFIG in
178 yes|YES|y|Y)
179 cflags=`pcre-config --cflags`
180 libs=`pcre-config --libs`
181 if [ ".$cflags" != "." ]; then
182 echo "INCLUDE += $cflags"
183 fi
184 echo "PCRE_LIBS=$libs"
185 ;;
186 esac
187 ;;
188
dde3daac
PP
189 esac
190 done
191 echo "# End of pkg-config fixups"
192 echo
193 ) >> $mft
194fi
195rm -f $mftt
196
0a349494
PP
197# make the lookups Makefile with the definitions
198
199## prepend stuff here; eg: grep LOOKUP_ $mft > $look_mft
200## cat ../src/lookups/Makefile >> $look_mft
201cp ../src/lookups/Makefile $look_mft
61ec970d
PH
202
203# See if there is a definition of EXIM_PERL in what we have built so far.
204# If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
205# and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
206# what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
207# if it has been defined.
208
209EXIM_PERL=`grep EXIM_PERL $mft`
210
211PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
212if [ "${PERL_COMMAND}" = "" ] ; then
213 PERL_COMMAND='perl'
214fi
215
216if [ "${EXIM_PERL}" != "" ] ; then
217 testperl=`$PERL_COMMAND --version`
218 if [ "$testperl" = "" ] ; then
219 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
220 exit 1
221 fi
222
177ebd9b
NM
223 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
224 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
225 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
226 exit 1;
227 fi
228
61ec970d
PH
229 mv $mft $mftt
230 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
231 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
232 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
233 echo "" >>$mft
234 cat $mftt >> $mft
235 rm -f $mftt
236fi
237
238# Record the build variable in the Makefile.
239
240echo "build=$build" >>$mft
241echo "" >>$mft
242
243# Finally, join on the generic base make file, which contains the actual
244# rules and stuff.
245
76ea0716 246echo "# From ../OS/Makefile-Base" >> $mft
61ec970d
PH
247cat ../OS/Makefile-Base >> $mft || exit 1
248
249# If the new makefile is the same as the existing one, say so, and just
250# update the timestamp. Otherwise remove the old and install the new.
251
0a349494 252if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mft $look_mf
61ec970d
PH
253then echo ">>> rebuilt $mf unchanged"
254 echo " "
255 touch $mf || exit
256 rm -f $mft
0a349494 257elif rm -f $mf $look_mf
61ec970d 258 mv $mft $mf
0a349494
PP
259 mv $look_mft $look_mf
260then echo ">>> New $mf & $look_mf installed"
61ec970d
PH
261 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
262 echo " "
263else echo " "
264 echo "*** Failed to install $mf - see $mft"
0a349494 265 echo " (or $look_mft)"
61ec970d
PH
266 echo " "
267 exit 1;
268fi
269
dde3daac 270# vim: set ft=sh :
61ec970d 271# End of Configure-Makefile