6 sub parse_target_metadata() {
7 my ($target, @target, $profile);
10 /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
11 my $conf = uc $3.'_'.$2;
20 push @target, $target;
22 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
23 /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
24 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
25 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
26 /^Target-Description:/ and do {
32 $target->{desc} = $desc;
34 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
35 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
36 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
37 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
38 /^Target-Profile:\s*(.+)\s*$/ and do {
44 push @{$target->{profiles}}, $profile;
46 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
47 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
52 sub parse_package_metadata() {
58 /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
63 /^Package: \s*(.+)\s*$/ and do {
66 $pkg->{makefile} = $makefile;
68 $pkg->{default} = "m if ALL";
71 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
72 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
73 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
74 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
75 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
76 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
77 /^Provides: \s*(.+)\s*$/ and do {
78 my @vpkg = split /\s+/, $1;
79 foreach my $vpkg (@vpkg) {
80 $package{$vpkg} or $package{$vpkg} = { vdepends => [] };
81 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
84 /^Depends: \s*(.+)\s*$/ and do {
85 my @dep = split /\s+/, $1;
86 $pkg->{depends} = \@dep;
88 /^Category: \s*(.+)\s*$/ and do {
89 $pkg->{category} = $1;
90 defined $category{$1} or $category{$1} = {};
91 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
92 push @{$category{$1}->{$src}}, $pkg;
94 /^Description: \s*(.*)\s*$/ and do {
95 my $desc = "\t\t$1\n\n";
98 last if $line =~ /^@@/;
101 $pkg->{description} = $desc;
103 /^Config: \s*(.*)\s*$/ and do {
107 last if $line =~ /^@@/;
110 $pkg->{config} = $conf;
117 sub gen_target_mk() {
118 my @target = parse_target_metadata();
121 $a->{id} cmp $b->{id}
124 foreach my $target (@target) {
125 my ($profiles_def, $profiles_eval);
126 my $conf = uc $target->{kernel}.'_'.$target->{board};
129 foreach my $profile (@{$target->{profiles}}) {
131 define Profile/$conf\_$profile->{id}
133 NAME:=$profile->{name}
134 PACKAGES:=".join(" ", @{$profile->{packages}})."
137 \$(eval \$(call Profile,$conf\_$profile->{id}))"
140 ifeq (\$(CONFIG_LINUX_$conf),y)
142 KERNEL:=$target->{kernel}
143 BOARD:=$target->{board}
144 BOARDNAME:=$target->{name}
145 LINUX_VERSION:=$target->{version}
146 LINUX_RELEASE:=$target->{release}
147 LINUX_KARCH:=$target->{karch}
148 DEFAULT_PACKAGES:=".join(" ", @{$target->{packages}})."
154 print "\$(eval \$(call Target))\n";
157 sub target_config_features(@) {
160 while ($_ = shift @_) {
161 /broken/ and $ret .= "\tdepends BROKEN\n";
162 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
163 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
164 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
165 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
166 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
167 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
168 /ext2/ and $ret .= "\tselect USES_EXT2\n";
174 sub gen_target_config() {
175 my @target = parse_target_metadata();
178 $a->{name} cmp $b->{name}
184 prompt "Target System"
185 default LINUX_2_4_BRCM
189 foreach my $target (@target) {
190 my $features = target_config_features(@{$target->{features}});
191 my $help = $target->{desc};
192 my $kernel = $target->{kernel};
197 if ($help =~ /\w+/) {
198 $help =~ s/^\s*/\t /mg;
199 $help = "\thelp\n$help";
205 config LINUX_$target->{conf}
206 bool "$target->{name}"
207 select $target->{arch}
218 bool "UNSUPPORTED little-endian arm platform"
223 config LINUX_2_6_CRIS
224 bool "UNSUPPORTED cris platform"
229 config LINUX_2_6_M68K
230 bool "UNSUPPORTED m68k platform"
236 bool "UNSUPPORTED little-endian sh3 platform"
241 config LINUX_2_6_SH3EB
242 bool "UNSUPPORTED big-endian sh3 platform"
248 bool "UNSUPPORTED little-endian sh4 platform"
253 config LINUX_2_6_SH4EB
254 bool "UNSUPPORTED big-endian sh4 platform"
259 config LINUX_2_6_SPARC
260 bool "UNSUPPORTED sparc platform"
270 prompt "Target Profile"
274 foreach my $target (@target) {
275 my $profiles = $target->{profiles};
277 @$profiles > 0 or $profiles = [
284 foreach my $profile (@$profiles) {
286 config LINUX_$target->{conf}_$profile->{id}
287 bool "$profile->{name}"
288 depends LINUX_$target->{conf}
290 foreach my $pkg (@{$target->{packages}}, @{$profile->{packages}}) {
291 print "\tselect DEFAULT_$pkg\n";
300 sub find_package_dep($$) {
303 my $deps = ($pkg->{vdepends} or $pkg->{depends});
305 return 0 unless defined $deps;
306 foreach my $dep (@{$deps}) {
307 return 1 if $dep eq $name;
308 return 1 if ($package{$dep} and (find_package_dep($package{$dep},$name) == 1));
313 sub package_depends($$) {
318 return 0 if ($a->{submenu} ne $b->{submenu});
319 if (find_package_dep($a, $b->{name}) == 1) {
321 } elsif (find_package_dep($b, $a->{name}) == 1) {
329 sub print_package_config_category($) {
334 return unless $category{$cat};
336 print "menu \"$cat\"\n\n";
337 my %spkg = %{$category{$cat}};
339 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
340 foreach my $pkg (@{$spkg{$spkg}}) {
341 my $menu = $pkg->{submenu};
343 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
347 $menus{$menu} or $menus{$menu} = [];
348 push @{$menus{$menu}}, $pkg;
349 print "\tconfig DEFAULT_".$pkg->{name}."\n";
350 print "\t\tbool\n\n";
354 ($a eq 'undef' ? 1 : 0) or
355 ($b eq 'undef' ? -1 : 0) or
359 foreach my $menu (@menus) {
361 package_depends($a, $b) or
362 ($a->{name} cmp $b->{name})
364 if ($menu ne 'undef') {
365 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
366 print "menu \"$menu\"\n";
368 foreach my $pkg (@pkgs) {
369 my $title = $pkg->{name};
370 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
372 $title .= ("." x $c). " ". $pkg->{title};
375 $pkg->{menu} and print "menu";
376 print "config PACKAGE_".$pkg->{name}."\n";
377 print "\t\ttristate \"$title\"\n";
378 print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
379 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
380 print "\t\tdefault $default\n";
382 foreach my $depend (@{$pkg->{depends}}) {
384 $depend =~ s/^([@\+]+)//;
388 if ($vdep = $package{$depend}->{vdepends}) {
389 $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
391 $flags =~ /@/ or $depend = "PACKAGE_$depend";
392 $flags =~ /\+/ and $m = "select";
394 print "\t\t$m $depend\n";
397 print $pkg->{description};
400 $pkg->{config} and print $pkg->{config}."\n";
402 if ($menu ne 'undef') {
404 $menu_dep{$menu} and print "endif\n";
409 undef $category{$cat};
412 sub gen_package_config() {
413 parse_package_metadata();
414 print_package_config_category 'Base system';
415 foreach my $cat (keys %category) {
416 print_package_config_category $cat;
420 sub parse_command() {
421 my $cmd = shift @ARGV;
423 /^target_mk$/ and return gen_target_mk();
424 /^target_config$/ and return gen_target_config();
425 /^package_config$/ and return gen_package_config();
429 $0 target_mk [file] Target metadata in makefile format
430 $0 target_config [file] Target metadata in Kconfig format
431 $0 package_config [file] Package metadata in Kconfig format