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 /minor/ and $ret .= "\tselect USES_MINOR\n";
31 /ubifs/ and $ret .= "\tselect USES_UBIFS\n";
32 /fpu/ and $ret .= "\tselect HAS_FPU\n";
33 /spe_fpu/ and $ret .= "\tselect HAS_SPE_FPU\n";
34 /ramdisk/ and $ret .= "\tselect USES_INITRAMFS\n";
35 /powerpc64/ and $ret .= "\tselect powerpc64\n";
36 /nommu/ and $ret .= "\tselect NOMMU\n";
37 /mips16/ and $ret .= "\tselect HAS_MIPS16\n";
38 /rfkill/ and $ret .= "\tselect RFKILL_SUPPORT\n";
39 /low_mem/ and $ret .= "\tselect LOW_MEMORY_FOOTPRINT\n";
40 /small_flash/ and $ret .= "\tselect SMALL_FLASH\n";
41 /nand/ and $ret .= "\tselect NAND_SUPPORT\n";
48 my $parent = $target->{parent};
50 return $target->{parent}->{name}." - ".$target->{name};
52 return $target->{name};
59 if (substr($v,0,2) eq "2_") {
60 $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
62 $v =~ /(\d+_\d+)(_\d+)?/ and $v = $1;
69 my $features = target_config_features(@{$target->{features}});
70 my $help = $target->{desc};
76 $help =~ s/^\s*/\t /mg;
77 $help = "\thelp\n$help";
82 my $v = kver($target->{version});
83 if (@{$target->{subtargets}} == 0) {
85 config TARGET_$target->{conf}
86 bool "$target->{name}"
92 config TARGET_$target->{conf}
93 bool "$target->{name}"
96 if ($target->{subtarget}) {
97 $confstr .= "\tdepends on TARGET_$target->{boardconf}\n";
99 if (@{$target->{subtargets}} > 0) {
100 $confstr .= "\tselect HAS_SUBTARGETS\n";
101 grep { /broken/ } @{$target->{features}} and $confstr .= "\tdepends on BROKEN\n";
103 $confstr .= $features;
104 if ($target->{arch} =~ /\w/) {
105 $confstr .= "\tselect $target->{arch}\n";
107 if ($target->{has_devices}) {
108 $confstr .= "\tselect HAS_DEVICES\n";
112 foreach my $dep (@{$target->{depends}}) {
113 my $mode = "depends on";
117 $dep =~ /^([@\+\-]+)(.+)$/;
121 next if $name =~ /:/;
122 $flags =~ /-/ and $mode = "deselect";
123 $flags =~ /\+/ and $mode = "select";
124 $flags =~ /@/ and $confstr .= "\t$mode $name\n";
126 $confstr .= "$help\n\n";
130 sub merge_package_lists($$) {
136 foreach my $pkg (@$list1, @$list2) {
139 foreach my $pkg (keys %pkgs) {
140 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
145 sub gen_target_config() {
146 my $file = shift @ARGV;
147 my @target = parse_target_metadata($file);
150 my @target_sort = sort {
151 target_name($a) cmp target_name($b);
154 foreach my $target (@target_sort) {
155 next if @{$target->{subtargets}} > 0;
157 config DEFAULT_TARGET_$target->{conf}
159 depends on TARGET_PER_DEVICE_ROOTFS
160 default y if TARGET_$target->{conf}
162 foreach my $pkg (@{$target->{packages}}) {
163 print "\tselect DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
169 prompt "Target System"
170 default TARGET_ar71xx
175 foreach my $target (@target_sort) {
176 next if $target->{subtarget};
177 print_target($target);
184 prompt "Subtarget" if HAS_SUBTARGETS
186 foreach my $target (@target) {
187 next unless $target->{def_subtarget};
189 default TARGET_$target->{conf}_$target->{def_subtarget} if TARGET_$target->{conf}
195 foreach my $target (@target) {
196 next unless $target->{subtarget};
197 print_target($target);
204 prompt "Target Profile"
207 foreach my $target (@target) {
208 my $profile = $target->{profiles}->[0];
211 default TARGET_$target->{conf}_$profile->{id} if TARGET_$target->{conf}
217 config TARGET_MULTI_PROFILE
218 bool "Multiple devices"
219 depends on HAS_DEVICES
223 foreach my $target (@target) {
224 my $profiles = $target->{profiles};
225 foreach my $profile (@{$target->{profiles}}) {
227 config TARGET_$target->{conf}_$profile->{id}
228 bool "$profile->{name}"
229 depends on TARGET_$target->{conf}
231 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
232 foreach my $pkg (@pkglist) {
233 print "\tselect DEFAULT_$pkg\n";
236 my $help = $profile->{desc};
237 if ($help =~ /\w+/) {
238 $help =~ s/^\s*/\t /mg;
239 $help = "\thelp\n$help";
250 menu "Target Devices"
251 depends on TARGET_MULTI_PROFILE
253 config TARGET_ALL_PROFILES
254 bool "Enable all profiles by default"
256 config TARGET_PER_DEVICE_ROOTFS
257 bool "Use a per-device root filesystem that adds profile packages"
260 foreach my $target (@target) {
261 my $profiles = $target->{profiles};
262 foreach my $profile (@{$target->{profiles}}) {
263 next unless $profile->{id} =~ /^DEVICE_/;
265 config TARGET_DEVICE_$target->{conf}_$profile->{id}
266 bool "$profile->{name}"
267 depends on TARGET_$target->{conf}
268 default y if TARGET_ALL_PROFILES
270 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
271 foreach my $pkg (@pkglist) {
272 print "\tselect DEFAULT_$pkg if !TARGET_PER_DEVICE_ROOTFS\n";
273 print "\tselect MODULE_DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
283 config HAS_SUBTARGETS
293 foreach my $target (@target) {
294 $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
297 config TARGET_SUBTARGET
299 default "generic" if !HAS_SUBTARGETS
303 foreach my $target (@target) {
304 foreach my $subtarget (@{$target->{subtargets}}) {
305 print "\t\tdefault \"$subtarget\" if TARGET_".$target->{conf}."_$subtarget\n";
309 config TARGET_PROFILE
312 foreach my $target (@target) {
313 my $profiles = $target->{profiles};
314 foreach my $profile (@$profiles) {
315 print "\tdefault \"$profile->{id}\" if TARGET_$target->{conf}_$profile->{id}\n";
321 config TARGET_ARCH_PACKAGES
325 foreach my $target (@target) {
326 next if @{$target->{subtargets}} > 0;
327 print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
331 config DEFAULT_TARGET_OPTIMIZATION
334 foreach my $target (@target) {
335 next if @{$target->{subtargets}} > 0;
336 print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
338 print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
344 foreach my $target (@target) {
345 next if @{$target->{subtargets}} > 0;
346 print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
348 print "\tdefault \"\"\n";
351 foreach my $target (@target) {
352 my $v = kver($target->{version});
362 foreach my $def (sort keys %defaults) {
367 config MODULE_DEFAULT_$def
369 depends on TARGET_PER_DEVICE_ROOTFS
371 default m if DEFAULT_$def
378 sub gen_profile_mk() {
379 my $file = shift @ARGV;
380 my $target = shift @ARGV;
381 my @targets = parse_target_metadata($file);
382 foreach my $cur (@targets) {
383 next unless $cur->{id} eq $target;
384 print "PROFILE_NAMES = ".join(" ", map { $_->{id} } @{$cur->{profiles}})."\n";
385 foreach my $profile (@{$cur->{profiles}}) {
386 print $profile->{id}.'_NAME:='.$profile->{name}."\n";
387 print $profile->{id}.'_PACKAGES:='.join(' ', @{$profile->{packages}})."\n";
392 sub parse_command() {
393 GetOptions("ignore=s", \@ignore);
394 my $cmd = shift @ARGV;
396 /^config$/ and return gen_target_config();
397 /^profile_mk$/ and return gen_profile_mk();
401 $0 config [file] Target metadata in Kconfig format
402 $0 profile_mk [file] [target] Profile metadata in makefile format