3 use lib
"$FindBin::Bin";
11 $conf =~ tr
#/\.\-/#___#;
15 sub parse_target_metadata
() {
16 my $file = shift @ARGV;
17 my ($target, @target, $profile);
18 open FILE
, "<$file" or do {
19 warn "Can't open file '$file': $!\n";
24 /^Target:\s*(.+)\s*$/ and do {
32 push @target, $target;
34 /^Target-Board:\s*(.+)\s*$/ and do {
35 $target->{board
} = $1;
36 $target->{boardconf
} = confstr
($1);
38 /^Target-Kernel:\s*(\d+\.\d+)\s*$/ and $target->{kernel
} = $1;
39 /^Target-Name:\s*(.+)\s*$/ and $target->{name
} = $1;
40 /^Target-Path:\s*(.+)\s*$/ and $target->{path
} = $1;
41 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch
} = $1;
42 /^Target-Features:\s*(.+)\s*$/ and $target->{features
} = [ split(/\s+/, $1) ];
43 /^Target-Depends:\s*(.+)\s*$/ and $target->{depends
} = [ split(/\s+/, $1) ];
44 /^Target-Description:/ and $target->{desc
} = get_multiline
(*FILE
);
45 /^Linux-Version:\s*(.+)\s*$/ and $target->{version
} = $1;
46 /^Linux-Release:\s*(.+)\s*$/ and $target->{release
} = $1;
47 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch
} = $1;
48 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages
} = [ split(/\s+/, $1) ];
49 /^Target-Profile:\s*(.+)\s*$/ and do {
55 push @
{$target->{profiles
}}, $profile;
57 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name
} = $1;
58 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages
} = [ split(/\s+/, $1) ];
59 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc
} = get_multiline
(*FILE
);
60 /^Target-Profile-Config:/ and $profile->{config
} = get_multiline
(*FILE
, "\t");
61 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
64 foreach my $target (@target) {
65 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
76 sub gen_kconfig_overrides
() {
80 my $pkginfo = shift @ARGV;
81 my $cfgfile = shift @ARGV;
83 # parameter 2: build system config
84 open FILE
, "<$cfgfile" or return;
86 /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
90 # parameter 1: package metadata
91 open FILE
, "<$pkginfo" or return;
93 /^Package:\s*(.+?)\s*$/ and $package = $1;
94 /^Kernel-Config:\s*(.+?)\s*$/ and do {
95 my @config = split /\s+/, $1;
96 foreach my $config (@config) {
99 if ($config =~ /^(.+?)=(.+)$/) {
104 if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
105 $kconfig{$config} = $val;
106 } elsif (!$override) {
107 $kconfig{$config} or $kconfig{$config} = 'n';
114 foreach my $kconfig (sort keys %kconfig) {
115 if ($kconfig{$kconfig} eq 'n') {
116 print "# $kconfig is not set\n";
118 print "$kconfig=$kconfig{$kconfig}\n";
123 sub merge_package_lists
($$) {
129 foreach my $pkg (@
$list1, @
$list2) {
132 foreach my $pkg (keys %pkgs) {
133 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
138 sub target_config_features
(@
) {
141 while ($_ = shift @_) {
142 /broken/ and $ret .= "\tdepends BROKEN\n";
143 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
144 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
145 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
146 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
147 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
148 /ext2/ and $ret .= "\tselect USES_EXT2\n";
149 /tgz/ and $ret .= "\tselect USES_TGZ\n";
155 sub gen_target_config
() {
156 my @target = parse_target_metadata
();
159 $a->{name
} cmp $b->{name
}
165 prompt "Target System"
166 default TARGET_brcm_2_4
171 foreach my $target (@target) {
172 my $features = target_config_features
(@
{$target->{features
}});
173 my $help = $target->{desc
};
174 my $kernel = $target->{kernel
};
179 if ($help =~ /\w+/) {
180 $help =~ s/^\s*/\t /mg;
181 $help = "\thelp\n$help";
187 config TARGET_$target->{conf}
188 bool "$target->{name}"
189 select $target->{arch}
192 if ($target->{id
} ne $target->{board
}) {
193 print "\tselect TARGET_".$target->{boardconf
}."\n";
195 foreach my $dep (@
{$target->{depends
}}) {
196 my $mode = "depends";
200 $dep =~ /^([@\+\-]+)(.+)$/;
204 $flags =~ /-/ and $mode = "deselect";
205 $flags =~ /\+/ and $mode = "select";
206 $flags =~ /@/ and print "\t$mode $name\n";
209 print "$features$help\n\n"
218 foreach my $target (@target) {
219 print "\t\tdefault \"".$target->{board
}."\" if TARGET_".$target->{conf
}."\n";
222 # add hidden target config options
223 foreach my $target (@target) {
224 next if $board{$target->{board
}};
225 if ($target->{id
} ne $target->{board
}) {
226 print "\nconfig TARGET_".$target->{boardconf
}."\n\tbool\n";
227 $board{$target->{board
}} = 1;
233 prompt "Target Profile"
237 foreach my $target (@target) {
238 my $profiles = $target->{profiles
};
240 foreach my $profile (@
$profiles) {
242 config TARGET_$target->{conf}_$profile->{id}
243 bool "$profile->{name}"
244 depends TARGET_$target->{conf}
247 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
248 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
249 foreach my $pkg (@pkglist) {
250 print "\tselect DEFAULT_$pkg\n";
260 sub __find_package_dep
($$) {
263 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
265 return 0 unless defined $deps;
266 foreach my $dep (@
{$deps}) {
267 next if $dep_check{$dep};
268 $dep_check{$dep} = 1;
269 return 1 if $dep eq $name;
270 return 1 if ($package{$dep} and (__find_package_dep
($package{$dep},$name) == 1));
275 # wrapper to avoid infinite recursion
276 sub find_package_dep
($$) {
281 return __find_package_dep
($pkg, $name);
284 sub package_depends
($$) {
289 return 0 if ($a->{submenu
} ne $b->{submenu
});
290 if (find_package_dep
($a, $b->{name
}) == 1) {
292 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
300 sub mconf_depends
($$) {
302 my $only_dep = shift;
308 my @depends = @
$depends;
309 foreach my $depend (@depends) {
311 $depend =~ s/^([@\+]+)//;
315 if ($vdep = $package{$depend}->{vdepends
}) {
316 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
318 $flags =~ /\+/ and do {
322 # Menuconfig will not treat 'select FOO' as a real dependency
323 # thus if FOO depends on other config options, these dependencies
324 # will not be checked. To fix this, we simply emit all of FOO's
325 # depends here as well.
326 $package{$depend} and mconf_depends
($package{$depend}->{depends
}, 1, $dep);
328 $flags =~ /@/ or $depend = "PACKAGE_$depend";
330 $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
332 foreach my $depend (keys %$dep) {
333 my $m = $dep->{$depend};
334 $res .= "\t\t$m $depend\n";
339 sub print_package_config_category
($) {
344 return unless $category{$cat};
346 print "menu \"$cat\"\n\n";
347 my %spkg = %{$category{$cat}};
349 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
350 foreach my $pkg (@
{$spkg{$spkg}}) {
351 my $menu = $pkg->{submenu
};
353 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
357 $menus{$menu} or $menus{$menu} = [];
358 push @
{$menus{$menu}}, $pkg;
359 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
360 print "\t\tbool\n\n";
364 ($a eq 'undef' ?
1 : 0) or
365 ($b eq 'undef' ?
-1 : 0) or
369 foreach my $menu (@menus) {
371 package_depends
($a, $b) or
372 ($a->{name
} cmp $b->{name
})
374 if ($menu ne 'undef') {
375 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
376 print "menu \"$menu\"\n";
378 foreach my $pkg (@pkgs) {
379 my $title = $pkg->{name
};
380 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
382 $title .= ("." x
$c). " ". $pkg->{title
};
385 $pkg->{menu
} and print "menu";
386 print "config PACKAGE_".$pkg->{name
}."\n";
387 print "\t\t".($pkg->{tristate
} ?
'tristate' : 'bool')." \"$title\"\n";
388 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
389 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
390 print "\t\tdefault $default\n";
392 print mconf_depends
($pkg->{depends
}, 0);
394 print $pkg->{description
};
397 $pkg->{config
} and print $pkg->{config
}."\n";
399 if ($menu ne 'undef') {
401 $menu_dep{$menu} and print "endif\n";
406 undef $category{$cat};
409 sub gen_package_config
() {
410 parse_package_metadata
($ARGV[0]) or exit 1;
411 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
412 foreach my $preconfig (keys %preconfig) {
413 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
414 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
417 config UCI_PRECONFIG_$conf
418 string "$preconfig{$preconfig}->{$cfg}->{label}" if UCI_PRECONFIG
419 depends PACKAGE_$preconfig
420 default "$preconfig{$preconfig}->{$cfg}->{default}"
425 print_package_config_category
'Base system';
426 foreach my $cat (keys %category) {
427 print_package_config_category
$cat;
431 sub gen_package_mk
() {
436 parse_package_metadata
($ARGV[0]) or exit 1;
437 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
439 my $pkg = $package{$name};
441 next if defined $pkg->{vdepends
};
443 $conf{$pkg->{src
}} or do {
445 $conf{$pkg->{src
}} = 1;
448 $config = "\$(CONFIG_PACKAGE_$name)"
451 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
452 $pkg->{prereq
} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
457 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
461 my $pkg_dep = $package{$dep};
462 next if defined $pkg_dep->{vdepends
};
464 if (defined $pkg_dep->{src
}) {
465 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{subdir
}.$pkg_dep->{src
};
466 } elsif (defined($srcpackage{$dep})) {
467 $idx = $subdir{$dep}.$dep;
469 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
471 next if $dep{$pkg->{src
}."->".$idx};
472 $depline .= " \$(curdir)/$idx/compile";
473 $dep{$pkg->{src
}."->".$idx} = 1;
477 $line .= "\$(curdir)/".$pkg->{subdir
}."$pkg->{src}/compile += $depline\n";
484 foreach my $preconfig (keys %preconfig) {
486 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
487 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
489 $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
494 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
499 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
500 package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
507 sub parse_command
() {
508 my $cmd = shift @ARGV;
510 /^target_config$/ and return gen_target_config
();
511 /^package_mk$/ and return gen_package_mk
();
512 /^package_config$/ and return gen_package_config
();
513 /^kconfig/ and return gen_kconfig_overrides
();
517 $0 target_config [file] Target metadata in Kconfig format
518 $0 package_mk [file] Package metadata in makefile format
519 $0 package_config [file] Package metadata in Kconfig format
520 $0 kconfig [file] [config] Kernel config overrides