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 {
30 push @target, $target;
32 /^Target-Board:\s*(.+)\s*$/ and do {
33 $target->{board
} = $1;
34 $target->{boardconf
} = confstr
($1);
36 /^Target-Kernel:\s*(\d+\.\d+)\s*$/ and $target->{kernel
} = $1;
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
(*FILE
);
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
(*FILE
);
57 /^Target-Profile-Config:/ and $profile->{config
} = get_multiline
(*FILE
, "\t");
58 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
61 foreach my $target (@target) {
62 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
73 sub gen_kconfig_overrides
() {
77 my $pkginfo = shift @ARGV;
78 my $cfgfile = shift @ARGV;
80 # parameter 2: build system config
81 open FILE
, "<$cfgfile" or return;
83 /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
87 # parameter 1: package metadata
88 open FILE
, "<$pkginfo" or return;
90 /^Package:\s*(.+?)\s*$/ and $package = $1;
91 /^Kernel-Config:\s*(.+?)\s*$/ and do {
92 my @config = split /\s+/, $1;
93 foreach my $config (@config) {
96 if ($config =~ /^(.+?)=(.+)$/) {
101 if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
102 $kconfig{$config} = $val;
103 } elsif (!$override) {
104 $kconfig{$config} or $kconfig{$config} = 'n';
111 foreach my $kconfig (sort keys %kconfig) {
112 if ($kconfig{$kconfig} eq 'n') {
113 print "# $kconfig is not set\n";
115 print "$kconfig=$kconfig{$kconfig}\n";
120 sub merge_package_lists
($$) {
126 foreach my $pkg (@
$list1, @
$list2) {
129 foreach my $pkg (keys %pkgs) {
130 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
135 sub target_config_features
(@
) {
138 while ($_ = shift @_) {
139 /broken/ and $ret .= "\tdepends BROKEN\n";
140 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
141 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
142 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
143 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
144 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
145 /ext2/ and $ret .= "\tselect USES_EXT2\n";
146 /tgz/ and $ret .= "\tselect USES_TGZ\n";
152 sub gen_target_config
() {
153 my @target = parse_target_metadata
();
156 $a->{name
} cmp $b->{name
}
162 prompt "Target System"
163 default TARGET_brcm_2_4
168 foreach my $target (@target) {
169 my $features = target_config_features
(@
{$target->{features
}});
170 my $help = $target->{desc
};
171 my $kernel = $target->{kernel
};
176 if ($help =~ /\w+/) {
177 $help =~ s/^\s*/\t /mg;
178 $help = "\thelp\n$help";
184 config TARGET_$target->{conf}
185 bool "$target->{name}"
186 select $target->{arch}
189 if ($target->{id
} ne $target->{board
}) {
190 print "\tselect TARGET_".$target->{boardconf
}."\n";
192 print "$features$help\n\n"
201 foreach my $target (@target) {
202 print "\t\tdefault \"".$target->{board
}."\" if TARGET_".$target->{conf
}."\n";
205 # add hidden target config options
206 foreach my $target (@target) {
207 next if $board{$target->{board
}};
208 if ($target->{id
} ne $target->{board
}) {
209 print "\nconfig TARGET_".$target->{boardconf
}."\n\tbool\n";
210 $board{$target->{board
}} = 1;
216 prompt "Target Profile"
220 foreach my $target (@target) {
221 my $profiles = $target->{profiles
};
223 foreach my $profile (@
$profiles) {
225 config TARGET_$target->{conf}_$profile->{id}
226 bool "$profile->{name}"
227 depends TARGET_$target->{conf}
230 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
231 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
232 foreach my $pkg (@pkglist) {
233 print "\tselect DEFAULT_$pkg\n";
243 sub __find_package_dep
($$) {
246 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
248 return 0 unless defined $deps;
249 foreach my $dep (@
{$deps}) {
250 next if $dep_check{$dep};
251 $dep_check{$dep} = 1;
252 return 1 if $dep eq $name;
253 return 1 if ($package{$dep} and (__find_package_dep
($package{$dep},$name) == 1));
258 # wrapper to avoid infinite recursion
259 sub find_package_dep
($$) {
264 return __find_package_dep
($pkg, $name);
267 sub package_depends
($$) {
272 return 0 if ($a->{submenu
} ne $b->{submenu
});
273 if (find_package_dep
($a, $b->{name
}) == 1) {
275 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
283 sub mconf_depends
($$) {
285 my $only_dep = shift;
289 my @depends = @
$depends;
290 foreach my $depend (@depends) {
292 $depend =~ s/^([@\+]+)//;
296 if ($vdep = $package{$depend}->{vdepends
}) {
297 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
299 $flags =~ /\+/ and do {
303 # Menuconfig will not treat 'select FOO' as a real dependency
304 # thus if FOO depends on other config options, these dependencies
305 # will not be checked. To fix this, we simply emit all of FOO's
306 # depends here as well.
307 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
309 $flags =~ /@/ or $depend = "PACKAGE_$depend";
311 $res .= "\t\t$m $depend\n";
316 sub print_package_config_category
($) {
321 return unless $category{$cat};
323 print "menu \"$cat\"\n\n";
324 my %spkg = %{$category{$cat}};
326 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
327 foreach my $pkg (@
{$spkg{$spkg}}) {
328 my $menu = $pkg->{submenu
};
330 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
334 $menus{$menu} or $menus{$menu} = [];
335 push @
{$menus{$menu}}, $pkg;
336 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
337 print "\t\tbool\n\n";
341 ($a eq 'undef' ?
1 : 0) or
342 ($b eq 'undef' ?
-1 : 0) or
346 foreach my $menu (@menus) {
348 package_depends
($a, $b) or
349 ($a->{name
} cmp $b->{name
})
351 if ($menu ne 'undef') {
352 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
353 print "menu \"$menu\"\n";
355 foreach my $pkg (@pkgs) {
356 my $title = $pkg->{name
};
357 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
359 $title .= ("." x
$c). " ". $pkg->{title
};
362 $pkg->{menu
} and print "menu";
363 print "config PACKAGE_".$pkg->{name
}."\n";
364 print "\t\t".($pkg->{tristate
} ?
'tristate' : 'bool')." \"$title\"\n";
365 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
366 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
367 print "\t\tdefault $default\n";
369 print mconf_depends
($pkg->{depends
}, 0);
371 print $pkg->{description
};
374 $pkg->{config
} and print $pkg->{config
}."\n";
376 if ($menu ne 'undef') {
378 $menu_dep{$menu} and print "endif\n";
383 undef $category{$cat};
386 sub gen_package_config
() {
387 parse_package_metadata
($ARGV[0]) or exit 1;
388 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
389 foreach my $preconfig (keys %preconfig) {
390 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
391 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
394 config UCI_PRECONFIG_$conf
395 string "$preconfig{$preconfig}->{$cfg}->{label}" if UCI_PRECONFIG
396 depends PACKAGE_$preconfig
397 default "$preconfig{$preconfig}->{$cfg}->{default}"
402 print_package_config_category
'Base system';
403 foreach my $cat (keys %category) {
404 print_package_config_category
$cat;
408 sub gen_package_mk
() {
413 parse_package_metadata
($ARGV[0]) or exit 1;
414 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
416 my $pkg = $package{$name};
418 next if defined $pkg->{vdepends
};
420 $conf{$pkg->{src
}} or do {
422 $conf{$pkg->{src
}} = 1;
425 $config = "\$(CONFIG_PACKAGE_$name)"
428 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
429 $pkg->{prereq
} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
434 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
438 my $pkg_dep = $package{$dep};
439 next if defined $pkg_dep->{vdepends
};
441 if (defined $pkg_dep->{src
}) {
442 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{subdir
}.$pkg_dep->{src
};
443 } elsif (defined($srcpackage{$dep})) {
444 $idx = $subdir{$dep}.$dep;
446 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
448 next if $dep{$pkg->{src
}."->".$idx};
449 $depline .= " \$(curdir)/$idx/compile";
450 $dep{$pkg->{src
}."->".$idx} = 1;
454 $line .= "\$(curdir)/".$pkg->{subdir
}."$pkg->{src}/compile += $depline\n";
461 foreach my $preconfig (keys %preconfig) {
463 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
464 my $conf = $preconfig{$preconfig}->{$cfg}->{id
};
466 $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
471 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
476 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
477 package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
484 sub parse_command
() {
485 my $cmd = shift @ARGV;
487 /^target_config$/ and return gen_target_config
();
488 /^package_mk$/ and return gen_package_mk
();
489 /^package_config$/ and return gen_package_config
();
490 /^kconfig/ and return gen_kconfig_overrides
();
494 $0 target_config [file] Target metadata in Kconfig format
495 $0 package_mk [file] Package metadata in makefile format
496 $0 package_config [file] Package metadata in Kconfig format
497 $0 kconfig [file] [config] Kernel config overrides