6 sub parse_target_metadata
() {
7 my ($target, @target, $profile);
10 /^Target:\s*((.+)-(\d+\.\d+))\s*$/ and do {
11 my $conf = uc $3.'_'.$2;
20 push @target, $target;
22 /^Target-Name:\s*(.+)\s*$/ and $target->{name
} = $1;
23 /^Target-Path:\s*(.+)\s*$/ and $target->{path
} = $1;
24 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch
} = $1;
25 /^Target-Features:\s*(.+)\s*$/ and $target->{features
} = [ split(/\s+/, $1) ];
26 /^Target-Description:/ and do {
32 $target->{desc
} = $desc;
34 /^Linux-Version:\s*(.+)\s*$/ and $target->{version
} = $1;
35 /^Linux-Release:\s*(.+)\s*$/ and $target->{release
} = $1;
36 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch
} = $1;
37 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages
} = [ split(/\s+/, $1) ];
38 /^Target-Profile:\s*(.+)\s*$/ and do {
44 push @
{$target->{profiles
}}, $profile;
46 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name
} = $1;
47 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages
} = [ split(/\s+/, $1) ];
48 /^Target-Profile-Description:/ and do {
54 $profile->{desc
} = $desc;
57 foreach my $target (@target) {
58 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
69 sub parse_package_metadata
() {
75 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
80 /^Package: \s*(.+)\s*$/ and do {
83 $pkg->{makefile
} = $makefile;
85 $pkg->{default} = "m if ALL";
88 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
89 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
90 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
91 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
92 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
93 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
94 /^Provides: \s*(.+)\s*$/ and do {
95 my @vpkg = split /\s+/, $1;
96 foreach my $vpkg (@vpkg) {
97 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
98 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
101 /^Depends: \s*(.+)\s*$/ and do {
102 my @dep = split /\s+/, $1;
103 $pkg->{depends
} = \
@dep;
105 /^Category: \s*(.+)\s*$/ and do {
106 $pkg->{category
} = $1;
107 defined $category{$1} or $category{$1} = {};
108 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
109 push @
{$category{$1}->{$src}}, $pkg;
111 /^Description: \s*(.*)\s*$/ and do {
112 my $desc = "\t\t$1\n\n";
115 last if $line =~ /^@@/;
116 $desc .= "\t\t$line";
118 $pkg->{description
} = $desc;
120 /^Config: \s*(.*)\s*$/ and do {
124 last if $line =~ /^@@/;
127 $pkg->{config
} = $conf;
134 sub gen_target_mk
() {
135 my @target = parse_target_metadata
();
138 $a->{id
} cmp $b->{id
}
141 foreach my $target (@target) {
142 my ($profiles_def, $profiles_eval);
143 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
146 foreach my $profile (@
{$target->{profiles
}}) {
148 define Profile/$conf\_$profile->{id}
150 NAME:=$profile->{name}
151 PACKAGES:=".join(" ", @
{$profile->{packages
}})."
154 \$(eval \$(call Profile,$conf\_$profile->{id}))"
157 ifeq (\$(CONFIG_LINUX_$conf),y)
159 KERNEL:=$target->{kernel}
160 BOARD:=$target->{board}
161 BOARDNAME:=$target->{name}
162 LINUX_VERSION:=$target->{version}
163 LINUX_RELEASE:=$target->{release}
164 LINUX_KARCH:=$target->{karch}
165 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
171 print "\$(eval \$(call Target))\n";
174 sub target_config_features
(@
) {
177 while ($_ = shift @_) {
178 /broken/ and $ret .= "\tdepends BROKEN\n";
179 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
180 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
181 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
182 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
183 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
184 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
185 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
186 /ext2/ and $ret .= "\tselect USES_EXT2\n";
192 sub gen_target_config
() {
193 my @target = parse_target_metadata
();
196 $a->{name
} cmp $b->{name
}
202 prompt "Target System"
203 default LINUX_2_4_BRCM
207 foreach my $target (@target) {
208 my $features = target_config_features
(@
{$target->{features
}});
209 my $help = $target->{desc
};
210 my $kernel = $target->{kernel
};
215 if ($help =~ /\w+/) {
216 $help =~ s/^\s*/\t /mg;
217 $help = "\thelp\n$help";
223 config LINUX_$target->{conf}
224 bool "$target->{name}"
225 select $target->{arch}
236 bool "UNSUPPORTED little-endian arm platform"
241 config LINUX_2_6_CRIS
242 bool "UNSUPPORTED cris platform"
247 config LINUX_2_6_M68K
248 bool "UNSUPPORTED m68k platform"
254 bool "UNSUPPORTED little-endian sh3 platform"
259 config LINUX_2_6_SH3EB
260 bool "UNSUPPORTED big-endian sh3 platform"
266 bool "UNSUPPORTED little-endian sh4 platform"
271 config LINUX_2_6_SH4EB
272 bool "UNSUPPORTED big-endian sh4 platform"
277 config LINUX_2_6_SPARC
278 bool "UNSUPPORTED sparc platform"
288 prompt "Target Profile"
292 foreach my $target (@target) {
293 my $profiles = $target->{profiles
};
295 foreach my $profile (@
$profiles) {
297 config LINUX_$target->{conf}_$profile->{id}
298 bool "$profile->{name}"
299 depends LINUX_$target->{conf}
302 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
305 foreach my $pkg (keys %pkgs) {
306 print "\tselect DEFAULT_$pkg\n" unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
315 sub find_package_dep
($$) {
318 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
320 return 0 unless defined $deps;
321 foreach my $dep (@
{$deps}) {
322 return 1 if $dep eq $name;
323 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
328 sub package_depends
($$) {
333 return 0 if ($a->{submenu
} ne $b->{submenu
});
334 if (find_package_dep
($a, $b->{name
}) == 1) {
336 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
344 sub mconf_depends
($$) {
346 my $only_dep = shift;
350 my @depends = @
$depends;
351 foreach my $depend (@depends) {
353 $depend =~ s/^([@\+]+)//;
357 if ($vdep = $package{$depend}->{vdepends
}) {
358 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
360 $flags =~ /\+/ and do {
364 # Menuconfig will not treat 'select FOO' as a real dependency
365 # thus if FOO depends on other config options, these dependencies
366 # will not be checked. To fix this, we simply emit all of FOO's
367 # depends here as well.
368 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
370 $flags =~ /@/ or $depend = "PACKAGE_$depend";
372 $res .= "\t\t$m $depend\n";
377 sub print_package_config_category
($) {
382 return unless $category{$cat};
384 print "menu \"$cat\"\n\n";
385 my %spkg = %{$category{$cat}};
387 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
388 foreach my $pkg (@
{$spkg{$spkg}}) {
389 my $menu = $pkg->{submenu
};
391 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
395 $menus{$menu} or $menus{$menu} = [];
396 push @
{$menus{$menu}}, $pkg;
397 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
398 print "\t\tbool\n\n";
402 ($a eq 'undef' ?
1 : 0) or
403 ($b eq 'undef' ?
-1 : 0) or
407 foreach my $menu (@menus) {
409 package_depends
($a, $b) or
410 ($a->{name
} cmp $b->{name
})
412 if ($menu ne 'undef') {
413 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
414 print "menu \"$menu\"\n";
416 foreach my $pkg (@pkgs) {
417 my $title = $pkg->{name
};
418 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
420 $title .= ("." x
$c). " ". $pkg->{title
};
423 $pkg->{menu
} and print "menu";
424 print "config PACKAGE_".$pkg->{name
}."\n";
425 print "\t\ttristate \"$title\"\n";
426 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
427 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
428 print "\t\tdefault $default\n";
430 print mconf_depends
($pkg->{depends
}, 0);
432 print $pkg->{description
};
435 $pkg->{config
} and print $pkg->{config
}."\n";
437 if ($menu ne 'undef') {
439 $menu_dep{$menu} and print "endif\n";
444 undef $category{$cat};
447 sub gen_package_config
() {
448 parse_package_metadata
();
449 print_package_config_category
'Base system';
450 foreach my $cat (keys %category) {
451 print_package_config_category
$cat;
455 sub parse_command
() {
456 my $cmd = shift @ARGV;
458 /^target_mk$/ and return gen_target_mk
();
459 /^target_config$/ and return gen_target_config
();
460 /^package_config$/ and return gen_package_config
();
464 $0 target_mk [file] Target metadata in makefile format
465 $0 target_config [file] Target metadata in Kconfig format
466 $0 package_config [file] Package metadata in Kconfig format