X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=build-aux%2Fbuild_info.pl;h=eddfd52a2504ea75aafd1bd3ad7cbf4794413f83;hp=a006b6da0173132028d3f024fe41d9441d6c81a7;hb=2f6aa1d7417df1dfc58597777686fbd77179b9fd;hpb=c794a7e82668a68b39461d267649d8b94cfe6fae diff --git a/build-aux/build_info.pl b/build-aux/build_info.pl index a006b6da..eddfd52a 100755 --- a/build-aux/build_info.pl +++ b/build-aux/build_info.pl @@ -1,8 +1,8 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Generate build_info.c. -# Copyright (C) 2009 Free Software Foundation, Inc. +# Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,8 +20,7 @@ use strict; use warnings; -use FindBin qw($Bin); -use File::Spec (); +use Carp qw(croak); my $file = shift @ARGV; @@ -32,59 +31,92 @@ my $file = shift @ARGV; sub parse_config { - my (%block, @defines, %feature); - - open(my $fh, '<', $file) or die "Cannot open $file: $!"; - my $cfg = do { local $/; <$fh> }; - close($fh); + my $features = []; + my $choice_key; + my $choice = []; + my $list = $features; + + open(my $fh, '<', "$file.in") or die "Cannot open $file.in: $!"; + + while (<$fh>) { + next if /^\s*$/; + + if ($list eq $choice) { + unless (s/^\s+//) { + $list = $features; + push @$features, [$choice_key, $choice]; + $choice = []; + undef $choice_key; + } + } elsif (/^([A-Za-z0-9_-]+) \s+ choice:\s*$/x) { + $choice_key = $1; + $list = $choice; + next; + } - while ($cfg =~ /^\ *? (\w+) (?:\s+?)? (\w+?)? \s*$/gmx) { - $feature{$1} = $2 || '_MISSING'; - push @defines, $1; + if (/^([A-Za-z0-9_-]+) \s+ (.*)$/x) { + push @$list, [$1, $2]; + } else { + croak "Can't parse line: $_"; + } } - while ($cfg =~ /^(\ *? \#\w+? \s+? (\w+) .+ \#\w+)/gmsx) { - $block{$2} = $1; + + if ($list eq $choice) { + push @$features, [$choice_key, $choice]; } - my %data = ( - block => \%block, - defines => \@defines, - feature => \%feature, - ); + close($fh); - return \%data; + return $features; } sub output_code { - my ($block, $defines, $feature) = - map $_[0]->{$_}, qw(block defines feature); + my $features = shift; - print do { local $/; }, "\n"; - print <', "$file") or die "Cannot open $file: $!"; + + print $fh do { local $/; }, "\n"; + print $fh <{$define}) { - push @output, <{$define}", -#else - "-$feature->{$define}", + foreach my $feature (sort { $a->[0] cmp $b->[0] } @$features) { + my ($name, $check) = @$feature; + + if (ref $check eq 'ARRAY') { + my ($ch_name, $ch_check) = @{ shift @$check }; + print $fh <{$define} + } else { + print $fh <