metadata.pl 21 KB

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