metadata.pl: fix menuconfig code for package features
[openwrt/openwrt.git] / scripts / metadata.pl
1 #!/usr/bin/env perl
2 use FindBin;
3 use lib "$FindBin::Bin";
4 use strict;
5 use metadata;
6
7 my %board;
8
9 sub confstr($) {
10 my $conf = shift;
11 $conf =~ tr#/\.\-/#___#;
12 return $conf;
13 }
14
15 sub parse_target_metadata() {
16 my $file = shift @ARGV;
17 my ($target, @target, $profile);
18 my %target;
19
20 open FILE, "<$file" or do {
21 warn "Can't open file '$file': $!\n";
22 return;
23 };
24 while (<FILE>) {
25 chomp;
26 /^Target:\s*(.+)\s*$/ and do {
27 my $name = $1;
28 $target = {
29 id => $name,
30 board => $name,
31 boardconf => confstr($name),
32 conf => confstr($name),
33 profiles => [],
34 features => [],
35 depends => [],
36 subtargets => []
37 };
38 push @target, $target;
39 $target{$name} = $target;
40 if ($name =~ /([^\/]+)\/([^\/]+)/) {
41 push @{$target{$1}->{subtargets}}, $2;
42 $target->{board} = $1;
43 $target->{boardconf} = confstr($1);
44 $target->{subtarget} = 1;
45 $target->{parent} = $target{$1};
46 }
47 };
48 /^Target-Kernel:\s*(\d+\.\d+)\s*$/ and $target->{kernel} = $1;
49 /^Target-Name:\s*(.+)\s*$/ and $target->{name} = $1;
50 /^Target-Path:\s*(.+)\s*$/ and $target->{path} = $1;
51 /^Target-Arch:\s*(.+)\s*$/ and $target->{arch} = $1;
52 /^Target-Features:\s*(.+)\s*$/ and $target->{features} = [ split(/\s+/, $1) ];
53 /^Target-Depends:\s*(.+)\s*$/ and $target->{depends} = [ split(/\s+/, $1) ];
54 /^Target-Description:/ and $target->{desc} = get_multiline(*FILE);
55 /^Target-Optimization:\s*(.+)\s*$/ and $target->{cflags} = $1;
56 /^Linux-Version:\s*(.+)\s*$/ and $target->{version} = $1;
57 /^Linux-Release:\s*(.+)\s*$/ and $target->{release} = $1;
58 /^Linux-Kernel-Arch:\s*(.+)\s*$/ and $target->{karch} = $1;
59 /^Default-Packages:\s*(.+)\s*$/ and $target->{packages} = [ split(/\s+/, $1) ];
60 /^Target-Profile:\s*(.+)\s*$/ and do {
61 $profile = {
62 id => $1,
63 name => $1,
64 packages => []
65 };
66 push @{$target->{profiles}}, $profile;
67 };
68 /^Target-Profile-Name:\s*(.+)\s*$/ and $profile->{name} = $1;
69 /^Target-Profile-Packages:\s*(.*)\s*$/ and $profile->{packages} = [ split(/\s+/, $1) ];
70 /^Target-Profile-Description:\s*(.*)\s*/ and $profile->{desc} = get_multiline(*FILE);
71 /^Target-Profile-Config:/ and $profile->{config} = get_multiline(*FILE, "\t");
72 /^Target-Profile-Kconfig:/ and $profile->{kconfig} = 1;
73 }
74 close FILE;
75 foreach my $target (@target) {
76 next if @{$target->{subtargets}} > 0;
77 @{$target->{profiles}} > 0 or $target->{profiles} = [
78 {
79 id => 'Default',
80 name => 'Default',
81 packages => []
82 }
83 ];
84 }
85 return @target;
86 }
87
88 sub gen_kconfig_overrides() {
89 my %config;
90 my %kconfig;
91 my $package;
92 my $pkginfo = shift @ARGV;
93 my $cfgfile = shift @ARGV;
94
95 # parameter 2: build system config
96 open FILE, "<$cfgfile" or return;
97 while (<FILE>) {
98 /^(CONFIG_.+?)=(.+)$/ and $config{$1} = 1;
99 }
100 close FILE;
101
102 # parameter 1: package metadata
103 open FILE, "<$pkginfo" or return;
104 while (<FILE>) {
105 /^Package:\s*(.+?)\s*$/ and $package = $1;
106 /^Kernel-Config:\s*(.+?)\s*$/ and do {
107 my @config = split /\s+/, $1;
108 foreach my $config (@config) {
109 my $val = 'm';
110 my $override;
111 if ($config =~ /^(.+?)=(.+)$/) {
112 $config = $1;
113 $override = 1;
114 $val = $2;
115 }
116 if ($config{"CONFIG_PACKAGE_$package"} and ($config ne 'n')) {
117 $kconfig{$config} = $val;
118 } elsif (!$override) {
119 $kconfig{$config} or $kconfig{$config} = 'n';
120 }
121 }
122 };
123 };
124 close FILE;
125
126 foreach my $kconfig (sort keys %kconfig) {
127 if ($kconfig{$kconfig} eq 'n') {
128 print "# $kconfig is not set\n";
129 } else {
130 print "$kconfig=$kconfig{$kconfig}\n";
131 }
132 }
133 }
134
135 sub merge_package_lists($$) {
136 my $list1 = shift;
137 my $list2 = shift;
138 my @l = ();
139 my %pkgs;
140
141 foreach my $pkg (@$list1, @$list2) {
142 $pkgs{$pkg} = 1;
143 }
144 foreach my $pkg (keys %pkgs) {
145 push @l, $pkg unless ($pkg =~ /^-/ or $pkgs{"-$pkg"});
146 }
147 return sort(@l);
148 }
149
150 sub target_config_features(@) {
151 my $ret;
152
153 while ($_ = shift @_) {
154 /broken/ and $ret .= "\tdepends BROKEN\n";
155 /display/ and $ret .= "\tselect DISPLAY_SUPPORT\n";
156 /gpio/ and $ret .= "\tselect GPIO_SUPPORT\n";
157 /pci/ and $ret .= "\tselect PCI_SUPPORT\n";
158 /pcie/ and $ret .= "\tselect PCIE_SUPPORT\n";
159 /usb/ and $ret .= "\tselect USB_SUPPORT\n";
160 /pcmcia/ and $ret .= "\tselect PCMCIA_SUPPORT\n";
161 /squashfs/ and $ret .= "\tselect USES_SQUASHFS\n";
162 /jffs2/ and $ret .= "\tselect USES_JFFS2\n";
163 /ext2/ and $ret .= "\tselect USES_EXT2\n";
164 /tgz/ and $ret .= "\tselect USES_TGZ\n";
165 /cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n";
166 /fpu/ and $ret .= "\tselect HAS_FPU\n";
167 /ramdisk/ and $ret .= "\tselect USES_INITRAMFS\n";
168 /powerpc64/ and $ret .= "\tselect powerpc64\n";
169 /nommu/ and $ret .= "\tselect NOMMU\n";
170 }
171 return $ret;
172 }
173
174 sub target_name($) {
175 my $target = shift;
176 my $parent = $target->{parent};
177 if ($parent) {
178 return $target->{parent}->{name}." - ".$target->{name};
179 } else {
180 return $target->{name};
181 }
182 }
183
184 sub kver($) {
185 my $v = shift;
186 $v =~ tr/\./_/;
187 $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
188 return $v;
189 }
190
191 sub print_target($) {
192 my $target = shift;
193 my $features = target_config_features(@{$target->{features}});
194 my $help = $target->{desc};
195 my $kernel = $target->{kernel};
196 my $confstr;
197 $kernel =~ tr/./_/;
198
199 chomp $features;
200 $features .= "\n";
201 if ($help =~ /\w+/) {
202 $help =~ s/^\s*/\t /mg;
203 $help = "\thelp\n$help";
204 } else {
205 undef $help;
206 }
207
208 my $v = kver($target->{version});
209 if (@{$target->{subtargets}} == 0) {
210 $confstr = <<EOF;
211 config TARGET_$target->{conf}
212 bool "$target->{name}"
213 select LINUX_$kernel
214 select LINUX_$v
215 EOF
216 }
217 else {
218 $confstr = <<EOF;
219 config TARGET_$target->{conf}
220 bool "$target->{name}"
221 EOF
222 }
223 if ($target->{subtarget}) {
224 $confstr .= "\tdepends TARGET_$target->{boardconf}\n";
225 }
226 if (@{$target->{subtargets}} > 0) {
227 $confstr .= "\tselect HAS_SUBTARGETS\n";
228 }
229
230 if ($target->{arch} =~ /\w/) {
231 $confstr .= "\tselect $target->{arch}\n";
232 }
233 foreach my $dep (@{$target->{depends}}) {
234 my $mode = "depends";
235 my $flags;
236 my $name;
237
238 $dep =~ /^([@\+\-]+)(.+)$/;
239 $flags = $1;
240 $name = $2;
241
242 next if $name =~ /:/;
243 $flags =~ /-/ and $mode = "deselect";
244 $flags =~ /\+/ and $mode = "select";
245 $flags =~ /@/ and $confstr .= "\t$mode $name\n";
246 }
247 $confstr .= $features;
248 $confstr .= "$help\n\n";
249 print $confstr;
250 }
251
252 sub gen_target_config() {
253 my @target = parse_target_metadata();
254 my %defaults;
255
256 my @target_sort = sort {
257 target_name($a) cmp target_name($b);
258 } @target;
259
260
261 print <<EOF;
262 choice
263 prompt "Target System"
264 default TARGET_brcm_2_4
265 reset if !DEVEL
266
267 EOF
268
269 foreach my $target (@target_sort) {
270 next if $target->{subtarget};
271 print_target($target);
272 }
273
274 print <<EOF;
275 endchoice
276
277 choice
278 prompt "Subtarget" if HAS_SUBTARGETS
279
280 EOF
281 foreach my $target (@target) {
282 next unless $target->{subtarget};
283 print_target($target);
284 }
285
286 print <<EOF;
287 endchoice
288
289 choice
290 prompt "Target Profile"
291
292 EOF
293
294 foreach my $target (@target) {
295 my $profiles = $target->{profiles};
296
297 foreach my $profile (@$profiles) {
298 print <<EOF;
299 config TARGET_$target->{conf}_$profile->{id}
300 bool "$profile->{name}"
301 depends TARGET_$target->{conf}
302 $profile->{config}
303 EOF
304 $profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n";
305 my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
306 foreach my $pkg (@pkglist) {
307 print "\tselect DEFAULT_$pkg\n";
308 $defaults{$pkg} = 1;
309 }
310 my $help = $profile->{desc};
311 if ($help =~ /\w+/) {
312 $help =~ s/^\s*/\t /mg;
313 $help = "\thelp\n$help";
314 } else {
315 undef $help;
316 }
317 print "$help\n";
318 }
319 }
320
321 print <<EOF;
322 endchoice
323
324 config HAS_SUBTARGETS
325 bool
326
327 config TARGET_BOARD
328 string
329
330 EOF
331 foreach my $target (@target) {
332 $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
333 }
334 print <<EOF;
335
336 config DEFAULT_TARGET_OPTIMIZATION
337 string
338 EOF
339 foreach my $target (@target) {
340 next if @{$target->{subtargets}} > 0;
341 print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
342 }
343 print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
344
345 my %kver;
346 foreach my $target (@target) {
347 my $v = kver($target->{version});
348 next if $kver{$v};
349 $kver{$v} = 1;
350 print <<EOF;
351
352 config LINUX_$v
353 bool
354
355 EOF
356 }
357 foreach my $def (sort keys %defaults) {
358 print "\tconfig DEFAULT_".$def."\n";
359 print "\t\tbool\n\n";
360 }
361 }
362
363 my %dep_check;
364 sub __find_package_dep($$) {
365 my $pkg = shift;
366 my $name = shift;
367 my $deps = ($pkg->{vdepends} or $pkg->{depends});
368
369 return 0 unless defined $deps;
370 foreach my $dep (@{$deps}) {
371 next if $dep_check{$dep};
372 $dep_check{$dep} = 1;
373 return 1 if $dep eq $name;
374 return 1 if ($package{$dep} and (__find_package_dep($package{$dep},$name) == 1));
375 }
376 return 0;
377 }
378
379 # wrapper to avoid infinite recursion
380 sub find_package_dep($$) {
381 my $pkg = shift;
382 my $name = shift;
383
384 %dep_check = ();
385 return __find_package_dep($pkg, $name);
386 }
387
388 sub package_depends($$) {
389 my $a = shift;
390 my $b = shift;
391 my $ret;
392
393 return 0 if ($a->{submenu} ne $b->{submenu});
394 if (find_package_dep($a, $b->{name}) == 1) {
395 $ret = 1;
396 } elsif (find_package_dep($b, $a->{name}) == 1) {
397 $ret = -1;
398 } else {
399 return 0;
400 }
401 return $ret;
402 }
403
404 sub mconf_depends {
405 my $pkgname = shift;
406 my $depends = shift;
407 my $only_dep = shift;
408 my $res;
409 my $dep = shift;
410 my $seen = shift;
411 my $parent_condition = shift;
412 $dep or $dep = {};
413 $seen or $seen = {};
414
415 $depends or return;
416 my @depends = @$depends;
417 foreach my $depend (@depends) {
418 my $m = "depends";
419 my $flags = "";
420 $depend =~ s/^([@\+]+)// and $flags = $1;
421 my $vdep;
422 my $condition = $parent_condition;
423
424 if ($depend =~ /^(.+):(.+)$/) {
425 if ($1 ne "PACKAGE_$pkgname") {
426 if ($condition) {
427 $condition = "$condition && $1";
428 } else {
429 $condition = $1;
430 }
431 }
432 $depend = $2;
433 }
434 next if $seen->{$depend};
435 next if $package{$depend} and $package{$depend}->{buildonly};
436 $seen->{$depend} = 1;
437 if ($vdep = $package{$depend}->{vdepends}) {
438 $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
439 } else {
440 $flags =~ /\+/ and do {
441 # Menuconfig will not treat 'select FOO' as a real dependency
442 # thus if FOO depends on other config options, these dependencies
443 # will not be checked. To fix this, we simply emit all of FOO's
444 # depends here as well.
445 $package{$depend} and mconf_depends($pkgname, $package{$depend}->{depends}, 1, $dep, $seen, $condition);
446
447 $m = "select";
448 next if $only_dep;
449 };
450 $flags =~ /@/ or $depend = "PACKAGE_$depend";
451 if ($condition) {
452 if ($m =~ /select/) {
453 $depend = "$depend if $condition";
454 } else {
455 $depend = "!($condition) || $depend";
456 }
457 }
458 }
459 $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
460 }
461 foreach my $depend (keys %$dep) {
462 my $m = $dep->{$depend};
463 $res .= "\t\t$m $depend\n";
464 }
465 return $res;
466 }
467
468 sub print_package_config_category($) {
469 my $cat = shift;
470 my %menus;
471 my %menu_dep;
472
473 return unless $category{$cat};
474
475 print "menu \"$cat\"\n\n";
476 my %spkg = %{$category{$cat}};
477
478 foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
479 foreach my $pkg (@{$spkg{$spkg}}) {
480 next if $pkg->{buildonly};
481 my $menu = $pkg->{submenu};
482 if ($menu) {
483 $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
484 } else {
485 $menu = 'undef';
486 }
487 $menus{$menu} or $menus{$menu} = [];
488 push @{$menus{$menu}}, $pkg;
489 }
490 }
491 my @menus = sort {
492 ($a eq 'undef' ? 1 : 0) or
493 ($b eq 'undef' ? -1 : 0) or
494 ($a cmp $b)
495 } keys %menus;
496
497 foreach my $menu (@menus) {
498 my @pkgs = sort {
499 package_depends($a, $b) or
500 ($a->{name} cmp $b->{name})
501 } @{$menus{$menu}};
502 if ($menu ne 'undef') {
503 $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
504 print "menu \"$menu\"\n";
505 }
506 foreach my $pkg (@pkgs) {
507 my $title = $pkg->{name};
508 my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
509 if ($c > 0) {
510 $title .= ("." x $c). " ". $pkg->{title};
511 }
512 print "\t";
513 $pkg->{menu} and print "menu";
514 print "config PACKAGE_".$pkg->{name}."\n";
515 print "\t\t".($pkg->{tristate} ? 'tristate' : 'bool')." \"$title\"\n";
516 print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
517 foreach my $default (split /\s*,\s*/, $pkg->{default}) {
518 print "\t\tdefault $default\n";
519 }
520 print mconf_depends($pkg->{name}, $pkg->{depends}, 0);
521 print "\t\thelp\n";
522 print $pkg->{description};
523 print "\n";
524
525 $pkg->{config} and print $pkg->{config}."\n";
526 }
527 if ($menu ne 'undef') {
528 print "endmenu\n";
529 $menu_dep{$menu} and print "endif\n";
530 }
531 }
532 print "endmenu\n\n";
533
534 undef $category{$cat};
535 }
536
537 sub print_package_features() {
538 keys %features > 0 or return;
539 print "menu \"Package features\"\n";
540 foreach my $n (keys %features) {
541 my @features = sort { $b->{priority} <=> $a->{priority} or $a->{title} cmp $b->{title} } @{$features{$n}};
542 print <<EOF;
543 choice
544 prompt "$features[0]->{target_title}"
545 default FEATURE_$features[0]->{name}
546 EOF
547
548 foreach my $feature (@features) {
549 print <<EOF;
550 config FEATURE_$feature->{name}
551 bool "$feature->{title}"
552 EOF
553 $feature->{description} =~ /\w/ and do {
554 print "\t\thelp\n".$feature->{description}."\n";
555 };
556 }
557 print "endchoice\n"
558 }
559 print "endmenu\n\n";
560 }
561
562 sub gen_package_config() {
563 parse_package_metadata($ARGV[0]) or exit 1;
564 print "menuconfig UCI_PRECONFIG\n\tbool \"Image configuration\"\n" if %preconfig;
565 foreach my $preconfig (keys %preconfig) {
566 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
567 my $conf = $preconfig{$preconfig}->{$cfg}->{id};
568 $conf =~ tr/\.-/__/;
569 print <<EOF
570 config UCI_PRECONFIG_$conf
571 string "$preconfig{$preconfig}->{$cfg}->{label}" if UCI_PRECONFIG
572 depends PACKAGE_$preconfig
573 default "$preconfig{$preconfig}->{$cfg}->{default}"
574
575 EOF
576 }
577 }
578 print_package_features();
579 print_package_config_category 'Base system';
580 foreach my $cat (keys %category) {
581 print_package_config_category $cat;
582 }
583 }
584
585 sub get_conditional_dep($$) {
586 my $condition = shift;
587 my $depstr = shift;
588 if ($condition) {
589 if ($condition =~ /^!(.+)/) {
590 return "\$(if \$(CONFIG_$1),,$depstr)";
591 } else {
592 return "\$(if \$(CONFIG_$condition),$depstr)";
593 }
594 } else {
595 return $depstr;
596 }
597 }
598
599 sub gen_package_mk() {
600 my %conf;
601 my %dep;
602 my %done;
603 my $line;
604
605 parse_package_metadata($ARGV[0]) or exit 1;
606 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
607 my $config;
608 my $pkg = $package{$name};
609 my @srcdeps;
610
611 next if defined $pkg->{vdepends};
612
613 if ($ENV{SDK}) {
614 $conf{$pkg->{src}} or do {
615 $config = 'm';
616 $conf{$pkg->{src}} = 1;
617 };
618 } else {
619 $config = "\$(CONFIG_PACKAGE_$name)"
620 }
621 if ($config) {
622 $pkg->{buildonly} and $config = "";
623 print "package-$config += $pkg->{subdir}$pkg->{src}\n";
624 if ($pkg->{variant}) {
625 print "\$(curdir)/$pkg->{subdir}$pkg->{src}/variants += \$(if $config,$pkg->{variant})\n"
626 }
627 $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
628 }
629
630 next if $done{$pkg->{src}};
631 $done{$pkg->{src}} = 1;
632
633 if (@{$pkg->{buildtypes}} > 0) {
634 print "buildtypes-$pkg->{subdir}$pkg->{src} = ".join(' ', @{$pkg->{buildtypes}})."\n";
635 }
636
637 foreach my $spkg (@{$srcpackage{$pkg->{src}}}) {
638 foreach my $dep (@{$spkg->{depends}}, @{$spkg->{builddepends}}) {
639 $dep =~ /@/ or do {
640 $dep =~ s/\+//g;
641 push @srcdeps, $dep;
642 };
643 }
644 }
645 foreach my $type (@{$pkg->{buildtypes}}) {
646 my @extra_deps;
647 my %deplines;
648
649 next unless $pkg->{"builddepends/$type"};
650 foreach my $dep (@{$pkg->{"builddepends/$type"}}) {
651 my $suffix = "";
652 my $condition;
653
654 if ($dep =~ /^(.+):(.+)/) {
655 $condition = $1;
656 $dep = $2;
657 }
658 if ($dep =~ /^(.+)(\/.+)/) {
659 $dep = $1;
660 $suffix = $2;
661 }
662 my $pkg_dep = $package{$dep};
663 next unless $pkg_dep;
664
665 my $idx = "";
666 if (defined $pkg_dep->{src}) {
667 $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
668 } elsif (defined($srcpackage{$dep})) {
669 $idx = $subdir{$dep}.$dep;
670 }
671 my $depstr = "\$(curdir)/$idx$suffix/compile";
672 my $depline = get_conditional_dep($condition, $depstr);
673 if ($depline) {
674 $deplines{$dep} = $depline;
675 }
676 }
677 my $depline = join(" ", values %deplines);
678 if ($depline) {
679 $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/$type/compile += $depline\n";
680 }
681 }
682
683 my $hasdeps = 0;
684 my %deplines;
685 foreach my $deps (@srcdeps) {
686 my $idx;
687 my $condition;
688 my $prefix = "";
689 my $suffix = "";
690
691 if ($deps =~ /^(.+):(.+)/) {
692 $condition = $1;
693 $deps = $2;
694 }
695 if ($deps =~ /^(.+)(\/.+)/) {
696 $deps = $1;
697 $suffix = $2;
698 }
699
700 my $pkg_dep = $package{$deps};
701 my @deps;
702
703 if ($pkg_dep->{vdepends}) {
704 @deps = @{$pkg_dep->{vdepends}};
705 } else {
706 @deps = ($deps);
707 }
708
709 foreach my $dep (@deps) {
710 $pkg_dep = $package{$deps};
711 if (defined $pkg_dep->{src}) {
712 ($pkg->{src} ne $pkg_dep->{src}.$suffix) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
713 } elsif (defined($srcpackage{$dep})) {
714 $idx = $subdir{$dep}.$dep;
715 }
716 $idx .= $suffix;
717 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
718 if ($idx) {
719 my $depline;
720 next if $pkg->{src} eq $pkg_dep->{src}.$suffix;
721 next if $dep{$pkg->{src}."->".$idx};
722 next if $dep{$pkg->{src}."->($dep)".$idx} and $pkg_dep->{vdepends};
723 my $depstr;
724
725 if ($pkg_dep->{vdepends}) {
726 $depstr = "\$(if \$(CONFIG_PACKAGE_$dep),\$(curdir)/$idx/compile)";
727 $dep{$pkg->{src}."->($dep)".$idx} = 1;
728 } else {
729 $depstr = "\$(curdir)/$idx/compile";
730 $dep{$pkg->{src}."->".$idx} = 1;
731 }
732 $depline = get_conditional_dep($condition, $depstr);
733 if ($depline) {
734 $deplines{$idx.$dep} = $depline;
735 }
736 }
737 }
738 }
739 my $depline = join(" ", values %deplines);
740 if ($depline) {
741 $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
742 }
743 }
744
745 if ($line ne "") {
746 print "\n$line";
747 }
748 foreach my $preconfig (keys %preconfig) {
749 my $cmds;
750 foreach my $cfg (keys %{$preconfig{$preconfig}}) {
751 my $conf = $preconfig{$preconfig}->{$cfg}->{id};
752 $conf =~ tr/\.-/__/;
753 $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
754 }
755 next unless $cmds;
756 print <<EOF
757
758 \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
759 ( \\
760 $cmds \\
761 ) > \$@
762
763 ifneq (\$(UCI_PRECONFIG)\$(CONFIG_UCI_PRECONFIG),)
764 package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
765 endif
766 EOF
767 }
768 }
769
770 sub gen_package_source() {
771 parse_package_metadata($ARGV[0]) or exit 1;
772 foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
773 my $pkg = $package{$name};
774 if ($pkg->{name} && $pkg->{source}) {
775 print "$pkg->{name}: ";
776 print "$pkg->{source}\n";
777 }
778 }
779 }
780
781 sub parse_command() {
782 my $cmd = shift @ARGV;
783 for ($cmd) {
784 /^target_config$/ and return gen_target_config();
785 /^package_mk$/ and return gen_package_mk();
786 /^package_config$/ and return gen_package_config();
787 /^kconfig/ and return gen_kconfig_overrides();
788 /^package_source$/ and return gen_package_source();
789 }
790 print <<EOF
791 Available Commands:
792 $0 target_config [file] Target metadata in Kconfig format
793 $0 package_mk [file] Package metadata in makefile format
794 $0 package_config [file] Package metadata in Kconfig format
795 $0 kconfig [file] [config] Kernel config overrides
796 $0 package_source [file] Package source file information
797
798 EOF
799 }
800
801 parse_command();