e282ee3ed2d95a8b96f210af5af392eade2af32d
[openwrt.git] / scripts / gen_menuconfig.pl
1 #!/usr/bin/perl
2 use strict;
3
4 my $src;
5 my $makefile;
6 my $pkg;
7 my %category;
8
9 sub print_category($) {
10 my $cat = shift;
11
12 return unless $category{$cat};
13
14 print "menu \"$cat\"\n\n";
15 my %spkg = %{$category{$cat}};
16 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
17 foreach my $pkg (@{$spkg{$spkg}}) {
18 my $title = $pkg->{name};
19 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
20 if ($c > 0) {
21 $title .= ("." x $c). " ". $pkg->{title};
22 }
23 print "\t";
24 $pkg->{menu} and print "menu";
25 print "config PACKAGE_".$pkg->{name}."\n";
26 print "\t\ttristate \"$title\"\n";
27 print "\t\tdefault ".$pkg->{default}."\n";
28 foreach my $depend (@{$pkg->{depends}}) {
29 print "\t\tdepends PACKAGE_$depend\n";
30 }
31 print "\t\thelp\n";
32 print $pkg->{description};
33 print "\n";
34
35 $pkg->{config} and print $pkg->{config}."\n";
36 }
37 }
38 print "endmenu\n\n";
39
40 undef $category{$cat};
41 }
42
43 my $line;
44 while ($line = <>) {
45 chomp $line;
46 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
47 $makefile = $1;
48 $src = $2;
49 undef $pkg;
50 };
51 $line =~ /^Package: \s*(.+)\s*$/ and do {
52 $pkg = {};
53 $pkg->{src} = $src;
54 $pkg->{makefile} = $makefile;
55 $pkg->{name} = $1;
56 $pkg->{default} = "m if ALL";
57 };
58 $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
59 $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
60 $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
61 $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
62 $line =~ /^Depends: \s*(.+)\s*$/ and do {
63 my @dep = split /,\s*/, $1;
64 $pkg->{depends} = \@dep;
65 };
66 $line =~ /^Category: \s*(.+)\s*$/ and do {
67 $pkg->{category} = $1;
68 defined $category{$1} or $category{$1} = {};
69 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
70 push @{$category{$1}->{$src}}, $pkg;
71 };
72 $line =~ /^Description: \s*(.*)\s*$/ and do {
73 my $desc = "\t\t$1\n\n";
74 my $line;
75 while ($line = <>) {
76 last if $line =~ /^@@/;
77 $desc .= "\t\t$line";
78 }
79 $pkg->{description} = $desc;
80 };
81 $line =~ /^Config: \s*(.*)\s*$/ and do {
82 my $conf = "$1\n";
83 my $line;
84 while ($line = <>) {
85 last if $line =~ /^@@/;
86 $conf .= "$line";
87 }
88 $pkg->{config} = $conf;
89 }
90 }
91
92 print_category 'Base system';
93 foreach my $cat (keys %category) {
94 print_category $cat;
95 }
This page took 0.054059 seconds and 3 git commands to generate.