improve dependency handling, fix some package makefile bugs
[openwrt/staging/dedeckeh.git] / openwrt / 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 my $m = "depends";
30 $depend =~ s/^([@\+])//;
31 my $flags = $1;
32 $flags =~ /@/ or $depend = "PACKAGE_$depend";
33 $flags =~ /\+/ and $m = "select";
34 print "\t\t$m $depend\n";
35 }
36 print "\t\thelp\n";
37 print $pkg->{description};
38 print "\n";
39
40 $pkg->{config} and print $pkg->{config}."\n";
41 }
42 }
43 print "endmenu\n\n";
44
45 undef $category{$cat};
46 }
47
48 my $line;
49 while ($line = <>) {
50 chomp $line;
51 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
52 $makefile = $1;
53 $src = $2;
54 undef $pkg;
55 };
56 $line =~ /^Package: \s*(.+)\s*$/ and do {
57 $pkg = {};
58 $pkg->{src} = $src;
59 $pkg->{makefile} = $makefile;
60 $pkg->{name} = $1;
61 $pkg->{default} = "m if ALL";
62 };
63 $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
64 $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
65 $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
66 $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
67 $line =~ /^Depends: \s*(.+)\s*$/ and do {
68 my @dep = split /\s+/, $1;
69 $pkg->{depends} = \@dep;
70 };
71 $line =~ /^Category: \s*(.+)\s*$/ and do {
72 $pkg->{category} = $1;
73 defined $category{$1} or $category{$1} = {};
74 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
75 push @{$category{$1}->{$src}}, $pkg;
76 };
77 $line =~ /^Description: \s*(.*)\s*$/ and do {
78 my $desc = "\t\t$1\n\n";
79 my $line;
80 while ($line = <>) {
81 last if $line =~ /^@@/;
82 $desc .= "\t\t$line";
83 }
84 $pkg->{description} = $desc;
85 };
86 $line =~ /^Config: \s*(.*)\s*$/ and do {
87 my $conf = "$1\n";
88 my $line;
89 while ($line = <>) {
90 last if $line =~ /^@@/;
91 $conf .= "$line";
92 }
93 $pkg->{config} = $conf;
94 }
95 }
96
97 print_category 'Base system';
98 foreach my $cat (keys %category) {
99 print_category $cat;
100 }