]> sjero.net Git - wget/blob - build_info.pl
Updated config.guess, config.sub, install.sh.
[wget] / build_info.pl
1 #!/usr/bin/perl
2
3 # Generate build_info.c.
4
5 # Copyright (C) 2009 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 use strict;
21 use warnings;
22
23 use FindBin qw($Bin);
24 use File::Spec ();
25
26 my $file = File::Spec->catfile($Bin, 'src', 'build_info.c.in');
27
28 {
29     my $data = parse_config();
30     output_code($data);
31 }
32
33 sub parse_config
34 {
35     my (%block, @defines, %feature);
36
37     open(my $fh, '<', $file) or die "Cannot open $file: $!";
38     my $cfg = do { local $/; <$fh> };
39     close($fh);
40
41     while ($cfg =~ /^\ *? (\w+) (?:\s+?)? (\w+?)? \s*$/gmx) {
42         $feature{$1} = $2 || '_MISSING';
43         push @defines, $1;
44     }
45     while ($cfg =~ /^(\ *? \#\w+? \s+? (\w+) .+ \#\w+)/gmsx) {
46         $block{$2} = $1;
47     }
48
49     my %data = (
50         block   => \%block,
51         defines => \@defines,
52         feature => \%feature,
53     );
54
55     return \%data;
56 }
57
58 sub output_code
59 {
60     my ($block, $defines, $feature) =
61       map $_[0]->{$_}, qw(block defines feature);
62
63     print do { local $/; <DATA> }, "\n";
64     print <<EOC;
65 const char* (compiled_features[]) =
66 {
67
68 EOC
69     my @output;
70     foreach my $define (@$defines) {
71         if (!exists $block->{$define}) {
72             push @output, <<EOC;
73 #ifdef $define
74   "+$feature->{$define}",
75 #else
76   "-$feature->{$define}",
77 #endif
78 EOC
79         }
80         else {
81             push @output, <<EOC;
82 $block->{$define}
83 EOC
84         }
85     }
86     print join "\n", @output;
87     print <<EOC;
88
89   /* sentinel value */
90   NULL
91 };
92
93
94 EOC
95 }
96
97 __DATA__
98 /* Autogenerated by build_info.pl - DO NOT EDIT */
99
100 /* This stores global variables that are initialized with
101    preprocessor declarations for output with the --version flag.
102
103    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
104    2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.  */
105
106 #include "wget.h"
107 #include <stdio.h>