source: trunk/run_autotools @ 2362

Last change on this file since 2362 was 2362, checked in by stefan, 8 years ago

report error if autoconf or automake cannot be found

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 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 Eclipse Public License.
7# It is part of the BuildTools project in COIN-OR (www.coin-or.org)
8#
9## $Id: run_autotools 2362 2011-07-09 12:29:54Z 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
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'`
109if autoconf --version > confauto.out 2>&1 ; then : ; else
110  echo "autoconf $ver_autoconf not available"
111  rm -f confauto.out
112  exit 2
113fi
114if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
115  echo You are not using the correct version of autoconf
116  rm -f confauto.out
117  exit 2
118fi
119rm -f confauto.out
120autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
121autoconf_dir=`cd $autoconf_dir; pwd`
122if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
123  echo autoconf is not picked up from the correct location
124  exit 2
125fi
126
127grep_version=`echo  $ver_automake | sed -e 's/\\./\\\\\\./g'`
128if automake --version > confauto.out 2>&1 ; then : ; else
129  echo "automake $ver_automake not available"
130  rm -f confauto.out
131  exit 2
132fi
133if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
134  echo You are not using the correct version of automake
135  rm -f confauto.out
136  exit 2
137fi
138rm -f confauto.out
139autoconf_dir=`which automake | sed -e 's=/automake=='`
140autoconf_dir=`cd $autoconf_dir; pwd`
141if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
142  echo automake is not picked up from the correct location
143  exit 2
144fi
145
146# Failure to find the correct version of libtool isn't fatal here, but
147# the user should be warned.
148
149grep_version=`echo  $ver_libtool | sed -e 's/\\./\\\\\\./g'`
150ltfile=$AUTOTOOLS_DIR/share/libtool/ltmain.sh
151if test -r $ltfile; then :; else
152  echo WARNING: Cannot find libtool shell $ltfile
153fi
154if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else
155  echo WARNING: You are not using the correct version of libtool
156fi
157
158# Set up to process parameters. No parameters is the default.
159
160printHelp=0
161doRecurse=1
162forceScripts=0
163userSpecifiedDirs=0
164dirsToProcess=
165
166# Process the parameters. A parameter without an opening `-' is assumed to be
167# a spec for a directory to be processed.
168
169while test $# -gt 0 && test $printHelp = 0 ; do
170  case "$1" in
171    -h* | --h* )
172         printHelp=1
173         ;;
174    -nr* | --no-recursion )
175         doRecurse=0
176         ;;
177    -i | --independent )
178         forceScripts=1
179         doRecurse=0
180         ;;
181    -* ) echo "$0: unrecognised command line switch '"$1"'."
182         printHelp=1
183         ;;
184     * ) dirsToProcess="$dirsToProcess $1"
185         userSpecifiedDirs=1
186         ;;
187  esac
188  shift
189done
190
191# Help?
192
193if test $printHelp = 1 ; then
194  cat <<EOF
195usage: run_autotools [-h] [-nr] [ directory directory ... ]
196
197  -h  | --help           print help message and exit
198  -nr | --no-recursion   do not do recursive search for configure.ac files
199  -i  | --independent    install scripts necessary for an independent unit
200
201  If no directories are specified, the tree rooted at the current directory
202  is searched recursively for directories with configure.ac files containing
203  COIN configuration macros (AC_COIN_*) and autotools is run in those
204  directories. Directories listed in COIN_SKIP_PROJECTS are skipped.
205  If directories are specified on the command line, the search for configure.ac
206  files is restricted to the specified directories.
207
208  If directories are specified on the command line *and* --no-recursion is
209  given, the specified directories are processed with no checks.
210
211  The --independent option will force installation of install-sh and other
212  scripts necessary for a unit that is installed independently. This will
213  be forced in *all* directories processed. Most often what is desired is
214  to install these scripts in the top-level directory of a unit, so -i
215  forces -nr. It's a good idea to explicitly specify the directories you want
216  to process.
217EOF
218  exit
219fi
220
221# Did the user give directories on the command line? If not, assume the current
222# directory.
223
224if test -z "$dirsToProcess" ; then
225  dirsToProcess='.'
226fi
227
228# If recursion is permitted, find directories which contain a file
229# configure.ac. When all is said and done, each entry in dirs will be of the
230# form `./path/to/directory'
231
232candDirs=
233if test $doRecurse = 1 ; then
234  for dir in $dirsToProcess ; do
235    tmp=`find $dir -name configure.ac | sed -e s%/configure.ac%%g`
236    case "$candDirs" in
237      *"$tmp"* )
238          ;;
239      * )
240          candDirs="$candDirs $tmp"
241          ;;
242      esac
243  done
244else
245  candDirs=$dirsToProcess
246fi
247
248# Did the user specify these directories *and* forbid recursion? In that case,
249# use the directories exactly as given. If not, winnow the candidates.
250# Process a directory only if the configure.ac file contains at least one
251# macro that starts with AC_COIN_, and it's not listed in COIN_SKIP_PROJECTS.
252
253if test $userSpecifiedDirs = 1 && test $doRecurse = 0 ; then
254  dirs=$candDirs
255else
256  dirs=
257  for dir in $candDirs; do
258    if grep AC_COIN_ $dir/configure.ac >/dev/null 2>&1 ; then
259      dirs="$dirs $dir"
260    else
261      echo "  Skipping foreign configure.ac in $dir."
262    fi
263  done
264
265# Now compare against the skip entries in COIN_SKIP_PROJECTS. To match the
266# entries we just collected, add `./' to the front of each skip entry.
267
268  candDirs=$dirs
269  if test x${COIN_SKIP_PROJECTS+set} = xset ; then
270    dirs=
271    for dir in $COIN_SKIP_PROJECTS ; do
272      skip_dirs="$skip_dirs ./$dir"
273    done
274    for dir in $candDirs ; do
275      skip=0
276      for skipdir in $skip_dirs ; do
277        if test $dir = $skipdir ; then
278          skip=1
279          break
280        fi
281      done
282      if test $skip = 0 ; then
283        dirs="$dirs $dir"
284      else
285        echo "  Skipping $dir listed in COIN_SKIP_PROJECTS."
286      fi
287    done
288  fi
289fi
290
291# Set a trap so that we'll clean up any links on exit, for whatever reason.
292# Note that this executes on normal exit, too, so don't do anything rash.
293
294topLink=
295subLink=
296trap 'exit_status=$?
297  cleanupOnErrorExit
298  exit $exit_status' 0
299
300# And now the main event. Process each directory.
301
302echo "Running autotools in $dirs"
303
304autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
305m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4"
306buildtoolsLinks=
307
308for dir in $dirs; do
309  if test -r $dir/configure.ac; then
310    cd $dir
311    echo "Processing $dir ..."
312
313# Do we need a BuildTools subdirectory here? The criteria is that install-sh
314# already exists, or Makefile.am (which may include Makemain.inc), or we're
315# forcing installation of the configure scripts.  Assuming we need BuildTools,
316# what BuildTools should we use? If a BuildTools is already present, that's
317# it.  Otherwise, assume that runautotooldDir is BuildTools. Allow that the
318# user may have linked to a BuildTools.
319
320    needScripts=0
321    if test -f install-sh || test $forceScripts = 1 ; then
322      needScripts=1
323    fi
324    if test -f Makefile.am || test $needScripts = 1 ; then
325      if test -d BuildTools || test -L BuildTools ; then
326        createLink=0
327        toolsDir=`pwd`/BuildTools
328      else
329        createLink=1
330        toolsDir=$runautotoolDir
331      fi
332      echo "  BuildTools directory: $toolsDir"
333
334# Test to be sure that run_autotools is coming from the BuildTools directory.
335
336      if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then
337        echo "WARNING: using run_autotools from $runautotoolDir"
338        echo "         but BuildTools is $toolsDir."
339        echo "         Consider carefully if this is what you wanted to do."
340      fi
341
342# coin.m4 should live in the same directory; failure is fatal.
343
344      if test ! -r $toolsDir/coin.m4 ; then
345        echo "Cannot find Coin autotools macro file $toolsDir/coin.m4."
346        echo "It should be in the BuildTools directory."
347        exit 1
348      fi
349
350# Install a link, if needed.
351
352      if test $createLink = 1 ; then
353        ln -s $toolsDir BuildTools
354        buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools"
355        echo "  creating temporary link for ./BuildTools -> $toolsDir"
356      fi
357
358# And refresh the autotools scripts, if needed.
359
360      if test $needScripts = 1 ; then
361        echo "  refreshing autotools scripts in this directory."
362        for file in $autotoolsFiles ; do
363          cp BuildTools/$file .
364        done
365      fi
366
367    fi
368
369# Get on with running the autotools.
370
371    echo "  creating acinclude.m4 in $dir"
372    cat $m4Files $toolsDir/coin.m4 > acinclude.m4
373    echo "  running aclocal in $dir"
374    if test -d m4; then
375      aclocal -I m4 || exit 1
376    else
377      aclocal || exit 1
378    fi
379    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
380      echo "  running autoheader in $dir"
381      autoheader || exit 1
382    fi
383    echo "  running automake in $dir"
384    automake || exit 1
385    echo "  running autoconf in $dir"
386    autoconf || exit 1
387    cd $startDir
388  else
389    # Serious confusion! Should not reach here.
390    echo "*** No configure.ac file in $dir - SKIPPING! ***"
391  fi
392done
393
394# Remove the links. Yeah, the trap will do this, but it never hurts to clean
395# up properly.
396
397if test -n "$buildtoolsLinks" ; then
398  echo "Removing temporary links to BuildTools."
399  for link in $buildtoolsLinks ; do
400    # echo "  removing temporary link for BuildTools: $link"
401    rm $link
402  done
403  buildtoolsLinks=
404fi
405
406exit
407
Note: See TracBrowser for help on using the repository browser.