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.
9 # First off, get the OS type, and check that there is a make file for it.
11 ostype=`../scripts/os-type -generic` || exit 1
13 if [ ! -r ../OS/Makefile-$ostype ] ; then
15 echo "*** Sorry - operating system $ostype is not supported"
16 echo "*** See OS/Makefile-* for supported systems" 1>&2
21 # We also need the architecture type, in order to test for any architecture-
22 # specific configuration files.
24 archtype=`../scripts/arch-type` || exit 1
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.
30 editme=../Local/Makefile
33 if [ -f Makefile ] ; then
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
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.
50 if [ "X$build" != "X" ] ; then
51 mfb=Local/Makefile-$build
52 if ../scripts/newer $editme-$build Makefile ; then
60 # If Makefile is up-to-date, no need to rebuild it.
62 if [ $rebuild = no ] ; then
63 echo "\`Makefile' is up to date."
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.
80 look_mf=lookups/Makefile.predynamic
83 # Ensure the temporary does not exist and start the new one by setting
84 # the OSTYPE and ARCHTYPE variables.
86 rm -f $mft $mftt $look_mf-t
87 (echo "OSTYPE=$ostype"; echo "ARCHTYPE=$archtype"; echo "") > $mft || exit 1
89 # Now concatenate the files to the temporary file. Copy the files using sed to
90 # remove comments, blank lines, and trailing white space.
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.
99 for f in OS/Makefile-Default \
100 OS/Makefile-$ostype \
102 Local/Makefile-$ostype \
103 Local/Makefile-$archtype \
104 Local/Makefile-$ostype-$archtype \
107 then echo "# From $f"
108 sed "/^#/d;/^[$st]*\$/d;s/[$st]*\$//" ../$f || exit 1
112 done >> $mft || exit 1
115 # beware portability of extended regexps with sed.
117 egrep "^[$st]*(AUTH|LOOKUP)_[A-Z0-9_]*[$st]*=[$st]*" $mft | \
118 sed "s/[$st]*=/='/" | \
119 sed "s/\$/'/" > $mftt
123 echo "# pkg-config fixups"
125 for var in `cut -d = -f 1 < $mftt`; do
128 eval "pc_value=\"\$$var\""
129 base=`echo $var | sed 's/_PC$//'`
130 eval "basevalue=\"\$$base\""
131 if [ ".$basevalue" = "." ]; then
132 # not pulling in this module, _PC defined as default? Ignore
134 elif [ $basevalue = 2 ]; then
135 # module; handled in scripts/lookups-Makefile
139 cflags=`pkg-config --cflags $pc_value`
140 libs=`pkg-config --libs $pc_value`
141 if [ "$var" != "${var#LOOKUP_}" ]; then
142 echo "LOOKUP_INCLUDE += $cflags"
143 echo "LOOKUP_LIBS += $libs"
144 elif [ "$var" != "${var#AUTH_}" ]; then
145 echo "CFLAGS += $cflags"
146 echo "AUTH_LIBS += $libs"
148 echo >&2 "Don't know how to handle pkg-config for $var"
154 echo "# End of pkg-config fixups"
160 # make the lookups Makefile with the definitions
162 ## prepend stuff here; eg: grep LOOKUP_ $mft > $look_mft
163 ## cat ../src/lookups/Makefile >> $look_mft
164 cp ../src/lookups/Makefile $look_mft
166 # See if there is a definition of EXIM_PERL in what we have built so far.
167 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
168 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
169 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
170 # if it has been defined.
172 EXIM_PERL=`grep EXIM_PERL $mft`
174 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
175 if [ "${PERL_COMMAND}" = "" ] ; then
179 if [ "${EXIM_PERL}" != "" ] ; then
180 testperl=`$PERL_COMMAND --version`
181 if [ "$testperl" = "" ] ; then
182 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
186 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
187 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
188 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
193 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
194 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
195 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
201 # Record the build variable in the Makefile.
203 echo "build=$build" >>$mft
206 # Finally, join on the generic base make file, which contains the actual
209 echo "# From ../OS/Makefile-Base" >> $mft
210 cat ../OS/Makefile-Base >> $mft || exit 1
212 # If the new makefile is the same as the existing one, say so, and just
213 # update the timestamp. Otherwise remove the old and install the new.
215 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mft $look_mf
216 then echo ">>> rebuilt $mf unchanged"
220 elif rm -f $mf $look_mf
222 mv $look_mft $look_mf
223 then echo ">>> New $mf & $look_mf installed"
224 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
227 echo "*** Failed to install $mf - see $mft"
228 echo " (or $look_mft)"
234 # End of Configure-Makefile