source: branches/autotools-update/run_autotools @ 2552

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

add install_autotools.sh and adapt run_autotools to expect install/expect autotools in ~/local2

  • 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 2552 2012-02-29 11:44:33Z 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
57AUTOTOOLS_DIR=$HOME/local2
58export PATH=$HOME/local2/bin:$PATH
59
60# Make sure we bail out if there is an error
61set -e
62
63# Define a cleanup function. We'll set a trap below, just before we start to
64# do actual work.
65
66cleanupOnErrorExit ()
67{ for link in $buildtoolsLinks; do
68    echo Trap: removing $link
69    rm -f $link
70  done
71  cd $startDir
72}
73
74# Note that vanilla sh doesn't like negative exit values.
75
76# Determine the location of run_autotools.  If there are no '/' chars in
77# the command name, we're running in the current directory (almost certainly
78# not what's wanted). Otherwise, strip the command name, leaving the prefix.
79# Convert the prefix to an absolute path, if needed, and clean it up, removing
80# `XXX/..', '/./', '//' sequences.
81
82startDir=`pwd`
83if expr "$0" : '.*/.*' >/dev/null 2>&1 ; then
84  runautotoolDir=`echo $0 | sed -e 's,\(.*\)/[^/]*,\1,'`
85else
86  runautotoolDir='.'
87fi
88if  expr "$runautotoolDir" : '/.*' >/dev/null 2>&1 ; then
89  :
90else
91  runautotoolDir=$startDir/$runautotoolDir
92fi
93while expr "$runautotoolDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
94  runautotoolDir=`echo $runautotoolDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
95done
96runautotoolDir=`echo $runautotoolDir | sed -e 's,/\./,/,g' -e 's,//,/,g'`
97
98# Make sure we're using the correct versions of the autotools. Failure to
99# satisfy this requirement is a fatal error.
100
101ver_autoconf='2.68'
102ver_automake='1.11.3'
103ver_libtool='2.4.2'
104EGREP='grep -E'
105
106# Check if the correct version of the autotools is used
107if test x$AUTOTOOLS_DIR = x; then
108  AUTOTOOLS_DIR=$HOME
109fi
110
111grep_version=`echo  $ver_autoconf | sed -e 's/\\./\\\\\\./g'`
112if autoconf --version > confauto.out 2>&1 ; then : ; else
113  echo "autoconf $ver_autoconf not available"
114  rm -f confauto.out
115  exit 2
116fi
117if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
118  echo You are not using the correct version of autoconf
119  rm -f confauto.out
120  exit 2
121fi
122rm -f confauto.out
123autoconf_dir=`which autoconf | sed -e 's=/autoconf=='`
124autoconf_dir=`cd $autoconf_dir; pwd`
125if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
126  echo autoconf is not picked up from the correct location
127  exit 2
128fi
129
130grep_version=`echo  $ver_automake | sed -e 's/\\./\\\\\\./g'`
131if automake --version > confauto.out 2>&1 ; then : ; else
132  echo "automake $ver_automake not available"
133  rm -f confauto.out
134  exit 2
135fi
136if $EGREP $grep_version confauto.out >/dev/null 2>&1; then :; else
137  echo You are not using the correct version of automake
138  rm -f confauto.out
139  exit 2
140fi
141rm -f confauto.out
142autoconf_dir=`which automake | sed -e 's=/automake=='`
143autoconf_dir=`cd $autoconf_dir; pwd`
144if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
145  echo automake is not picked up from the correct location
146  exit 2
147fi
148
149# Failure to find the correct version of libtool isn't fatal here, but
150# the user should be warned.
151
152grep_version=`echo  $ver_libtool | sed -e 's/\\./\\\\\\./g'`
153ltfile=$AUTOTOOLS_DIR/share/libtool/config/ltmain.sh
154if test -r $ltfile; then :; else
155  echo WARNING: Cannot find libtool shell $ltfile
156fi
157if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else
158  echo WARNING: You are not using the correct version of libtool
159fi
160
161# Set up to process parameters. No parameters is the default.
162
163printHelp=0
164doRecurse=1
165forceScripts=0
166userSpecifiedDirs=0
167dirsToProcess=
168
169# Process the parameters. A parameter without an opening `-' is assumed to be
170# a spec for a directory to be processed.
171
172while test $# -gt 0 && test $printHelp = 0 ; do
173  case "$1" in
174    -h* | --h* )
175         printHelp=1
176         ;;
177    -nr* | --no-recursion )
178         doRecurse=0
179         ;;
180    -i | --independent )
181         forceScripts=1
182         doRecurse=0
183         ;;
184    -* ) echo "$0: unrecognised command line switch '"$1"'."
185         printHelp=1
186         ;;
187     * ) dirsToProcess="$dirsToProcess $1"
188         userSpecifiedDirs=1
189         ;;
190  esac
191  shift
192done
193
194# Help?
195
196if test $printHelp = 1 ; then
197  cat <<EOF
198usage: run_autotools [-h] [-nr] [ directory directory ... ]
199
200  -h  | --help           print help message and exit
201  -nr | --no-recursion   do not do recursive search for configure.ac files
202  -i  | --independent    install scripts necessary for an independent unit
203
204  If no directories are specified, the tree rooted at the current directory
205  is searched recursively for directories with configure.ac files containing
206  COIN configuration macros (AC_COIN_*) and autotools is run in those
207  directories. Directories listed in COIN_SKIP_PROJECTS are skipped.
208  If directories are specified on the command line, the search for configure.ac
209  files is restricted to the specified directories.
210
211  If directories are specified on the command line *and* --no-recursion is
212  given, the specified directories are processed with no checks.
213
214  The --independent option will force installation of install-sh and other
215  scripts necessary for a unit that is installed independently. This will
216  be forced in *all* directories processed. Most often what is desired is
217  to install these scripts in the top-level directory of a unit, so -i
218  forces -nr. It's a good idea to explicitly specify the directories you want
219  to process.
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# And now the main event. Process each directory.
304
305echo "Running autotools in $dirs"
306
307autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
308m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4"
309buildtoolsLinks=
310
311for dir in $dirs; do
312  if test -r $dir/configure.ac; then
313    cd $dir
314    echo "Processing $dir ..."
315
316# Do we need a BuildTools subdirectory here? The criteria is that install-sh
317# already exists, or Makefile.am (which may include Makemain.inc), or we're
318# forcing installation of the configure scripts.  Assuming we need BuildTools,
319# what BuildTools should we use? If a BuildTools is already present, that's
320# it.  Otherwise, assume that runautotooldDir is BuildTools. Allow that the
321# user may have linked to a BuildTools.
322
323    needScripts=0
324    if test -f install-sh || test $forceScripts = 1 ; then
325      needScripts=1
326    fi
327    if test -f Makefile.am || test $needScripts = 1 ; then
328      if test -d BuildTools || test -L BuildTools ; then
329        createLink=0
330        toolsDir=`pwd`/BuildTools
331      else
332        createLink=1
333        toolsDir=$runautotoolDir
334      fi
335      echo "  BuildTools directory: $toolsDir"
336
337# Test to be sure that run_autotools is coming from the BuildTools directory.
338
339      if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then
340        echo "WARNING: using run_autotools from $runautotoolDir"
341        echo "         but BuildTools is $toolsDir."
342        echo "         Consider carefully if this is what you wanted to do."
343      fi
344
345# coin.m4 should live in the same directory; failure is fatal.
346
347      if test ! -r $toolsDir/coin.m4 ; then
348        echo "Cannot find Coin autotools macro file $toolsDir/coin.m4."
349        echo "It should be in the BuildTools directory."
350        exit 1
351      fi
352
353# Install a link, if needed.
354
355      if test $createLink = 1 ; then
356        ln -s $toolsDir BuildTools
357        buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools"
358        echo "  creating temporary link for ./BuildTools -> $toolsDir"
359      fi
360
361# And refresh the autotools scripts, if needed.
362
363      if test $needScripts = 1 ; then
364        echo "  refreshing autotools scripts in this directory."
365        for file in $autotoolsFiles ; do
366          cp BuildTools/$file .
367        done
368      fi
369
370    fi
371
372# Get on with running the autotools.
373
374    echo "  creating acinclude.m4 in $dir"
375    cat $m4Files $toolsDir/coin.m4 > acinclude.m4
376    echo "  running aclocal in $dir"
377    if test -d m4; then
378      aclocal -I m4 || exit 1
379    else
380      aclocal || exit 1
381    fi
382    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
383      echo "  running autoheader in $dir"
384      autoheader || exit 1
385    fi
386    echo "  running automake in $dir"
387    automake || exit 1
388    echo "  running autoconf in $dir"
389    autoconf || exit 1
390    cd $startDir
391  else
392    # Serious confusion! Should not reach here.
393    echo "*** No configure.ac file in $dir - SKIPPING! ***"
394  fi
395done
396
397# Remove the links. Yeah, the trap will do this, but it never hurts to clean
398# up properly.
399
400if test -n "$buildtoolsLinks" ; then
401  echo "Removing temporary links to BuildTools."
402  for link in $buildtoolsLinks ; do
403    # echo "  removing temporary link for BuildTools: $link"
404    rm $link
405  done
406  buildtoolsLinks=
407fi
408
409exit
410
Note: See TracBrowser for help on using the repository browser.