source: trunk/run_autotools @ 1597

Last change on this file since 1597 was 1597, checked in by lou, 10 years ago

Add some quoting to fix a bug Andreas found.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 12.9 KB
Line 
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 Common Public License.
7# It is part of the BuildTools project in COIN-OR (www.coin-or.org)
8#
9## $Id: run_autotools 1597 2010-07-09 15:39:37Z lou $
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
58set -e
59
60# Define a cleanup function. We'll set a trap below, just before we start to
61# do actual work.
62
63cleanupOnErrorExit ()
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
79startDir=`pwd`
80if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then
81  runautotoolDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'`
82else
83  runautotoolDir='.'
84fi
85if  expr "$runautotoolDir" : '/.*' >/dev/null 2>&1 ; then
86  :
87else
88  runautotoolDir=$startDir/$runautotoolDir
89fi
90while expr "$runautotoolDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
91  runautotoolDir=`echo $runautotoolDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
92done
93runautotoolDir=`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
98ver_autoconf='2.59'
99ver_automake='1.9.6'
100ver_libtool='1.5.22'
101EGREP='grep -E'
102
103# Check if the correct version of the autotools is used
104if test x$AUTOTOOLS_DIR = x; then
105  AUTOTOOLS_DIR=$HOME
106fi
107
108grep_version=`echo  $ver_autoconf | sed -e 's/\\./\\\\\\./g'`
109autoconf --version > confauto.out 2>&1
110if $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
114fi
115rm -f confauto.out
116autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
117autoconf_dir=`cd $autoconf_dir; pwd`
118if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
119  echo autoconf is not picked up from the correct location
120  exit 2
121fi
122
123grep_version=`echo  $ver_automake | sed -e 's/\\./\\\\\\./g'`
124automake --version > confauto.out 2>&1
125if $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
129fi
130rm -f confauto.out
131autoconf_dir=`which automake | sed -e 's=/automake=='`
132autoconf_dir=`cd $autoconf_dir; pwd`
133if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
134  echo automake is not picked up from the correct location
135  exit 2
136fi
137
138# Failure to find the correct version of libtool isn't fatal here, but
139# the user should be warned.
140
141grep_version=`echo  $ver_libtool | sed -e 's/\\./\\\\\\./g'`
142ltfile=$AUTOTOOLS_DIR/share/libtool/ltmain.sh
143if test -r $ltfile; then :; else
144  echo WARNING: Cannot file libtool shell $ltfile
145fi
146if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else
147  echo WARNING: You are not using the correct version of libtool
148fi
149
150# Set up to process parameters. No parameters is the default.
151
152printHelp=0
153doRecurse=1
154forceScripts=0
155userSpecifiedDirs=0
156dirsToProcess=
157
158# Process the parameters. A parameter without an opening `-' is assumed to be
159# a spec for a directory to be processed.
160
161while 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
181done
182
183# Help?
184
185if test $printHelp = 1 ; then
186  cat <<EOF
187usage: 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.
209EOF
210  exit
211fi
212
213# Did the user give directories on the command line? If not, assume the current
214# directory.
215
216if test -z "$dirsToProcess" ; then
217  dirsToProcess='.'
218fi
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
224candDirs=
225if 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
236else
237  candDirs=$dirsToProcess
238fi
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
245if test $userSpecifiedDirs = 1 && test $doRecurse = 0 ; then
246  dirs=$candDirs
247else
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
281fi
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
286topLink=
287subLink=
288trap 'exit_status=$?
289  cleanupOnErrorExit
290  exit $exit_status' 0
291
292# Get down to business
293
294echo "Running autotools in $dirs"
295
296# And now the main event. Process each directory.
297
298echo "Running autotools in $dirs"
299
300autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
301m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4"
302buildtoolsLinks=
303
304for dir in $dirs; do
305  if test -r $dir/configure.ac; then
306    cd $dir
307    echo "Processing $dir ..."
308
309# Do we need a BuildTools subdirectory here? The criteria is that install-sh
310# already exists, or Makefile.am (which may include Makemain.inc), or we're
311# forcing installation of the configure scripts.  Assuming we need BuildTools,
312# what BuildTools should we use? If a BuildTools is already present, that's
313# it.  Otherwise, assume that runautotooldDir is BuildTools. Allow that the
314# user may have linked to a BuildTools.
315
316    needScripts=0
317    if test -f install-sh || test $forceScripts = 1 ; then
318      needScripts=1
319    fi
320    if test -f Makefile.am || test $needScripts = 1 ; then
321      if test -d BuildTools || test -L BuildTools ; then
322        createLink=0
323        toolsDir=`pwd`/BuildTools
324      else
325        createLink=1
326        toolsDir=$runautotoolDir
327      fi
328      echo "  BuildTools directory: $toolsDir"
329
330# Test to be sure that run_autotools is coming from the BuildTools directory.
331
332      if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then
333        echo "WARNING: using run_autotools from $runautotoolDir"
334        echo "         but BuildTools is $toolsDir."
335        echo "         Consider carefully if this is what you wanted to do."
336      fi
337
338# coin.m4 should live in the same directory; failure is fatal.
339
340      if test ! -r $toolsDir/coin.m4 ; then
341        echo "Cannot find Coin autotools macro file $toolsDir/coin.m4."
342        echo "It should be in the BuildTools directory."
343        exit 1
344      fi
345
346# Install a link, if needed.
347
348      if test $createLink = 1 ; then
349        ln -s $toolsDir BuildTools
350        buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools"
351        echo "  creating temporary link for ./BuildTools -> $toolsDir"
352      fi
353
354# And refresh the autotools scripts, if needed.
355
356      if test $needScripts = 1 ; then
357        echo "  refreshing autotools scripts in this directory."
358        for file in $autotoolsFiles ; do
359          cp BuildTools/$file .
360        done
361      fi
362
363    fi
364
365# Get on with running the autotools.
366
367    echo "  creating acinclude.m4 in $dir"
368    cat $m4Files $toolsDir/coin.m4 > acinclude.m4
369    echo "  running aclocal in $dir"
370    if test -d m4; then
371      aclocal -I m4 || exit 1
372    else
373      aclocal || exit 1
374    fi
375    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
376      echo "  running autoheader in $dir"
377      autoheader || exit 1
378    fi
379    echo "  running automake in $dir"
380    automake || exit 1
381    echo "  running autoconf in $dir"
382    autoconf || exit 1
383    cd $startDir
384  else
385    # Serious confusion! Should not reach here.
386    echo "*** No configure.ac file in $dir - SKIPPING! ***"
387  fi
388done
389
390# Remove the links. Yeah, the trap will do this, but it never hurts to clean
391# up properly.
392
393if test -n "$buildtoolsLinks" ; then
394  echo "Removing temporary links to BuildTools."
395  for link in $buildtoolsLinks ; do
396    # echo "  removing temporary link for BuildTools: $link"
397    rm $link
398  done
399  buildtoolsLinks=
400fi
401
402exit
403
Note: See TracBrowser for help on using the repository browser.