3 use lib "$FindBin::Bin";
8 sub target_config_features(@) {
11 while ($_ = shift @_) {
12 /arm_v(\w+)/ and $ret .= "\tselect arm_v$1\n";
13 /broken/ and $ret .= "\tdepends on BROKEN\n";
14 /audio/ and $ret .= "\tselect AUDIO_SUPPORT\n";
15 /display/ and $ret .= "\tselect DISPLAY_SUPPORT\n";
16 /dt/ and $ret .= "\tselect USES_DEVICETREE\n";
17 /gpio/ and $ret .= "\tselect GPIO_SUPPORT\n";
18 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
19 /pcie/ and $ret .= "\tselect PCIE_SUPPORT\n";
20 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
21 /usbgadget/ and $ret .= "\tselect USB_GADGET_SUPPORT\n";
22 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
23 /rtc/ and $ret .= "\tselect RTC_SUPPORT\n";
24 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
25 /jffs2$/ and $ret .= "\tselect USES_JFFS2\n";
26 /jffs2_nand/ and $ret .= "\tselect USES_JFFS2_NAND\n";
27 /ext4/ and $ret .= "\tselect USES_EXT4\n";
28 /targz/ and $ret .= "\tselect USES_TARGZ\n";
29 /cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n";
30 /ubifs/ and $ret .= "\tselect USES_UBIFS\n";
31 /fpu/ and $ret .= "\tselect HAS_FPU\n";
32 /spe_fpu/ and $ret .= "\tselect HAS_SPE_FPU\n";
33 /ramdisk/ and $ret .= "\tselect USES_INITRAMFS\n";
34 /powerpc64/ and $ret .= "\tselect powerpc64\n";
35 /nommu/ and $ret .= "\tselect NOMMU\n";
36 /mips16/ and $ret .= "\tselect HAS_MIPS16\n";
37 /rfkill/ and $ret .= "\tselect RFKILL_SUPPORT\n";
38 /low_mem/ and $ret .= "\tselect LOW_MEMORY_FOOTPRINT\n";
39 /nand/ and $ret .= "\tselect NAND_SUPPORT\n";
46 my $parent = $target->{parent};
48 return $target->{parent}->{name}." - ".$target->{name};
50 return $target->{name};
57 if (substr($v,0,2) eq "2_") {
58 $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
60 $v =~ /(\d+_\d+)(_\d+)?/ and $v = $1;
67 my $features = target_config_features(@{$target->{features}});
68 my $help = $target->{desc};
74 $help =~ s/^\s*/\t /mg;
75 $help = "\thelp\n$help";
80 my $v = kver($target->{version});
81 if (@{$target->{subtargets}} == 0) {
83 config TARGET_$target->{conf}
84 bool "$target->{name}"
90 config TARGET_$target->{conf}
91 bool "$target->{name}"
94 if ($target->{subtarget}) {
95 $confstr .= "\tdepends on TARGET_$target->{boardconf}\n";
97 if (@{$target->{subtargets}} > 0) {
98 $confstr .= "\tselect HAS_SUBTARGETS\n";
99 grep { /broken/ } @{$target->{features}} and $confstr .= "\tdepends on BROKEN\n";
101 $confstr .= $features;
102 if ($target->{arch} =~ /\w/) {
103 $confstr .= "\tselect $target->{arch}\n";
105 if ($target->{has_devices}) {
106 $confstr .= "\tselect HAS_DEVICES\n";
110 foreach my $dep (@{$target->{depends}}) {
111 my $mode = "depends on";
115 $dep =~ /^([@\+\-]+)(.+)$/;
119 next if $name =~ /:/;
120 $flags =~ /-/ and $mode = "deselect";
121 $flags =~ /\+/ and $mode = "select";
122 $flags =~ /@/ and $confstr .= "\t$mode $name\n";
124 $confstr .= "$help\n\n";
128 sub merge_package_lists($$) {
134 foreach my $pkg (@$list1, @$list2) {
137 foreach my $pkg (keys %pkgs) {
138 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
143 sub gen_target_config() {
144 my $file = shift @ARGV;
145 my @target = parse_target_metadata($file);
148 my @target_sort = sort {
149 target_name($a) cmp target_name($b);
155 prompt "Target System"
156 default TARGET_ar71xx
161 foreach my $target (@target_sort) {
162 next if $target->{subtarget};
163 print_target($target);
170 prompt "Subtarget" if HAS_SUBTARGETS
172 foreach my $target (@target) {
173 next unless $target->{def_subtarget};
175 default TARGET_$target->{conf}_$target->{def_subtarget} if TARGET_$target->{conf}
181 foreach my $target (@target) {
182 next unless $target->{subtarget};
183 print_target($target);
190 prompt "Target Profile"
193 foreach my $target (@target) {
194 my $profile = $target->{profiles}->[0];
197 default TARGET_$target->{conf}_$profile->{id} if TARGET_$target->{conf}
203 config TARGET_MULTI_PROFILE
204 bool "Multiple devices"
205 depends on HAS_DEVICES
209 foreach my $target (@target) {
210 my $profiles = $target->{profiles};
211 foreach my $profile (@{$target->{profiles}}) {
213 config TARGET_$target->{conf}_$profile->{id}
214 bool "$profile->{name}"
215 depends on TARGET_$target->{conf}
217 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
218 foreach my $pkg (@pkglist) {
219 print "\tselect DEFAULT_$pkg\n";
222 my $help = $profile->{desc};
223 if ($help =~ /\w+/) {
224 $help =~ s/^\s*/\t /mg;
225 $help = "\thelp\n$help";
236 menu "Target Devices"
237 depends on TARGET_MULTI_PROFILE
240 foreach my $target (@target) {
241 my $profiles = $target->{profiles};
242 foreach my $profile (@{$target->{profiles}}) {
243 next unless $profile->{id} =~ /^DEVICE_/;
245 config TARGET_DEVICE_$target->{conf}_$profile->{id}
246 bool "$profile->{name}"
247 depends on TARGET_$target->{conf}
249 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
250 foreach my $pkg (@pkglist) {
251 print "\tselect DEFAULT_$pkg\n";
261 config HAS_SUBTARGETS
271 foreach my $target (@target) {
272 $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
275 config TARGET_SUBTARGET
277 default "generic" if !HAS_SUBTARGETS
281 foreach my $target (@target) {
282 foreach my $subtarget (@{$target->{subtargets}}) {
283 print "\t\tdefault \"$subtarget\" if TARGET_".$target->{conf}."_$subtarget\n";
287 config TARGET_PROFILE
290 foreach my $target (@target) {
291 my $profiles = $target->{profiles};
292 foreach my $profile (@$profiles) {
293 print "\tdefault \"$profile->{id}\" if TARGET_$target->{conf}_$profile->{id}\n";
299 config TARGET_ARCH_PACKAGES
303 foreach my $target (@target) {
304 next if @{$target->{subtargets}} > 0;
305 print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
309 config DEFAULT_TARGET_OPTIMIZATION
312 foreach my $target (@target) {
313 next if @{$target->{subtargets}} > 0;
314 print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
316 print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
322 foreach my $target (@target) {
323 next if @{$target->{subtargets}} > 0;
324 print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
326 print "\tdefault \"\"\n";
329 foreach my $target (@target) {
330 my $v = kver($target->{version});
340 foreach my $def (sort keys %defaults) {
341 print "\tconfig DEFAULT_".$def."\n";
342 print "\t\tbool\n\n";
346 sub gen_profile_mk() {
347 my $file = shift @ARGV;
348 my $target = shift @ARGV;
349 my @targets = parse_target_metadata($file);
350 foreach my $cur (@targets) {
351 next unless $cur->{id} eq $target;
352 print "PROFILE_NAMES = ".join(" ", map { $_->{id} } @{$cur->{profiles}})."\n";
353 foreach my $profile (@{$cur->{profiles}}) {
354 print $profile->{id}.'_NAME:='.$profile->{name}."\n";
355 print $profile->{id}.'_PACKAGES:='.join(' ', @{$profile->{packages}})."\n";
360 sub parse_command() {
361 GetOptions("ignore=s", \@ignore);
362 my $cmd = shift @ARGV;
364 /^config$/ and return gen_target_config();
365 /^profile_mk$/ and return gen_profile_mk();
369 $0 config [file] Target metadata in Kconfig format
370 $0 profile_mk [file] [target] Profile metadata in makefile format