credit where credit is due
[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
17 sub print_category($) {
18 my $cat = shift;
19
20 return unless $category{$cat};
21
22 print "menu \"$cat\"\n\n";
23 my %spkg = %{$category{$cat}};
24 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
25 foreach my $pkg (@{$spkg{$spkg}}) {
26 if ($cur_menu ne $pkg->{submenu}) {
27 if ($cur_menu) {
28 print "endmenu\n";
29 undef $cur_menu;
30 }
31 if ($pkg->{submenu}) {
32 $cur_menu = $pkg->{submenu};
33 print "menu \"$cur_menu\"\n";
34 }
35 }
36 my $title = $pkg->{name};
37 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
38 if ($c > 0) {
39 $title .= ("." x $c). " ". $pkg->{title};
40 }
41 print "\t";
42 $pkg->{menu} and print "menu";
43 print "config PACKAGE_".$pkg->{name}."\n";
44 print "\t\ttristate \"$title\"\n";
45 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
46 print "\t\tdefault $default\n";
47 }
48 foreach my $depend (@{$pkg->{depends}}) {
49 my $m = "depends";
50 $depend =~ s/^([@\+]+)//;
51 my $flags = $1;
52 $flags =~ /@/ or $depend = "PACKAGE_$depend";
53 $flags =~ /\+/ and $m = "select";
54 print "\t\t$m $depend\n";
55 }
56 print "\t\thelp\n";
57 print $pkg->{description};
58 print "\n";
59
60 $pkg->{config} and print $pkg->{config}."\n";
61 }
62 }
63 print "endmenu\n\n";
64
65 undef $category{$cat};
66 }
67
68 my $line;
69 while ($line = <>) {
70 chomp $line;
71 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
72 $makefile = $1;
73 $src = $2;
74 undef $pkg;
75 };
76 $line =~ /^Package: \s*(.+)\s*$/ and do {
77 $pkg = {};
78 $pkg->{src} = $src;
79 $pkg->{makefile} = $makefile;
80 $pkg->{name} = $1;
81 $pkg->{default} = "m if ALL";
82 };
83 $line =~ /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
84 $line =~ /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
85 $line =~ /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
86 $line =~ /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
87 $line =~ /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
88 $line =~ /^Depends: \s*(.+)\s*$/ and do {
89 my @dep = split /\s+/, $1;
90 $pkg->{depends} = \@dep;
91 };
92 $line =~ /^Category: \s*(.+)\s*$/ and do {
93 $pkg->{category} = $1;
94 defined $category{$1} or $category{$1} = {};
95 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
96 push @{$category{$1}->{$src}}, $pkg;
97 };
98 $line =~ /^Description: \s*(.*)\s*$/ and do {
99 my $desc = "\t\t$1\n\n";
100 my $line;
101 while ($line = <>) {
102 last if $line =~ /^@@/;
103 $desc .= "\t\t$line";
104 }
105 $pkg->{description} = $desc;
106 };
107 $line =~ /^Config: \s*(.*)\s*$/ and do {
108 my $conf = "$1\n";
109 my $line;
110 while ($line = <>) {
111 last if $line =~ /^@@/;
112 $conf .= "$line";
113 }
114 $pkg->{config} = $conf;
115 }
116 }
117
118 print_category 'Base system';
119 foreach my $cat (keys %category) {
120 print_category $cat;
121 }