source: stable/0.8/run_autotools @ 4195

Last change on this file since 4195 was 4195, checked in by stefan, 11 months ago

always prefix PATH with AUTOTOOLS_DIR, if set

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