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;
56 /^Target-Profile-Kconfig:/ and $profile->{kconfig
} = 1;
58 foreach my $target (@target) {
59 @
{$target->{profiles
}} > 0 or $target->{profiles
} = [
70 sub parse_package_metadata
() {
76 /^Source-Makefile: \s*(.+\/([^\
/]+)\/Makefile
)\s
*$/ and do {
81 /^Package: \s*(.+)\s*$/ and do {
84 $pkg->{makefile
} = $makefile;
86 $pkg->{default} = "m if ALL";
89 /^Version: \s*(.+)\s*$/ and $pkg->{version
} = $1;
90 /^Title: \s*(.+)\s*$/ and $pkg->{title
} = $1;
91 /^Menu: \s*(.+)\s*$/ and $pkg->{menu
} = $1;
92 /^Submenu: \s*(.+)\s*$/ and $pkg->{submenu
} = $1;
93 /^Submenu-Depends: \s*(.+)\s*$/ and $pkg->{submenudep
} = $1;
94 /^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
95 /^Provides: \s*(.+)\s*$/ and do {
96 my @vpkg = split /\s+/, $1;
97 foreach my $vpkg (@vpkg) {
98 $package{$vpkg} or $package{$vpkg} = { vdepends
=> [] };
99 push @
{$package{$vpkg}->{vdepends
}}, $pkg->{name
};
102 /^Depends: \s*(.+)\s*$/ and do {
103 my @dep = split /\s+/, $1;
104 $pkg->{depends
} = \
@dep;
106 /^Category: \s*(.+)\s*$/ and do {
107 $pkg->{category
} = $1;
108 defined $category{$1} or $category{$1} = {};
109 defined $category{$1}->{$src} or $category{$1}->{$src} = [];
110 push @
{$category{$1}->{$src}}, $pkg;
112 /^Description: \s*(.*)\s*$/ and do {
113 my $desc = "\t\t$1\n\n";
116 last if $line =~ /^@@/;
117 $desc .= "\t\t$line";
119 $pkg->{description
} = $desc;
121 /^Config: \s*(.*)\s*$/ and do {
125 last if $line =~ /^@@/;
128 $pkg->{config
} = $conf;
135 sub gen_target_mk
() {
136 my @target = parse_target_metadata
();
139 $a->{id
} cmp $b->{id
}
142 foreach my $target (@target) {
143 my ($profiles_def, $profiles_eval);
144 my $conf = uc $target->{kernel
}.'_'.$target->{board
};
147 foreach my $profile (@
{$target->{profiles
}}) {
149 define Profile/$conf\_$profile->{id}
151 NAME:=$profile->{name}
152 PACKAGES:=".join(" ", @
{$profile->{packages
}})."\n";
153 $profile->{kconfig
} and $profiles_def .= " KCONFIG:=1\n";
154 $profiles_def .= " endef";
156 \$(eval \$(call AddProfile,$conf\_$profile->{id}))"
159 ifeq (\$(CONFIG_LINUX_$conf),y)
161 KERNEL:=$target->{kernel}
162 BOARD:=$target->{board}
163 BOARDNAME:=$target->{name}
164 LINUX_VERSION:=$target->{version}
165 LINUX_RELEASE:=$target->{release}
166 LINUX_KARCH:=$target->{karch}
167 DEFAULT_PACKAGES:=".join(" ", @
{$target->{packages
}})."
173 print "\$(eval \$(call Target))\n";
176 sub target_config_features
(@
) {
179 while ($_ = shift @_) {
180 /broken/ and $ret .= "\tdepends BROKEN\n";
181 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
182 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
183 /atm/ and $ret .= "\tselect ATM_SUPPORT\n";
184 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
185 /video/ and $ret .= "\tselect VIDEO_SUPPORT\n";
186 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
187 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
188 /ext2/ and $ret .= "\tselect USES_EXT2\n";
194 sub gen_target_config
() {
195 my @target = parse_target_metadata
();
198 $a->{name
} cmp $b->{name
}
204 prompt "Target System"
205 default LINUX_2_4_BRCM
209 foreach my $target (@target) {
210 my $features = target_config_features
(@
{$target->{features
}});
211 my $help = $target->{desc
};
212 my $kernel = $target->{kernel
};
217 if ($help =~ /\w+/) {
218 $help =~ s/^\s*/\t /mg;
219 $help = "\thelp\n$help";
225 config LINUX_$target->{conf}
226 bool "$target->{name}"
227 select $target->{arch}
238 bool "UNSUPPORTED little-endian arm platform"
243 config LINUX_2_6_CRIS
244 bool "UNSUPPORTED cris platform"
249 config LINUX_2_6_M68K
250 bool "UNSUPPORTED m68k platform"
256 bool "UNSUPPORTED little-endian sh3 platform"
261 config LINUX_2_6_SH3EB
262 bool "UNSUPPORTED big-endian sh3 platform"
268 bool "UNSUPPORTED little-endian sh4 platform"
273 config LINUX_2_6_SH4EB
274 bool "UNSUPPORTED big-endian sh4 platform"
279 config LINUX_2_6_SPARC
280 bool "UNSUPPORTED sparc platform"
290 prompt "Target Profile"
294 foreach my $target (@target) {
295 my $profiles = $target->{profiles
};
297 foreach my $profile (@
$profiles) {
299 config LINUX_$target->{conf}_$profile->{id}
300 bool "$profile->{name}"
301 depends LINUX_$target->{conf}
303 $profile->{kconfig
} and print "\tselect PROFILE_KCONFIG\n";
305 foreach my $pkg (@
{$target->{packages
}}, @
{$profile->{packages
}}) {
308 foreach my $pkg (keys %pkgs) {
309 print "\tselect DEFAULT_$pkg\n" unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
318 sub find_package_dep
($$) {
321 my $deps = ($pkg->{vdepends
} or $pkg->{depends
});
323 return 0 unless defined $deps;
324 foreach my $dep (@
{$deps}) {
325 return 1 if $dep eq $name;
326 return 1 if ($package{$dep} and (find_package_dep
($package{$dep},$name) == 1));
331 sub package_depends
($$) {
336 return 0 if ($a->{submenu
} ne $b->{submenu
});
337 if (find_package_dep
($a, $b->{name
}) == 1) {
339 } elsif (find_package_dep
($b, $a->{name
}) == 1) {
347 sub mconf_depends
($$) {
349 my $only_dep = shift;
353 my @depends = @
$depends;
354 foreach my $depend (@depends) {
356 $depend =~ s/^([@\+]+)//;
360 if ($vdep = $package{$depend}->{vdepends
}) {
361 $depend = join("||", map { "PACKAGE_".$_ } @
$vdep);
363 $flags =~ /\+/ and do {
367 # Menuconfig will not treat 'select FOO' as a real dependency
368 # thus if FOO depends on other config options, these dependencies
369 # will not be checked. To fix this, we simply emit all of FOO's
370 # depends here as well.
371 $package{$depend} and $res .= mconf_depends
($package{$depend}->{depends
}, 1);
373 $flags =~ /@/ or $depend = "PACKAGE_$depend";
375 $res .= "\t\t$m $depend\n";
380 sub print_package_config_category
($) {
385 return unless $category{$cat};
387 print "menu \"$cat\"\n\n";
388 my %spkg = %{$category{$cat}};
390 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
391 foreach my $pkg (@
{$spkg{$spkg}}) {
392 my $menu = $pkg->{submenu
};
394 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep
};
398 $menus{$menu} or $menus{$menu} = [];
399 push @
{$menus{$menu}}, $pkg;
400 print "\tconfig DEFAULT_".$pkg->{name
}."\n";
401 print "\t\tbool\n\n";
405 ($a eq 'undef' ?
1 : 0) or
406 ($b eq 'undef' ?
-1 : 0) or
410 foreach my $menu (@menus) {
412 package_depends
($a, $b) or
413 ($a->{name
} cmp $b->{name
})
415 if ($menu ne 'undef') {
416 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
417 print "menu \"$menu\"\n";
419 foreach my $pkg (@pkgs) {
420 my $title = $pkg->{name
};
421 my $c = (72 - length($pkg->{name
}) - length($pkg->{title
}));
423 $title .= ("." x
$c). " ". $pkg->{title
};
426 $pkg->{menu
} and print "menu";
427 print "config PACKAGE_".$pkg->{name
}."\n";
428 print "\t\ttristate \"$title\"\n";
429 print "\t\tdefault y if DEFAULT_".$pkg->{name
}."\n";
430 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
431 print "\t\tdefault $default\n";
433 print mconf_depends
($pkg->{depends
}, 0);
435 print $pkg->{description
};
438 $pkg->{config
} and print $pkg->{config
}."\n";
440 if ($menu ne 'undef') {
442 $menu_dep{$menu} and print "endif\n";
447 undef $category{$cat};
450 sub gen_package_config
() {
451 parse_package_metadata
();
452 print_package_config_category
'Base system';
453 foreach my $cat (keys %category) {
454 print_package_config_category
$cat;
458 sub parse_command
() {
459 my $cmd = shift @ARGV;
461 /^target_mk$/ and return gen_target_mk
();
462 /^target_config$/ and return gen_target_config
();
463 /^package_config$/ and return gen_package_config
();
467 $0 target_mk [file] Target metadata in makefile format
468 $0 target_config [file] Target metadata in Kconfig format
469 $0 package_config [file] Package metadata in Kconfig format