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