metadata.pl 22 KB

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