1 | #!/bin/sh |
---|
2 | |
---|
3 | # Copyright (C) 2006, 2007, 2008, 2009, 2010 International Business Machines |
---|
4 | # and others. |
---|
5 | # All Rights Reserved. |
---|
6 | # This file is distributed under the Eclipse Public License. |
---|
7 | # It is part of the BuildTools project in COIN-OR (www.coin-or.org) |
---|
8 | # |
---|
9 | ## $Id: run_autotools 1950 2010-12-22 15:31:49Z stefan $ |
---|
10 | # |
---|
11 | # Author: Andreas Waechter IBM 2006-04-14 |
---|
12 | # Modified: Lou Hafer SFU 2010-06-11 |
---|
13 | # Mods to allow variations from standard package structure. Decision to |
---|
14 | # process a configure.ac file is based on presence of COIN macros. |
---|
15 | # Directories specified on the command line are recursively searched |
---|
16 | # for configure.ac files. Install-sh signals an independent unit. |
---|
17 | # Modified: Lou Hafer SFU 2010-07-08 |
---|
18 | # More mods to maintain flexibility but be a bit less aggressive about |
---|
19 | # forcing installation of autotools auxilliary scripts. Also add some |
---|
20 | # command line options and restore ability to specify individual |
---|
21 | # directories on the command line. |
---|
22 | |
---|
23 | # run_autotools takes care of running the autotools (automake, autoconf, |
---|
24 | # and helpers) and also makes a few arrangements for when configure and |
---|
25 | # libtool execute at configuration, build, and installation. |
---|
26 | |
---|
27 | # Run_autotools can be given a set of directories on the command line; if none |
---|
28 | # are specified, it assumes the current directory (`,'). Subdirectories are |
---|
29 | # searched for configure.ac files unless suppressed with the -nr option. |
---|
30 | # Autotools will consider a directory for processing if any AC_COIN_ macro is |
---|
31 | # present in the configure.ac file. Should it be necessary to fool this script |
---|
32 | # into processing a file that otherwise contains no COIN macros, just add a |
---|
33 | # line with AC_COIN_. The resulting list is winnowed to remove directories |
---|
34 | # specified in COIN_SKIP_PROJECTS. |
---|
35 | |
---|
36 | # Each directory processed gets a temporary link to BuildTools, unless a |
---|
37 | # BuildTools subdirectory is already present. Mostly this is a convenience, but |
---|
38 | # one thing makes it mandatory: Many Makefile.am files in COIN use an include |
---|
39 | # directive to pull in BuildTools/Makemain.inc. There's no way I (lh) can see |
---|
40 | # to alter the path that's hardcoded in the include directive. Just to make it |
---|
41 | # more interesting, COIN projects are generally constructed with the assumption |
---|
42 | # that BuildTools will be one or two directories up, so you'll see things like |
---|
43 | # `include ../BuildTools/Makemain.inc'. run_autotools doesn't understand this |
---|
44 | # hierarchy, so it keeps all those temporary BuildTools links until the very |
---|
45 | # end. That way, it works with the old-style COIN organisation where a |
---|
46 | # BuildTools directory is pulled in as an external in the top directory of a |
---|
47 | # package, and with the new-style independent organisation, where there may be |
---|
48 | # only a single copy of BuildTools out there somewhere. |
---|
49 | |
---|
50 | # If any subdirectory queued for processing is found to contain an install-sh |
---|
51 | # script, it is treated as an independent unit (i.e., you can run `make |
---|
52 | # install' from this directory) and the set of auxilliary scripts is refreshed |
---|
53 | # from BuildTools. You can force installation of install-sh and associated |
---|
54 | # scripts with the -i option. It's good to read the autoconf documentation for |
---|
55 | # AC_CONFIG_AUX_DIR if this doesn't make sense to you. |
---|
56 | |
---|
57 | # Make sure we bail out if there is an error |
---|
58 | set -e |
---|
59 | |
---|
60 | # Define a cleanup function. We'll set a trap below, just before we start to |
---|
61 | # do actual work. |
---|
62 | |
---|
63 | cleanupOnErrorExit () |
---|
64 | { for link in $buildtoolsLinks; do |
---|
65 | echo Trap: removing $link |
---|
66 | rm -f $link |
---|
67 | done |
---|
68 | cd $startDir |
---|
69 | } |
---|
70 | |
---|
71 | # Note that vanilla sh doesn't like negative exit values. |
---|
72 | |
---|
73 | # Determine the location of run_autotools. If there are no '/' chars in |
---|
74 | # the command name, we're running in the current directory (almost certainly |
---|
75 | # not what's wanted). Otherwise, strip the command name, leaving the prefix. |
---|
76 | # Convert the prefix to an absolute path, if needed, and clean it up, removing |
---|
77 | # `XXX/..', '/./', '//' sequences. |
---|
78 | |
---|
79 | startDir=`pwd` |
---|
80 | if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then |
---|
81 | runautotoolDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'` |
---|
82 | else |
---|
83 | runautotoolDir='.' |
---|
84 | fi |
---|
85 | if expr "$runautotoolDir" : '/.*' >/dev/null 2>&1 ; then |
---|
86 | : |
---|
87 | else |
---|
88 | runautotoolDir=$startDir/$runautotoolDir |
---|
89 | fi |
---|
90 | while expr "$runautotoolDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do |
---|
91 | runautotoolDir=`echo $runautotoolDir | sed -e 's,/[^/][^/]*/\.\./,/,'` |
---|
92 | done |
---|
93 | runautotoolDir=`echo $runautotoolDir | sed -e 's,/\./,/,g' -e 's,//,/,g'` |
---|
94 | |
---|
95 | # Make sure we're using the correct versions of the autotools. Failure to |
---|
96 | # satisfy this requirement is a fatal error. |
---|
97 | |
---|
98 | ver_autoconf='2.59' |
---|
99 | ver_automake='1.9.6' |
---|
100 | ver_libtool='1.5.22' |
---|
101 | EGREP='grep -E' |
---|
102 | |
---|
103 | # Check if the correct version of the autotools is used |
---|
104 | if test x$AUTOTOOLS_DIR = x; then |
---|
105 | AUTOTOOLS_DIR=$HOME |
---|
106 | fi |
---|
107 | |
---|
108 | grep_version=`echo $ver_autoconf | sed -e 's/\\./\\\\\\./g'` |
---|
109 | autoconf --version > confauto.out 2>&1 |
---|
110 | if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else |
---|
111 | echo You are not using the correct version of autoconf |
---|
112 | rm -f confauto.out |
---|
113 | exit 2 |
---|
114 | fi |
---|
115 | rm -f confauto.out |
---|
116 | autoconf_dir=`which autoconf | sed -e 's=/autoconf=='` |
---|
117 | autoconf_dir=`cd $autoconf_dir; pwd` |
---|
118 | if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else |
---|
119 | echo autoconf is not picked up from the correct location |
---|
120 | exit 2 |
---|
121 | fi |
---|
122 | |
---|
123 | grep_version=`echo $ver_automake | sed -e 's/\\./\\\\\\./g'` |
---|
124 | automake --version > confauto.out 2>&1 |
---|
125 | if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else |
---|
126 | echo You are not using the correct version of automake |
---|
127 | rm -f confauto.out |
---|
128 | exit 2 |
---|
129 | fi |
---|
130 | rm -f confauto.out |
---|
131 | autoconf_dir=`which automake | sed -e 's=/automake=='` |
---|
132 | autoconf_dir=`cd $autoconf_dir; pwd` |
---|
133 | if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else |
---|
134 | echo automake is not picked up from the correct location |
---|
135 | exit 2 |
---|
136 | fi |
---|
137 | |
---|
138 | # Failure to find the correct version of libtool isn't fatal here, but |
---|
139 | # the user should be warned. |
---|
140 | |
---|
141 | grep_version=`echo $ver_libtool | sed -e 's/\\./\\\\\\./g'` |
---|
142 | ltfile=$AUTOTOOLS_DIR/share/libtool/ltmain.sh |
---|
143 | if test -r $ltfile; then :; else |
---|
144 | echo WARNING: Cannot file libtool shell $ltfile |
---|
145 | fi |
---|
146 | if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else |
---|
147 | echo WARNING: You are not using the correct version of libtool |
---|
148 | fi |
---|
149 | |
---|
150 | # Set up to process parameters. No parameters is the default. |
---|
151 | |
---|
152 | printHelp=0 |
---|
153 | doRecurse=1 |
---|
154 | forceScripts=0 |
---|
155 | userSpecifiedDirs=0 |
---|
156 | dirsToProcess= |
---|
157 | |
---|
158 | # Process the parameters. A parameter without an opening `-' is assumed to be |
---|
159 | # a spec for a directory to be processed. |
---|
160 | |
---|
161 | while test $# -gt 0 && test $printHelp = 0 ; do |
---|
162 | case "$1" in |
---|
163 | -h* | --h* ) |
---|
164 | printHelp=1 |
---|
165 | ;; |
---|
166 | -nr* | --no-recursion ) |
---|
167 | doRecurse=0 |
---|
168 | ;; |
---|
169 | -i | --independent ) |
---|
170 | forceScripts=1 |
---|
171 | doRecurse=0 |
---|
172 | ;; |
---|
173 | -* ) echo "$0: unrecognised command line switch '"$1"'." |
---|
174 | printHelp=1 |
---|
175 | ;; |
---|
176 | * ) dirsToProcess="$dirsToProcess $1" |
---|
177 | userSpecifiedDirs=1 |
---|
178 | ;; |
---|
179 | esac |
---|
180 | shift |
---|
181 | done |
---|
182 | |
---|
183 | # Help? |
---|
184 | |
---|
185 | if test $printHelp = 1 ; then |
---|
186 | cat <<EOF |
---|
187 | usage: run_autotools [-h] [-nr] [ directory directory ... ] |
---|
188 | |
---|
189 | -h | --help print help message and exit |
---|
190 | -nr | --no-recursion do not do recursive search for configure.ac files |
---|
191 | -i | --independent install scripts necessary for an independent unit |
---|
192 | |
---|
193 | If no directories are specified, the tree rooted at the current directory |
---|
194 | is searched recursively for directories with configure.ac files containing |
---|
195 | COIN configuration macros (AC_COIN_*) and autotools is run in those |
---|
196 | directories. Directories listed in COIN_SKIP_PROJECTS are skipped. |
---|
197 | If directories are specified on the command line, the search for configure.ac |
---|
198 | files is restricted to the specified directories. |
---|
199 | |
---|
200 | If directories are specified on the command line *and* --no-recursion is |
---|
201 | given, the specified directories are processed with no checks. |
---|
202 | |
---|
203 | The --independent option will force installation of install-sh and other |
---|
204 | scripts necessary for a unit that is installed independently. This will |
---|
205 | be forced in *all* directories processed. Most often what is desired is |
---|
206 | to install these scripts in the top-level directory of a unit, so -i |
---|
207 | forces -nr. It's a good idea to explicitly specify the directories you want |
---|
208 | to process. |
---|
209 | EOF |
---|
210 | exit |
---|
211 | fi |
---|
212 | |
---|
213 | # Did the user give directories on the command line? If not, assume the current |
---|
214 | # directory. |
---|
215 | |
---|
216 | if test -z "$dirsToProcess" ; then |
---|
217 | dirsToProcess='.' |
---|
218 | fi |
---|
219 | |
---|
220 | # If recursion is permitted, find directories which contain a file |
---|
221 | # configure.ac. When all is said and done, each entry in dirs will be of the |
---|
222 | # form `./path/to/directory' |
---|
223 | |
---|
224 | candDirs= |
---|
225 | if test $doRecurse = 1 ; then |
---|
226 | for dir in $dirsToProcess ; do |
---|
227 | tmp=`find $dir -name configure.ac | sed -e s%/configure.ac%%g` |
---|
228 | case "$candDirs" in |
---|
229 | *"$tmp"* ) |
---|
230 | ;; |
---|
231 | * ) |
---|
232 | candDirs="$candDirs $tmp" |
---|
233 | ;; |
---|
234 | esac |
---|
235 | done |
---|
236 | else |
---|
237 | candDirs=$dirsToProcess |
---|
238 | fi |
---|
239 | |
---|
240 | # Did the user specify these directories *and* forbid recursion? In that case, |
---|
241 | # use the directories exactly as given. If not, winnow the candidates. |
---|
242 | # Process a directory only if the configure.ac file contains at least one |
---|
243 | # macro that starts with AC_COIN_, and it's not listed in COIN_SKIP_PROJECTS. |
---|
244 | |
---|
245 | if test $userSpecifiedDirs = 1 && test $doRecurse = 0 ; then |
---|
246 | dirs=$candDirs |
---|
247 | else |
---|
248 | dirs= |
---|
249 | for dir in $candDirs; do |
---|
250 | if grep AC_COIN_ $dir/configure.ac >/dev/null 2>&1 ; then |
---|
251 | dirs="$dirs $dir" |
---|
252 | else |
---|
253 | echo " Skipping foreign configure.ac in $dir." |
---|
254 | fi |
---|
255 | done |
---|
256 | |
---|
257 | # Now compare against the skip entries in COIN_SKIP_PROJECTS. To match the |
---|
258 | # entries we just collected, add `./' to the front of each skip entry. |
---|
259 | |
---|
260 | candDirs=$dirs |
---|
261 | if test x${COIN_SKIP_PROJECTS+set} = xset ; then |
---|
262 | dirs= |
---|
263 | for dir in $COIN_SKIP_PROJECTS ; do |
---|
264 | skip_dirs="$skip_dirs ./$dir" |
---|
265 | done |
---|
266 | for dir in $candDirs ; do |
---|
267 | skip=0 |
---|
268 | for skipdir in $skip_dirs ; do |
---|
269 | if test $dir = $skipdir ; then |
---|
270 | skip=1 |
---|
271 | break |
---|
272 | fi |
---|
273 | done |
---|
274 | if test $skip = 0 ; then |
---|
275 | dirs="$dirs $dir" |
---|
276 | else |
---|
277 | echo " Skipping $dir listed in COIN_SKIP_PROJECTS." |
---|
278 | fi |
---|
279 | done |
---|
280 | fi |
---|
281 | fi |
---|
282 | |
---|
283 | # Set a trap so that we'll clean up any links on exit, for whatever reason. |
---|
284 | # Note that this executes on normal exit, too, so don't do anything rash. |
---|
285 | |
---|
286 | topLink= |
---|
287 | subLink= |
---|
288 | trap 'exit_status=$? |
---|
289 | cleanupOnErrorExit |
---|
290 | exit $exit_status' 0 |
---|
291 | |
---|
292 | # And now the main event. Process each directory. |
---|
293 | |
---|
294 | echo "Running autotools in $dirs" |
---|
295 | |
---|
296 | autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing" |
---|
297 | m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4" |
---|
298 | buildtoolsLinks= |
---|
299 | |
---|
300 | for dir in $dirs; do |
---|
301 | if test -r $dir/configure.ac; then |
---|
302 | cd $dir |
---|
303 | echo "Processing $dir ..." |
---|
304 | |
---|
305 | # Do we need a BuildTools subdirectory here? The criteria is that install-sh |
---|
306 | # already exists, or Makefile.am (which may include Makemain.inc), or we're |
---|
307 | # forcing installation of the configure scripts. Assuming we need BuildTools, |
---|
308 | # what BuildTools should we use? If a BuildTools is already present, that's |
---|
309 | # it. Otherwise, assume that runautotooldDir is BuildTools. Allow that the |
---|
310 | # user may have linked to a BuildTools. |
---|
311 | |
---|
312 | needScripts=0 |
---|
313 | if test -f install-sh || test $forceScripts = 1 ; then |
---|
314 | needScripts=1 |
---|
315 | fi |
---|
316 | if test -f Makefile.am || test $needScripts = 1 ; then |
---|
317 | if test -d BuildTools || test -L BuildTools ; then |
---|
318 | createLink=0 |
---|
319 | toolsDir=`pwd`/BuildTools |
---|
320 | else |
---|
321 | createLink=1 |
---|
322 | toolsDir=$runautotoolDir |
---|
323 | fi |
---|
324 | echo " BuildTools directory: $toolsDir" |
---|
325 | |
---|
326 | # Test to be sure that run_autotools is coming from the BuildTools directory. |
---|
327 | |
---|
328 | if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then |
---|
329 | echo "WARNING: using run_autotools from $runautotoolDir" |
---|
330 | echo " but BuildTools is $toolsDir." |
---|
331 | echo " Consider carefully if this is what you wanted to do." |
---|
332 | fi |
---|
333 | |
---|
334 | # coin.m4 should live in the same directory; failure is fatal. |
---|
335 | |
---|
336 | if test ! -r $toolsDir/coin.m4 ; then |
---|
337 | echo "Cannot find Coin autotools macro file $toolsDir/coin.m4." |
---|
338 | echo "It should be in the BuildTools directory." |
---|
339 | exit 1 |
---|
340 | fi |
---|
341 | |
---|
342 | # Install a link, if needed. |
---|
343 | |
---|
344 | if test $createLink = 1 ; then |
---|
345 | ln -s $toolsDir BuildTools |
---|
346 | buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools" |
---|
347 | echo " creating temporary link for ./BuildTools -> $toolsDir" |
---|
348 | fi |
---|
349 | |
---|
350 | # And refresh the autotools scripts, if needed. |
---|
351 | |
---|
352 | if test $needScripts = 1 ; then |
---|
353 | echo " refreshing autotools scripts in this directory." |
---|
354 | for file in $autotoolsFiles ; do |
---|
355 | cp BuildTools/$file . |
---|
356 | done |
---|
357 | fi |
---|
358 | |
---|
359 | fi |
---|
360 | |
---|
361 | # Get on with running the autotools. |
---|
362 | |
---|
363 | echo " creating acinclude.m4 in $dir" |
---|
364 | cat $m4Files $toolsDir/coin.m4 > acinclude.m4 |
---|
365 | echo " running aclocal in $dir" |
---|
366 | if test -d m4; then |
---|
367 | aclocal -I m4 || exit 1 |
---|
368 | else |
---|
369 | aclocal || exit 1 |
---|
370 | fi |
---|
371 | if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then |
---|
372 | echo " running autoheader in $dir" |
---|
373 | autoheader || exit 1 |
---|
374 | fi |
---|
375 | echo " running automake in $dir" |
---|
376 | automake || exit 1 |
---|
377 | echo " running autoconf in $dir" |
---|
378 | autoconf || exit 1 |
---|
379 | cd $startDir |
---|
380 | else |
---|
381 | # Serious confusion! Should not reach here. |
---|
382 | echo "*** No configure.ac file in $dir - SKIPPING! ***" |
---|
383 | fi |
---|
384 | done |
---|
385 | |
---|
386 | # Remove the links. Yeah, the trap will do this, but it never hurts to clean |
---|
387 | # up properly. |
---|
388 | |
---|
389 | if test -n "$buildtoolsLinks" ; then |
---|
390 | echo "Removing temporary links to BuildTools." |
---|
391 | for link in $buildtoolsLinks ; do |
---|
392 | # echo " removing temporary link for BuildTools: $link" |
---|
393 | rm $link |
---|
394 | done |
---|
395 | buildtoolsLinks= |
---|
396 | fi |
---|
397 | |
---|
398 | exit |
---|
399 | |
---|