Commit | Line | Data |
---|---|---|
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 | ||
11 | ostype=`../scripts/os-type -generic` || exit 1 | |
12 | ||
13 | if [ ! -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 | |
19 | fi | |
20 | ||
21 | # We also need the architecture type, in order to test for any architecture- | |
22 | # specific configuration files. | |
23 | ||
24 | archtype=`../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 | ||
30 | editme=../Local/Makefile | |
31 | rebuild=yes | |
32 | ||
33 | if [ -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 | |
45 | fi | |
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 | ||
50 | if [ "X$build" != "X" ] ; then | |
51 | mfb=Local/Makefile-$build | |
52 | if ../scripts/newer $editme-$build Makefile ; then | |
53 | rebuild=yes | |
54 | fi | |
55 | else | |
56 | mfb= | |
57 | fi | |
58 | ||
59 | ||
60 | # If Makefile is up-to-date, no need to rebuild it. | |
61 | ||
62 | if [ $rebuild = no ] ; then | |
63 | echo "\`Makefile' is up to date." | |
64 | echo " " | |
65 | exit | |
66 | fi | |
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 | ||
76 | mf=Makefile | |
77 | mft=$mf-t | |
78 | mftt=$mf-tt | |
79 | ||
0a349494 PP |
80 | look_mf=lookups/Makefile.predynamic |
81 | look_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 | 86 | rm -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 | ||
97 | st=' ' | |
98 | ||
99 | for 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 | |
106 | do 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 |
112 | done >> $mft || exit 1 |
113 | ||
114 | # make the lookups Makefile with the definitions | |
115 | ||
116 | ## prepend stuff here; eg: grep LOOKUP_ $mft > $look_mft | |
117 | ## cat ../src/lookups/Makefile >> $look_mft | |
118 | cp ../src/lookups/Makefile $look_mft | |
61ec970d PH |
119 | |
120 | # See if there is a definition of EXIM_PERL in what we have built so far. | |
121 | # If so, run Perl to find the default values for PERL_CC, PERL_CCOPTS, | |
122 | # and PERL_LIBS. These need to be put at the top of the Makefile, so we rename | |
123 | # what we have so far and then copy it afterwards. Use the value of PERL_COMMAND | |
124 | # if it has been defined. | |
125 | ||
126 | EXIM_PERL=`grep EXIM_PERL $mft` | |
127 | ||
128 | PERL_COMMAND=`grep PERL_COMMAND $mft | sed -e "\\$!d;s/^[$st]*PERL_COMMAND[$st]*=[$st]*//"` | |
129 | if [ "${PERL_COMMAND}" = "" ] ; then | |
130 | PERL_COMMAND='perl' | |
131 | fi | |
132 | ||
133 | if [ "${EXIM_PERL}" != "" ] ; then | |
134 | testperl=`$PERL_COMMAND --version` | |
135 | if [ "$testperl" = "" ] ; then | |
136 | echo "*** EXIM_PERL is set, but '$PERL_COMMAND --version' failed" | |
137 | exit 1 | |
138 | fi | |
139 | ||
177ebd9b NM |
140 | EXTUTILS_EMBED_NOT_INSTALLED=`$PERL_COMMAND -MExtUtils::Embed -e ";" 2>&1` |
141 | if [ "${EXTUTILS_EMBED_NOT_INSTALLED}" != "" ] ; then | |
142 | echo "Please install ExtUtils::Embed for $PERL_COMMAND" | |
143 | exit 1; | |
144 | fi | |
145 | ||
61ec970d PH |
146 | mv $mft $mftt |
147 | echo "PERL_CC=`$PERL_COMMAND -MConfig -e 'print $Config{cc}'`" >>$mft | |
148 | echo "PERL_CCOPTS=`$PERL_COMMAND -MExtUtils::Embed -e ccopts`" >>$mft | |
149 | echo "PERL_LIBS=`$PERL_COMMAND -MExtUtils::Embed -e ldopts`" >>$mft | |
150 | echo "" >>$mft | |
151 | cat $mftt >> $mft | |
152 | rm -f $mftt | |
153 | fi | |
154 | ||
155 | # Record the build variable in the Makefile. | |
156 | ||
157 | echo "build=$build" >>$mft | |
158 | echo "" >>$mft | |
159 | ||
160 | # Finally, join on the generic base make file, which contains the actual | |
161 | # rules and stuff. | |
162 | ||
76ea0716 | 163 | echo "# From ../OS/Makefile-Base" >> $mft |
61ec970d PH |
164 | cat ../OS/Makefile-Base >> $mft || exit 1 |
165 | ||
166 | # If the new makefile is the same as the existing one, say so, and just | |
167 | # update the timestamp. Otherwise remove the old and install the new. | |
168 | ||
0a349494 | 169 | if [ -s $mf ] && cmp -s $mft $mf && [ -s $look_mf ] && cmp -s $look_mft $look_mf |
61ec970d PH |
170 | then echo ">>> rebuilt $mf unchanged" |
171 | echo " " | |
172 | touch $mf || exit | |
173 | rm -f $mft | |
0a349494 | 174 | elif rm -f $mf $look_mf |
61ec970d | 175 | mv $mft $mf |
0a349494 PP |
176 | mv $look_mft $look_mf |
177 | then echo ">>> New $mf & $look_mf installed" | |
61ec970d PH |
178 | echo '>>> Use "make makefile" if you need to force rebuilding of the makefile' |
179 | echo " " | |
180 | else echo " " | |
181 | echo "*** Failed to install $mf - see $mft" | |
0a349494 | 182 | echo " (or $look_mft)" |
61ec970d PH |
183 | echo " " |
184 | exit 1; | |
185 | fi | |
186 | ||
187 | # End of Configure-Makefile |