]> sjero.net Git - wget/blob - build-aux/build_info.pl
mass change: update copyright years.
[wget] / build-aux / build_info.pl
1 #!/usr/bin/env perl
2
3 # Generate build_info.c.
4
5 # Copyright (C) 2009, 2010, 2011 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 Carp qw(croak);
24
25 my $file = shift @ARGV;
26
27 {
28     my $data = parse_config();
29     output_code($data);
30 }
31
32 sub parse_config
33 {
34     my $features = [];
35     my $choice_key;
36     my $choice = [];
37     my $list = $features;
38
39     open(my $fh, '<', "$file.in") or die "Cannot open $file.in: $!";
40
41     while (<$fh>) {
42         next if /^\s*$/;
43
44         if ($list eq $choice) {
45             unless (s/^\s+//) {
46                 $list = $features;
47                 push @$features, [$choice_key, $choice];
48                 $choice = [];
49                 undef $choice_key;
50             }
51         } elsif (/^([A-Za-z0-9_-]+) \s+ choice:\s*$/x) {
52             $choice_key = $1;
53             $list = $choice;
54             next;
55         }
56
57         if (/^([A-Za-z0-9_-]+) \s+ (.*)$/x) {
58             push @$list, [$1, $2];
59         } else {
60             croak "Can't parse line: $_";
61         }
62     }
63
64     if ($list eq $choice) {
65         push @$features, [$choice_key, $choice];
66     }
67
68     close($fh);
69
70     return $features;
71 }
72
73 sub output_code
74 {
75     my $features = shift;
76
77     open(my $fh, '>', "$file") or die "Cannot open $file: $!";
78
79     print $fh do { local $/; <DATA> }, "\n";
80     print $fh <<EOC;
81 const char *compiled_features[] =
82 {
83
84 EOC
85     foreach my $feature (sort { $a->[0] cmp $b->[0] } @$features) {
86         my ($name, $check) = @$feature;
87
88         if (ref $check eq 'ARRAY') {
89             my ($ch_name, $ch_check) = @{ shift @$check };
90             print $fh <<EOC;
91 #if $ch_check
92   "+$name/$ch_name",
93 EOC
94             foreach my $choice (@$check) {
95                 ($ch_name, $ch_check) = @$choice;
96
97                 print $fh <<EOC;
98 #elif $ch_check
99   "+$name/$ch_name",
100 EOC
101             }
102                 print $fh <<EOC;
103 #else 
104   "-$name",
105 #endif
106
107 EOC
108         } else {
109             print $fh <<EOC;
110 #if $check
111   "+$name",
112 #else
113   "-$name",
114 #endif
115
116 EOC
117         }
118     }
119     print $fh <<EOC;
120
121   /* sentinel value */
122   NULL
123 };
124
125
126 EOC
127 }
128
129 __DATA__
130 /* Autogenerated by build_info.pl - DO NOT EDIT */
131
132 /* This stores global variables that are initialized with
133    preprocessor declarations for output with the --version flag.
134
135    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
136    2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.  */
137
138 #include "wget.h"
139 #include <stdio.h>