15 $str .= (($_ and $prefix) ? $prefix . $_ : $_);
21 sub parse_target_metadata() {
22 my ($target, @target, $profile);
25 /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
26 my $conf = uc $3.'_'.$2;
35 push @target, $target;
37 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
38 /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
39 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
40 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
41 /^Target-Description:/ and $target->{desc} = get_multiline();
42 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
43 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
44 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
45 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
46 /^Target-Profile:\s*(.+)\s*$/ and do {
52 push @{$target->{profiles}}, $profile;
54 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
55 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
56 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline();
57 /^Target-Profile-Config:/ and $profile->{config} = get_multiline("\t");
58 /^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1;
60 foreach my $target (@target) {
61 @{$target->{profiles}} > 0 or $target->{profiles} = [
72 sub parse_package_metadata() {
80 /^Source-Makefile: \s*((.+\/)([^\/]+)\/Makefile)\s*$/ and do {
84 $subdir =~ s/^package\///;
85 $subdir{$src} = $subdir;
86 $srcpackage{$src} = [];
89 /^Package:\s*(.+?)\s*$/ and do {
92 $pkg->{makefile} = $makefile;
94 $pkg->{default} = "m if ALL";
96 $pkg->{builddepends} = [];
97 $pkg->{subdir} = $subdir;
99 push @{$srcpackage{$src}}, $pkg;
101 /^Version: \s*(.+)\s*$/ and $pkg->{version} = $1;
102 /^Title: \s*(.+)\s*$/ and $pkg->{title} = $1;
103 /^Menu: \s*(.+)\s*$/ and $pkg->{menu} = $1;
104 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu} = $1;
105 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep} = $1;
106 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
107 /^Provides: \s*(.+)\s*$/ and do {
108 my @vpkg = split /\s+/, $1;
109 foreach my $vpkg (@vpkg) {
110 $package{$vpkg} or $package{$vpkg} = { vdepends => [] };
111 push @{$package{$vpkg}->{vdepends}}, $pkg->{name};
114 /^Depends: \s*(.+)\s*$/ and $pkg->{depends} = [ split /\s+/, $1 ];
115 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends} = [ split /\s+/, $1 ];
116 /^Category: \s*(.+)\s*$/ and do {
117 $pkg->{category} = $1;
118 defined $category{$1} or $category{$1} = {};
119 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
120 push @{$category{$1}->{$src}}, $pkg;
122 /^Description: \s*(.*)\s*$/ and $pkg->{description} = "\t\t $1\n". get_multiline("\t\t ");
123 /^Config: \s*(.*)\s*$/ and $pkg->{config} = "$1\n".get_multiline();
124 /^Prereq-Check:/ and $pkg->{prereq} = 1;
125 /^Preconfig:\s*(.+)\s*$/ and do {
126 my $pkgname = $pkg->{name};
127 $preconfig{$pkgname} or $preconfig{$pkgname} = [];
131 push @{$preconfig{$pkgname}}, $preconfig;
133 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type} = $1;
134 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label} = $1;
135 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
140 sub merge_package_lists($$) {
146 foreach my $pkg (@$list1, @$list2) {
149 foreach my $pkg (keys %pkgs) {
150 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
155 sub gen_target_mk() {
156 my @target = parse_target_metadata();
159 $a->{id} cmp $b->{id}
162 foreach my $target (@target) {
163 my ($profiles_def, $profiles_eval);
164 my $conf = uc $target->{kernel}.'_'.$target->{board};
167 foreach my $profile (@{$target->{profiles}}) {
169 define Profile/$conf\_$profile->{id}
171 NAME:=$profile->{name}
172 PACKAGES:=".join(" ", merge_package_lists($target->{packages}, $profile->{packages}))."\n";
173 $profile->{kconfig} and $profiles_def .= " KCONFIG:=1\n";
174 $profiles_def .= " endef";
176 \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
179 ifeq (\$(CONFIG_LINUX_$conf),y)
181 KERNEL:=$target->{kernel}
182 BOARD:=$target->{board}
183 BOARDNAME:=$target->{name}
184 LINUX_VERSION:=$target->{version}
185 LINUX_RELEASE:=$target->{release}
186 LINUX_KARCH:=$target->{karch}
187 DEFAULT_PACKAGES:=".join(" ", @{$target->{packages}})."
193 print "\$(eval \$(call Target))\n";
196 sub target_config_features(@) {
199 while ($_ = shift @_) {
200 /broken/ and $ret .= "\tdepends BROKEN\n";
201 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
202 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
203 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
204 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
205 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
206 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
207 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
208 /ext2/ and $ret .= "\tselect USES_EXT2\n";
214 sub gen_target_config() {
215 my @target = parse_target_metadata();
218 $a->{name} cmp $b->{name}
224 prompt "Target System"
225 default LINUX_2_4_BRCM
230 foreach my $target (@target) {
231 my $features = target_config_features(@{$target->{features}});
232 my $help = $target->{desc};
233 my $kernel = $target->{kernel};
238 if ($help =~ /\w+/) {
239 $help =~ s/^\s*/\t /mg;
240 $help = "\thelp\n$help";
246 config LINUX_$target->{conf}
247 bool "$target->{name}"
248 select $target->{arch}
259 bool "UNSUPPORTED little-endian arm platform"
264 config LINUX_2_6_CRIS
265 bool "UNSUPPORTED cris platform"
270 config LINUX_2_6_M68K
271 bool "UNSUPPORTED m68k platform"
277 bool "UNSUPPORTED little-endian sh3 platform"
282 config LINUX_2_6_SH3EB
283 bool "UNSUPPORTED big-endian sh3 platform"
289 bool "UNSUPPORTED little-endian sh4 platform"
294 config LINUX_2_6_SH4EB
295 bool "UNSUPPORTED big-endian sh4 platform"
300 config LINUX_2_6_SPARC
301 bool "UNSUPPORTED sparc platform"
311 prompt "Target Profile"
315 foreach my $target (@target) {
316 my $profiles = $target->{profiles};
318 foreach my $profile (@$profiles) {
320 config LINUX_$target->{conf}_$profile->{id}
321 bool "$profile->{name}"
322 depends LINUX_$target->{conf}
325 $profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n";
326 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
327 foreach my $pkg (@pkglist) {
328 print "\tselect DEFAULT_$pkg\n";
338 sub find_package_dep($$) {
341 my $deps = ($pkg->{vdepends} or $pkg->{depends});
343 return 0 unless defined $deps;
344 foreach my $dep (@{$deps}) {
345 return 1 if $dep eq $name;
346 return 1 if ($package{$dep} and (find_package_dep($package{$dep},$name) == 1));
351 sub package_depends($$) {
356 return 0 if ($a->{submenu} ne $b->{submenu});
357 if (find_package_dep($a, $b->{name}) == 1) {
359 } elsif (find_package_dep($b, $a->{name}) == 1) {
367 sub mconf_depends($$) {
369 my $only_dep = shift;
373 my @depends = @$depends;
374 foreach my $depend (@depends) {
376 $depend =~ s/^([@\+]+)//;
380 if ($vdep = $package{$depend}->{vdepends}) {
381 $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
383 $flags =~ /\+/ and do {
387 # Menuconfig will not treat 'select FOO' as a real dependency
388 # thus if FOO depends on other config options, these dependencies
389 # will not be checked. To fix this, we simply emit all of FOO's
390 # depends here as well.
391 $package{$depend} and $res .= mconf_depends($package{$depend}->{depends}, 1);
393 $flags =~ /@/ or $depend = "PACKAGE_$depend";
395 $res .= "\t\t$m $depend\n";
400 sub print_package_config_category($) {
405 return unless $category{$cat};
407 print "menu \"$cat\"\n\n";
408 my %spkg = %{$category{$cat}};
410 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
411 foreach my $pkg (@{$spkg{$spkg}}) {
412 my $menu = $pkg->{submenu};
414 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
418 $menus{$menu} or $menus{$menu} = [];
419 push @{$menus{$menu}}, $pkg;
420 print "\tconfig DEFAULT_".$pkg->{name}."\n";
421 print "\t\tbool\n\n";
425 ($a eq 'undef' ? 1 : 0) or
426 ($b eq 'undef' ? -1 : 0) or
430 foreach my $menu (@menus) {
432 package_depends($a, $b) or
433 ($a->{name} cmp $b->{name})
435 if ($menu ne 'undef') {
436 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
437 print "menu \"$menu\"\n";
439 foreach my $pkg (@pkgs) {
440 my $title = $pkg->{name};
441 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
443 $title .= ("." x $c). " ". $pkg->{title};
446 $pkg->{menu} and print "menu";
447 print "config PACKAGE_".$pkg->{name}."\n";
448 print "\t\ttristate \"$title\"\n";
449 print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
450 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
451 print "\t\tdefault $default\n";
453 print mconf_depends($pkg->{depends}, 0);
455 print $pkg->{description};
458 $pkg->{config} and print $pkg->{config}."\n";
460 if ($menu ne 'undef') {
462 $menu_dep{$menu} and print "endif\n";
467 undef $category{$cat};
470 sub gen_package_config() {
471 parse_package_metadata();
472 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
473 foreach my $preconfig (keys %preconfig) {
474 foreach my $cfg (@{$preconfig{$preconfig}}) {
475 my $conf = $cfg->{id};
478 config UCI_PRECONFIG_$conf
479 string "$cfg->{label}" if UCI_PRECONFIG
480 depends PACKAGE_$preconfig
481 default "$cfg->{default}"
486 print_package_config_category 'Base system';
487 foreach my $cat (keys %category) {
488 print_package_config_category $cat;
492 sub gen_package_mk() {
497 parse_package_metadata();
498 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
500 my $pkg = $package{$name};
502 next if defined $pkg->{vdepends};
504 $conf{$pkg->{src}} or do {
506 $conf{$pkg->{src}} = 1;
509 $config = "\$(CONFIG_PACKAGE_$name)"
512 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
513 $pkg->{prereq} and print "prereq-$config += $pkg->{src}\n";
518 foreach my $dep (@{$pkg->{depends}}, @{$pkg->{builddepends}}) {
522 my $pkg_dep = $package{$dep};
523 next if defined $pkg_dep->{vdepends};
525 if (defined $pkg_dep->{src}) {
526 ($pkg->{src} ne $pkg_dep->{src}) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
527 } elsif (defined($srcpackage{$dep})) {
528 $idx = $subdir{$dep}.$dep;
530 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
532 next if $dep{$pkg->{src}."->".$idx};
533 $depline .= " $idx\-compile";
534 $dep{$pkg->{src}."->".$idx} = 1;
538 $line .= $pkg->{subdir}."$pkg->{src}-compile: $depline\n";
545 foreach my $preconfig (keys %preconfig) {
547 foreach my $cfg (@{$preconfig{$preconfig}}) {
548 my $conf = $cfg->{id};
550 $cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
555 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
560 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
561 preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
568 sub parse_command() {
569 my $cmd = shift @ARGV;
571 /^target_mk$/ and return gen_target_mk();
572 /^target_config$/ and return gen_target_config();
573 /^package_mk$/ and return gen_package_mk();
574 /^package_config$/ and return gen_package_config();
578 $0 target_mk [file] Target metadata in makefile format
579 $0 target_config [file] Target metadata in Kconfig format
580 $0 package_mk [file] Package metadata in makefile format
581 $0 package_config [file] Package metadata in Kconfig format