8 sub parse_target_metadata
() {
9 my ($target, @target, $profile);
12 /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
13 my $conf = uc $3.'_'.$2;
22 push @target, $target;
24 /^Target-Name:\s*(.+)\s*$/ and $target->{name
} = $1;
25 /^Target-Path:\s*(.+)\s*$/ and $target->{path
} = $1;
26 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch
} = $1;
27 /^Target-Features:\s*(.+)\s*$/ and $target->{features
} = [ split(/\s+/, $1) ];
28 /^Target-Description:/ and do {
34 $target->{desc
} = $desc;
36 /^Linux-Version:\s*(.+)\s*$/ and $target->{version
} = $1;
37 /^Linux-Release:\s*(.+)\s*$/ and $target->{release
} = $1;
38 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch
} = $1;
39 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages
} = [ split(/\s+/, $1) ];
40 /^Target-Profile:\s*(.+)\s*$/ and do {
46 push @
{$target->{profiles
}}, $profile;
48 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name
} = $1;
49 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages
} = [ split(/\s+/, $1) ];
50 /^Target-Profile-Description:/ and do {
56 $profile->{desc
} = $desc;
58 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
60 foreach my $target (@target) {
61 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
72 sub parse_package_metadata
() {
79 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
82 $srcpackage{$src} = [];
85 /^Package:\s*(.+?)\s*$/ and do {
88 $pkg->{makefile
} = $makefile;
90 $pkg->{default} = "m if ALL";
92 $pkg->{builddepends
} = [];
94 push @
{$srcpackage{$src}}, $pkg;
96 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
97 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
98 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
99 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
100 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
101 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
102 /^Provides: \s*(.+)\s*$/ and do {
103 my @vpkg = split /\s+/, $1;
104 foreach my $vpkg (@vpkg) {
105 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
106 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
109 /^Depends: \s*(.+)\s*$/ and do {
110 my @dep = split /\s+/, $1;
111 $pkg->{depends
} = \
@dep;
113 /^Build-Depends: \s*(.+)\s*$/ and do {
114 my @dep = split /\s+/, $1;
115 $pkg->{builddepends
} = \
@dep;
117 /^Category: \s*(.+)\s*$/ and do {
118 $pkg->{category
} = $1;
119 defined $category{$1} or $category{$1} = {};
120 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
121 push @
{$category{$1}->{$src}}, $pkg;
123 /^Description: \s*(.*)\s*$/ and do {
124 my $desc = "\t\t$1\n\n";
127 last if $line =~ /^@@/;
128 $desc .= "\t\t$line";
130 $pkg->{description
} = $desc;
132 /^Config: \s*(.*)\s*$/ and do {
136 last if $line =~ /^@@/;
139 $pkg->{config
} = $conf;
141 /^Prereq-Check:/ and $pkg->{prereq
} = 1;
142 /^Preconfig:\s*(.+)\s*$/ and do {
143 my $pkgname = $pkg->{name
};
144 $preconfig{$pkgname} or $preconfig{$pkgname} = [];
148 push @
{$preconfig{$pkgname}}, $preconfig;
150 /^Preconfig-Type:\s*(.*?)\s*$/ and $preconfig->{type
} = $1;
151 /^Preconfig-Label:\s*(.*?)\s*$/ and $preconfig->{label
} = $1;
152 /^Preconfig-Default:\s*(.*?)\s*$/ and $preconfig->{default} = $1;
158 sub gen_target_mk
() {
159 my @target = parse_target_metadata
();
162 $a->{id
} cmp $b->{id
}
165 foreach my $target (@target) {
166 my ($profiles_def, $profiles_eval);
167 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
170 foreach my $profile (@
{$target->{profiles
}}) {
172 define Profile/$conf\_$profile->{id}
174 NAME:=$profile->{name}
175 PACKAGES:=".join(" ", @
{$profile->{packages
}})."\n";
176 $profile->{kconfig
} and $profiles_def .= " KCONFIG:=1\n";
177 $profiles_def .= " endef";
179 \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
182 ifeq (\$(CONFIG_LINUX_$conf),y)
184 KERNEL:=$target->{kernel}
185 BOARD:=$target->{board}
186 BOARDNAME:=$target->{name}
187 LINUX_VERSION:=$target->{version}
188 LINUX_RELEASE:=$target->{release}
189 LINUX_KARCH:=$target->{karch}
190 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
196 print "\$(eval \$(call Target))\n";
199 sub target_config_features
(@
) {
202 while ($_ = shift @_) {
203 /broken/ and $ret .= "\tdepends BROKEN\n";
204 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
205 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
206 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
207 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
208 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
209 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
210 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
211 /ext2/ and $ret .= "\tselect USES_EXT2\n";
217 sub gen_target_config
() {
218 my @target = parse_target_metadata
();
221 $a->{name
} cmp $b->{name
}
227 prompt "Target System"
228 default LINUX_2_4_BRCM
233 foreach my $target (@target) {
234 my $features = target_config_features
(@
{$target->{features
}});
235 my $help = $target->{desc
};
236 my $kernel = $target->{kernel
};
241 if ($help =~ /\w+/) {
242 $help =~ s/^\s*/\t /mg;
243 $help = "\thelp\n$help";
249 config LINUX_$target->{conf}
250 bool "$target->{name}"
251 select $target->{arch}
262 bool "UNSUPPORTED little-endian arm platform"
267 config LINUX_2_6_CRIS
268 bool "UNSUPPORTED cris platform"
273 config LINUX_2_6_M68K
274 bool "UNSUPPORTED m68k platform"
280 bool "UNSUPPORTED little-endian sh3 platform"
285 config LINUX_2_6_SH3EB
286 bool "UNSUPPORTED big-endian sh3 platform"
292 bool "UNSUPPORTED little-endian sh4 platform"
297 config LINUX_2_6_SH4EB
298 bool "UNSUPPORTED big-endian sh4 platform"
303 config LINUX_2_6_SPARC
304 bool "UNSUPPORTED sparc platform"
314 prompt "Target Profile"
318 foreach my $target (@target) {
319 my $profiles = $target->{profiles
};
321 foreach my $profile (@
$profiles) {
323 config LINUX_$target->{conf}_$profile->{id}
324 bool "$profile->{name}"
325 depends LINUX_$target->{conf}
327 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
329 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
332 foreach my $pkg (keys %pkgs) {
333 print "\tselect DEFAULT_$pkg\n" unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
342 sub find_package_dep
($$) {
345 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
347 return 0 unless defined $deps;
348 foreach my $dep (@
{$deps}) {
349 return 1 if $dep eq $name;
350 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
355 sub package_depends
($$) {
360 return 0 if ($a->{submenu
} ne $b->{submenu
});
361 if (find_package_dep
($a, $b->{name
}) == 1) {
363 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
371 sub mconf_depends
($$) {
373 my $only_dep = shift;
377 my @depends = @
$depends;
378 foreach my $depend (@depends) {
380 $depend =~ s/^([@\+]+)//;
384 if ($vdep = $package{$depend}->{vdepends
}) {
385 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
387 $flags =~ /\+/ and do {
391 # Menuconfig will not treat 'select FOO' as a real dependency
392 # thus if FOO depends on other config options, these dependencies
393 # will not be checked. To fix this, we simply emit all of FOO's
394 # depends here as well.
395 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
397 $flags =~ /@/ or $depend = "PACKAGE_$depend";
399 $res .= "\t\t$m $depend\n";
404 sub print_package_config_category
($) {
409 return unless $category{$cat};
411 print "menu \"$cat\"\n\n";
412 my %spkg = %{$category{$cat}};
414 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
415 foreach my $pkg (@
{$spkg{$spkg}}) {
416 my $menu = $pkg->{submenu
};
418 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
422 $menus{$menu} or $menus{$menu} = [];
423 push @
{$menus{$menu}}, $pkg;
424 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
425 print "\t\tbool\n\n";
429 ($a eq 'undef' ?
1 : 0) or
430 ($b eq 'undef' ?
-1 : 0) or
434 foreach my $menu (@menus) {
436 package_depends
($a, $b) or
437 ($a->{name
} cmp $b->{name
})
439 if ($menu ne 'undef') {
440 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
441 print "menu \"$menu\"\n";
443 foreach my $pkg (@pkgs) {
444 my $title = $pkg->{name
};
445 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
447 $title .= ("." x
$c). " ". $pkg->{title
};
450 $pkg->{menu
} and print "menu";
451 print "config PACKAGE_".$pkg->{name
}."\n";
452 print "\t\ttristate \"$title\"\n";
453 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
454 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
455 print "\t\tdefault $default\n";
457 print mconf_depends
($pkg->{depends
}, 0);
459 print $pkg->{description
};
462 $pkg->{config
} and print $pkg->{config
}."\n";
464 if ($menu ne 'undef') {
466 $menu_dep{$menu} and print "endif\n";
471 undef $category{$cat};
474 sub gen_package_config
() {
475 parse_package_metadata
();
476 print "menu \"Image configuration\"\n";
477 foreach my $preconfig (keys %preconfig) {
478 print "\tcomment \"$preconfig\"\n";
479 foreach my $cfg (@
{$preconfig{$preconfig}}) {
480 my $conf = $cfg->{id
};
483 config UCI_PRECONFIG_$conf
484 string "$cfg->{label}"
485 depends PACKAGE_$preconfig
486 default "$cfg->{default}"
492 print_package_config_category
'Base system';
493 foreach my $cat (keys %category) {
494 print_package_config_category
$cat;
498 sub gen_package_mk
() {
503 parse_package_metadata
();
504 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
506 my $pkg = $package{$name};
508 next if defined $pkg->{vdepends
};
510 $conf{$pkg->{src
}} or do {
512 $conf{$pkg->{src
}} = 1;
515 $config = "\$(CONFIG_PACKAGE_$name)"
518 print "package-$config += $pkg->{src}\n";
519 $pkg->{prereq
} and print "prereq-$config += $pkg->{src}\n";
524 foreach my $dep (@
{$pkg->{depends
}}, @
{$pkg->{builddepends
}}) {
528 my $pkg_dep = $package{$dep};
529 $pkg_dep or $pkg_dep = $srcpackage{$dep}->[0];
530 next unless defined $pkg_dep;
531 next if defined $pkg_dep->{vdepends
};
533 if (defined $pkg_dep->{src
}) {
534 ($pkg->{src
} ne $pkg_dep->{src
}) and $idx = $pkg_dep->{src
};
535 } elsif (defined($pkg_dep) && !defined($ENV{SDK
})) {
538 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
540 next if $dep{$pkg->{src
}."->".$idx};
541 $depline .= " $idx\-compile";
542 $dep{$pkg->{src
}."->".$idx} = 1;
546 $line .= "$pkg->{src}-compile: $depline\n";
553 foreach my $preconfig (keys %preconfig) {
555 foreach my $cfg (@
{$preconfig{$preconfig}}) {
556 my $conf = $cfg->{id
};
558 $cmds .= "\techo \"uci set '$cfg->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
563 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
568 preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
574 sub parse_command
() {
575 my $cmd = shift @ARGV;
577 /^target_mk$/ and return gen_target_mk
();
578 /^target_config$/ and return gen_target_config
();
579 /^package_mk$/ and return gen_package_mk
();
580 /^package_config$/ and return gen_package_config
();
584 $0 target_mk [file] Target metadata in makefile format
585 $0 target_config [file] Target metadata in Kconfig format
586 $0 package_mk [file] Package metadata in makefile format
587 $0 package_config [file] Package metadata in Kconfig format