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";
107 foreach my $dep (@{$target->{depends}}) {
108 my $mode = "depends on";
112 $dep =~ /^([@\+\-]+)(.+)$/;
116 next if $name =~ /:/;
117 $flags =~ /-/ and $mode = "deselect";
118 $flags =~ /\+/ and $mode = "select";
119 $flags =~ /@/ and $confstr .= "\t$mode $name\n";
121 $confstr .= "$help\n\n";
125 sub merge_package_lists($$) {
131 foreach my $pkg (@$list1, @$list2) {
134 foreach my $pkg (keys %pkgs) {
135 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
140 sub gen_target_config() {
141 my $file = shift @ARGV;
142 my @target = parse_target_metadata($file);
145 my @target_sort = sort {
146 target_name($a) cmp target_name($b);
152 prompt "Target System"
153 default TARGET_ar71xx
158 foreach my $target (@target_sort) {
159 next if $target->{subtarget};
160 print_target($target);
167 prompt "Subtarget" if HAS_SUBTARGETS
169 foreach my $target (@target) {
170 next unless $target->{def_subtarget};
172 default TARGET_$target->{conf}_$target->{def_subtarget} if TARGET_$target->{conf}
178 foreach my $target (@target) {
179 next unless $target->{subtarget};
180 print_target($target);
187 prompt "Target Profile"
191 foreach my $target (@target) {
192 my $profiles = $target->{profiles};
193 foreach my $profile (@{$target->{profiles}}) {
195 config TARGET_$target->{conf}_$profile->{id}
196 bool "$profile->{name}"
197 depends on TARGET_$target->{conf}
199 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
200 foreach my $pkg (@pkglist) {
201 print "\tselect DEFAULT_$pkg\n";
204 my $help = $profile->{desc};
205 if ($help =~ /\w+/) {
206 $help =~ s/^\s*/\t /mg;
207 $help = "\thelp\n$help";
218 config HAS_SUBTARGETS
225 foreach my $target (@target) {
226 $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
229 config TARGET_SUBTARGET
231 default "generic" if !HAS_SUBTARGETS
235 foreach my $target (@target) {
236 foreach my $subtarget (@{$target->{subtargets}}) {
237 print "\t\tdefault \"$subtarget\" if TARGET_".$target->{conf}."_$subtarget\n";
241 config TARGET_PROFILE
244 foreach my $target (@target) {
245 my $profiles = $target->{profiles};
246 foreach my $profile (@$profiles) {
247 print "\tdefault \"$profile->{id}\" if TARGET_$target->{conf}_$profile->{id}\n";
253 config TARGET_ARCH_PACKAGES
257 foreach my $target (@target) {
258 next if @{$target->{subtargets}} > 0;
259 print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
263 config DEFAULT_TARGET_OPTIMIZATION
266 foreach my $target (@target) {
267 next if @{$target->{subtargets}} > 0;
268 print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
270 print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
276 foreach my $target (@target) {
277 next if @{$target->{subtargets}} > 0;
278 print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
280 print "\tdefault \"\"\n";
283 foreach my $target (@target) {
284 my $v = kver($target->{version});
294 foreach my $def (sort keys %defaults) {
295 print "\tconfig DEFAULT_".$def."\n";
296 print "\t\tbool\n\n";
300 sub gen_profile_mk() {
301 my $file = shift @ARGV;
302 my $target = shift @ARGV;
303 my @targets = parse_target_metadata($file);
304 foreach my $cur (@targets) {
305 next unless $cur->{id} eq $target;
306 print "PROFILE_NAMES = ".join(" ", map { $_->{id} } @{$cur->{profiles}})."\n";
307 foreach my $profile (@{$cur->{profiles}}) {
308 print $profile->{id}.'_NAME:='.$profile->{name}."\n";
309 print $profile->{id}.'_PACKAGES:='.join(' ', @{$profile->{packages}})."\n";
314 sub parse_command() {
315 GetOptions("ignore=s", \@ignore);
316 my $cmd = shift @ARGV;
318 /^config$/ and return gen_target_config();
319 /^profile_mk$/ and return gen_profile_mk();
323 $0 config [file] Target metadata in Kconfig format
324 $0 profile_mk [file] [target] Profile metadata in makefile format