-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-config.pl
174 lines (145 loc) · 4.44 KB
/
make-config.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/perl -w
use File::Find qw< find >;
use Data::Dumper qw< Dumper >;
open CONFIG_IN, ">Config.in" or die $!;
# Might look like:
# { "." => "a bunch of lines of text",
# "Games" => { "." => "a bunch of lines of text",
# "Strategy" => { "." => "a bunch of lines of text" },
# ...
# },
# ...
# }
our %MenuStructure;
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime time;
$year += 1900; $mon++;
print CONFIG_IN <<EOF;
#
# Automatically generated podzilla2 Config.in. Do not edit.
# Generated @{[ sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $mon, $mday, $hour, $min, $sec) ]}
# Do not edit.
#
mainmenu "podzilla2 module configuration"
config MODULES
bool
default y
EOF
sub parse_menu_stuff {
my($fh) = shift;
my($root) = shift;
while (<$fh>) {
my($line) = $_;
if ($line =~ /^\s*menu\s+"(.*?)"/) {
my($name) = $1;
$root->{$name} = {} unless defined $root->{$name};
parse_menu_stuff($fh, $root->{$name});
} elsif ($line =~ /^\s*endmenu/) {
return;
} else {
$root->{'.'} = "" unless defined $root->{'.'};
$root->{'.'} .= $line;
}
}
}
# Layout:
# each element is a hashref
# $Modules{name} => { name => <name>, dir => <dir the module is in>, modinf => { modinf file },
# ordered => <0 or 1> }
our %Modules;
sub process_file {
if (m[/([^/]+)/Module$]) {
my($name) = $1;
my(%modfile);
open MODFILE, $File::Find::name or die "$!";
while (<MODFILE>) {
chomp;
/^#/ and next;
/^\s*$/ and next;
/^\s*([A-Z][A-Za-z-]+):\s*(.*)\s*$/ or do { warn "bad Module file line"; next; };
my($prop,$val) = ($1,$2);
$prop =~ s/-//;
$modfile{$prop} = $val;
}
$Modules{$name} = { name => $name, dir => $File::Find::dir, modinf => \%modfile, ordered => 0 };
}
}
find { wanted => \&process_file, no_chdir => 1 }, 'modules';
our(@Modules) = sort {$a cmp $b} keys %Modules;
our(@OrderedModules) = ();
sub add_deps {
my($mod) = shift;
my($name) = $mod->{name};
return if $mod->{ordered};
$mod->{ordered} = 1;
push @OrderedModules, $mod;
for (@Modules) {
next unless defined $Modules{$_}{modinf}{Dependencies};
if ($Modules{$_}{modinf}{Dependencies} =~ /\b$name\b/) {
add_deps($Modules{$_});
}
}
}
for (@Modules) {
add_deps $Modules{$_};
}
for (@OrderedModules) {
my($mod) = $_;
my(%modfile) = %{$mod->{modinf}};
my($dir) = $mod->{dir};
if (open KCF, "$dir/Config") {
parse_menu_stuff *KCF{IO}, \%MenuStructure;
close KCF;
} else {
$modfile{Category} = "Miscellaneous" unless defined $modfile{Category};
my($cat) = $modfile{Category};
my(@tree) = split /\//, $cat;
my($menuptr) = \%MenuStructure;
while (scalar @tree) {
my($nextent) = shift @tree;
$menuptr->{$nextent} = {} unless defined $menuptr->{$nextent};
$menuptr = $menuptr->{$nextent};
}
my($deps) = "";
if (defined $modfile{Dependencies}) {
my(@deps) = split /,/ => $modfile{Dependencies};
for (@deps) {
$deps .= "\n depends on MODULE_$_";
}
}
$modfile{Displayname} = $modfile{Module} unless defined $modfile{Displayname};
$modfile{Description} = $modfile{Displayname} unless defined $modfile{Description};
$menuptr->{'.'} = "" unless defined $menuptr->{'.'};
$menuptr->{'.'} .= <<EOF;
config MODULE_$modfile{Module}
tristate "$modfile{Displayname}"
default m$deps
help
$modfile{Description}
This is a module with no configuration information; if you need more
information about it, check http://ipodlinux.org/Special:Module/$modfile{Module}.
EOF
}
}
sub write_menu {
my($fh) = shift;
my($root) = shift;
my($topvals) = 0;
if (defined $root->{'.'}) {
print $fh $root->{'.'};
$topvals++;
}
for (keys %$root) {
/^\.$/ and next;
if ($topvals) {
print $fh "\ncomment \"\"";
$topvals = 0;
}
print $fh "\nmenu \"$_\"\n";
write_menu($fh, $root->{$_});
print $fh "endmenu\n";
}
}
write_menu *CONFIG_IN{IO}, \%MenuStructure;
print CONFIG_IN "\n# End:\n";
close CONFIG_IN;
exit 0;