16 $str .= (($_ and $prefix) ?
$prefix . $_ : $_);
24 $conf =~ tr
#/\.\-/#___#;
28 sub parse_target_metadata
() {
29 my ($target, @target, $profile);
32 /^Target:\s*(.+)\s*$/ and do {
38 push @target, $target;
40 /^Target-Board:\s*(.+)\s*$/ and do {
41 $target->{board
} = $1;
42 $target->{boardconf
} = confstr
($1);
44 /^Target-Kernel:\s*(\d+\.\d+)\s*$/ and $target->{kernel
} = $1;
45 /^Target-Name:\s*(.+)\s*$/ and $target->{name
} = $1;
46 /^Target-Path:\s*(.+)\s*$/ and $target->{path
} = $1;
47 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch
} = $1;
48 /^Target-Features:\s*(.+)\s*$/ and $target->{features
} = [ split(/\s+/, $1) ];
49 /^Target-Description:/ and $target->{desc
} = get_multiline
();
50 /^Linux-Version:\s*(.+)\s*$/ and $target->{version
} = $1;
51 /^Linux-Release:\s*(.+)\s*$/ and $target->{release
} = $1;
52 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch
} = $1;
53 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages
} = [ split(/\s+/, $1) ];
54 /^Target-Profile:\s*(.+)\s*$/ and do {
60 push @
{$target->{profiles
}}, $profile;
62 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name
} = $1;
63 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages
} = [ split(/\s+/, $1) ];
64 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc
} = get_multiline
();
65 /^Target-Profile-Config:/ and $profile->{config
} = get_multiline
("\t");
66 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
68 foreach my $target (@target) {
69 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
80 sub parse_package_metadata
() {
88 /^Source-Makefile: \s*((.+\/)([^\
/]+)\/Makefile
)\s
*$/ and do {
92 $subdir =~ s/^package\///;
93 $subdir{$src} = $subdir;
94 $srcpackage{$src} = [];
97 /^Package:\s*(.+?)\s*$/ and do {
100 $pkg->{makefile
} = $makefile;
102 $pkg->{default} = "m if ALL";
103 $pkg->{depends
} = [];
104 $pkg->{builddepends
} = [];
105 $pkg->{subdir
} = $subdir;
107 push @
{$srcpackage{$src}}, $pkg;
109 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
110 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
111 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
112 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
113 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
114 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
115 /^Provides: \s*(.+)\s*$/ and do {
116 my @vpkg = split /\s+/, $1;
117 foreach my $vpkg (@vpkg) {
118 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
119 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
122 /^Depends: \s*(.+)\s*$/ and $pkg->{depends
} = [ split /\s+/, $1 ];
123 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends
} = [ split /\s+/, $1 ];
124 /^Category: \s*(.+)\s*$/ and do {
125 $pkg->{category
} = $1;
126 defined $category{$1} or $category{$1} = {};
127 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
128 push @
{$category{$1}->{$src}}, $pkg;
130 /^Description: \s*(.*)\s*$/ and $pkg->{description
} = "\t\t $1\n". get_multiline
("\t\t ");
131 /^Config: \s*(.*)\s*$/ and $pkg->{config
} = "$1\n".get_multiline
();
132 /^Prereq-Check:/ and $pkg->{prereq
} = 1;
133 /^Preconfig:\s*(.+)\s*$/ and do {
134 my $pkgname = $pkg->{name
};
135 $preconfig{$pkgname} or $preconfig{$pkgname} = {};
136 if (exists $preconfig{$pkgname}->{$1}) {
137 $preconfig = $preconfig{$pkgname}->{$1};
142 $preconfig{$pkgname}->{$1} = $preconfig;
145 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type
} = $1;
146 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label
} = $1;
147 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
152 sub gen_kconfig_overrides
() {
156 my $pkginfo = shift @ARGV;
157 my $cfgfile = shift @ARGV;
159 # parameter 2: build system config
160 open FILE
, "<$cfgfile" or return;
162 /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
166 # parameter 1: package metadata
167 open FILE
, "<$pkginfo" or return;
169 /^Package:\s*(.+?)\s*$/ and $package = $1;
170 /^Kernel-Config:\s*(.+?)\s*$/ and do {
171 my @config = split /\s+/, $1;
172 foreach my $config (@config) {
175 if ($config =~ /^(.+?)=(.+)$/) {
180 if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
181 $kconfig{$config} = $val;
182 } elsif (!$override) {
183 $kconfig{$config} or $kconfig{$config} = 'n';
190 foreach my $kconfig (sort keys %kconfig) {
191 if ($kconfig{$kconfig} eq 'n') {
192 print "# $kconfig is not set\n";
194 print "$kconfig=$kconfig{$kconfig}\n";
199 sub merge_package_lists
($$) {
205 foreach my $pkg (@
$list1, @
$list2) {
208 foreach my $pkg (keys %pkgs) {
209 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
214 sub target_config_features
(@
) {
217 while ($_ = shift @_) {
218 /broken/ and $ret .= "\tdepends BROKEN\n";
219 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
220 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
221 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
222 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
223 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
224 /ext2/ and $ret .= "\tselect USES_EXT2\n";
225 /tgz/ and $ret .= "\tselect USES_TGZ\n";
231 sub gen_target_config
() {
232 my @target = parse_target_metadata
();
235 $a->{name
} cmp $b->{name
}
241 prompt "Target System"
242 default TARGET_brcm_2_4
247 foreach my $target (@target) {
248 my $features = target_config_features
(@
{$target->{features
}});
249 my $help = $target->{desc
};
250 my $kernel = $target->{kernel
};
255 if ($help =~ /\w+/) {
256 $help =~ s/^\s*/\t /mg;
257 $help = "\thelp\n$help";
263 config TARGET_$target->{conf}
264 bool "$target->{name}"
265 select $target->{arch}
268 if ($target->{id
} ne $target->{board
}) {
269 print "\tselect TARGET_".$target->{boardconf
}."\n";
271 print "$features$help\n\n"
280 foreach my $target (@target) {
281 print "\t\tdefault \"".$target->{board
}."\" if TARGET_".$target->{conf
}."\n";
284 # add hidden target config options
285 foreach my $target (@target) {
286 next if $board{$target->{board
}};
287 if ($target->{id
} ne $target->{board
}) {
288 print "\nconfig TARGET_".$target->{boardconf
}."\n\tbool\n";
289 $board{$target->{board
}} = 1;
295 prompt "Target Profile"
299 foreach my $target (@target) {
300 my $profiles = $target->{profiles
};
302 foreach my $profile (@
$profiles) {
304 config TARGET_$target->{conf}_$profile->{id}
305 bool "$profile->{name}"
306 depends TARGET_$target->{conf}
309 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
310 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
311 foreach my $pkg (@pkglist) {
312 print "\tselect DEFAULT_$pkg\n";
322 sub find_package_dep
($$) {
325 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
327 return 0 unless defined $deps;
328 foreach my $dep (@
{$deps}) {
329 return 1 if $dep eq $name;
330 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
335 sub package_depends
($$) {
340 return 0 if ($a->{submenu
} ne $b->{submenu
});
341 if (find_package_dep
($a, $b->{name
}) == 1) {
343 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
351 sub mconf_depends
($$) {
353 my $only_dep = shift;
357 my @depends = @
$depends;
358 foreach my $depend (@depends) {
360 $depend =~ s/^([@\+]+)//;
364 if ($vdep = $package{$depend}->{vdepends
}) {
365 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
367 $flags =~ /\+/ and do {
371 # Menuconfig will not treat 'select FOO' as a real dependency
372 # thus if FOO depends on other config options, these dependencies
373 # will not be checked. To fix this, we simply emit all of FOO's
374 # depends here as well.
375 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
377 $flags =~ /@/ or $depend = "PACKAGE_$depend";
379 $res .= "\t\t$m $depend\n";
384 sub print_package_config_category
($) {
389 return unless $category{$cat};
391 print "menu \"$cat\"\n\n";
392 my %spkg = %{$category{$cat}};
394 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
395 foreach my $pkg (@
{$spkg{$spkg}}) {
396 my $menu = $pkg->{submenu
};
398 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
402 $menus{$menu} or $menus{$menu} = [];
403 push @
{$menus{$menu}}, $pkg;
404 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
405 print "\t\tbool\n\n";
409 ($a eq 'undef' ?
1 : 0) or
410 ($b eq 'undef' ?
-1 : 0) or
414 foreach my $menu (@menus) {
416 package_depends
($a, $b) or
417 ($a->{name
} cmp $b->{name
})
419 if ($menu ne 'undef') {
420 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
421 print "menu \"$menu\"\n";
423 foreach my $pkg (@pkgs) {
424 my $title = $pkg->{name
};
425 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
427 $title .= ("." x
$c). " ". $pkg->{title
};
430 $pkg->{menu
} and print "menu";
431 print "config PACKAGE_".$pkg->{name
}."\n";
432 print "\t\ttristate \"$title\"\n";
433 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
434 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
435 print "\t\tdefault $default\n";
437 print mconf_depends
($pkg->{depends
}, 0);
439 print $pkg->{description
};
442 $pkg->{config
} and print $pkg->{config
}."\n";
444 if ($menu ne 'undef') {
446 $menu_dep{$menu} and print "endif\n";
451 undef $category{$cat};
454 sub gen_package_config
() {
455 parse_package_metadata
();
456 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
457 foreach my $preconfig (keys %preconfig) {
458 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
459 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
462 config UCI_PRECONFIG_$conf
463 string "$preconfig{$preconfig}->{$cfg}->{label}" if UCI_PRECONFIG
464 depends PACKAGE_$preconfig
465 default "$preconfig{$preconfig}->{$cfg}->{default}"
470 print_package_config_category
'Base system';
471 foreach my $cat (keys %category) {
472 print_package_config_category
$cat;
476 sub gen_package_mk
() {
481 parse_package_metadata
();
482 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
484 my $pkg = $package{$name};
486 next if defined $pkg->{vdepends
};
488 $conf{$pkg->{src
}} or do {
490 $conf{$pkg->{src
}} = 1;
493 $config = "\$(CONFIG_PACKAGE_$name)"
496 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
497 $pkg->{prereq
} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
502 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
506 my $pkg_dep = $package{$dep};
507 next if defined $pkg_dep->{vdepends
};
509 if (defined $pkg_dep->{src
}) {
510 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{subdir
}.$pkg_dep->{src
};
511 } elsif (defined($srcpackage{$dep})) {
512 $idx = $subdir{$dep}.$dep;
514 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
516 next if $dep{$pkg->{src
}."->".$idx};
517 $depline .= " \$(curdir)/$idx/compile";
518 $dep{$pkg->{src
}."->".$idx} = 1;
522 $line .= "\$(curdir)/".$pkg->{subdir
}."$pkg->{src}/compile += $depline\n";
529 foreach my $preconfig (keys %preconfig) {
531 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
532 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
534 $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
539 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
544 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
545 package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
552 sub parse_command
() {
553 my $cmd = shift @ARGV;
555 /^target_config$/ and return gen_target_config
();
556 /^package_mk$/ and return gen_package_mk
();
557 /^package_config$/ and return gen_package_config
();
558 /^kconfig/ and return gen_kconfig_overrides
();
562 $0 target_config [file] Target metadata in Kconfig format
563 $0 package_mk [file] Package metadata in makefile format
564 $0 package_config [file] Package metadata in Kconfig format
565 $0 kconfig [file] [config] Kernel config overrides