summaryrefslogtreecommitdiff
path: root/automake.in
diff options
context:
space:
mode:
authorStefano Lattarini <stefano.lattarini@gmail.com>2012-01-18 17:55:40 +0100
committerStefano Lattarini <stefano.lattarini@gmail.com>2012-01-18 18:26:25 +0100
commit52246cc7355cedbc9cb992095870572beb767ca1 (patch)
tree91124e12405b69cc274462705516988f9b662e67 /automake.in
parenta1e77caf20a62b14d549307a73131fedb9c0f696 (diff)
downloadautomake-52246cc7355cedbc9cb992095870572beb767ca1.tar.gz
cmdline parsing: move into a dedicated perl module
With this change, we delegate most of the automake and aclocal code for command-line options parsing to a new module "Automake::Getopt". This allows better code sharing between automake and aclocal, and also with Autoconf, which will sync the new module from us. See also autoconf commit 'v2.68-120-gf4be358' (2012-01-17, "getopt: new Autom4te::Getopt module"), and this mailing list discussion: <http://lists.gnu.org/archive/html/autoconf-patches/2012-01/msg00033.html> This change might interact with the behaviour described in automake bug#7434; for example, starting from now, "automake -Wfoo --version" will cause automake to emit diagnostic like "unknown warning category 'foo'" before actually printing the version number and exiting. This is not a big deal in practice, and the code sharing and simplifications introduced by this patch is certainly worth it. Still, we should revisited the issue in the future. * lib/Automake/Getopt.pm: New module, basically a slightly-edited copy of the 'lib/Autom4te/Getopt.pm' file from the autoconf devel repository (commit v2.68-120-gf4be358). It defines and exports ... (parse_options): ... this new function. * automake.in (parse_arguments): Use the new function. * aclocal.in (parse_arguments): Likewise. * lib/Automake/Makefile.am (dist_perllib_DATA): Add the new file. * tests/getopt.test: Remove. * tests/list-of-tests.mk: Update.
Diffstat (limited to 'automake.in')
-rw-r--r--automake.in56
1 files changed, 4 insertions, 52 deletions
diff --git a/automake.in b/automake.in
index 24d5872dd..3c70b38e2 100644
--- a/automake.in
+++ b/automake.in
@@ -8496,6 +8496,8 @@ sub parse_arguments ()
my $cli_where = new Automake::Location;
my %cli_options =
(
+ 'version' => \&version,
+ 'help' => \&usage,
'libdir=s' => \$libdir,
'gnu' => sub { set_strictness ('gnu'); },
'gnits' => sub { set_strictness ('gnits'); },
@@ -8516,32 +8518,9 @@ sub parse_arguments ()
'Werror' => sub { parse_warnings 'W', 'error'; },
'Wno-error' => sub { parse_warnings 'W', 'no-error'; },
);
- use Getopt::Long;
- Getopt::Long::config ("bundling", "pass_through");
-
- # See if --version or --help is used. We want to process these before
- # anything else because the GNU Coding Standards require us to
- # `exit 0' after processing these options, and we can't guarantee this
- # if we treat other options first. (Handling other options first
- # could produce error diagnostics, and in this condition it is
- # confusing if Automake does `exit 0'.)
- my %cli_options_1st_pass =
- (
- 'version' => \&version,
- 'help' => \&usage,
- # Recognize all other options (and their arguments) but do nothing.
- map { $_ => sub {} } (keys %cli_options)
- );
- my @ARGV_backup = @ARGV;
- Getopt::Long::GetOptions %cli_options_1st_pass
- or exit 1;
- @ARGV = @ARGV_backup;
- # Now *really* process the options. This time we know that --help
- # and --version are not present, but we specify them nonetheless so
- # that ambiguous abbreviation are diagnosed.
- Getopt::Long::GetOptions %cli_options, 'version' => sub {}, 'help' => sub {}
- or exit 1;
+ use Automake::Getopt ();
+ Automake::Getopt::parse_options %cli_options;
if (defined $output_directory)
{
@@ -8555,33 +8534,6 @@ sub parse_arguments ()
return unless @ARGV;
- if ($ARGV[0] =~ /^-./)
- {
- my %argopts;
- for my $k (keys %cli_options)
- {
- if ($k =~ /(.*)=s$/)
- {
- map { $argopts{(length ($_) == 1)
- ? "-$_" : "--$_" } = 1; } (split (/\|/, $1));
- }
- }
- if ($ARGV[0] eq '--')
- {
- shift @ARGV;
- }
- elsif (exists $argopts{$ARGV[0]})
- {
- fatal ("option `$ARGV[0]' requires an argument\n"
- . "Try `$0 --help' for more information.");
- }
- else
- {
- fatal ("unrecognized option `$ARGV[0]'.\n"
- . "Try `$0 --help' for more information.");
- }
- }
-
my $errspec = 0;
foreach my $arg (@ARGV)
{