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) ];
49 foreach my $target (@target) {
50 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
61 sub parse_package_metadata
() {
67 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
72 /^Package: \s*(.+)\s*$/ and do {
75 $pkg->{makefile
} = $makefile;
77 $pkg->{default} = "m if ALL";
80 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
81 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
82 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
83 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
84 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
85 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
86 /^Provides: \s*(.+)\s*$/ and do {
87 my @vpkg = split /\s+/, $1;
88 foreach my $vpkg (@vpkg) {
89 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
90 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
93 /^Depends: \s*(.+)\s*$/ and do {
94 my @dep = split /\s+/, $1;
95 $pkg->{depends
} = \
@dep;
97 /^Category: \s*(.+)\s*$/ and do {
98 $pkg->{category
} = $1;
99 defined $category{$1} or $category{$1} = {};
100 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
101 push @
{$category{$1}->{$src}}, $pkg;
103 /^Description: \s*(.*)\s*$/ and do {
104 my $desc = "\t\t$1\n\n";
107 last if $line =~ /^@@/;
108 $desc .= "\t\t$line";
110 $pkg->{description
} = $desc;
112 /^Config: \s*(.*)\s*$/ and do {
116 last if $line =~ /^@@/;
119 $pkg->{config
} = $conf;
126 sub gen_target_mk
() {
127 my @target = parse_target_metadata
();
130 $a->{id
} cmp $b->{id
}
133 foreach my $target (@target) {
134 my ($profiles_def, $profiles_eval);
135 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
138 foreach my $profile (@
{$target->{profiles
}}) {
140 define Profile/$conf\_$profile->{id}
142 NAME:=$profile->{name}
143 PACKAGES:=".join(" ", @
{$profile->{packages
}})."
146 \$(eval \$(call Profile,$conf\_$profile->{id}))"
149 ifeq (\$(CONFIG_LINUX_$conf),y)
151 KERNEL:=$target->{kernel}
152 BOARD:=$target->{board}
153 BOARDNAME:=$target->{name}
154 LINUX_VERSION:=$target->{version}
155 LINUX_RELEASE:=$target->{release}
156 LINUX_KARCH:=$target->{karch}
157 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
163 print "\$(eval \$(call Target))\n";
166 sub target_config_features
(@
) {
169 while ($_ = shift @_) {
170 /broken/ and $ret .= "\tdepends BROKEN\n";
171 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
172 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
173 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
174 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
175 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
176 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
177 /ext2/ and $ret .= "\tselect USES_EXT2\n";
183 sub gen_target_config
() {
184 my @target = parse_target_metadata
();
187 $a->{name
} cmp $b->{name
}
193 prompt "Target System"
194 default LINUX_2_4_BRCM
198 foreach my $target (@target) {
199 my $features = target_config_features
(@
{$target->{features
}});
200 my $help = $target->{desc
};
201 my $kernel = $target->{kernel
};
206 if ($help =~ /\w+/) {
207 $help =~ s/^\s*/\t /mg;
208 $help = "\thelp\n$help";
214 config LINUX_$target->{conf}
215 bool "$target->{name}"
216 select $target->{arch}
227 bool "UNSUPPORTED little-endian arm platform"
232 config LINUX_2_6_CRIS
233 bool "UNSUPPORTED cris platform"
238 config LINUX_2_6_M68K
239 bool "UNSUPPORTED m68k platform"
245 bool "UNSUPPORTED little-endian sh3 platform"
250 config LINUX_2_6_SH3EB
251 bool "UNSUPPORTED big-endian sh3 platform"
257 bool "UNSUPPORTED little-endian sh4 platform"
262 config LINUX_2_6_SH4EB
263 bool "UNSUPPORTED big-endian sh4 platform"
268 config LINUX_2_6_SPARC
269 bool "UNSUPPORTED sparc platform"
279 prompt "Target Profile"
283 foreach my $target (@target) {
284 my $profiles = $target->{profiles
};
286 foreach my $profile (@
$profiles) {
288 config LINUX_$target->{conf}_$profile->{id}
289 bool "$profile->{name}"
290 depends LINUX_$target->{conf}
292 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
293 print "\tselect DEFAULT_$pkg\n";
302 sub find_package_dep
($$) {
305 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
307 return 0 unless defined $deps;
308 foreach my $dep (@
{$deps}) {
309 return 1 if $dep eq $name;
310 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
315 sub package_depends
($$) {
320 return 0 if ($a->{submenu
} ne $b->{submenu
});
321 if (find_package_dep
($a, $b->{name
}) == 1) {
323 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
331 sub print_package_config_category
($) {
336 return unless $category{$cat};
338 print "menu \"$cat\"\n\n";
339 my %spkg = %{$category{$cat}};
341 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
342 foreach my $pkg (@
{$spkg{$spkg}}) {
343 my $menu = $pkg->{submenu
};
345 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
349 $menus{$menu} or $menus{$menu} = [];
350 push @
{$menus{$menu}}, $pkg;
351 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
352 print "\t\tbool\n\n";
356 ($a eq 'undef' ?
1 : 0) or
357 ($b eq 'undef' ?
-1 : 0) or
361 foreach my $menu (@menus) {
363 package_depends
($a, $b) or
364 ($a->{name
} cmp $b->{name
})
366 if ($menu ne 'undef') {
367 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
368 print "menu \"$menu\"\n";
370 foreach my $pkg (@pkgs) {
371 my $title = $pkg->{name
};
372 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
374 $title .= ("." x
$c). " ". $pkg->{title
};
377 $pkg->{menu
} and print "menu";
378 print "config PACKAGE_".$pkg->{name
}."\n";
379 print "\t\ttristate \"$title\"\n";
380 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
381 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
382 print "\t\tdefault $default\n";
384 foreach my $depend (@
{$pkg->{depends
}}) {
386 $depend =~ s/^([@\+]+)//;
390 if ($vdep = $package{$depend}->{vdepends
}) {
391 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
393 $flags =~ /@/ or $depend = "PACKAGE_$depend";
394 $flags =~ /\+/ and $m = "select";
396 print "\t\t$m $depend\n";
399 print $pkg->{description
};
402 $pkg->{config
} and print $pkg->{config
}."\n";
404 if ($menu ne 'undef') {
406 $menu_dep{$menu} and print "endif\n";
411 undef $category{$cat};
414 sub gen_package_config
() {
415 parse_package_metadata
();
416 print_package_config_category
'Base system';
417 foreach my $cat (keys %category) {
418 print_package_config_category
$cat;
422 sub parse_command
() {
423 my $cmd = shift @ARGV;
425 /^target_mk$/ and return gen_target_mk
();
426 /^target_config$/ and return gen_target_config
();
427 /^package_config$/ and return gen_package_config
();
431 $0 target_mk [file] Target metadata in makefile format
432 $0 target_config [file] Target metadata in Kconfig format
433 $0 package_config [file] Package metadata in Kconfig format