source: trunk/run_autotools @ 1595

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

Restore command line specification of directories. Add parameters to request
help and suppress recursive search for configure.ac files.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 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 1595 2010-07-08 21:20:16Z 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
18# run_autotools takes care of running the autotools (automake, autoconf,
19# and helpers) and also makes a few arrangements for when configure and
20# libtool execute at configuration, build, and installation.
21
22# The operating assumption is that run_autotools is run in the top level of a
23# directory tree, and that directory tree is the top of an independent unit. If
24# there is no BuildTools subdirectory present, run_autotools will create
25# a link to the directory where it lives, which is assumed to be a BuildTools
26# directory somewhere else. The advantage to this approach is that BuildTools
27# appears to live in a known location (constant within the directory tree
28# of the unit).  This is necessary for proper handling by automake of some
29# standard COIN includes in Makefile.am which reference files in BuildTools.
30# run_autotools will also copy a number of autotools scripts (required for
31# build and installation of any independent unit) from BuildTools into the
32# directory where it is run. This, too, is required. The location of these
33# files is frozen when automake and autoconf run, and they must move with
34# the independent unit because they will be required when configure is run
35# and the unit is built and installed.
36
37# Subdirectories are searched for configure.ac files. Autotools will be run
38# in these directories if any AC_COIN_ macro is present in the configure.ac
39# file. Should it be necessary to fool this script into processing a file that
40# otherwise contains no COIN macros, just add a line with AC_COIN_.
41
42# If any subdirectory queued for processing is found to contain an install-sh
43# script, it is treated as an independent unit (BuildTools link and script
44# copies).
45
46# Make sure we bail out if there is an error
47set -e
48
49# Define a cleanup function. We'll set a trap below, just before we start to
50# do actual work.
51
52cleanupOnErrorExit ()
53{ for link in $topLink $subLink ; do
54    echo Trap: removing $link
55    rm -f $link
56  done
57  cd $startDir
58}
59
60# Note that vanilla sh doesn't like negative exit values.
61
62# Determine the location of run_autotools.  If there are no '/' chars in
63# the command name, we're running in the current directory (almost certainly
64# not what's wanted). Otherwise, strip the command name, leaving the prefix.
65
66startDir=`pwd`
67if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then
68  runautotoolDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'`
69else
70  runautotoolDir='.'
71fi
72runautotoolDir=$startDir/$runautotoolDir
73while expr "$runautotoolDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
74  runautotoolDir=`echo $runautotoolDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
75done
76
77# Determine the location of BuildTools. If there's a BuildTools subdirectory
78# in the current directory, that's it.  Otherwise, assume that runautotooldDir
79# is BuildTools. Allow that the user may have linked to a BuildTools.
80
81createLink=0
82if test -d BuildTools || test -L BuildTools ; then
83  toolsDir=BuildTools
84else
85  createLink=1
86  toolsDir=$runautotoolDir
87fi
88
89# Create an absolute path if we don't have one, because we'll be moving
90# around. Clean up the path by removing `XXX/..', '/./', '//' sequences.
91
92if expr "$toolsDir" : '/.*' >/dev/null 2>&1 ; then
93  :
94else
95  toolsDir=$startDir/$toolsDir
96fi
97while expr "$toolsDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
98  toolsDir=`echo $toolsDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
99done
100toolsDir=`echo $toolsDir | sed -e 's,/\./,/,g' -e 's,//,/,g'`
101
102# Test to be sure that run_autotools is coming from the BuildTools directory.
103
104if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then
105  echo "WARNING: using run_autotools from $runautotoolDir"
106  echo "         but BuildTools is $toolsDir."
107  echo "         Consider carefully if this is what you wanted to do."
108fi
109
110echo "BuildTools directory: $toolsDir"
111
112# coin.m4 should live in the same directory, but this failure is fatal.
113
114if test ! -r $toolsDir/coin.m4 ; then
115  echo "Cannot find Coin autotools macro file $toolsDir/coin.m4. It should"
116  echo "be in the BuildTools directory."
117  exit 1
118fi
119
120# As is the failure to find the correct versions of autoconf or automake.
121
122ver_autoconf='2.59'
123ver_automake='1.9.6'
124ver_libtool='1.5.22'
125EGREP='grep -E'
126
127# Check if the correct version of the autotools is used
128if test x$AUTOTOOLS_DIR = x; then
129  AUTOTOOLS_DIR=$HOME
130fi
131
132grep_version=`echo  $ver_autoconf | sed -e 's/\\./\\\\\\./g'`
133autoconf --version > confauto.out 2>&1
134if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
135  echo You are not using the correct version of autoconf
136  rm -f confauto.out
137  exit 2
138fi
139rm -f confauto.out
140autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
141autoconf_dir=`cd $autoconf_dir; pwd`
142if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
143  echo autoconf is not picked up from the correct location
144  exit 2
145fi
146
147grep_version=`echo  $ver_automake | sed -e 's/\\./\\\\\\./g'`
148automake --version > confauto.out 2>&1
149if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
150  echo You are not using the correct version of automake
151  rm -f confauto.out
152  exit 2
153fi
154rm -f confauto.out
155autoconf_dir=`which automake | sed -e 's=/automake=='`
156autoconf_dir=`cd $autoconf_dir; pwd`
157if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
158  echo automake is not picked up from the correct location
159  exit 2
160fi
161
162# Failure to find the correct version of libtool isn't fatal here, but
163# the user should be warned.
164
165grep_version=`echo  $ver_libtool | sed -e 's/\\./\\\\\\./g'`
166ltfile=$AUTOTOOLS_DIR/share/libtool/ltmain.sh
167if test -r $ltfile; then :; else
168  echo WARNING: Cannot file libtool shell $ltfile
169fi
170if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else
171  echo WARNING: You are not using the correct version of libtool
172fi
173
174# Set up to process parameters. No parameters is the default.
175
176printHelp=0
177doRecurse=1
178userSpecifiedDirs=0
179dirsToProcess=
180
181# Process the parameters. A parameter without an opening `-' is assumed to be
182# a spec for a directory to be processed.
183
184while test $# -gt 0 && test $printHelp = 0 ; do
185  case "$1" in
186    -h* | --h* )
187         printHelp=1
188         ;;
189    -nr* | --no-recursion )
190         doRecurse=0
191         ;;
192     -* ) echo "$0: unrecognised command line switch '"$1"'."
193          printHelp=1
194          ;;
195      * ) dirsToProcess="$dirsToProcess $1"
196          userSpecifiedDirs=1
197          ;;
198  esac
199  shift
200done
201
202# Help?
203
204if test $printHelp = 1 ; then
205  cat <<EOF
206usage: run_autotools [-h] [-nr] [ directory directory ... ]
207
208  -h  | --help           print help message and exit
209  -nr | --no-recursion   do not do recursive search for configure.ac files
210
211  If no directories are specified, the tree rooted at the current directory
212  is searched recursively for directories with configure.ac files containing
213  COIN configuration macros (AC_COIN_*) and autotools is run in those
214  directories. Directories listed in COIN_SKIP_PROJECTS are skipped.
215  If directories are specified on the command line, the search for configure.ac
216  files is restricted to the specified directories.
217
218  If directories are specified on the command line *and* --no-recursion is
219  given, the specified directories are processed with no checks.
220EOF
221  exit
222fi
223
224# Did the user give directories on the command line? If not, assume the current
225# directory.
226
227if test -z "$dirsToProcess" ; then
228  dirsToProcess='.'
229fi
230
231# If recursion is permitted, find directories which contain a file
232# configure.ac. When all is said and done, each entry in dirs will be of the
233# form `./path/to/directory'
234
235candDirs=
236if test $doRecurse = 1 ; then
237  for dir in $dirsToProcess ; do
238    tmp=`find $dir -name configure.ac | sed -e s%/configure.ac%%g`
239    case "$candDirs" in
240      *"$tmp"* )
241          ;;
242      * )
243          candDirs="$candDirs $tmp"
244          ;;
245      esac
246  done
247else
248  candDirs=$dirsToProcess
249fi
250
251# Did the user specify these directories *and* forbid recursion? In that case,
252# use the directories exactly as given. If not, winnow the candidates.
253# Process a directory only if the configure.ac file contains at least one
254# macro that starts with AC_COIN_, and it's not listed in COIN_SKIP_PROJECTS.
255
256if test $userSpecifiedDirs = 1 && test $doRecurse = 0 ; then
257  dirs=$candDirs
258else
259  dirs=
260  for dir in $candDirs; do
261    if grep AC_COIN_ $dir/configure.ac >/dev/null 2>&1 ; then
262      dirs="$dirs $dir"
263    else
264      echo "  Skipping foreign configure.ac in $dir."
265    fi
266  done
267
268# Now compare against the skip entries in COIN_SKIP_PROJECTS. To match the
269# entries we just collected, add `./' to the front of each skip entry.
270
271  candDirs=$dirs
272  if test x${COIN_SKIP_PROJECTS+set} = xset ; then
273    dirs=
274    for dir in $COIN_SKIP_PROJECTS ; do
275      skip_dirs="$skip_dirs ./$dir"
276    done
277    for dir in $candDirs ; do
278      skip=0
279      for skipdir in $skip_dirs ; do
280        if test $dir = $skipdir ; then
281          skip=1
282          break
283        fi
284      done
285      if test $skip = 0 ; then
286        dirs="$dirs $dir"
287      else
288        echo "  Skipping $dir listed in COIN_SKIP_PROJECTS."
289      fi
290    done
291  fi
292fi
293
294# Set a trap so that we'll clean up any links on exit, for whatever reason.
295# Note that this executes on normal exit, too, so don't do anything rash.
296
297topLink=
298subLink=
299trap 'exit_status=$?
300  cleanupOnErrorExit
301  exit $exit_status' 0
302
303# Get down to business
304
305echo "Running autotools in $dirs"
306
307if test $createLink = 1 ; then
308  echo "Creating temporary link for ./BuildTools -> $toolsDir"
309  ln -s $toolsDir BuildTools
310  topLink="$startDir/BuildTools"
311fi
312
313# Copy over files that are used during configure, build, and install. Their
314# location will be frozen in files created by automake and autoconf, so they
315# must be present in order to move with the directory tree.
316
317autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
318echo "Copying autotools scripts into this directory."
319for file in $autotoolsFiles ; do
320  cp BuildTools/$file .
321done
322
323# And now the main event.  Presence of install-sh in a directory is the
324# trigger for processing as an independent unit.
325
326echo "Running autotools in $dirs"
327
328m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4 $toolsDir/coin.m4"
329for dir in $dirs; do
330  if test -r $dir/configure.ac; then
331    cd $dir
332    tmpBT=0
333    echo "Processing $dir ..."
334    # Avoid repeat actions for current directory (".")
335    if test -f install-sh && test "$dir" != "." ; then
336      if test ! -d BuildTools ; then
337        ln -s $toolsDir BuildTools
338        tmpBT=1
339        subLink="`pwd`/BuildTools"
340        echo "  creating temporary link for ./BuildTools -> $toolsDir"
341      fi
342      echo "  refreshing autotools scripts in this directory."
343      for file in $autotoolsFiles ; do
344        cp BuildTools/$file .
345      done
346    fi
347    echo "  creating acinclude.m4 in $dir"
348    cat $m4Files > acinclude.m4
349    echo "  running aclocal in $dir"
350    if test -d m4; then
351      aclocal -I m4 || exit 1
352    else
353      aclocal || exit 1
354    fi
355    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
356      echo "  running autoheader in $dir"
357      autoheader || exit 1
358    fi
359    echo "  running automake in $dir"
360    automake || exit 1
361    echo "  running autoconf in $dir"
362    autoconf || exit 1
363    if test $tmpBT = 1 ; then
364      echo "  removing temporary link for ./BuildTools"
365      rm BuildTools
366      subLink=
367    fi
368    cd $startDir
369  else
370    # Serious confusion! Should not reach here.
371    echo "*** No configure.ac file in $dir - SKIPPING! ***"
372  fi
373done
374
375if test $createLink = 1 ; then
376  echo "Removing temporary link for ./BuildTools"
377  rm BuildTools
378  topLink=
379fi
380
Note: See TracBrowser for help on using the repository browser.