source: trunk/run_autotools @ 1580

Last change on this file since 1580 was 1580, checked in by lou, 11 years ago

Added warning when directory holding run_autotools doesn't match BuildTools?
directory. Added trap to remove temporary links on error exit.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.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 1580 2010-06-16 20:29:31Z 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
84  echo toolsDir is $toolsDir
85else
86  createLink=1
87  toolsDir=$runautotoolDir
88fi
89
90# Create an absolute path if we don't have one, because we'll be moving
91# around. Clean up the path by removing `XXX/..' sequences.
92
93if expr "$toolsDir" : '/.*' >/dev/null 2>&1 ; then
94  :
95else
96  toolsDir=$startDir/$toolsDir
97fi
98while expr "$toolsDir" : '.*/\.\./.*' >/dev/null 2>&1 ; do
99  toolsDir=`echo $toolsDir | sed -e 's,/[^/][^/]*/\.\./,/,'`
100done
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# Find directories which contain a file configure.ac. When all is said and
175# done, each entry in dirs will be of the form `./path/to/directory'
176
177if test $# != 0; then
178  srchDirs="$*"
179else
180  srchDirs='.'
181fi
182candDirs=
183for dir in $srchDirs ; do
184  tmp=`find $dir -name configure.ac | sed -e s%/configure.ac%%g`
185  candDirs="$candDirs $tmp"
186done
187
188# Winnow the candidates. Process a directory only if the configure.ac file
189# contains at least one macro that starts with AC_COIN_
190
191dirs=
192for dir in $candDirs; do
193  if grep AC_COIN_ $dir/configure.ac >/dev/null 2>&1 ; then
194    dirs="$dirs $dir"
195  else
196    echo "  Skipping foreign configure.ac in $dir."
197  fi
198done
199
200# Now compare against the skip entries in COIN_SKIP_PROJECTS. To match the
201# entries we just collected, add `./' to the front of each skip entry.
202
203candDirs=$dirs
204if test x${COIN_SKIP_PROJECTS+set} = xset ; then
205  dirs=
206  for dir in $COIN_SKIP_PROJECTS ; do
207    skip_dirs="$skip_dirs ./$dir"
208  done
209  for dir in $candDirs ; do
210    skip=0
211    for skipdir in $skip_dirs ; do
212      if test $dir = $skipdir ; then
213        skip=1
214        break
215      fi
216    done
217    if test $skip = 0 ; then
218      dirs="$dirs $dir"
219    else
220      echo "  Skipping $dir listed in COIN_SKIP_PROJECTS."
221    fi
222  done
223fi
224
225# Set a trap so that we'll clean up any links on exit, for whatever reason.
226# Note that this executes on normal exit, too, so don't do anything rash.
227
228topLink=
229subLink=
230trap 'exit_status=$?
231  cleanupOnErrorExit
232  exit $exit_status' 0
233
234# Get down to business
235
236echo "Running autotools in $dirs"
237
238if test $createLink = 1 ; then
239  echo "Creating temporary link for ./BuildTools -> $toolsDir"
240  ln -s $toolsDir BuildTools
241  topLink="$startDir/BuildTools"
242fi
243
244# Copy over files that are used during configure, build, and install. Their
245# location will be frozen in files created by automake and autoconf, so they
246# must be present in order to move with the directory tree.
247
248autotoolsFiles="config.guess config.sub depcomp install-sh ltmain.sh missing"
249echo "Copying autotools scripts into this directory."
250for file in $autotoolsFiles ; do
251  cp BuildTools/$file .
252done
253
254# And now the main event.  Presence of install-sh in a directory is the
255# trigger for processing as an independent unit.
256
257echo "Running autotools in $dirs"
258
259m4Files="$AUTOTOOLS_DIR/share/aclocal/libtool.m4 $toolsDir/coin.m4"
260for dir in $dirs; do
261  if test -r $dir/configure.ac; then
262    cd $dir
263    tmpBT=0
264    echo "Processing $dir ..."
265    # Avoid repeat actions for current directory (".")
266    if test -f install-sh && test "$dir" != "." ; then
267      if test ! -d BuildTools ; then
268        ln -s $toolsDir BuildTools
269        tmpBT=1
270        subLink="`pwd`/BuildTools"
271        echo "  creating temporary link for ./BuildTools -> $toolsDir"
272      fi
273      echo "  refreshing autotools scripts in this directory."
274      for file in $autotoolsFiles ; do
275        cp BuildTools/$file .
276      done
277    fi
278    echo "  creating acinclude.m4 in $dir"
279    cat $m4Files > acinclude.m4
280    echo "  running aclocal in $dir"
281    if test -d m4; then
282      aclocal -I m4 || exit 1
283    else
284      aclocal || exit 1
285    fi
286    if grep AC_CONFIG_HEADER configure.ac >/dev/null 2>&1; then
287      echo "  running autoheader in $dir"
288      autoheader || exit 1
289    fi
290    echo "  running automake in $dir"
291    automake || exit 1
292    echo "  running autoconf in $dir"
293    autoconf || exit 1
294    if test $tmpBT = 1 ; then
295      echo "  removing temporary link for ./BuildTools"
296      rm BuildTools
297      subLink=
298    fi
299    cd $startDir
300  else
301    # Serious confusion! Should not reach here.
302    echo "*** No configure.ac file in $dir - SKIPPING! ***"
303  fi
304done
305
306if test $createLink = 1 ; then
307  echo "Removing temporary link for ./BuildTools"
308  rm BuildTools
309  topLink=
310fi
311
Note: See TracBrowser for help on using the repository browser.