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) ];
48 /^Target-Profile-Description:/ and do {
54 $profile->{desc
} = $desc;
57 foreach my $target (@target) {
58 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
69 sub parse_package_metadata
() {
75 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
80 /^Package: \s*(.+)\s*$/ and do {
83 $pkg->{makefile
} = $makefile;
85 $pkg->{default} = "m if ALL";
88 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
89 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
90 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
91 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
92 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
93 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
94 /^Provides: \s*(.+)\s*$/ and do {
95 my @vpkg = split /\s+/, $1;
96 foreach my $vpkg (@vpkg) {
97 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
98 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
101 /^Depends: \s*(.+)\s*$/ and do {
102 my @dep = split /\s+/, $1;
103 $pkg->{depends
} = \
@dep;
105 /^Category: \s*(.+)\s*$/ and do {
106 $pkg->{category
} = $1;
107 defined $category{$1} or $category{$1} = {};
108 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
109 push @
{$category{$1}->{$src}}, $pkg;
111 /^Description: \s*(.*)\s*$/ and do {
112 my $desc = "\t\t$1\n\n";
115 last if $line =~ /^@@/;
116 $desc .= "\t\t$line";
118 $pkg->{description
} = $desc;
120 /^Config: \s*(.*)\s*$/ and do {
124 last if $line =~ /^@@/;
127 $pkg->{config
} = $conf;
134 sub gen_target_mk
() {
135 my @target = parse_target_metadata
();
138 $a->{id
} cmp $b->{id
}
141 foreach my $target (@target) {
142 my ($profiles_def, $profiles_eval);
143 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
146 foreach my $profile (@
{$target->{profiles
}}) {
148 define Profile/$conf\_$profile->{id}
150 NAME:=$profile->{name}
151 PACKAGES:=".join(" ", @
{$profile->{packages
}})."
154 \$(eval \$(call Profile,$conf\_$profile->{id}))"
157 ifeq (\$(CONFIG_LINUX_$conf),y)
159 KERNEL:=$target->{kernel}
160 BOARD:=$target->{board}
161 BOARDNAME:=$target->{name}
162 LINUX_VERSION:=$target->{version}
163 LINUX_RELEASE:=$target->{release}
164 LINUX_KARCH:=$target->{karch}
165 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
171 print "\$(eval \$(call Target))\n";
174 sub target_config_features
(@
) {
177 while ($_ = shift @_) {
178 /broken/ and $ret .= "\tdepends BROKEN\n";
179 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
180 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
181 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
182 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
183 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
184 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
185 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
186 /ext2/ and $ret .= "\tselect USES_EXT2\n";
192 sub gen_target_config
() {
193 my @target = parse_target_metadata
();
196 $a->{name
} cmp $b->{name
}
202 prompt "Target System"
203 default LINUX_2_4_BRCM
207 foreach my $target (@target) {
208 my $features = target_config_features
(@
{$target->{features
}});
209 my $help = $target->{desc
};
210 my $kernel = $target->{kernel
};
215 if ($help =~ /\w+/) {
216 $help =~ s/^\s*/\t /mg;
217 $help = "\thelp\n$help";
223 config LINUX_$target->{conf}
224 bool "$target->{name}"
225 select $target->{arch}
236 bool "UNSUPPORTED little-endian arm platform"
241 config LINUX_2_6_CRIS
242 bool "UNSUPPORTED cris platform"
247 config LINUX_2_6_M68K
248 bool "UNSUPPORTED m68k platform"
254 bool "UNSUPPORTED little-endian sh3 platform"
259 config LINUX_2_6_SH3EB
260 bool "UNSUPPORTED big-endian sh3 platform"
266 bool "UNSUPPORTED little-endian sh4 platform"
271 config LINUX_2_6_SH4EB
272 bool "UNSUPPORTED big-endian sh4 platform"
277 config LINUX_2_6_SPARC
278 bool "UNSUPPORTED sparc platform"
288 prompt "Target Profile"
292 foreach my $target (@target) {
293 my $profiles = $target->{profiles
};
295 foreach my $profile (@
$profiles) {
297 config LINUX_$target->{conf}_$profile->{id}
298 bool "$profile->{name}"
299 depends LINUX_$target->{conf}
302 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
305 foreach my $pkg (keys %pkgs) {
306 print "\tselect DEFAULT_$pkg\n" unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
315 sub find_package_dep
($$) {
318 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
320 return 0 unless defined $deps;
321 foreach my $dep (@
{$deps}) {
322 return 1 if $dep eq $name;
323 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
328 sub package_depends
($$) {
333 return 0 if ($a->{submenu
} ne $b->{submenu
});
334 if (find_package_dep
($a, $b->{name
}) == 1) {
336 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
344 sub print_package_config_category
($) {
349 return unless $category{$cat};
351 print "menu \"$cat\"\n\n";
352 my %spkg = %{$category{$cat}};
354 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
355 foreach my $pkg (@
{$spkg{$spkg}}) {
356 my $menu = $pkg->{submenu
};
358 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
362 $menus{$menu} or $menus{$menu} = [];
363 push @
{$menus{$menu}}, $pkg;
364 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
365 print "\t\tbool\n\n";
369 ($a eq 'undef' ?
1 : 0) or
370 ($b eq 'undef' ?
-1 : 0) or
374 foreach my $menu (@menus) {
376 package_depends
($a, $b) or
377 ($a->{name
} cmp $b->{name
})
379 if ($menu ne 'undef') {
380 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
381 print "menu \"$menu\"\n";
383 foreach my $pkg (@pkgs) {
384 my $title = $pkg->{name
};
385 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
387 $title .= ("." x
$c). " ". $pkg->{title
};
390 $pkg->{menu
} and print "menu";
391 print "config PACKAGE_".$pkg->{name
}."\n";
392 print "\t\ttristate \"$title\"\n";
393 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
394 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
395 print "\t\tdefault $default\n";
397 foreach my $depend (@
{$pkg->{depends
}}) {
399 $depend =~ s/^([@\+]+)//;
403 if ($vdep = $package{$depend}->{vdepends
}) {
404 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
406 $flags =~ /@/ or $depend = "PACKAGE_$depend";
407 $flags =~ /\+/ and $m = "select";
409 print "\t\t$m $depend\n";
412 print $pkg->{description
};
415 $pkg->{config
} and print $pkg->{config
}."\n";
417 if ($menu ne 'undef') {
419 $menu_dep{$menu} and print "endif\n";
424 undef $category{$cat};
427 sub gen_package_config
() {
428 parse_package_metadata
();
429 print_package_config_category
'Base system';
430 foreach my $cat (keys %category) {
431 print_package_config_category
$cat;
435 sub parse_command
() {
436 my $cmd = shift @ARGV;
438 /^target_mk$/ and return gen_target_mk
();
439 /^target_config$/ and return gen_target_config
();
440 /^package_config$/ and return gen_package_config
();
444 $0 target_mk [file] Target metadata in makefile format
445 $0 target_config [file] Target metadata in Kconfig format
446 $0 package_config [file] Package metadata in Kconfig format