add submenu dependencies (used to hide the proprietary broadcom driver on anything...
[openwrt/staging/dedeckeh.git] / openwrt / scripts / gen_menuconfig.pl
1 #!/usr/bin/perl
2 #
3 # Copyright (C) 2006 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 use strict;
10
11 my $src;
12 my $makefile;
13 my $pkg;
14 my %category;
15 my $cur_menu;
16 my $cur_menu_dep;
17
18 sub print_category($) {
19 my $cat = shift;
20
21 return unless $category{$cat};
22
23 print "menu \"$cat\"\n\n";
24 my %spkg = %{$category{$cat}};
25 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
26 foreach my $pkg (@{$spkg{$spkg}}) {
27 if ($cur_menu ne $pkg->{submenu}) {
28 if ($cur_menu) {
29 print "endmenu\n";
30 $cur_menu_dep and do {
31 print "endif\n";
32 $cur_menu_dep = undef;
33 };
34 undef $cur_menu;
35 }
36 if ($pkg->{submenu}) {
37 $cur_menu = $pkg->{submenu};
38 $cur_menu_dep = $pkg->{submenudep} and print "if $cur_menu_dep\n";
39 print "menu \"$cur_menu\"\n";
40 }
41 }
42 my $title = $pkg->{name};
43 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
44 if ($c > 0) {
45 $title .= ("." x $c). " ". $pkg->{title};
46 }
47 print "\t";
48 $pkg->{menu} and print "menu";
49 print "config PACKAGE_".$pkg->{name}."\n";
50 print "\t\ttristate \"$title\"\n";
51 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
52 print "\t\tdefault $default\n";
53 }
54 foreach my $depend (@{$pkg->{depends}}) {
55 my $m = "depends";
56 $depend =~ s/^([@\+]+)//;
57 my $flags = $1;
58 $flags =~ /@/ or $depend = "PACKAGE_$depend";
59 $flags =~ /\+/ and $m = "select";
60 print "\t\t$m $depend\n";
61 }
62 print "\t\thelp\n";
63 print $pkg->{description};
64 print "\n";
65
66 $pkg->{config} and print $pkg->{config}."\n";
67 }
68 }
69 print "endmenu\n\n";
70
71 undef $category{$cat};
72 }
73
74 my $line;
75 while ($line = <>) {
76 chomp $line;
77 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
78 $makefile = $1;
79 $src = $2;
80 undef $pkg;
81 };
82 $line =~ /^Package: \s*(.+)\s*$/ and do {
83 $pkg = {};
84 $pkg->{src} = $src;
85 $pkg->{makefile} = $makefile;
86 $pkg->{name} = $1;
87 $pkg->{default} = "m if ALL";
88 };
89 $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
90 $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
91 $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
92 $line =~ /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
93 $line =~ /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
94 $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
95 $line =~ /^Depends: \s*(.+)\s*$/ and do {
96 my @dep = split /\s+/, $1;
97 $pkg->{depends} = \@dep;
98 };
99 $line =~ /^Category: \s*(.+)\s*$/ and do {
100 $pkg->{category} = $1;
101 defined $category{$1} or $category{$1} = {};
102 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
103 push @{$category{$1}->{$src}}, $pkg;
104 };
105 $line =~ /^Description: \s*(.*)\s*$/ and do {
106 my $desc = "\t\t$1\n\n";
107 my $line;
108 while ($line = <>) {
109 last if $line =~ /^@@/;
110 $desc .= "\t\t$line";
111 }
112 $pkg->{description} = $desc;
113 };
114 $line =~ /^Config: \s*(.*)\s*$/ and do {
115 my $conf = "$1\n";
116 my $line;
117 while ($line = <>) {
118 last if $line =~ /^@@/;
119 $conf .= "$line";
120 }
121 $pkg->{config} = $conf;
122 }
123 }
124
125 print_category 'Base system';
126 foreach my $cat (keys %category) {
127 print_category $cat;
128 }