Module loading working on FreeBSD (and unbreak).
[exim.git] / src / scripts / Configure-Makefile
1 #! /bin/sh
2 # $Cambridge: exim/src/scripts/Configure-Makefile,v 1.3 2009/11/20 21:22:20 nm4 Exp $
3
4 # Shell script to build Makefile in a build directory. It must be called
5 # from inside the directory. It does its own checking of when to rebuild; it
6 # just got too horrendous to get it right in "make", because of the optionally
7 # existing configuration files.
8
9
10 # First off, get the OS type, and check that there is a make file for it.
11
12 ostype=`../scripts/os-type -generic` || exit 1
13
14 if [ ! -r ../OS/Makefile-$ostype ] ; then
15 echo ""
16 echo "*** Sorry - operating system $ostype is not supported"
17 echo "*** See OS/Makefile-* for supported systems" 1>&2
18 echo ""
19 exit 1
20 fi
21
22 # We also need the architecture type, in order to test for any architecture-
23 # specific configuration files.
24
25 archtype=`../scripts/arch-type` || exit 1
26
27 # Now test for either the non-existence of Makefile, or for any of its
28 # components being newer. Note that the "newer" script gives the right
29 # answer (for our purposes) when the first file is non-existent.
30
31 editme=../Local/Makefile
32 rebuild=yes
33
34 if [ -f Makefile ] ; then
35 rebuild=no
36 if ../scripts/newer $editme Makefile || \
37 ../scripts/newer $editme-$ostype Makefile || \
38 ../scripts/newer $editme-$archtype Makefile || \
39 ../scripts/newer $editme-$ostype-$archtype Makefile || \
40 ../scripts/newer ../scripts/Configure-Makefile Makefile || \
41 ../scripts/newer ../OS/Makefile-Base Makefile || \
42 ../scripts/newer ../OS/Makefile-Default Makefile
43 then
44 rebuild=yes
45 fi
46 fi
47
48 # If the "build" variable is set it means that a build name was explicitly
49 # given. Arrange to pick up a build-specific configuration file.
50
51 if [ "X$build" != "X" ] ; then
52 mfb=Local/Makefile-$build
53 if ../scripts/newer $editme-$build Makefile ; then
54 rebuild=yes
55 fi
56 else
57 mfb=
58 fi
59
60
61 # If Makefile is up-to-date, no need to rebuild it.
62
63 if [ $rebuild = no ] ; then
64 echo "\`Makefile' is up to date."
65 echo " "
66 exit
67 fi
68
69 # Makefile needs to be rebuilt in the current directory by joining
70 # the generic default makefile, the OS base makefile, and then local
71 # generic, OS-specific, architecture-specific, and OS+architecture-specific
72 # makefiles, if they exist. These files all contain macro definitions, with
73 # later definitions overriding earlier ones. Make a temporary file first, in
74 # case things go wrong. A second temporary is needed for sorting out the
75 # default Perl stuff. Use short macro names to save typing.
76
77 mf=Makefile
78 mft=$mf-t
79 mftt=$mf-tt
80
81 look_mf=lookups/Makefile.predynamic
82 look_mft=${look_mf}-t
83
84 # Ensure the temporary does not exist and start the new one by setting
85 # the OSTYPE and ARCHTYPE variables.
86
87 rm -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
98 st=' '
99
100 for 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
107 do 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
113 done >> $mft || exit 1
114
115 # make the lookups Makefile with the definitions
116
117 ## prepend stuff here; eg: grep LOOKUP_ $mft > $look_mft
118 ## cat ../src/lookups/Makefile >> $look_mft
119 cp ../src/lookups/Makefile $look_mft
120
121 # See if there is a definition of EXIM_PERL in what we have built so far.
122 # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS,
123 # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename
124 # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND
125 # if it has been defined.
126
127 EXIM_PERL=`grep EXIM_PERL $mft`
128
129 PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"`
130 if [ "${PERL_COMMAND}" = "" ] ; then
131 PERL_COMMAND='perl'
132 fi
133
134 if [ "${EXIM_PERL}" != "" ] ; then
135 testperl=`$PERL_COMMAND --version`
136 if [ "$testperl" = "" ] ; then
137 echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed"
138 exit 1
139 fi
140
141 EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1`
142 if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then
143 echo "Please install ExtUtils::Embed for $PERL_COMMAND"
144 exit 1;
145 fi
146
147 mv $mft $mftt
148 echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft
149 echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft
150 echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft
151 echo "" >>$mft
152 cat $mftt >> $mft
153 rm -f $mftt
154 fi
155
156 # Record the build variable in the Makefile.
157
158 echo "build=$build" >>$mft
159 echo "" >>$mft
160
161 # Finally, join on the generic base make file, which contains the actual
162 # rules and stuff.
163
164 echo "# From ../OS/Makefile-Base" >> $mft
165 cat ../OS/Makefile-Base >> $mft || exit 1
166
167 # If the new makefile is the same as the existing one, say so, and just
168 # update the timestamp. Otherwise remove the old and install the new.
169
170 if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mft $look_mf
171 then echo ">>> rebuilt $mf unchanged"
172 echo " "
173 touch $mf || exit
174 rm -f $mft
175 elif rm -f $mf $look_mf
176 mv $mft $mf
177 mv $look_mft $look_mf
178 then echo ">>> New $mf & $look_mf installed"
179 echo '>>> Use "make makefile" if you need to force rebuilding of the makefile'
180 echo " "
181 else echo " "
182 echo "*** Failed to install $mf - see $mft"
183 echo " (or $look_mft)"
184 echo " "
185 exit 1;
186 fi
187
188 # End of Configure-Makefile