14 $str .= (($_ and $prefix) ?
$prefix . $_ : $_);
20 sub parse_target_metadata
() {
21 my ($target, @target, $profile);
24 /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
25 my $conf = uc $3.'_'.$2;
34 push @target, $target;
36 /^Target-Name:\s*(.+)\s*$/ and $target->{name
} = $1;
37 /^Target-Path:\s*(.+)\s*$/ and $target->{path
} = $1;
38 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch
} = $1;
39 /^Target-Features:\s*(.+)\s*$/ and $target->{features
} = [ split(/\s+/, $1) ];
40 /^Target-Description:/ and $target->{desc
} = get_multiline
();
41 /^Linux-Version:\s*(.+)\s*$/ and $target->{version
} = $1;
42 /^Linux-Release:\s*(.+)\s*$/ and $target->{release
} = $1;
43 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch
} = $1;
44 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages
} = [ split(/\s+/, $1) ];
45 /^Target-Profile:\s*(.+)\s*$/ and do {
51 push @
{$target->{profiles
}}, $profile;
53 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name
} = $1;
54 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages
} = [ split(/\s+/, $1) ];
55 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc
} = get_multiline
();
56 /^Target-Profile-Config:/ and $profile->{config
} = get_multiline
("\t");
57 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
59 foreach my $target (@target) {
60 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
71 sub parse_package_metadata
() {
79 /^Source-Makefile: \s*((.+\/)([^\
/]+)\/Makefile
)\s
*$/ and do {
83 $subdir =~ s/^package\///;
84 $srcpackage{$src} = [];
87 /^Package:\s*(.+?)\s*$/ and do {
90 $pkg->{makefile
} = $makefile;
92 $pkg->{default} = "m if ALL";
94 $pkg->{builddepends
} = [];
95 $pkg->{subdir
} = $subdir;
97 push @
{$srcpackage{$src}}, $pkg;
99 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
100 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
101 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
102 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
103 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
104 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
105 /^Provides: \s*(.+)\s*$/ and do {
106 my @vpkg = split /\s+/, $1;
107 foreach my $vpkg (@vpkg) {
108 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
109 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
112 /^Depends: \s*(.+)\s*$/ and $pkg->{depends
} = [ split /\s+/, $1 ];
113 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends
} = [ split /\s+/, $1 ];
114 /^Category: \s*(.+)\s*$/ and do {
115 $pkg->{category
} = $1;
116 defined $category{$1} or $category{$1} = {};
117 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
118 push @
{$category{$1}->{$src}}, $pkg;
120 /^Description: \s*(.*)\s*$/ and $pkg->{description
} = "\t\t $1\n". get_multiline
("\t\t ");
121 /^Config: \s*(.*)\s*$/ and $pkg->{config
} = "$1\n".get_multiline
();
122 /^Prereq-Check:/ and $pkg->{prereq
} = 1;
123 /^Preconfig:\s*(.+)\s*$/ and do {
124 my $pkgname = $pkg->{name
};
125 $preconfig{$pkgname} or $preconfig{$pkgname} = [];
129 push @
{$preconfig{$pkgname}}, $preconfig;
131 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type
} = $1;
132 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label
} = $1;
133 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
138 sub merge_package_lists
($$) {
144 foreach my $pkg (@
$list1, @
$list2) {
147 foreach my $pkg (keys %pkgs) {
148 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
153 sub gen_target_mk
() {
154 my @target = parse_target_metadata
();
157 $a->{id
} cmp $b->{id
}
160 foreach my $target (@target) {
161 my ($profiles_def, $profiles_eval);
162 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
165 foreach my $profile (@
{$target->{profiles
}}) {
167 define Profile/$conf\_$profile->{id}
169 NAME:=$profile->{name}
170 PACKAGES:=".join(" ", merge_package_lists
($target->{packages
}, $profile->{packages
}))."\n";
171 $profile->{kconfig
} and $profiles_def .= " KCONFIG:=1\n";
172 $profiles_def .= " endef";
174 \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
177 ifeq (\$(CONFIG_LINUX_$conf),y)
179 KERNEL:=$target->{kernel}
180 BOARD:=$target->{board}
181 BOARDNAME:=$target->{name}
182 LINUX_VERSION:=$target->{version}
183 LINUX_RELEASE:=$target->{release}
184 LINUX_KARCH:=$target->{karch}
185 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
191 print "\$(eval \$(call Target))\n";
194 sub target_config_features
(@
) {
197 while ($_ = shift @_) {
198 /broken/ and $ret .= "\tdepends BROKEN\n";
199 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
200 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
201 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
202 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
203 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
204 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
205 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
206 /ext2/ and $ret .= "\tselect USES_EXT2\n";
212 sub gen_target_config
() {
213 my @target = parse_target_metadata
();
216 $a->{name
} cmp $b->{name
}
222 prompt "Target System"
223 default LINUX_2_4_BRCM
228 foreach my $target (@target) {
229 my $features = target_config_features
(@
{$target->{features
}});
230 my $help = $target->{desc
};
231 my $kernel = $target->{kernel
};
236 if ($help =~ /\w+/) {
237 $help =~ s/^\s*/\t /mg;
238 $help = "\thelp\n$help";
244 config LINUX_$target->{conf}
245 bool "$target->{name}"
246 select $target->{arch}
257 bool "UNSUPPORTED little-endian arm platform"
262 config LINUX_2_6_CRIS
263 bool "UNSUPPORTED cris platform"
268 config LINUX_2_6_M68K
269 bool "UNSUPPORTED m68k platform"
275 bool "UNSUPPORTED little-endian sh3 platform"
280 config LINUX_2_6_SH3EB
281 bool "UNSUPPORTED big-endian sh3 platform"
287 bool "UNSUPPORTED little-endian sh4 platform"
292 config LINUX_2_6_SH4EB
293 bool "UNSUPPORTED big-endian sh4 platform"
298 config LINUX_2_6_SPARC
299 bool "UNSUPPORTED sparc platform"
309 prompt "Target Profile"
313 foreach my $target (@target) {
314 my $profiles = $target->{profiles
};
316 foreach my $profile (@
$profiles) {
318 config LINUX_$target->{conf}_$profile->{id}
319 bool "$profile->{name}"
320 depends LINUX_$target->{conf}
323 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
324 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
325 foreach my $pkg (@pkglist) {
326 print "\tselect DEFAULT_$pkg\n";
336 sub find_package_dep
($$) {
339 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
341 return 0 unless defined $deps;
342 foreach my $dep (@
{$deps}) {
343 return 1 if $dep eq $name;
344 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
349 sub package_depends
($$) {
354 return 0 if ($a->{submenu
} ne $b->{submenu
});
355 if (find_package_dep
($a, $b->{name
}) == 1) {
357 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
365 sub mconf_depends
($$) {
367 my $only_dep = shift;
371 my @depends = @
$depends;
372 foreach my $depend (@depends) {
374 $depend =~ s/^([@\+]+)//;
378 if ($vdep = $package{$depend}->{vdepends
}) {
379 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
381 $flags =~ /\+/ and do {
385 # Menuconfig will not treat 'select FOO' as a real dependency
386 # thus if FOO depends on other config options, these dependencies
387 # will not be checked. To fix this, we simply emit all of FOO's
388 # depends here as well.
389 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
391 $flags =~ /@/ or $depend = "PACKAGE_$depend";
393 $res .= "\t\t$m $depend\n";
398 sub print_package_config_category
($) {
403 return unless $category{$cat};
405 print "menu \"$cat\"\n\n";
406 my %spkg = %{$category{$cat}};
408 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
409 foreach my $pkg (@
{$spkg{$spkg}}) {
410 my $menu = $pkg->{submenu
};
412 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
416 $menus{$menu} or $menus{$menu} = [];
417 push @
{$menus{$menu}}, $pkg;
418 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
419 print "\t\tbool\n\n";
423 ($a eq 'undef' ?
1 : 0) or
424 ($b eq 'undef' ?
-1 : 0) or
428 foreach my $menu (@menus) {
430 package_depends
($a, $b) or
431 ($a->{name
} cmp $b->{name
})
433 if ($menu ne 'undef') {
434 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
435 print "menu \"$menu\"\n";
437 foreach my $pkg (@pkgs) {
438 my $title = $pkg->{name
};
439 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
441 $title .= ("." x
$c). " ". $pkg->{title
};
444 $pkg->{menu
} and print "menu";
445 print "config PACKAGE_".$pkg->{name
}."\n";
446 print "\t\ttristate \"$title\"\n";
447 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
448 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
449 print "\t\tdefault $default\n";
451 print mconf_depends
($pkg->{depends
}, 0);
453 print $pkg->{description
};
456 $pkg->{config
} and print $pkg->{config
}."\n";
458 if ($menu ne 'undef') {
460 $menu_dep{$menu} and print "endif\n";
465 undef $category{$cat};
468 sub gen_package_config
() {
469 parse_package_metadata
();
470 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
471 foreach my $preconfig (keys %preconfig) {
472 foreach my $cfg (@
{$preconfig{$preconfig}}) {
473 my $conf = $cfg->{id
};
476 config UCI_PRECONFIG_$conf
477 string "$cfg->{label}" if UCI_PRECONFIG
478 depends PACKAGE_$preconfig
479 default "$cfg->{default}"
484 print_package_config_category
'Base system';
485 foreach my $cat (keys %category) {
486 print_package_config_category
$cat;
490 sub gen_package_mk
() {
495 parse_package_metadata
();
496 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
498 my $pkg = $package{$name};
500 next if defined $pkg->{vdepends
};
502 $conf{$pkg->{src
}} or do {
504 $conf{$pkg->{src
}} = 1;
507 $config = "\$(CONFIG_PACKAGE_$name)"
510 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
511 $pkg->{prereq
} and print "prereq-$config += $pkg->{src}\n";
516 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
520 my $pkg_dep = $package{$dep};
521 $pkg_dep or $pkg_dep = $srcpackage{$dep}->[0];
522 next unless defined $pkg_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($pkg_dep) && !defined($ENV{SDK
})) {
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