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