add a simple maintenance tool for kernel config files
[openwrt.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 $target->{kernel} =~ tr/\./_/;
44 push @target, $target;
45 };
46 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
47 /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
48 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
49 /^Target-Features:\s*(.+)\s*$/ and do {
50 my $f = [];
51 $target->{features} = $f;
52 @$f = split /\s+/, $1;
53 };
54 /^Target-Description:/ and do {
55 my $desc;
56 while (<>) {
57 last if /^@@/;
58 $desc .= $_;
59 }
60 $target->{desc} = $desc;
61 };
62 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
63 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
64 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
65 /^Default-Packages:\s*(.+)\s*$/ and do {
66 my @pkgs = split /\s+/, $1;
67 $target->{defaultpkgs} = \@pkgs;
68 };
69 /^Target-Profile:\s*(.+)\s*$/ and do {
70 $profiles = $target->{profiles} or $target->{profiles} = $profiles = [];
71 $profile = {
72 id => $1
73 };
74 push @$profiles, $profile;
75 };
76 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
77 /^Target-Profile-Packages:\s*(.+)\s*$/ and do {
78 my @pkgs = split /\s+/, $1;
79 $profile->{pkgs} = \@pkgs;
80 };
81 }
82
83 @target = sort {
84 $a->{name} cmp $b->{name}
85 } @target;
86
87
88 print <<EOF;
89 choice
90 prompt "Target System"
91 default LINUX_2_4_BRCM
92
93 EOF
94
95 foreach $target (@target) {
96 my $features = features(@{$target->{features}});
97 my $help = $target->{desc};
98 chomp $features;
99 $features .= "\n";
100 if ($help =~ /\w+/) {
101 $help =~ s/^\s*/\t /mg;
102 $help = "\thelp\n$help";
103 } else {
104 undef $help;
105 }
106
107 print <<EOF
108 config LINUX_$target->{conf}
109 bool "$target->{name}"
110 select $target->{arch}
111 select LINUX_$target->{kernel}
112 $features$help
113
114 EOF
115 }
116
117 print <<EOF;
118 if DEVEL
119
120 config LINUX_2_6_ARM
121 bool "UNSUPPORTED little-endian arm platform"
122 depends BROKEN
123 select LINUX_2_6
124 select arm
125
126 config LINUX_2_6_CRIS
127 bool "UNSUPPORTED cris platform"
128 depends BROKEN
129 select LINUX_2_6
130 select cris
131
132 config LINUX_2_6_M68K
133 bool "UNSUPPORTED m68k platform"
134 depends BROKEN
135 select LINUX_2_6
136 select m68k
137
138 config LINUX_2_6_SH3
139 bool "UNSUPPORTED little-endian sh3 platform"
140 depends BROKEN
141 select LINUX_2_6
142 select sh3
143
144 config LINUX_2_6_SH3EB
145 bool "UNSUPPORTED big-endian sh3 platform"
146 depends BROKEN
147 select LINUX_2_6
148 select sh3eb
149
150 config LINUX_2_6_SH4
151 bool "UNSUPPORTED little-endian sh4 platform"
152 depends BROKEN
153 select LINUX_2_6
154 select sh4
155
156 config LINUX_2_6_SH4EB
157 bool "UNSUPPORTED big-endian sh4 platform"
158 depends BROKEN
159 select LINUX_2_6
160 select sh4eb
161
162 config LINUX_2_6_SPARC
163 bool "UNSUPPORTED sparc platform"
164 depends BROKEN
165 select LINUX_2_6
166 select sparc
167
168 endif
169
170 endchoice
171
172 choice
173 prompt "Target Profile"
174
175 EOF
176
177 foreach $target (@target) {
178 my $profiles;
179
180 $profiles = $target->{profiles} or $profiles = [
181 {
182 id => 'Default',
183 name => 'Default',
184 pkgs => []
185 }
186 ];
187 foreach my $profile (@$profiles) {
188 print <<EOF;
189 config LINUX_$target->{conf}_$profile->{id}
190 bool "$profile->{name}"
191 depends LINUX_$target->{conf}
192 EOF
193 foreach my $pkg (@{$target->{defaultpkgs}}, @{$profile->{pkgs}}) {
194 print "\tselect DEFAULT_$pkg\n";
195 }
196 print "\n";
197 }
198 }
199
200 print "endchoice\n";
This page took 0.052559 seconds and 5 git commands to generate.