70e31a45f5b419d802c164c5c77e32cc966b9d3d
[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 "\n"
32                 }
33         }
34         print "endmenu\n\n";
35         
36         undef $category{$cat};
37 }
38
39 my $line;
40 while ($line = <>) {
41         chomp $line;
42         $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
43                 $makefile = $1;
44                 $src = $2;
45                 undef $pkg;
46         };
47         $line =~ /^Package: \s*(.+)\s*$/ and do {
48                 $pkg = {};
49                 $pkg->{src} = $src;
50                 $pkg->{makefile} = $makefile;
51                 $pkg->{name} = $1;
52                 $pkg->{default} = "m if ALL";
53         };
54         $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
55         $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
56         $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
57         $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
58         $line =~ /^Depends: \s*(.+)\s*$/ and do {
59                 my @dep = split /,\s*/, $1;
60                 $pkg->{depends} = \@dep;
61         };
62         $line =~ /^Category: \s*(.+)\s*$/ and do {
63                 $pkg->{category} = $1;
64                 defined $category{$1} or $category{$1} = {};
65                 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
66                 push @{$category{$1}->{$src}}, $pkg;
67         };
68         $line =~ /^Description: \s*(.*)\s*$/ and do {
69                 my $desc = $1;
70                 my $line;
71                 while (<>) {
72                         last if /^@@/;
73                         $desc .= $1;
74                 }
75                 $pkg->{description} = $desc;
76         }
77 }
78
79 print_category 'Base system';
80 foreach my $cat (keys %category) {
81         print_category $cat;
82 }