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 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
184 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
185 /ext2/ and $ret .= "\tselect USES_EXT2\n";
191 sub gen_target_config
() {
192 my @target = parse_target_metadata
();
195 $a->{name
} cmp $b->{name
}
201 prompt "Target System"
202 default LINUX_2_4_BRCM
206 foreach my $target (@target) {
207 my $features = target_config_features
(@
{$target->{features
}});
208 my $help = $target->{desc
};
209 my $kernel = $target->{kernel
};
214 if ($help =~ /\w+/) {
215 $help =~ s/^\s*/\t /mg;
216 $help = "\thelp\n$help";
222 config LINUX_$target->{conf}
223 bool "$target->{name}"
224 select $target->{arch}
235 bool "UNSUPPORTED little-endian arm platform"
240 config LINUX_2_6_CRIS
241 bool "UNSUPPORTED cris platform"
246 config LINUX_2_6_M68K
247 bool "UNSUPPORTED m68k platform"
253 bool "UNSUPPORTED little-endian sh3 platform"
258 config LINUX_2_6_SH3EB
259 bool "UNSUPPORTED big-endian sh3 platform"
265 bool "UNSUPPORTED little-endian sh4 platform"
270 config LINUX_2_6_SH4EB
271 bool "UNSUPPORTED big-endian sh4 platform"
276 config LINUX_2_6_SPARC
277 bool "UNSUPPORTED sparc platform"
287 prompt "Target Profile"
291 foreach my $target (@target) {
292 my $profiles = $target->{profiles
};
294 foreach my $profile (@
$profiles) {
296 config LINUX_$target->{conf}_$profile->{id}
297 bool "$profile->{name}"
298 depends LINUX_$target->{conf}
301 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
304 foreach my $pkg (keys %pkgs) {
305 print "\tselect DEFAULT_$pkg\n" unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
314 sub find_package_dep
($$) {
317 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
319 return 0 unless defined $deps;
320 foreach my $dep (@
{$deps}) {
321 return 1 if $dep eq $name;
322 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
327 sub package_depends
($$) {
332 return 0 if ($a->{submenu
} ne $b->{submenu
});
333 if (find_package_dep
($a, $b->{name
}) == 1) {
335 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
343 sub print_package_config_category
($) {
348 return unless $category{$cat};
350 print "menu \"$cat\"\n\n";
351 my %spkg = %{$category{$cat}};
353 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
354 foreach my $pkg (@
{$spkg{$spkg}}) {
355 my $menu = $pkg->{submenu
};
357 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
361 $menus{$menu} or $menus{$menu} = [];
362 push @
{$menus{$menu}}, $pkg;
363 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
364 print "\t\tbool\n\n";
368 ($a eq 'undef' ?
1 : 0) or
369 ($b eq 'undef' ?
-1 : 0) or
373 foreach my $menu (@menus) {
375 package_depends
($a, $b) or
376 ($a->{name
} cmp $b->{name
})
378 if ($menu ne 'undef') {
379 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
380 print "menu \"$menu\"\n";
382 foreach my $pkg (@pkgs) {
383 my $title = $pkg->{name
};
384 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
386 $title .= ("." x
$c). " ". $pkg->{title
};
389 $pkg->{menu
} and print "menu";
390 print "config PACKAGE_".$pkg->{name
}."\n";
391 print "\t\ttristate \"$title\"\n";
392 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
393 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
394 print "\t\tdefault $default\n";
396 foreach my $depend (@
{$pkg->{depends
}}) {
398 $depend =~ s/^([@\+]+)//;
402 if ($vdep = $package{$depend}->{vdepends
}) {
403 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
405 $flags =~ /@/ or $depend = "PACKAGE_$depend";
406 $flags =~ /\+/ and $m = "select";
408 print "\t\t$m $depend\n";
411 print $pkg->{description
};
414 $pkg->{config
} and print $pkg->{config
}."\n";
416 if ($menu ne 'undef') {
418 $menu_dep{$menu} and print "endif\n";
423 undef $category{$cat};
426 sub gen_package_config
() {
427 parse_package_metadata
();
428 print_package_config_category
'Base system';
429 foreach my $cat (keys %category) {
430 print_package_config_category
$cat;
434 sub parse_command
() {
435 my $cmd = shift @ARGV;
437 /^target_mk$/ and return gen_target_mk
();
438 /^target_config$/ and return gen_target_config
();
439 /^package_config$/ and return gen_package_config
();
443 $0 target_mk [file] Target metadata in makefile format
444 $0 target_config [file] Target metadata in Kconfig format
445 $0 package_config [file] Package metadata in Kconfig format