Ignore:
Timestamp:
Oct 30, 2010 6:24:42 PM (11 years ago)
Author:
tkr
Message:

Syncing stable/0.6 with trunk

Location:
stable/0.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable/0.6

  • stable/0.6/run_autotools

    r1363 r1695  
    11#!/bin/sh
    22
    3 # Copyright (C) 2006, 2007  International Business Machines.
     3# Copyright (C) 2006, 2007, 2008, 2009, 2010  International Business Machines
     4# and others.
    45# All Rights Reserved.
    56# This file is distributed under the Common Public License.
     
    910#
    1011# 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.
    1156
    1257# Make sure we bail out if there is an error
    1358set -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.
    1497
    1598ver_autoconf='2.59'
     
    28111  echo You are not using the correct version of autoconf
    29112  rm -f confauto.out
    30   exit -2
     113  exit 2
    31114fi
    32115rm -f confauto.out
     
    35118if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
    36119  echo autoconf is not picked up from the correct location
    37   exit -2
     120  exit 2
    38121fi
    39122
     
    43126  echo You are not using the correct version of automake
    44127  rm -f confauto.out
    45   exit -2
     128  exit 2
    46129fi
    47130rm -f confauto.out
     
    50133if test $autoconf_dir = `cd $AUTOTOOLS_DIR/bin; pwd`; then :; else
    51134  echo automake is not picked up from the correct location
    52   exit -2
    53 fi
     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.
    54140
    55141grep_version=`echo  $ver_libtool | sed -e 's/\\./\\\\\\./g'`
    56142ltfile=$AUTOTOOLS_DIR/share/libtool/ltmain.sh
    57143if test -r $ltfile; then :; else
    58   echo Cannot file $ltfile
     144  echo WARNING: Cannot file libtool shell $ltfile
    59145fi
    60146if $EGREP $grep_version $ltfile >/dev/null 2>&1; then :; else
    61   echo You are not using the correct verion of libtool
    62 fi
    63 
    64 # Find directories which contain a file configure.ac. When all is said and
    65 # done, each entry in dirs will be of the form `./path/to/directory'
    66 
    67 if test $# != 0; then
    68   dirs="$*"
     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
    69236else
    70   pos_dirs=`find . -name configure.ac | sed -e s%/configure.ac%%g | grep -v 'ThirdParty/[^/]*/[^/]*'`
     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
    71248  dirs=
    72   for dir in $pos_dirs; do
    73     if test -r $dir/configure.ac; then
     249  for dir in $candDirs; do
     250    if grep AC_COIN_ $dir/configure.ac >/dev/null 2>&1 ; then
    74251      dirs="$dirs $dir"
    75252    else
    76       echo "$dir/configure.ac doesn't appear to be a regular file; skipping."
     253      echo "  Skipping foreign configure.ac in $dir."
    77254    fi
    78255  done
    79 fi
    80256
    81257# Now compare against the skip entries in COIN_SKIP_PROJECTS. To match the
    82258# entries we just collected, add `./' to the front of each skip entry.
    83259
    84 pos_dirs=$dirs
    85 if test x${COIN_SKIP_PROJECTS+set} = xset ; then
    86   dirs=
    87   for dir in $COIN_SKIP_PROJECTS ; do
    88     skip_dirs="$skip_dirs ./$dir"
    89   done
    90   for dir in $pos_dirs ; do
    91     skip=0
    92     for skipdir in $skip_dirs ; do
    93       if test $dir = $skipdir ; then
    94         skip=1
    95         break
    96       fi
     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"
    97265    done
    98     if test $skip = 0 ; then
    99       dirs="$dirs $dir"
     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# And now the main event. Process each directory.
     293
     294echo "Running autotools in $dirs"
     295
     296autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
     297m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4"
     298buildtoolsLinks=
     299
     300for dir in $dirs; do
     301  if test -r $dir/configure.ac; then
     302    cd $dir
     303    echo "Processing $dir ..."
     304
     305# Do we need a BuildTools subdirectory here? The criteria is that install-sh
     306# already exists, or Makefile.am (which may include Makemain.inc), or we're
     307# forcing installation of the configure scripts.  Assuming we need BuildTools,
     308# what BuildTools should we use? If a BuildTools is already present, that's
     309# it.  Otherwise, assume that runautotooldDir is BuildTools. Allow that the
     310# user may have linked to a BuildTools.
     311
     312    needScripts=0
     313    if test -f install-sh || test $forceScripts = 1 ; then
     314      needScripts=1
     315    fi
     316    if test -f Makefile.am || test $needScripts = 1 ; then
     317      if test -d BuildTools || test -L BuildTools ; then
     318        createLink=0
     319        toolsDir=`pwd`/BuildTools
     320      else
     321        createLink=1
     322        toolsDir=$runautotoolDir
     323      fi
     324      echo "  BuildTools directory: $toolsDir"
     325
     326# Test to be sure that run_autotools is coming from the BuildTools directory.
     327
     328      if test $createLink = 0 && test "$toolsDir" != "$runautotoolDir" ; then
     329        echo "WARNING: using run_autotools from $runautotoolDir"
     330        echo "         but BuildTools is $toolsDir."
     331        echo "         Consider carefully if this is what you wanted to do."
     332      fi
     333
     334# coin.m4 should live in the same directory; failure is fatal.
     335
     336      if test ! -r $toolsDir/coin.m4 ; then
     337        echo "Cannot find Coin autotools macro file $toolsDir/coin.m4."
     338        echo "It should be in the BuildTools directory."
     339        exit 1
     340      fi
     341
     342# Install a link, if needed.
     343
     344      if test $createLink = 1 ; then
     345        ln -s $toolsDir BuildTools
     346        buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools"
     347        echo "  creating temporary link for ./BuildTools -> $toolsDir"
     348      fi
     349
     350# And refresh the autotools scripts, if needed.
     351
     352      if test $needScripts = 1 ; then
     353        echo "  refreshing autotools scripts in this directory."
     354        for file in $autotoolsFiles ; do
     355          cp BuildTools/$file .
     356        done
     357      fi
     358
     359    fi
     360
     361# Get on with running the autotools.
     362
     363    echo "  creating acinclude.m4 in $dir"
     364    cat $m4Files $toolsDir/coin.m4 > acinclude.m4
     365    echo "  running aclocal in $dir"
     366    if test -d m4; then
     367      aclocal -I m4 || exit 1
    100368    else
    101       echo "$dir listed in COIN_SKIP_PROJECTS; skipping."
    102     fi
    103   done
    104 fi
    105 
    106 echo Running autotools in $dirs
    107 
    108 currdir=`pwd`
    109 if test -r $currdir/BuildTools/coin.m4; then
    110   toolsdir=$currdir/BuildTools
    111 else
    112   echo Cannot find BuildTools directory.
    113   exit
    114 fi
    115 
    116 echo Copying autotools scripts into this directory
    117 cp $toolsdir/config.guess $toolsdir/config.sub $toolsdir/depcomp $toolsdir/install-sh $toolsdir/ltmain.sh $toolsdir/missing .
    118 
    119 if test x$AUTOTOOLS_DIR = x; then
    120   AUTOTOOLS_DIR=$HOME
    121 fi
    122 
    123 for dir in $dirs; do
    124   (if test -r $dir/configure.ac; then
    125      cd $dir
    126      echo creating acinclude.m4 in $dir
    127      cat $AUTOTOOLS_DIR/share/aclocal/libtool.m4 $toolsdir/coin.m4> acinclude.m4
    128      echo running aclocal in $dir
    129      if test -d m4; then
    130        aclocal -I m4 || exit -1
    131      else
    132        aclocal || exit -1
    133      fi
    134      if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
    135        echo running autoheader in $dir
    136        autoheader || exit -1
    137      fi
    138      echo running automake in $dir
    139      automake || exit -1
    140      echo running autoconf in $dir
    141      autoconf || exit -1
    142    else
    143      echo "*** No configure.ac file in $dir - SKIPPING! ***"
    144    fi
    145   )
    146   if test $? -ne 0; then
    147     exit -2;
     369      aclocal || exit 1
     370    fi
     371    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
     372      echo "  running autoheader in $dir"
     373      autoheader || exit 1
     374    fi
     375    echo "  running automake in $dir"
     376    automake || exit 1
     377    echo "  running autoconf in $dir"
     378    autoconf || exit 1
     379    cd $startDir
     380  else
     381    # Serious confusion! Should not reach here.
     382    echo "*** No configure.ac file in $dir - SKIPPING! ***"
    148383  fi
    149384done
     385
     386# Remove the links. Yeah, the trap will do this, but it never hurts to clean
     387# up properly.
     388
     389if test -n "$buildtoolsLinks" ; then
     390  echo "Removing temporary links to BuildTools."
     391  for link in $buildtoolsLinks ; do
     392    # echo "  removing temporary link for BuildTools: $link"
     393    rm $link
     394  done
     395  buildtoolsLinks=
     396fi
     397
     398exit
     399
Note: See TracChangeset for help on using the changeset viewer.