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";
42 /virtio/ and $ret .= "\tselect VIRTIO_SUPPORT\n";
49 my $parent = $target->{parent};
51 return $target->{parent}->{name}." - ".$target->{name};
53 return $target->{name};
60 if (substr($v,0,2) eq "2_") {
61 $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
63 $v =~ /(\d+_\d+)(_\d+)?/ and $v = $1;
70 my $features = target_config_features(@{$target->{features}});
71 my $help = $target->{desc};
77 $help =~ s/^\s*/\t /mg;
78 $help = "\thelp\n$help";
83 my $v = kver($target->{version});
84 if (@{$target->{subtargets}} == 0) {
86 config TARGET_$target->{conf}
87 bool "$target->{name}"
93 config TARGET_$target->{conf}
94 bool "$target->{name}"
97 if ($target->{subtarget}) {
98 $confstr .= "\tdepends on TARGET_$target->{boardconf}\n";
100 if (@{$target->{subtargets}} > 0) {
101 $confstr .= "\tselect HAS_SUBTARGETS\n";
102 grep { /broken/ } @{$target->{features}} and $confstr .= "\tdepends on BROKEN\n";
104 $confstr .= $features;
105 if ($target->{arch} =~ /\w/) {
106 $confstr .= "\tselect $target->{arch}\n";
108 if ($target->{has_devices}) {
109 $confstr .= "\tselect HAS_DEVICES\n";
113 foreach my $dep (@{$target->{depends}}) {
114 my $mode = "depends on";
118 $dep =~ /^([@\+\-]+)(.+)$/;
122 next if $name =~ /:/;
123 $flags =~ /-/ and $mode = "deselect";
124 $flags =~ /\+/ and $mode = "select";
125 $flags =~ /@/ and $confstr .= "\t$mode $name\n";
127 $confstr .= "$help\n\n";
131 sub merge_package_lists($$) {
137 foreach my $pkg (@$list1, @$list2) {
140 foreach my $pkg (keys %pkgs) {
141 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
146 sub gen_target_config() {
147 my $file = shift @ARGV;
148 my @target = parse_target_metadata($file);
151 my @target_sort = sort {
152 target_name($a) cmp target_name($b);
155 foreach my $target (@target_sort) {
156 next if @{$target->{subtargets}} > 0;
158 config DEFAULT_TARGET_$target->{conf}
160 depends on TARGET_PER_DEVICE_ROOTFS
161 default y if TARGET_$target->{conf}
163 foreach my $pkg (@{$target->{packages}}) {
164 print "\tselect DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
170 prompt "Target System"
171 default TARGET_ar71xx
176 foreach my $target (@target_sort) {
177 next if $target->{subtarget};
178 print_target($target);
185 prompt "Subtarget" if HAS_SUBTARGETS
187 foreach my $target (@target) {
188 next unless $target->{def_subtarget};
190 default TARGET_$target->{conf}_$target->{def_subtarget} if TARGET_$target->{conf}
196 foreach my $target (@target) {
197 next unless $target->{subtarget};
198 print_target($target);
205 prompt "Target Profile"
206 default TARGET_MULTI_PROFILE if BUILDBOT
209 foreach my $target (@target) {
210 my $profile = $target->{profiles}->[0];
213 default TARGET_$target->{conf}_$profile->{id} if TARGET_$target->{conf} && !BUILDBOT
219 config TARGET_MULTI_PROFILE
220 bool "Multiple devices"
221 depends on HAS_DEVICES
223 Instead of only building a single image, or all images, this allows you
224 to select images to be built for multiple devices in one build.
228 foreach my $target (@target) {
229 my $profiles = $target->{profiles};
230 foreach my $profile (@{$target->{profiles}}) {
232 config TARGET_$target->{conf}_$profile->{id}
233 bool "$profile->{name}"
234 depends on TARGET_$target->{conf}
236 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
237 foreach my $pkg (@pkglist) {
238 print "\tselect DEFAULT_$pkg\n";
241 my $help = $profile->{desc};
242 if ($help =~ /\w+/) {
243 $help =~ s/^\s*/\t /mg;
244 $help = "\thelp\n$help";
255 menu "Target Devices"
256 depends on TARGET_MULTI_PROFILE
258 config TARGET_ALL_PROFILES
259 bool "Enable all profiles by default"
262 config TARGET_PER_DEVICE_ROOTFS
263 bool "Use a per-device root filesystem that adds profile packages"
266 When disabled, all device packages from all selected devices
267 will be included in all images by default. (Marked as <*>) You will
268 still be able to manually deselect any/all packages.
269 When enabled, each device builds it's own image, including only the
270 profile packages for that device. (Marked as {M}) You will be able
271 to change a package to included in all images by marking as {*}, but
272 will not be able to disable a profile package completely.
274 To get the most use of this setting, you must set in a .config stub
275 before calling "make defconfig". Selecting TARGET_MULTI_PROFILE and
276 then manually selecting (via menuconfig for instance) this option
277 will have pre-defaulted all profile packages to included, making this
278 option appear to have had no effect.
281 foreach my $target (@target) {
282 my @profiles = sort {
286 } @{$target->{profiles}};
287 foreach my $profile (@profiles) {
288 next unless $profile->{id} =~ /^DEVICE_/;
290 menuconfig TARGET_DEVICE_$target->{conf}_$profile->{id}
291 bool "$profile->{name}"
292 depends on TARGET_$target->{conf}
293 default y if TARGET_ALL_PROFILES
295 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
296 foreach my $pkg (@pkglist) {
297 print "\tselect DEFAULT_$pkg if !TARGET_PER_DEVICE_ROOTFS\n";
298 print "\tselect MODULE_DEFAULT_$pkg if TARGET_PER_DEVICE_ROOTFS\n";
305 config TARGET_DEVICE_PACKAGES_$target->{conf}_$profile->{id}
306 string "$profile->{name} additional packages"
308 depends on TARGET_PER_DEVICE_ROOTFS
309 depends on TARGET_DEVICE_$target->{conf}_$profile->{id}
319 config HAS_SUBTARGETS
329 foreach my $target (@target) {
330 $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
333 config TARGET_SUBTARGET
335 default "generic" if !HAS_SUBTARGETS
339 foreach my $target (@target) {
340 foreach my $subtarget (@{$target->{subtargets}}) {
341 print "\t\tdefault \"$subtarget\" if TARGET_".$target->{conf}."_$subtarget\n";
345 config TARGET_PROFILE
348 foreach my $target (@target) {
349 my $profiles = $target->{profiles};
350 foreach my $profile (@$profiles) {
351 print "\tdefault \"$profile->{id}\" if TARGET_$target->{conf}_$profile->{id}\n";
357 config TARGET_ARCH_PACKAGES
361 foreach my $target (@target) {
362 next if @{$target->{subtargets}} > 0;
363 print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
367 config DEFAULT_TARGET_OPTIMIZATION
370 foreach my $target (@target) {
371 next if @{$target->{subtargets}} > 0;
372 print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
374 print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
380 foreach my $target (@target) {
381 next if @{$target->{subtargets}} > 0;
382 print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
384 print "\tdefault \"\"\n";
387 foreach my $target (@target) {
388 my $v = kver($target->{version});
398 foreach my $def (sort keys %defaults) {
403 config MODULE_DEFAULT_$def
405 depends on TARGET_PER_DEVICE_ROOTFS
407 default m if DEFAULT_$def
414 sub gen_profile_mk() {
415 my $file = shift @ARGV;
416 my $target = shift @ARGV;
417 my @targets = parse_target_metadata($file);
418 foreach my $cur (@targets) {
419 next unless $cur->{id} eq $target;
420 print "PROFILE_NAMES = ".join(" ", map { $_->{id} } @{$cur->{profiles}})."\n";
421 foreach my $profile (@{$cur->{profiles}}) {
422 print $profile->{id}.'_NAME:='.$profile->{name}."\n";
423 print $profile->{id}.'_PACKAGES:='.join(' ', @{$profile->{packages}})."\n";
428 sub parse_command() {
429 GetOptions("ignore=s", \@ignore);
430 my $cmd = shift @ARGV;
432 /^config$/ and return gen_target_config();
433 /^profile_mk$/ and return gen_profile_mk();
437 $0 config [file] Target metadata in Kconfig format
438 $0 profile_mk [file] [target] Profile metadata in makefile format