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
() {
78 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
81 $srcpackage{$src} = [];
84 /^Package:\s*(.+?)\s*$/ and do {
87 $pkg->{makefile
} = $makefile;
89 $pkg->{default} = "m if ALL";
91 $pkg->{builddepends
} = [];
93 push @
{$srcpackage{$src}}, $pkg;
95 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
96 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
97 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
98 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
99 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
100 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
101 /^Provides: \s*(.+)\s*$/ and do {
102 my @vpkg = split /\s+/, $1;
103 foreach my $vpkg (@vpkg) {
104 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
105 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
108 /^Depends: \s*(.+)\s*$/ and $pkg->{depends
} = [ split /\s+/, $1 ];
109 /^Build-Depends: \s*(.+)\s*$/ and $pkg->{builddepends
} = [ split /\s+/, $1 ];
110 /^Category: \s*(.+)\s*$/ and do {
111 $pkg->{category
} = $1;
112 defined $category{$1} or $category{$1} = {};
113 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
114 push @
{$category{$1}->{$src}}, $pkg;
116 /^Description: \s*(.*)\s*$/ and $pkg->{description
} = "\t\t $1\n". get_multiline
("\t\t ");
117 /^Config: \s*(.*)\s*$/ and $pkg->{config
} = "$1\n".get_multiline
();
118 /^Prereq-Check:/ and $pkg->{prereq
} = 1;
119 /^Preconfig:\s*(.+)\s*$/ and do {
120 my $pkgname = $pkg->{name
};
121 $preconfig{$pkgname} or $preconfig{$pkgname} = [];
125 push @
{$preconfig{$pkgname}}, $preconfig;
127 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type
} = $1;
128 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label
} = $1;
129 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
134 sub merge_package_lists
($$) {
140 foreach my $pkg (@
$list1, @
$list2) {
143 foreach my $pkg (keys %pkgs) {
144 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
149 sub gen_target_mk
() {
150 my @target = parse_target_metadata
();
153 $a->{id
} cmp $b->{id
}
156 foreach my $target (@target) {
157 my ($profiles_def, $profiles_eval);
158 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
161 foreach my $profile (@
{$target->{profiles
}}) {
163 define Profile/$conf\_$profile->{id}
165 NAME:=$profile->{name}
166 PACKAGES:=".join(" ", merge_package_lists
($target->{packages
}, $profile->{packages
}))."\n";
167 $profile->{kconfig
} and $profiles_def .= " KCONFIG:=1\n";
168 $profiles_def .= " endef";
170 \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
173 ifeq (\$(CONFIG_LINUX_$conf),y)
175 KERNEL:=$target->{kernel}
176 BOARD:=$target->{board}
177 BOARDNAME:=$target->{name}
178 LINUX_VERSION:=$target->{version}
179 LINUX_RELEASE:=$target->{release}
180 LINUX_KARCH:=$target->{karch}
181 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
187 print "\$(eval \$(call Target))\n";
190 sub target_config_features
(@
) {
193 while ($_ = shift @_) {
194 /broken/ and $ret .= "\tdepends BROKEN\n";
195 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
196 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
197 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
198 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
199 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
200 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
201 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
202 /ext2/ and $ret .= "\tselect USES_EXT2\n";
208 sub gen_target_config
() {
209 my @target = parse_target_metadata
();
212 $a->{name
} cmp $b->{name
}
218 prompt "Target System"
219 default LINUX_2_4_BRCM
224 foreach my $target (@target) {
225 my $features = target_config_features
(@
{$target->{features
}});
226 my $help = $target->{desc
};
227 my $kernel = $target->{kernel
};
232 if ($help =~ /\w+/) {
233 $help =~ s/^\s*/\t /mg;
234 $help = "\thelp\n$help";
240 config LINUX_$target->{conf}
241 bool "$target->{name}"
242 select $target->{arch}
253 bool "UNSUPPORTED little-endian arm platform"
258 config LINUX_2_6_CRIS
259 bool "UNSUPPORTED cris platform"
264 config LINUX_2_6_M68K
265 bool "UNSUPPORTED m68k platform"
271 bool "UNSUPPORTED little-endian sh3 platform"
276 config LINUX_2_6_SH3EB
277 bool "UNSUPPORTED big-endian sh3 platform"
283 bool "UNSUPPORTED little-endian sh4 platform"
288 config LINUX_2_6_SH4EB
289 bool "UNSUPPORTED big-endian sh4 platform"
294 config LINUX_2_6_SPARC
295 bool "UNSUPPORTED sparc platform"
305 prompt "Target Profile"
309 foreach my $target (@target) {
310 my $profiles = $target->{profiles
};
312 foreach my $profile (@
$profiles) {
314 config LINUX_$target->{conf}_$profile->{id}
315 bool "$profile->{name}"
316 depends LINUX_$target->{conf}
319 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
320 my @pkglist = merge_package_lists
($target->{packages
}, $profile->{packages
});
321 foreach my $pkg (@pkglist) {
322 print "\tselect DEFAULT_$pkg\n";
332 sub find_package_dep
($$) {
335 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
337 return 0 unless defined $deps;
338 foreach my $dep (@
{$deps}) {
339 return 1 if $dep eq $name;
340 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
345 sub package_depends
($$) {
350 return 0 if ($a->{submenu
} ne $b->{submenu
});
351 if (find_package_dep
($a, $b->{name
}) == 1) {
353 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
361 sub mconf_depends
($$) {
363 my $only_dep = shift;
367 my @depends = @
$depends;
368 foreach my $depend (@depends) {
370 $depend =~ s/^([@\+]+)//;
374 if ($vdep = $package{$depend}->{vdepends
}) {
375 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
377 $flags =~ /\+/ and do {
381 # Menuconfig will not treat 'select FOO' as a real dependency
382 # thus if FOO depends on other config options, these dependencies
383 # will not be checked. To fix this, we simply emit all of FOO's
384 # depends here as well.
385 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
387 $flags =~ /@/ or $depend = "PACKAGE_$depend";
389 $res .= "\t\t$m $depend\n";
394 sub print_package_config_category
($) {
399 return unless $category{$cat};
401 print "menu \"$cat\"\n\n";
402 my %spkg = %{$category{$cat}};
404 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
405 foreach my $pkg (@
{$spkg{$spkg}}) {
406 my $menu = $pkg->{submenu
};
408 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
412 $menus{$menu} or $menus{$menu} = [];
413 push @
{$menus{$menu}}, $pkg;
414 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
415 print "\t\tbool\n\n";
419 ($a eq 'undef' ?
1 : 0) or
420 ($b eq 'undef' ?
-1 : 0) or
424 foreach my $menu (@menus) {
426 package_depends
($a, $b) or
427 ($a->{name
} cmp $b->{name
})
429 if ($menu ne 'undef') {
430 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
431 print "menu \"$menu\"\n";
433 foreach my $pkg (@pkgs) {
434 my $title = $pkg->{name
};
435 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
437 $title .= ("." x
$c). " ". $pkg->{title
};
440 $pkg->{menu
} and print "menu";
441 print "config PACKAGE_".$pkg->{name
}."\n";
442 print "\t\ttristate \"$title\"\n";
443 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
444 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
445 print "\t\tdefault $default\n";
447 print mconf_depends
($pkg->{depends
}, 0);
449 print $pkg->{description
};
452 $pkg->{config
} and print $pkg->{config
}."\n";
454 if ($menu ne 'undef') {
456 $menu_dep{$menu} and print "endif\n";
461 undef $category{$cat};
464 sub gen_package_config
() {
465 parse_package_metadata
();
466 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n";
467 foreach my $preconfig (keys %preconfig) {
468 foreach my $cfg (@
{$preconfig{$preconfig}}) {
469 my $conf = $cfg->{id
};
472 config UCI_PRECONFIG_$conf
473 string "$cfg->{label}" if UCI_PRECONFIG
474 depends PACKAGE_$preconfig
475 default "$cfg->{default}"
480 print_package_config_category
'Base system';
481 foreach my $cat (keys %category) {
482 print_package_config_category
$cat;
486 sub gen_package_mk
() {
491 parse_package_metadata
();
492 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
494 my $pkg = $package{$name};
496 next if defined $pkg->{vdepends
};
498 $conf{$pkg->{src
}} or do {
500 $conf{$pkg->{src
}} = 1;
503 $config = "\$(CONFIG_PACKAGE_$name)"
506 print "package-$config += $pkg->{src}\n";
507 $pkg->{prereq
} and print "prereq-$config += $pkg->{src}\n";
512 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
516 my $pkg_dep = $package{$dep};
517 $pkg_dep or $pkg_dep = $srcpackage{$dep}->[0];
518 next unless defined $pkg_dep;
519 next if defined $pkg_dep->{vdepends
};
521 if (defined $pkg_dep->{src
}) {
522 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{src
};
523 } elsif (defined($pkg_dep) && !defined($ENV{SDK
})) {
526 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
528 next if $dep{$pkg->{src
}."->".$idx};
529 $depline .= " $idx\-compile";
530 $dep{$pkg->{src
}."->".$idx} = 1;
534 $line .= "$pkg->{src}-compile: $depline\n";
541 foreach my $preconfig (keys %preconfig) {
543 foreach my $cfg (@
{$preconfig{$preconfig}}) {
544 my $conf = $cfg->{id
};
546 $cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
551 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
556 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
557 preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
564 sub parse_command
() {
565 my $cmd = shift @ARGV;
567 /^target_mk$/ and return gen_target_mk
();
568 /^target_config$/ and return gen_target_config
();
569 /^package_mk$/ and return gen_package_mk
();
570 /^package_config$/ and return gen_package_config
();
574 $0 target_mk [file] Target metadata in makefile format
575 $0 target_config [file] Target metadata in Kconfig format
576 $0 package_mk [file] Package metadata in makefile format
577 $0 package_config [file] Package metadata in Kconfig format