use Automake::XFile;
use Automake::FileUtils;
use File::Basename;
-use File::stat;
-use Cwd;
+use File::Path ();
# Some globals.
################################################################
+# Prototypes for all subroutines.
+
+sub unlink_tmp (;$);
+sub xmkdir_p ($);
+sub check_acinclude ();
+sub reset_maps ();
+sub install_file ($$);
+sub list_compare (\@\@);
+sub scan_m4_dirs ($@);
+sub scan_m4_files ();
+sub add_macro ($);
+sub scan_configure_dep ($);
+sub add_file ($);
+sub scan_file ($$$);
+sub strip_redundant_includes (%);
+sub trace_used_macros ();
+sub scan_configure ();
+sub write_aclocal ($@);
+sub usage ($);
+sub version ();
+sub handle_acdir_option ($$);
+sub parse_arguments ();
+sub parse_ACLOCAL_PATH ();
+
+################################################################
+
# Erase temporary file ERASE_ME. Handle signals.
-sub unlink_tmp
+sub unlink_tmp (;$)
{
my ($sig) = @_;
$SIG{'INT'} = $SIG{'TERM'} = $SIG{'QUIT'} = $SIG{'HUP'} = 'unlink_tmp';
END { unlink_tmp }
+sub xmkdir_p ($)
+{
+ my $dir = shift;
+ local $@ = undef;
+ return
+ if -d $dir or eval { File::Path::mkpath $dir };
+ chomp $@;
+ $@ =~ s/\s+at\s.*\bline\s\d+.*$//;
+ fatal "could not create directory '$dir': $@";
+}
+
# Check macros in acinclude.m4. If one is not used, warn.
sub check_acinclude ()
{
undef &search;
}
-# install_file ($SRC, $DEST)
+# install_file ($SRC, $DESTDIR)
sub install_file ($$)
{
- my ($src, $dest) = @_;
+ my ($src, $destdir) = @_;
+ my $dest = $destdir . "/" . basename ($src);
my $diff_dest;
+ verb "installing $src to $dest";
+
if ($force_output
|| !exists $file_contents{$dest}
|| $file_contents{$src} ne $file_contents{$dest})
}
elsif (!$dry_run)
{
+ xmkdir_p ($destdir);
xsystem ('cp', $src, $dest);
}
}
# --------------------------
# Scan all M4 files installed in @DIRS for new macro definitions.
# Register each file as of type $TYPE (one of the FT_* constants).
+my $first_user_m4dir = 1;
sub scan_m4_dirs ($@)
{
my ($type, @dirlist) = @_;
{
if (! opendir (DIR, $m4dir))
{
+ if ($install && $type == FT_USER && $first_user_m4dir)
+ {
+ # We will try to create this directory later, so don't
+ # complain if it doesn't exist.
+ # TODO: maybe we should avoid complaining only if errno
+ # is ENONENT?
+ $first_user_m4dir = 0;
+ next;
+ }
fatal "couldn't open directory '$m4dir': $!";
}
next if $file eq 'aclocal.m4';
my $fullfile = File::Spec->canonpath ("$m4dir/$file");
- &scan_file ($type, $fullfile, 'aclocal');
+ scan_file ($type, $fullfile, 'aclocal');
}
closedir (DIR);
}
{
# First, scan configure.ac. It may contain macro definitions,
# or may include other files that define macros.
- &scan_file (FT_USER, $configure_ac, 'aclocal');
+ scan_file (FT_USER, $configure_ac, 'aclocal');
# Then, scan acinclude.m4 if it exists.
if (-f 'acinclude.m4')
{
- &scan_file (FT_USER, 'acinclude.m4', 'aclocal');
+ scan_file (FT_USER, 'acinclude.m4', 'aclocal');
}
# Finally, scan all files in our search paths.
my $search = "sub search {\nmy \$found = 0;\n";
foreach my $key (reverse sort keys %map)
{
- $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { & add_macro ("' . $key
+ $search .= ('if (/\b\Q' . $key . '\E(?!\w)/) { add_macro ("' . $key
. '"); $found = 1; }' . "\n");
}
$search .= "return \$found;\n};\n";
verb "saw macro $macro";
$macro_seen{$macro} = 1;
- &add_file ($map{$macro});
+ add_file ($map{$macro});
}
# scan_configure_dep ($file)
}
add_macro ($_) foreach (@rlist);
- &scan_configure_dep ($_) foreach @ilist;
+ scan_configure_dep ($_) foreach @ilist;
}
# add_file ($FILE)
my $dest;
for my $ifile (@{$file_includes{$file}}, $file)
{
- $dest = "$user_includes[0]/" . basename $ifile;
- verb "installing $ifile to $dest";
- install_file ($ifile, $dest);
+ install_file ($ifile, $user_includes[0]);
}
$installed = 1;
}
# name in the header.
$output = "# generated automatically by aclocal $VERSION -*- Autoconf -*-
-# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
-# Inc.
+# Copyright (C) 1996-$RELEASE_YEAR Free Software Foundation, Inc.
+
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
}
# Print version and exit.
-sub version()
+sub version ()
{
print <<EOF;
aclocal (GNU $PACKAGE) $VERSION
-Copyright (C) 2011 Free Software Foundation, Inc.
+Copyright (C) $RELEASE_YEAR Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
exit 0;
}
-# Using --acdir overrides both the automake (versioned) directory and
-# the public (unversioned) system directory. This usage is obsolete.
-sub handle_acdir_option ($$)
-{
- msg 'obsolete', '', "'--acdir' is deprecated\n";
- @system_includes = ($_[1]);
- @automake_includes = ();
-}
-
# Parse command line.
sub parse_arguments ()
{
(
'help' => sub { usage(0); },
'version' => \&version,
- 'acdir=s' => \&handle_acdir_option,
'system-acdir=s' => sub { shift; @system_includes = @_; },
'automake-acdir=s' => sub { shift; @automake_includes = @_; },
'diff:s' => \$diff_command,
use Automake::Getopt ();
Automake::Getopt::parse_options %cli_options;
+ if (@ARGV > 0)
+ {
+ fatal ("non-option arguments are not accepted: '$ARGV[0]'.\n"
+ . "Try '$0 --help' for more information.");
+ }
+
if ($print_and_exit)
{
print "@system_includes\n";