Changeset 1596


Ignore:
Timestamp:
Jul 8, 2010 8:40:44 PM (9 years ago)
Author:
lou
Message:

Make run_autotools less aggressive about installing autotools auxilliary
scripts. Add ability to force installation. Rework handling of temporary links
to BuildTools? so that it's compatible with old and new styles of packaging.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/run_autotools

    r1595 r1596  
    1515#      Directories specified on the command line are recursively searched
    1616#      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.
    1722
    1823# run_autotools takes care of running the autotools (automake, autoconf,
     
    2025# libtool execute at configuration, build, and installation.
    2126
    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_.
     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.
    4149
    4250# 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).
     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.
    4556
    4657# Make sure we bail out if there is an error
     
    5162
    5263cleanupOnErrorExit ()
    53 { for link in $topLink $subLink ; do
     64{ for link in $buildtoolsLinks; do
    5465    echo Trap: removing $link
    5566    rm -f $link
     
    6374# the command name, we're running in the current directory (almost certainly
    6475# 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.
    6578
    6679startDir=`pwd`
     
    7083  runautotoolDir='.'
    7184fi
    72 runautotoolDir=$startDir/$runautotoolDir
     85if  expr "$runautotoolDir" : '/.*' >/dev/null 2>&1 ; then
     86  :
     87else
     88  runautotoolDir=$startDir/$runautotoolDir
     89fi
    7390while expr "$runautotoolDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
    7491  runautotoolDir=`echo $runautotoolDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
    7592done
    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 
    81 createLink=0
    82 if test -d BuildTools || test -L BuildTools ; then
    83   toolsDir=BuildTools
    84 else
    85   createLink=1
    86   toolsDir=$runautotoolDir
    87 fi
    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 
    92 if expr "$toolsDir" : '/.*' >/dev/null 2>&1 ; then
    93   :
    94 else
    95   toolsDir=$startDir/$toolsDir
    96 fi
    97 while expr "$toolsDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
    98   toolsDir=`echo $toolsDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
    99 done
    100 toolsDir=`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 
    104 if 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."
    108 fi
    109 
    110 echo "BuildTools directory: $toolsDir"
    111 
    112 # coin.m4 should live in the same directory, but this failure is fatal.
    113 
    114 if 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
    118 fi
    119 
    120 # As is the failure to find the correct versions of autoconf or automake.
     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.
    12197
    12298ver_autoconf='2.59'
     
    176152printHelp=0
    177153doRecurse=1
     154forceScripts=0
    178155userSpecifiedDirs=0
    179156dirsToProcess=
     
    190167         doRecurse=0
    191168         ;;
    192      -* ) echo "$0: unrecognised command line switch '"$1"'."
    193           printHelp=1
    194           ;;
    195       * ) dirsToProcess="$dirsToProcess $1"
    196           userSpecifiedDirs=1
    197           ;;
     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         ;;
    198179  esac
    199180  shift
     
    208189  -h  | --help           print help message and exit
    209190  -nr | --no-recursion   do not do recursive search for configure.ac files
     191  -i  | --independent    install scripts necessary for an independent unit
    210192
    211193  If no directories are specified, the tree rooted at the current directory
     
    218200  If directories are specified on the command line *and* --no-recursion is
    219201  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.
    220209EOF
    221210  exit
     
    305294echo "Running autotools in $dirs"
    306295
    307 if test $createLink = 1 ; then
    308   echo "Creating temporary link for ./BuildTools -> $toolsDir"
    309   ln -s $toolsDir BuildTools
    310   topLink="$startDir/BuildTools"
    311 fi
    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.
     296# And now the main event. Process each directory.
     297
     298echo "Running autotools in $dirs"
    316299
    317300autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
    318 echo "Copying autotools scripts into this directory."
    319 for file in $autotoolsFiles ; do
    320   cp BuildTools/$file .
    321 done
    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 
    326 echo "Running autotools in $dirs"
    327 
    328 m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4 $toolsDir/coin.m4"
     301m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4"
     302buildtoolsLinks=
     303
    329304for dir in $dirs; do
    330305  if test -r $dir/configure.ac; then
    331306    cd $dir
    332     tmpBT=0
    333307    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
     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
    337349        ln -s $toolsDir BuildTools
    338         tmpBT=1
    339         subLink="`pwd`/BuildTools"
     350        buildtoolsLinks="$buildtoolsLinks `pwd`/BuildTools"
    340351        echo "  creating temporary link for ./BuildTools -> $toolsDir"
    341352      fi
    342       echo "  refreshing autotools scripts in this directory."
    343       for file in $autotoolsFiles ; do
    344         cp BuildTools/$file .
    345       done
     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
    346363    fi
     364
     365# Get on with running the autotools.
     366
    347367    echo "  creating acinclude.m4 in $dir"
    348     cat $m4Files > acinclude.m4
     368    cat $m4Files $toolsDir/coin.m4 > acinclude.m4
    349369    echo "  running aclocal in $dir"
    350370    if test -d m4; then
     
    361381    echo "  running autoconf in $dir"
    362382    autoconf || exit 1
    363     if test $tmpBT = 1 ; then
    364       echo "  removing temporary link for ./BuildTools"
    365       rm BuildTools
    366       subLink=
    367     fi
    368383    cd $startDir
    369384  else
     
    373388done
    374389
    375 if test $createLink = 1 ; then
    376   echo "Removing temporary link for ./BuildTools"
    377   rm BuildTools
    378   topLink=
    379 fi
    380 
     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 TracChangeset for help on using the changeset viewer.