Blame bin/autoreconf.in

Packit 47b4ca
#! @PERL@ -w
Packit 47b4ca
# -*- perl -*-
Packit 47b4ca
# @configure_input@
Packit 47b4ca
Packit 47b4ca
eval 'case $# in 0) exec @PERL@ -S "$0";; *) exec @PERL@ -S "$0" "$@";; esac'
Packit 47b4ca
    if 0;
Packit 47b4ca
Packit 47b4ca
# autoreconf - install the GNU Build System in a directory tree
Packit 47b4ca
# Copyright (C) 1994, 1999-2012 Free Software Foundation, Inc.
Packit 47b4ca
Packit 47b4ca
# This program is free software: you can redistribute it and/or modify
Packit 47b4ca
# it under the terms of the GNU General Public License as published by
Packit 47b4ca
# the Free Software Foundation, either version 3 of the License, or
Packit 47b4ca
# (at your option) any later version.
Packit 47b4ca
Packit 47b4ca
# This program is distributed in the hope that it will be useful,
Packit 47b4ca
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 47b4ca
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 47b4ca
# GNU General Public License for more details.
Packit 47b4ca
Packit 47b4ca
# You should have received a copy of the GNU General Public License
Packit 47b4ca
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit 47b4ca
Packit 47b4ca
# Written by David J. MacKenzie.
Packit 47b4ca
# Extended and rewritten in Perl by Akim Demaille.
Packit 47b4ca
Packit 47b4ca
BEGIN
Packit 47b4ca
{
Packit 47b4ca
  my $pkgdatadir = $ENV{'autom4te_perllibdir'} || '@pkgdatadir@';
Packit 47b4ca
  unshift @INC, $pkgdatadir;
Packit 47b4ca
Packit 47b4ca
  # Override SHELL.  On DJGPP SHELL may not be set to a shell
Packit 47b4ca
  # that can handle redirection and quote arguments correctly,
Packit 47b4ca
  # e.g.: COMMAND.COM.  For DJGPP always use the shell that configure
Packit 47b4ca
  # has detected.
Packit 47b4ca
  $ENV{'SHELL'} = '@SHELL@' if ($^O eq 'dos');
Packit 47b4ca
}
Packit 47b4ca
Packit 47b4ca
use Autom4te::ChannelDefs;
Packit 47b4ca
use Autom4te::Channels;
Packit 47b4ca
use Autom4te::Configure_ac;
Packit 47b4ca
use Autom4te::FileUtils;
Packit 47b4ca
use Autom4te::General;
Packit 47b4ca
use Autom4te::XFile;
Packit 47b4ca
# Do not use Cwd::chdir, since it might hang.
Packit 47b4ca
use Cwd 'cwd';
Packit 47b4ca
use strict;
Packit 47b4ca
Packit 47b4ca
## ----------- ##
Packit 47b4ca
## Variables.  ##
Packit 47b4ca
## ----------- ##
Packit 47b4ca
Packit 47b4ca
# $HELP
Packit 47b4ca
# -----
Packit 47b4ca
$help = "Usage: $0 [OPTION]... [DIRECTORY]...
Packit 47b4ca
Packit 47b4ca
Run `autoconf' (and `autoheader', `aclocal', `automake', `autopoint'
Packit 47b4ca
(formerly `gettextize'), and `libtoolize' where appropriate)
Packit 47b4ca
repeatedly to remake the GNU Build System files in specified
Packit 47b4ca
DIRECTORIES and their subdirectories (defaulting to `.').
Packit 47b4ca
Packit 47b4ca
By default, it only remakes those files that are older than their
Packit 47b4ca
sources.  If you install new versions of the GNU Build System,
Packit 47b4ca
you can make `autoreconf' remake all of the files by giving it the
Packit 47b4ca
`--force' option.
Packit 47b4ca
Packit 47b4ca
Operation modes:
Packit 47b4ca
  -h, --help               print this help, then exit
Packit 47b4ca
  -V, --version            print version number, then exit
Packit 47b4ca
  -v, --verbose            verbosely report processing
Packit 47b4ca
  -d, --debug              don't remove temporary files
Packit 47b4ca
  -f, --force              consider all files obsolete
Packit 47b4ca
  -i, --install            copy missing auxiliary files
Packit 47b4ca
      --no-recursive       don't rebuild sub-packages
Packit 47b4ca
  -s, --symlink            with -i, install symbolic links instead of copies
Packit 47b4ca
  -m, --make               when applicable, re-run ./configure && make
Packit 47b4ca
  -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [syntax]
Packit 47b4ca
Packit 47b4ca
" . Autom4te::ChannelDefs::usage . "
Packit 47b4ca
Packit 47b4ca
The environment variable \`WARNINGS\' is honored.  Some subtools might
Packit 47b4ca
support other warning types, using \`all' is encouraged.
Packit 47b4ca
Packit 47b4ca
Library directories:
Packit 47b4ca
  -B, --prepend-include=DIR  prepend directory DIR to search path
Packit 47b4ca
  -I, --include=DIR          append directory DIR to search path
Packit 47b4ca
Packit 47b4ca
The environment variables AUTOM4TE, AUTOCONF, AUTOHEADER, AUTOMAKE,
Packit 47b4ca
ACLOCAL, AUTOPOINT, LIBTOOLIZE, M4, and MAKE are honored.
Packit 47b4ca
Packit 47b4ca
Report bugs to <bug-autoconf\@gnu.org>.
Packit 47b4ca
GNU Autoconf home page: <http://www.gnu.org/software/autoconf/>.
Packit 47b4ca
General help using GNU software: <http://www.gnu.org/gethelp/>.
Packit 47b4ca
";
Packit 47b4ca
Packit 47b4ca
# $VERSION
Packit 47b4ca
# --------
Packit 47b4ca
$version = "autoreconf (@PACKAGE_NAME@) @VERSION@
Packit 47b4ca
Copyright (C) @RELEASE_YEAR@ Free Software Foundation, Inc.
Packit 47b4ca
License GPLv3+/Autoconf: GNU GPL version 3 or later
Packit 47b4ca
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
Packit 47b4ca
This is free software: you are free to change and redistribute it.
Packit 47b4ca
There is NO WARRANTY, to the extent permitted by law.
Packit 47b4ca
Packit 47b4ca
Written by David J. MacKenzie and Akim Demaille.
Packit 47b4ca
";
Packit 47b4ca
Packit 47b4ca
# Lib files.
Packit 47b4ca
my $autoconf   = $ENV{'AUTOCONF'}   || '@bindir@/@autoconf-name@';
Packit 47b4ca
my $autoheader = $ENV{'AUTOHEADER'} || '@bindir@/@autoheader-name@';
Packit 47b4ca
my $autom4te   = $ENV{'AUTOM4TE'}   || '@bindir@/@autom4te-name@';
Packit 47b4ca
my $automake   = $ENV{'AUTOMAKE'}   || 'automake';
Packit 47b4ca
my $aclocal    = $ENV{'ACLOCAL'}    || 'aclocal';
Packit 47b4ca
my $libtoolize = $ENV{'LIBTOOLIZE'} || 'libtoolize';
Packit 47b4ca
my $autopoint  = $ENV{'AUTOPOINT'}  || 'autopoint';
Packit 47b4ca
my $make       = $ENV{'MAKE'}       || 'make';
Packit 47b4ca
Packit 47b4ca
# --install -- as --add-missing in other tools.
Packit 47b4ca
my $install = 0;
Packit 47b4ca
# symlink -- when --install, use symlinks instead.
Packit 47b4ca
my $symlink = 0;
Packit 47b4ca
# Does aclocal support --force?
Packit 47b4ca
my $aclocal_supports_force = 0;
Packit 47b4ca
# Does aclocal support -Wfoo?
Packit 47b4ca
my $aclocal_supports_warnings = 0;
Packit 47b4ca
# Does automake support --force-missing?
Packit 47b4ca
my $automake_supports_force_missing = 0;
Packit 47b4ca
# Does automake support -Wfoo?
Packit 47b4ca
my $automake_supports_warnings = 0;
Packit 47b4ca
Packit 47b4ca
my @prepend_include;
Packit 47b4ca
my @include;
Packit 47b4ca
Packit 47b4ca
# List of command line warning requests.
Packit 47b4ca
my @warning;
Packit 47b4ca
Packit 47b4ca
# Rerun `./configure && make'?
Packit 47b4ca
my $run_make = 0;
Packit 47b4ca
Packit 47b4ca
# Recurse into subpackages
Packit 47b4ca
my $recursive = 1;
Packit 47b4ca
Packit 47b4ca
## ---------- ##
Packit 47b4ca
## Routines.  ##
Packit 47b4ca
## ---------- ##
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
# parse_args ()
Packit 47b4ca
# -------------
Packit 47b4ca
# Process any command line arguments.
Packit 47b4ca
sub parse_args ()
Packit 47b4ca
{
Packit 47b4ca
  my $srcdir;
Packit 47b4ca
Packit 47b4ca
  getopt ("W|warnings=s"         => \@warning,
Packit 47b4ca
	  'I|include=s'          => \@include,
Packit 47b4ca
	  'B|prepend-include=s'	 => \@prepend_include,
Packit 47b4ca
	  'i|install'            => \$install,
Packit 47b4ca
	  's|symlink'            => \$symlink,
Packit 47b4ca
	  'm|make'               => \$run_make,
Packit 47b4ca
	  'recursive!'           => \$recursive);
Packit 47b4ca
Packit 47b4ca
  # Split the warnings as a list of elements instead of a list of
Packit 47b4ca
  # lists.
Packit 47b4ca
  @warning = map { split /,/ } @warning;
Packit 47b4ca
  parse_WARNINGS;
Packit 47b4ca
  parse_warnings '--warnings', @warning;
Packit 47b4ca
Packit 47b4ca
  # Even if the user specified a configure.ac, trim to get the
Packit 47b4ca
  # directory, and look for configure.ac again.  Because (i) the code
Packit 47b4ca
  # is simpler, and (ii) we are still able to diagnose simultaneous
Packit 47b4ca
  # presence of configure.ac and configure.in.
Packit 47b4ca
  @ARGV = map { /configure\.(ac|in)$/ ? dirname ($_) : $_ } @ARGV;
Packit 47b4ca
  push @ARGV, '.' unless @ARGV;
Packit 47b4ca
Packit 47b4ca
  if ($verbose && $debug)
Packit 47b4ca
    {
Packit 47b4ca
      for my $prog ($autoconf, $autoheader,
Packit 47b4ca
		    $automake, $aclocal,
Packit 47b4ca
		    $autopoint,
Packit 47b4ca
		    $libtoolize)
Packit 47b4ca
	{
Packit 47b4ca
	  xsystem ("$prog --version | sed 1q >&2");
Packit 47b4ca
	  print STDERR "\n";
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  my $aclocal_help = `$aclocal --help 2>/dev/null`;
Packit 47b4ca
  my $automake_help = `$automake --help 2>/dev/null`;
Packit 47b4ca
  $aclocal_supports_force = $aclocal_help =~ /--force/;
Packit 47b4ca
  $aclocal_supports_warnings = $aclocal_help =~ /--warnings/;
Packit 47b4ca
  $automake_supports_force_missing = $automake_help =~ /--force-missing/;
Packit 47b4ca
  $automake_supports_warnings = $automake_help =~ /--warnings/;
Packit 47b4ca
Packit 47b4ca
  # Dispatch autoreconf's option to the tools.
Packit 47b4ca
  # --include;
Packit 47b4ca
  $aclocal    .= join (' -I ', '', map { shell_quote ($_) } @include);
Packit 47b4ca
  $autoconf   .= join (' --include=', '', map { shell_quote ($_) } @include);
Packit 47b4ca
  $autoconf   .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
Packit 47b4ca
  $autoheader .= join (' --include=', '', map { shell_quote ($_) } @include);
Packit 47b4ca
  $autoheader .= join (' --prepend-include=', '', map { shell_quote ($_) } @prepend_include);
Packit 47b4ca
Packit 47b4ca
  # --install and --symlink;
Packit 47b4ca
  if ($install)
Packit 47b4ca
    {
Packit 47b4ca
      $automake   .= ' --add-missing';
Packit 47b4ca
      $automake   .= ' --copy' unless $symlink;
Packit 47b4ca
      $libtoolize .= ' --copy' unless $symlink;
Packit 47b4ca
    }
Packit 47b4ca
  # --force;
Packit 47b4ca
  if ($force)
Packit 47b4ca
    {
Packit 47b4ca
      $aclocal    .= ' --force'
Packit 47b4ca
	if $aclocal_supports_force;
Packit 47b4ca
      $autoconf   .= ' --force';
Packit 47b4ca
      $autoheader .= ' --force';
Packit 47b4ca
      $automake   .= ' --force-missing'
Packit 47b4ca
	if $automake_supports_force_missing;
Packit 47b4ca
      $autopoint  .= ' --force';
Packit 47b4ca
      $libtoolize .= ' --force';
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      # The implementation of --no-force is bogus in all implementations
Packit 47b4ca
      # of Automake up to 1.8, so we avoid it in these cases.  (Automake
Packit 47b4ca
      # 1.8 is the first version where aclocal supports force, hence
Packit 47b4ca
      # the condition.)
Packit 47b4ca
      $automake .= ' --no-force'
Packit 47b4ca
	if $aclocal_supports_force;
Packit 47b4ca
    }
Packit 47b4ca
  # --verbose --verbose or --debug;
Packit 47b4ca
  if ($verbose > 1 || $debug)
Packit 47b4ca
    {
Packit 47b4ca
      $autoconf   .= ' --verbose';
Packit 47b4ca
      $autoheader .= ' --verbose';
Packit 47b4ca
      $automake   .= ' --verbose';
Packit 47b4ca
      $aclocal    .= ' --verbose';
Packit 47b4ca
    }
Packit 47b4ca
  if ($debug)
Packit 47b4ca
    {
Packit 47b4ca
      $autoconf   .= ' --debug';
Packit 47b4ca
      $autoheader .= ' --debug';
Packit 47b4ca
      $libtoolize .= ' --debug';
Packit 47b4ca
    }
Packit 47b4ca
  # --warnings;
Packit 47b4ca
  if (@warning)
Packit 47b4ca
    {
Packit 47b4ca
      my $warn = ' --warnings=' . join (',', @warning);
Packit 47b4ca
      $autoconf   .= $warn;
Packit 47b4ca
      $autoheader .= $warn;
Packit 47b4ca
      $automake   .= $warn
Packit 47b4ca
	if $automake_supports_warnings;
Packit 47b4ca
      $aclocal    .= $warn
Packit 47b4ca
        if $aclocal_supports_warnings;
Packit 47b4ca
    }
Packit 47b4ca
}
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
# &run_aclocal ($ACLOCAL, $FLAGS)
Packit 47b4ca
# -------------------------------
Packit 47b4ca
# Update aclocal.m4 as lazily as possible, as aclocal pre-1.8 always
Packit 47b4ca
# overwrites aclocal.m4, hence triggers autoconf, autoheader, automake
Packit 47b4ca
# etc. uselessly.  aclocal 1.8+ does not need this.
Packit 47b4ca
sub run_aclocal ($$)
Packit 47b4ca
{
Packit 47b4ca
  my ($aclocal, $flags) = @_;
Packit 47b4ca
Packit 47b4ca
  # aclocal 1.8+ does all this for free.  It can be recognized by its
Packit 47b4ca
  # --force support.
Packit 47b4ca
  if ($aclocal_supports_force)
Packit 47b4ca
    {
Packit 47b4ca
      xsystem ("$aclocal $flags");
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      xsystem ("$aclocal $flags --output=aclocal.m4t");
Packit 47b4ca
      # aclocal may produce no output.
Packit 47b4ca
      if (-f 'aclocal.m4t')
Packit 47b4ca
	{
Packit 47b4ca
	  update_file ('aclocal.m4t', 'aclocal.m4');
Packit 47b4ca
	  # Make sure that the local m4 files are older than
Packit 47b4ca
	  # aclocal.m4.
Packit 47b4ca
	  #
Packit 47b4ca
	  # Why is not always the case?  Because we already run
Packit 47b4ca
	  # aclocal at first (before tracing), which, for instance,
Packit 47b4ca
	  # can find Gettext's macros in .../share/aclocal, so we may
Packit 47b4ca
	  # have had the right aclocal.m4 already.  Then autopoint is
Packit 47b4ca
	  # run, and installs locally these M4 files.  Then
Packit 47b4ca
	  # autoreconf, via update_file, sees it is the _same_
Packit 47b4ca
	  # aclocal.m4, and doesn't change its timestamp.  But later,
Packit 47b4ca
	  # Automake's Makefile expresses that aclocal.m4 depends on
Packit 47b4ca
	  # these local files, which are newer, so it triggers aclocal
Packit 47b4ca
	  # again.
Packit 47b4ca
	  #
Packit 47b4ca
	  # To make sure aclocal.m4 is no older, we change the
Packit 47b4ca
	  # modification times of the local M4 files to be not newer
Packit 47b4ca
	  # than it.
Packit 47b4ca
	  #
Packit 47b4ca
	  # First, where are the local files?
Packit 47b4ca
	  my $aclocal_local_dir = '.';
Packit 47b4ca
	  if ($flags =~ /-I\s+(\S+)/)
Packit 47b4ca
	    {
Packit 47b4ca
	      $aclocal_local_dir = $1;
Packit 47b4ca
	    }
Packit 47b4ca
	  # All the local files newer than aclocal.m4 are to be
Packit 47b4ca
	  # made not newer than it.
Packit 47b4ca
	  my $aclocal_m4_mtime = mtime ('aclocal.m4');
Packit 47b4ca
	  for my $file (glob ("$aclocal_local_dir/*.m4"), 'acinclude.m4')
Packit 47b4ca
	    {
Packit 47b4ca
	      if ($aclocal_m4_mtime < mtime ($file))
Packit 47b4ca
		{
Packit 47b4ca
		  debug "aging $file to be not newer than aclocal.m4";
Packit 47b4ca
		  utime $aclocal_m4_mtime, $aclocal_m4_mtime, $file;
Packit 47b4ca
		}
Packit 47b4ca
	    }
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
}
Packit 47b4ca
Packit 47b4ca
# &autoreconf_current_directory
Packit 47b4ca
# -----------------------------
Packit 47b4ca
sub autoreconf_current_directory ()
Packit 47b4ca
{
Packit 47b4ca
  my $configure_ac = find_configure_ac;
Packit 47b4ca
Packit 47b4ca
  # ---------------------- #
Packit 47b4ca
  # Is it using Autoconf?  #
Packit 47b4ca
  # ---------------------- #
Packit 47b4ca
Packit 47b4ca
  my $uses_autoconf;
Packit 47b4ca
  my $uses_gettext;
Packit 47b4ca
  if (-f $configure_ac)
Packit 47b4ca
    {
Packit 47b4ca
      my $configure_ac_file = new Autom4te::XFile "< $configure_ac";
Packit 47b4ca
      while ($_ = $configure_ac_file->getline)
Packit 47b4ca
	{
Packit 47b4ca
	  s/#.*//;
Packit 47b4ca
	  s/dnl.*//;
Packit 47b4ca
	  $uses_autoconf = 1 if /AC_INIT/;
Packit 47b4ca
	  # See below for why we look for gettext here.
Packit 47b4ca
	  $uses_gettext = 1  if /^AM_GNU_GETTEXT_VERSION/;
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
  if (!$uses_autoconf)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using Autoconf";
Packit 47b4ca
      return;
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ------------------- #
Packit 47b4ca
  # Running autopoint.  #
Packit 47b4ca
  # ------------------- #
Packit 47b4ca
Packit 47b4ca
  # Gettext is a bit of a problem: its macros are not necessarily
Packit 47b4ca
  # visible to aclocal, so if we start with a completely striped down
Packit 47b4ca
  # package (think of a fresh CVS checkout), running `aclocal' first
Packit 47b4ca
  # will fail: the Gettext macros are missing.
Packit 47b4ca
  #
Packit 47b4ca
  # Therefore, we can't use the traces to decide if we use Gettext or
Packit 47b4ca
  # not.  I guess that once Gettext move to 2.5x we will be able to,
Packit 47b4ca
  # but in the meanwhile forget it.
Packit 47b4ca
  #
Packit 47b4ca
  # We can only grep for AM_GNU_GETTEXT_VERSION in configure.ac.  You
Packit 47b4ca
  # might think this approach is naive, and indeed it is, as it
Packit 47b4ca
  # prevents one to embed AM_GNU_GETTEXT_VERSION in another *.m4, but
Packit 47b4ca
  # anyway we don't limit the generality, since... that's what
Packit 47b4ca
  # autopoint does.  Actually, it is even more restrictive, as it
Packit 47b4ca
  # greps for `^AM_GNU_GETTEXT_VERSION('.  We did this above, while
Packit 47b4ca
  # scanning configure.ac.
Packit 47b4ca
  if (!$uses_gettext)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using Gettext";
Packit 47b4ca
    }
Packit 47b4ca
  elsif (!$install)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not running autopoint: --install not given";
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      xsystem_hint ("autopoint is needed because this package uses Gettext", "$autopoint");
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ----------------- #
Packit 47b4ca
  # Running aclocal.  #
Packit 47b4ca
  # ----------------- #
Packit 47b4ca
Packit 47b4ca
  # Run it first: it might discover new macros to add, e.g.,
Packit 47b4ca
  # AC_PROG_LIBTOOL, which we will trace later to see if Libtool is
Packit 47b4ca
  # used.
Packit 47b4ca
  #
Packit 47b4ca
  # Always run it.  Tracking its sources for up-to-dateness is too
Packit 47b4ca
  # complex and too error prone.  The best we can do is avoiding
Packit 47b4ca
  # nuking the time stamp.
Packit 47b4ca
  my $uses_aclocal = 1;
Packit 47b4ca
Packit 47b4ca
  # Nevertheless, if aclocal.m4 exists and is not made by aclocal,
Packit 47b4ca
  # don't run aclocal.
Packit 47b4ca
Packit 47b4ca
  if (-f 'aclocal.m4')
Packit 47b4ca
    {
Packit 47b4ca
      my $aclocal_m4 = new Autom4te::XFile 'aclocal.m4';
Packit 47b4ca
      $_ = $aclocal_m4->getline;
Packit 47b4ca
      $uses_aclocal = 0
Packit 47b4ca
	unless defined ($_) && /generated.*by aclocal/;
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  # If there are flags for aclocal in Makefile.am, use them.
Packit 47b4ca
  my $aclocal_flags = '';
Packit 47b4ca
  if ($uses_aclocal && -f 'Makefile.am')
Packit 47b4ca
    {
Packit 47b4ca
      my $makefile = new Autom4te::XFile 'Makefile.am';
Packit 47b4ca
      while ($_ = $makefile->getline)
Packit 47b4ca
	{
Packit 47b4ca
	  if (/^ACLOCAL_[A-Z_]*FLAGS\s*=\s*(.*)/)
Packit 47b4ca
	    {
Packit 47b4ca
	      $aclocal_flags = $1;
Packit 47b4ca
	      last;
Packit 47b4ca
	    }
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  if (!$uses_aclocal)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using aclocal";
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      # Some file systems have sub-second time stamps, and if so we may
Packit 47b4ca
      # run into trouble later, after we rerun autoconf and set the
Packit 47b4ca
      # time stamps of input files to be no greater than aclocal.m4,
Packit 47b4ca
      # because the time-stamp-setting operation (utime) has a
Packit 47b4ca
      # resolution of only 1 second.  Work around the problem by
Packit 47b4ca
      # ensuring that there is at least a one-second window before the
Packit 47b4ca
      # time stamp of aclocal.m4t in which no file time stamps can
Packit 47b4ca
      # fall.
Packit 47b4ca
      sleep 1;
Packit 47b4ca
Packit 47b4ca
      run_aclocal ($aclocal, $aclocal_flags);
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  # We might have to rerun aclocal if Libtool (or others) imports new
Packit 47b4ca
  # macros.
Packit 47b4ca
  my $rerun_aclocal = 0;
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ------------------------------- #
Packit 47b4ca
  # See what tools will be needed.  #
Packit 47b4ca
  # ------------------------------- #
Packit 47b4ca
Packit 47b4ca
  # Perform a single trace reading to avoid --force forcing a rerun
Packit 47b4ca
  # between two --trace, that's useless.  If there is no AC_INIT, then
Packit 47b4ca
  # we are not interested: it looks like a Cygnus thingy.
Packit 47b4ca
  my $aux_dir;
Packit 47b4ca
  my $uses_gettext_via_traces;
Packit 47b4ca
  my $uses_libtool;
Packit 47b4ca
  my $uses_libltdl;
Packit 47b4ca
  my $uses_autoheader;
Packit 47b4ca
  my $uses_automake;
Packit 47b4ca
  my @subdir;
Packit 47b4ca
  verb "$configure_ac: tracing";
Packit 47b4ca
  my $traces = new Autom4te::XFile
Packit 47b4ca
    ("$autoconf"
Packit 47b4ca
     . join (' ',
Packit 47b4ca
	     map { ' --trace=' . $_ . ':\$n::\${::}%' }
Packit 47b4ca
	     # If you change this list, update the
Packit 47b4ca
	     # `Autoreconf-preselections' section of autom4te.in.
Packit 47b4ca
	     'AC_CONFIG_AUX_DIR',
Packit 47b4ca
	     'AC_CONFIG_HEADERS',
Packit 47b4ca
	     'AC_CONFIG_SUBDIRS',
Packit 47b4ca
	     'AC_INIT',
Packit 47b4ca
	     'AC_PROG_LIBTOOL',
Packit 47b4ca
	     'LT_INIT',
Packit 47b4ca
	     'LT_CONFIG_LTDL_DIR',
Packit 47b4ca
	     'AM_GNU_GETTEXT',
Packit 47b4ca
	     'AM_INIT_AUTOMAKE',
Packit 47b4ca
	    )
Packit 47b4ca
     . ' |');
Packit 47b4ca
  while ($_ = $traces->getline)
Packit 47b4ca
    {
Packit 47b4ca
      chomp;
Packit 47b4ca
      my ($macro, @args) = split (/::/);
Packit 47b4ca
      $aux_dir = $args[0]           if $macro eq "AC_CONFIG_AUX_DIR";
Packit 47b4ca
      $uses_autoconf = 1            if $macro eq "AC_INIT";
Packit 47b4ca
      $uses_gettext_via_traces = 1  if $macro eq "AM_GNU_GETTEXT";
Packit 47b4ca
      $uses_libtool = 1             if $macro eq "AC_PROG_LIBTOOL"
Packit 47b4ca
                                       || $macro eq "LT_INIT";
Packit 47b4ca
      $uses_libltdl = 1             if $macro eq "LT_CONFIG_LTDL_DIR";
Packit 47b4ca
      $uses_autoheader = 1          if $macro eq "AC_CONFIG_HEADERS";
Packit 47b4ca
      $uses_automake = 1            if $macro eq "AM_INIT_AUTOMAKE";
Packit 47b4ca
      push @subdir, split (' ', $args[0])
Packit 47b4ca
                                    if $macro eq "AC_CONFIG_SUBDIRS" && $recursive;
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  # The subdirs are *optional*, they may not exist.
Packit 47b4ca
  foreach (@subdir)
Packit 47b4ca
    {
Packit 47b4ca
      if (-d)
Packit 47b4ca
	{
Packit 47b4ca
	  verb "$configure_ac: adding subdirectory $_ to autoreconf";
Packit 47b4ca
	  autoreconf ($_);
Packit 47b4ca
	}
Packit 47b4ca
      else
Packit 47b4ca
	{
Packit 47b4ca
	  verb "$configure_ac: subdirectory $_ not present";
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
  # Gettext consistency checks...
Packit 47b4ca
  error "$configure_ac: AM_GNU_GETTEXT is used, but not AM_GNU_GETTEXT_VERSION"
Packit 47b4ca
    if $uses_gettext_via_traces && ! $uses_gettext;
Packit 47b4ca
  error "$configure_ac: AM_GNU_GETTEXT_VERSION is used, but not AM_GNU_GETTEXT"
Packit 47b4ca
    if $uses_gettext && ! $uses_gettext_via_traces;
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ---------------------------- #
Packit 47b4ca
  # Setting up the source tree.  #
Packit 47b4ca
  # ---------------------------- #
Packit 47b4ca
Packit 47b4ca
  # libtoolize, automake --add-missing etc. will drop files in the
Packit 47b4ca
  # $AUX_DIR.  But these tools fail to install these files if the
Packit 47b4ca
  # directory itself does not exist, which valid: just imagine a CVS
Packit 47b4ca
  # repository with hand written code only (there is not even a need
Packit 47b4ca
  # for a Makefile.am!).
Packit 47b4ca
Packit 47b4ca
  if (defined $aux_dir && ! -d $aux_dir)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: creating directory $aux_dir";
Packit 47b4ca
      mkdir $aux_dir, 0755
Packit 47b4ca
	or error "cannot create $aux_dir: $!";
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # -------------------- #
Packit 47b4ca
  # Running libtoolize.  #
Packit 47b4ca
  # -------------------- #
Packit 47b4ca
Packit 47b4ca
  if (!$uses_libtool)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using Libtool";
Packit 47b4ca
    }
Packit 47b4ca
  elsif ($install)
Packit 47b4ca
    {
Packit 47b4ca
      if ($uses_libltdl)
Packit 47b4ca
	{
Packit 47b4ca
	  $libtoolize .= " --ltdl";
Packit 47b4ca
	}
Packit 47b4ca
      xsystem_hint ("libtoolize is needed because this package uses Libtool", $libtoolize);
Packit 47b4ca
      $rerun_aclocal = 1;
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not running libtoolize: --install not given";
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ------------------- #
Packit 47b4ca
  # Rerunning aclocal.  #
Packit 47b4ca
  # ------------------- #
Packit 47b4ca
Packit 47b4ca
  # If we re-installed Libtool or Gettext, the macros might have changed.
Packit 47b4ca
  # Automake also needs an up-to-date aclocal.m4.
Packit 47b4ca
  if ($rerun_aclocal)
Packit 47b4ca
    {
Packit 47b4ca
      if (!$uses_aclocal)
Packit 47b4ca
	{
Packit 47b4ca
	  verb "$configure_ac: not using aclocal";
Packit 47b4ca
	}
Packit 47b4ca
      else
Packit 47b4ca
	{
Packit 47b4ca
	  run_aclocal ($aclocal, $aclocal_flags);
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ------------------ #
Packit 47b4ca
  # Running autoconf.  #
Packit 47b4ca
  # ------------------ #
Packit 47b4ca
Packit 47b4ca
  # Don't try to be smarter than `autoconf', which does its own up to
Packit 47b4ca
  # date checks.
Packit 47b4ca
  #
Packit 47b4ca
  # We prefer running autoconf before autoheader, because (i) the
Packit 47b4ca
  # latter runs the former, and (ii) autoconf is stricter than
Packit 47b4ca
  # autoheader.  So all in all, autoconf should give better error
Packit 47b4ca
  # messages.
Packit 47b4ca
  xsystem ($autoconf);
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # -------------------- #
Packit 47b4ca
  # Running autoheader.  #
Packit 47b4ca
  # -------------------- #
Packit 47b4ca
Packit 47b4ca
  # We now consider that if AC_CONFIG_HEADERS is used, then autoheader
Packit 47b4ca
  # is used too.
Packit 47b4ca
  #
Packit 47b4ca
  # Just as for autoconf, up to date ness is performed by the tool
Packit 47b4ca
  # itself.
Packit 47b4ca
  #
Packit 47b4ca
  # Run it before automake, since the latter checks the presence of
Packit 47b4ca
  # config.h.in when it sees an AC_CONFIG_HEADERS.
Packit 47b4ca
  if (!$uses_autoheader)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using Autoheader";
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      xsystem ($autoheader);
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # ------------------ #
Packit 47b4ca
  # Running automake.  #
Packit 47b4ca
  # ------------------ #
Packit 47b4ca
Packit 47b4ca
  if (!$uses_automake)
Packit 47b4ca
    {
Packit 47b4ca
      verb "$configure_ac: not using Automake";
Packit 47b4ca
    }
Packit 47b4ca
  else
Packit 47b4ca
    {
Packit 47b4ca
      # We should always run automake, and let it decide whether it shall
Packit 47b4ca
      # update the file or not.  In fact, the effect of `$force' is already
Packit 47b4ca
      # included in `$automake' via `--no-force'.
Packit 47b4ca
      xsystem ($automake);
Packit 47b4ca
    }
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
  # -------------- #
Packit 47b4ca
  # Running make.  #
Packit 47b4ca
  # -------------- #
Packit 47b4ca
Packit 47b4ca
  if ($run_make)
Packit 47b4ca
    {
Packit 47b4ca
      if (!-f "config.status")
Packit 47b4ca
	{
Packit 47b4ca
	  verb "no config.status: cannot re-make";
Packit 47b4ca
	}
Packit 47b4ca
      else
Packit 47b4ca
	{
Packit 47b4ca
	  xsystem ("./config.status --recheck");
Packit 47b4ca
	  xsystem ("./config.status");
Packit 47b4ca
	  if (!-f "Makefile")
Packit 47b4ca
	    {
Packit 47b4ca
	      verb "no Makefile: cannot re-make";
Packit 47b4ca
	    }
Packit 47b4ca
	  else
Packit 47b4ca
	    {
Packit 47b4ca
	      xsystem ("$make");
Packit 47b4ca
	    }
Packit 47b4ca
	}
Packit 47b4ca
    }
Packit 47b4ca
}
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
# &autoreconf ($DIRECTORY)
Packit 47b4ca
# ------------------------
Packit 47b4ca
# Reconf the $DIRECTORY.
Packit 47b4ca
sub autoreconf ($)
Packit 47b4ca
{
Packit 47b4ca
  my ($directory) = @_;
Packit 47b4ca
  my $cwd = cwd;
Packit 47b4ca
Packit 47b4ca
  # The format for this message is not free: taken from Emacs, itself
Packit 47b4ca
  # using GNU Make's format.
Packit 47b4ca
  verb "Entering directory `$directory'";
Packit 47b4ca
  chdir $directory
Packit 47b4ca
    or error "cannot chdir to $directory: $!";
Packit 47b4ca
Packit 47b4ca
  autoreconf_current_directory;
Packit 47b4ca
Packit 47b4ca
  # The format is not free: taken from Emacs, itself using GNU Make's
Packit 47b4ca
  # format.
Packit 47b4ca
  verb "Leaving directory `$directory'";
Packit 47b4ca
  chdir $cwd
Packit 47b4ca
    or error "cannot chdir to $cwd: $!";
Packit 47b4ca
}
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
## ------ ##
Packit 47b4ca
## Main.  ##
Packit 47b4ca
## ------ ##
Packit 47b4ca
Packit 47b4ca
# When debugging, it is convenient that all the related temporary
Packit 47b4ca
# files be at the same place.
Packit 47b4ca
mktmpdir ('ar');
Packit 47b4ca
$ENV{'TMPDIR'} = $tmp;
Packit 47b4ca
parse_args;
Packit 47b4ca
Packit 47b4ca
# Autoreconf all the given configure.ac.  Unless `--no-recursive' is passed,
Packit 47b4ca
# AC_CONFIG_SUBDIRS will be traversed in &autoreconf_current_directory.
Packit 47b4ca
$ENV{'AUTOM4TE'} = $autom4te;
Packit 47b4ca
for my $directory (@ARGV)
Packit 47b4ca
  {
Packit 47b4ca
    require_configure_ac ($directory);
Packit 47b4ca
    autoreconf ($directory);
Packit 47b4ca
  }
Packit 47b4ca
Packit 47b4ca
### Setup "GNU" style for perl-mode and cperl-mode.
Packit 47b4ca
## Local Variables:
Packit 47b4ca
## perl-indent-level: 2
Packit 47b4ca
## perl-continued-statement-offset: 2
Packit 47b4ca
## perl-continued-brace-offset: 0
Packit 47b4ca
## perl-brace-offset: 0
Packit 47b4ca
## perl-brace-imaginary-offset: 0
Packit 47b4ca
## perl-label-offset: -2
Packit 47b4ca
## cperl-indent-level: 2
Packit 47b4ca
## cperl-brace-offset: 0
Packit 47b4ca
## cperl-continued-brace-offset: 0
Packit 47b4ca
## cperl-label-offset: -2
Packit 47b4ca
## cperl-extra-newline-before-brace: t
Packit 47b4ca
## cperl-merge-trailing-else: nil
Packit 47b4ca
## cperl-continued-statement-offset: 2
Packit 47b4ca
## End: