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} = [];
139 push @
{$preconfig{$pkgname}}, $preconfig;
141 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type
} = $1;
142 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label
} = $1;
143 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
148 sub gen_kconfig_overrides
() {
152 my $pkginfo = shift @ARGV;
153 my $cfgfile = shift @ARGV;
155 # parameter 2: build system config
156 open FILE
, "<$cfgfile" or return;
158 /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
162 # parameter 1: package metadata
163 open FILE
, "<$pkginfo" or return;
165 /^Package:\s*(.+?)\s*$/ and $package = $1;
166 /^Kernel-Config:\s*(.+?)\s*$/ and do {
167 my @config = split /\s+/, $1;
168 foreach my $config (@config) {
171 if ($config =~ /^(.+?)=(.+)$/) {
176 if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
177 $kconfig{$config} = $val;
178 } elsif (!$override) {
179 $kconfig{$config} or $kconfig{$config} = 'n';
186 foreach my $kconfig (sort keys %kconfig) {
187 if ($kconfig{$kconfig} eq 'n') {
188 print "# $kconfig is not set\n";
190 print "$kconfig=$kconfig{$kconfig}\n";
195 sub merge_package_lists
($$) {
201 foreach my $pkg (@
$list1, @
$list2) {
204 foreach my $pkg (keys %pkgs) {
205 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
210 sub target_config_features
(@
) {
213 while ($_ = shift @_) {
214 /broken/ and $ret .= "\tdepends BROKEN\n";
215 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
216 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
217 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
218 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
219 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
220 /ext2/ and $ret .= "\tselect USES_EXT2\n";
221 /tgz/ and $ret .= "\tselect USES_TGZ\n";
227 sub gen_target_config
() {
228 my @target = parse_target_metadata
();
231 $a->{name
} cmp $b->{name
}
237 prompt "Target System"
238 default TARGET_brcm_2_4
243 foreach my $target (@target) {
244 my $features = target_config_features
(@
{$target->{features
}});
245 my $help = $target->{desc
};
246 my $kernel = $target->{kernel
};
251 if ($help =~ /\w+/) {
252 $help =~ s/^\s*/\t /mg;
253 $help = "\thelp\n$help";
259 config TARGET_$target->{conf}
260 bool "$target->{name}"
261 select $target->{arch}
264 if ($target->{id
} ne $target->{board
}) {
265 print "\tselect TARGET_".$target->{boardconf
}."\n";
267 print "$features$help\n\n"
276 foreach my $target (@target) {
277 print "\t\tdefault \"".$target->{board
}."\" if TARGET_".$target->{conf
}."\n";
280 # add hidden target config options
281 foreach my $target (@target) {
282 next if $board{$target->{board
}};
283 if ($target->{id
} ne $target->{board
}) {
284 print "\nconfig TARGET_".$target->{boardconf
}."\n\tbool\n";
285 $board{$target->{board
}} = 1;
291 prompt "Target Profile"
295 foreach my $target (@target) {
296 my $profiles = $target->{profiles
};
298 foreach my $profile (@
$profiles) {
300 config TARGET_$target->{conf}_$profile->{id}
301 bool "$profile->{name}"
302 depends TARGET_$target->{conf}
305 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
306 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
307 foreach my $pkg (@pkglist) {
308 print "\tselect DEFAULT_$pkg\n";
318 sub find_package_dep
($$) {
321 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
323 return 0 unless defined $deps;
324 foreach my $dep (@
{$deps}) {
325 return 1 if $dep eq $name;
326 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
331 sub package_depends
($$) {
336 return 0 if ($a->{submenu
} ne $b->{submenu
});
337 if (find_package_dep
($a, $b->{name
}) == 1) {
339 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
347 sub mconf_depends
($$) {
349 my $only_dep = shift;
353 my @depends = @
$depends;
354 foreach my $depend (@depends) {
356 $depend =~ s/^([@\+]+)//;
360 if ($vdep = $package{$depend}->{vdepends
}) {
361 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
363 $flags =~ /\+/ and do {
367 # Menuconfig will not treat 'select FOO' as a real dependency
368 # thus if FOO depends on other config options, these dependencies
369 # will not be checked. To fix this, we simply emit all of FOO's
370 # depends here as well.
371 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
373 $flags =~ /@/ or $depend = "PACKAGE_$depend";
375 $res .= "\t\t$m $depend\n";
380 sub print_package_config_category
($) {
385 return unless $category{$cat};
387 print "menu \"$cat\"\n\n";
388 my %spkg = %{$category{$cat}};
390 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
391 foreach my $pkg (@
{$spkg{$spkg}}) {
392 my $menu = $pkg->{submenu
};
394 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
398 $menus{$menu} or $menus{$menu} = [];
399 push @
{$menus{$menu}}, $pkg;
400 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
401 print "\t\tbool\n\n";
405 ($a eq 'undef' ?
1 : 0) or
406 ($b eq 'undef' ?
-1 : 0) or
410 foreach my $menu (@menus) {
412 package_depends
($a, $b) or
413 ($a->{name
} cmp $b->{name
})
415 if ($menu ne 'undef') {
416 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
417 print "menu \"$menu\"\n";
419 foreach my $pkg (@pkgs) {
420 my $title = $pkg->{name
};
421 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
423 $title .= ("." x
$c). " ". $pkg->{title
};
426 $pkg->{menu
} and print "menu";
427 print "config PACKAGE_".$pkg->{name
}."\n";
428 print "\t\ttristate \"$title\"\n";
429 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
430 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
431 print "\t\tdefault $default\n";
433 print mconf_depends
($pkg->{depends
}, 0);
435 print $pkg->{description
};
438 $pkg->{config
} and print $pkg->{config
}."\n";
440 if ($menu ne 'undef') {
442 $menu_dep{$menu} and print "endif\n";
447 undef $category{$cat};
450 sub gen_package_config
() {
451 parse_package_metadata
();
452 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
453 foreach my $preconfig (keys %preconfig) {
454 foreach my $cfg (@
{$preconfig{$preconfig}}) {
455 my $conf = $cfg->{id
};
458 config UCI_PRECONFIG_$conf
459 string "$cfg->{label}" if UCI_PRECONFIG
460 depends PACKAGE_$preconfig
461 default "$cfg->{default}"
466 print_package_config_category
'Base system';
467 foreach my $cat (keys %category) {
468 print_package_config_category
$cat;
472 sub gen_package_mk
() {
477 parse_package_metadata
();
478 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
480 my $pkg = $package{$name};
482 next if defined $pkg->{vdepends
};
484 $conf{$pkg->{src
}} or do {
486 $conf{$pkg->{src
}} = 1;
489 $config = "\$(CONFIG_PACKAGE_$name)"
492 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
493 $pkg->{prereq
} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
498 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
502 my $pkg_dep = $package{$dep};
503 next if defined $pkg_dep->{vdepends
};
505 if (defined $pkg_dep->{src
}) {
506 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{subdir
}.$pkg_dep->{src
};
507 } elsif (defined($srcpackage{$dep})) {
508 $idx = $subdir{$dep}.$dep;
510 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
512 next if $dep{$pkg->{src
}."->".$idx};
513 $depline .= " \$(curdir)/$idx/compile";
514 $dep{$pkg->{src
}."->".$idx} = 1;
518 $line .= "\$(curdir)/".$pkg->{subdir
}."$pkg->{src}/compile += $depline\n";
525 foreach my $preconfig (keys %preconfig) {
527 foreach my $cfg (@
{$preconfig{$preconfig}}) {
528 my $conf = $cfg->{id
};
530 $cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
535 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
540 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
541 package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
548 sub parse_command
() {
549 my $cmd = shift @ARGV;
551 /^target_config$/ and return gen_target_config
();
552 /^package_mk$/ and return gen_package_mk
();
553 /^package_config$/ and return gen_package_config
();
554 /^kconfig/ and return gen_kconfig_overrides
();
558 $0 target_config [file] Target metadata in Kconfig format
559 $0 package_mk [file] Package metadata in makefile format
560 $0 package_config [file] Package metadata in Kconfig format
561 $0 kconfig [file] [config] Kernel config overrides