implement target profiles in menuconfig
[openwrt-10.03/.git] / scripts / gen_target_config.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 @target;
12 my $target;
13 my $profiles;
14 my $profile;
15
16 sub features(@) {
17         my $ret;
18
19         while ($_ = shift @_) {
20                 /broken/ and $ret .= "\tdepends BROKEN\n";
21                 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
22                 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
23                 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
24                 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
25                 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
26                 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
27                 /ext2/ and $ret .= "\tselect USES_EXT2\n";
28         }
29         return $ret;
30 }
31
32 while (<>) {
33         chomp;
34         /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
35                 my $conf = uc $3.'_'.$2;
36                 $conf =~ tr/\.-/__/;
37                 $target = {
38                         id => $1,
39                         conf => $conf,
40                         board => $2,
41                         kernel => $3
42                 };
43                 push @target, $target;
44         };
45         /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
46         /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
47         /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
48         /^Target-Features:\s*(.+)\s*$/ and do {
49                 my $f = [];
50                 $target->{features} = $f;
51                 @$f = split /\s+/, $1;
52         };
53         /^Target-Description:/ and do {
54                 my $desc;
55                 while (<>) {
56                         last if /^@@/;
57                         $desc .= $_;
58                 }
59                 $target->{desc} = $desc;
60         };
61         /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
62         /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
63         /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
64         /^Default-Packages:\s*(.+)\s*$/ and do {
65                 my @pkgs = split /\s+/, $1;
66                 $target->{defaultpkgs} = \@pkgs;
67         };
68         /^Target-Profile:\s*(.+)\s*$/ and do {
69                 $profiles = $target->{profiles} or $target->{profiles} = $profiles = [];
70                 $profile = {
71                         id => $1
72                 };
73                 push @$profiles, $profile;
74         };
75         /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
76         /^Target-Profile-Packages:\s*(.+)\s*$/ and do {
77                 my @pkgs = split /\s+/, $1;
78                 $profile->{pkgs} = \@pkgs;
79         };
80 }
81
82 @target = sort {
83         $a->{name} cmp $b->{name}
84 } @target;
85
86
87 print <<EOF;
88 choice
89         prompt "Target System"
90         default LINUX_2_4_BRCM
91         
92 EOF
93
94 foreach $target (@target) {
95         my $features = features(@{$target->{features}});
96         my $help = $target->{desc};
97         chomp $features;
98         $features .= "\n";
99         if ($help =~ /\w+/) {
100                 $help =~ s/^\s*/\t  /mg;
101                 $help = "\thelp\n$help";
102         } else {
103                 undef $help;
104         }
105
106         print <<EOF
107 config LINUX_$target->{conf}
108         bool "$target->{name}"
109         select $target->{arch}
110 $features$help
111
112 EOF
113 }
114
115 print <<EOF;
116 if DEVEL
117
118 config LINUX_2_6_ARM
119         bool "UNSUPPORTED little-endian arm platform"
120         depends BROKEN
121         select LINUX_2_6
122         select arm
123
124 config LINUX_2_6_CRIS
125         bool "UNSUPPORTED cris platform"
126         depends BROKEN
127         select LINUX_2_6
128         select cris
129
130 config LINUX_2_6_M68K
131         bool "UNSUPPORTED m68k platform"
132         depends BROKEN
133         select LINUX_2_6
134         select m68k
135
136 config LINUX_2_6_SH3
137         bool "UNSUPPORTED little-endian sh3 platform"
138         depends BROKEN
139         select LINUX_2_6
140         select sh3
141
142 config LINUX_2_6_SH3EB
143         bool "UNSUPPORTED big-endian sh3 platform"
144         depends BROKEN
145         select LINUX_2_6
146         select sh3eb
147
148 config LINUX_2_6_SH4
149         bool "UNSUPPORTED little-endian sh4 platform"
150         depends BROKEN
151         select LINUX_2_6
152         select sh4
153
154 config LINUX_2_6_SH4EB
155         bool "UNSUPPORTED big-endian sh4 platform"
156         depends BROKEN
157         select LINUX_2_6
158         select sh4eb
159
160 config LINUX_2_6_SPARC
161         bool "UNSUPPORTED sparc platform"
162         depends BROKEN
163         select LINUX_2_6
164         select sparc
165
166 endif
167
168 endchoice
169
170 choice
171         prompt "Target Profile"
172
173 EOF
174
175 foreach $target (@target) {
176         my $profiles;
177         
178         $profiles = $target->{profiles} or $profiles = [
179                 {
180                         id => 'Default',
181                         name => 'Default',
182                         pkgs => []
183                 }
184         ];
185         foreach my $profile (@$profiles) {
186                 print <<EOF;
187 config LINUX_$target->{conf}_$profile->{id}
188         bool "$profile->{name}"
189         depends LINUX_$target->{conf}
190 EOF
191                 foreach my $pkg (@{$target->{defaultpkgs}}, @{$profile->{pkgs}}) {
192                         print "\tselect DEFAULT_$pkg\n";
193                 }
194                 print "\n";
195         }
196 }
197
198 print "endchoice\n";