2
0

metadata.pl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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. $target->{sort} and @$profiles = sort {
  248. $a->{priority} <=> $b->{priority} or
  249. $a->{name} cmp $b->{name};
  250. } @$profiles;
  251. foreach my $profile (@$profiles) {
  252. print <<EOF;
  253. config TARGET_$target->{conf}_$profile->{id}
  254. bool "$profile->{name}"
  255. depends on TARGET_$target->{conf}
  256. $profile->{config}
  257. EOF
  258. $profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n";
  259. my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
  260. foreach my $pkg (@pkglist) {
  261. print "\tselect DEFAULT_$pkg\n";
  262. $defaults{$pkg} = 1;
  263. }
  264. my $help = $profile->{desc};
  265. if ($help =~ /\w+/) {
  266. $help =~ s/^\s*/\t /mg;
  267. $help = "\thelp\n$help";
  268. } else {
  269. undef $help;
  270. }
  271. print "$help\n";
  272. }
  273. }
  274. print <<EOF;
  275. endchoice
  276. config HAS_SUBTARGETS
  277. bool
  278. config TARGET_BOARD
  279. string
  280. EOF
  281. foreach my $target (@target) {
  282. $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
  283. }
  284. print <<EOF;
  285. config TARGET_SUBTARGET
  286. string
  287. default "generic" if !HAS_SUBTARGETS
  288. EOF
  289. foreach my $target (@target) {
  290. foreach my $subtarget (@{$target->{subtargets}}) {
  291. print "\t\tdefault \"$subtarget\" if TARGET_".$target->{conf}."_$subtarget\n";
  292. }
  293. }
  294. print <<EOF;
  295. config TARGET_PROFILE
  296. string
  297. EOF
  298. foreach my $target (@target) {
  299. my $profiles = $target->{profiles};
  300. foreach my $profile (@$profiles) {
  301. print "\tdefault \"$profile->{id}\" if TARGET_$target->{conf}_$profile->{id}\n";
  302. }
  303. }
  304. print <<EOF;
  305. config TARGET_ARCH_PACKAGES
  306. string
  307. EOF
  308. foreach my $target (@target) {
  309. next if @{$target->{subtargets}} > 0;
  310. print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
  311. }
  312. print <<EOF;
  313. config DEFAULT_TARGET_OPTIMIZATION
  314. string
  315. EOF
  316. foreach my $target (@target) {
  317. next if @{$target->{subtargets}} > 0;
  318. print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
  319. }
  320. print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
  321. print <<EOF;
  322. config CPU_TYPE
  323. string
  324. EOF
  325. foreach my $target (@target) {
  326. next if @{$target->{subtargets}} > 0;
  327. print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
  328. }
  329. print "\tdefault \"\"\n";
  330. my %kver;
  331. foreach my $target (@target) {
  332. my $v = kver($target->{version});
  333. next if $kver{$v};
  334. $kver{$v} = 1;
  335. print <<EOF;
  336. config LINUX_$v
  337. bool
  338. EOF
  339. }
  340. foreach my $def (sort keys %defaults) {
  341. print "\tconfig DEFAULT_".$def."\n";
  342. print "\t\tbool\n\n";
  343. }
  344. }
  345. my %dep_check;
  346. sub __find_package_dep($$) {
  347. my $pkg = shift;
  348. my $name = shift;
  349. my $deps = ($pkg->{vdepends} or $pkg->{depends});
  350. return 0 unless defined $deps;
  351. foreach my $dep (@{$deps}) {
  352. next if $dep_check{$dep};
  353. $dep_check{$dep} = 1;
  354. return 1 if $dep eq $name;
  355. return 1 if ($package{$dep} and (__find_package_dep($package{$dep},$name) == 1));
  356. }
  357. return 0;
  358. }
  359. # wrapper to avoid infinite recursion
  360. sub find_package_dep($$) {
  361. my $pkg = shift;
  362. my $name = shift;
  363. %dep_check = ();
  364. return __find_package_dep($pkg, $name);
  365. }
  366. sub package_depends($$) {
  367. my $a = shift;
  368. my $b = shift;
  369. my $ret;
  370. return 0 if ($a->{submenu} ne $b->{submenu});
  371. if (find_package_dep($a, $b->{name}) == 1) {
  372. $ret = 1;
  373. } elsif (find_package_dep($b, $a->{name}) == 1) {
  374. $ret = -1;
  375. } else {
  376. return 0;
  377. }
  378. return $ret;
  379. }
  380. sub mconf_depends {
  381. my $pkgname = shift;
  382. my $depends = shift;
  383. my $only_dep = shift;
  384. my $res;
  385. my $dep = shift;
  386. my $seen = shift;
  387. my $parent_condition = shift;
  388. $dep or $dep = {};
  389. $seen or $seen = {};
  390. my @t_depends;
  391. $depends or return;
  392. my @depends = @$depends;
  393. foreach my $depend (@depends) {
  394. my $m = "depends on";
  395. my $flags = "";
  396. $depend =~ s/^([@\+]+)// and $flags = $1;
  397. my $vdep;
  398. my $condition = $parent_condition;
  399. next if $condition eq $depend;
  400. next if $seen->{"$parent_condition:$depend"};
  401. next if $seen->{":$depend"};
  402. $seen->{"$parent_condition:$depend"} = 1;
  403. if ($depend =~ /^(.+):(.+)$/) {
  404. if ($1 ne "PACKAGE_$pkgname") {
  405. if ($condition) {
  406. $condition = "$condition && $1";
  407. } else {
  408. $condition = $1;
  409. }
  410. }
  411. $depend = $2;
  412. }
  413. next if $package{$depend} and $package{$depend}->{buildonly};
  414. if ($flags =~ /\+/) {
  415. if ($vdep = $package{$depend}->{vdepends}) {
  416. my @vdeps = @$vdep;
  417. $depend = shift @vdeps;
  418. if (@vdeps > 1) {
  419. $condition = '!('.join("||", map { "PACKAGE_".$_ } @vdeps).')';
  420. } elsif (@vdeps > 0) {
  421. $condition = '!PACKAGE_'.$vdeps[0];
  422. }
  423. }
  424. # Menuconfig will not treat 'select FOO' as a real dependency
  425. # thus if FOO depends on other config options, these dependencies
  426. # will not be checked. To fix this, we simply emit all of FOO's
  427. # depends here as well.
  428. $package{$depend} and push @t_depends, [ $package{$depend}->{depends}, $condition ];
  429. $m = "select";
  430. next if $only_dep;
  431. } else {
  432. if ($vdep = $package{$depend}->{vdepends}) {
  433. $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
  434. }
  435. }
  436. $flags =~ /@/ or $depend = "PACKAGE_$depend";
  437. if ($condition) {
  438. if ($m =~ /select/) {
  439. next if $depend eq $condition;
  440. $depend = "$depend if $condition";
  441. } else {
  442. $depend = "!($condition) || $depend" unless $dep->{$condition} eq 'select';
  443. }
  444. }
  445. $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
  446. }
  447. foreach my $tdep (@t_depends) {
  448. mconf_depends($pkgname, $tdep->[0], 1, $dep, $seen, $tdep->[1]);
  449. }
  450. foreach my $depend (keys %$dep) {
  451. my $m = $dep->{$depend};
  452. $res .= "\t\t$m $depend\n";
  453. }
  454. return $res;
  455. }
  456. sub mconf_conflicts {
  457. my $pkgname = shift;
  458. my $depends = shift;
  459. my $res = "";
  460. foreach my $depend (@$depends) {
  461. next unless $package{$depend};
  462. $res .= "\t\tdepends on m || (PACKAGE_$depend != y)\n";
  463. }
  464. return $res;
  465. }
  466. sub print_package_config_category($) {
  467. my $cat = shift;
  468. my %menus;
  469. my %menu_dep;
  470. return unless $category{$cat};
  471. print "menu \"$cat\"\n\n";
  472. my %spkg = %{$category{$cat}};
  473. foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
  474. foreach my $pkg (@{$spkg{$spkg}}) {
  475. next if $pkg->{buildonly};
  476. my $menu = $pkg->{submenu};
  477. if ($menu) {
  478. $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
  479. } else {
  480. $menu = 'undef';
  481. }
  482. $menus{$menu} or $menus{$menu} = [];
  483. push @{$menus{$menu}}, $pkg;
  484. }
  485. }
  486. my @menus = sort {
  487. ($a eq 'undef' ? 1 : 0) or
  488. ($b eq 'undef' ? -1 : 0) or
  489. ($a cmp $b)
  490. } keys %menus;
  491. foreach my $menu (@menus) {
  492. my @pkgs = sort {
  493. package_depends($a, $b) or
  494. ($a->{name} cmp $b->{name})
  495. } @{$menus{$menu}};
  496. if ($menu ne 'undef') {
  497. $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
  498. print "menu \"$menu\"\n";
  499. }
  500. foreach my $pkg (@pkgs) {
  501. my $title = $pkg->{name};
  502. my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
  503. if ($c > 0) {
  504. $title .= ("." x $c). " ". $pkg->{title};
  505. }
  506. $title = "\"$title\"";
  507. print "\t";
  508. $pkg->{menu} and print "menu";
  509. print "config PACKAGE_".$pkg->{name}."\n";
  510. $pkg->{hidden} and $title = "";
  511. print "\t\t".($pkg->{tristate} ? 'tristate' : 'bool')." $title\n";
  512. print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
  513. unless ($pkg->{hidden}) {
  514. my @def = ("ALL");
  515. if (!exists($pkg->{repository})) {
  516. push @def, "ALL_NONSHARED";
  517. }
  518. if ($pkg->{name} =~ /^kmod-/) {
  519. push @def, "ALL_KMODS";
  520. }
  521. $pkg->{default} ||= "m if " . join("||", @def);
  522. }
  523. if ($pkg->{default}) {
  524. foreach my $default (split /\s*,\s*/, $pkg->{default}) {
  525. print "\t\tdefault $default\n";
  526. }
  527. }
  528. print mconf_depends($pkg->{name}, $pkg->{depends}, 0);
  529. print mconf_depends($pkg->{name}, $pkg->{mdepends}, 0);
  530. print mconf_conflicts($pkg->{name}, $pkg->{conflicts});
  531. print "\t\thelp\n";
  532. print $pkg->{description};
  533. print "\n";
  534. $pkg->{config} and print $pkg->{config}."\n";
  535. }
  536. if ($menu ne 'undef') {
  537. print "endmenu\n";
  538. $menu_dep{$menu} and print "endif\n";
  539. }
  540. }
  541. print "endmenu\n\n";
  542. undef $category{$cat};
  543. }
  544. sub print_package_features() {
  545. keys %features > 0 or return;
  546. print "menu \"Package features\"\n";
  547. foreach my $n (keys %features) {
  548. my @features = sort { $b->{priority} <=> $a->{priority} or $a->{title} cmp $b->{title} } @{$features{$n}};
  549. print <<EOF;
  550. choice
  551. prompt "$features[0]->{target_title}"
  552. default FEATURE_$features[0]->{name}
  553. EOF
  554. foreach my $feature (@features) {
  555. print <<EOF;
  556. config FEATURE_$feature->{name}
  557. bool "$feature->{title}"
  558. EOF
  559. $feature->{description} =~ /\w/ and do {
  560. print "\t\thelp\n".$feature->{description}."\n";
  561. };
  562. }
  563. print "endchoice\n"
  564. }
  565. print "endmenu\n\n";
  566. }
  567. sub print_package_overrides() {
  568. keys %overrides > 0 or return;
  569. print "\tconfig OVERRIDE_PKGS\n";
  570. print "\t\tstring\n";
  571. print "\t\tdefault \"".join(" ", keys %overrides)."\"\n\n";
  572. }
  573. sub gen_package_config() {
  574. parse_package_metadata($ARGV[0]) or exit 1;
  575. print "menuconfig IMAGEOPT\n\tbool \"Image configuration\"\n\tdefault n\n";
  576. foreach my $preconfig (keys %preconfig) {
  577. foreach my $cfg (keys %{$preconfig{$preconfig}}) {
  578. my $conf = $preconfig{$preconfig}->{$cfg}->{id};
  579. $conf =~ tr/\.-/__/;
  580. print <<EOF
  581. config UCI_PRECONFIG_$conf
  582. string "$preconfig{$preconfig}->{$cfg}->{label}" if IMAGEOPT
  583. depends on PACKAGE_$preconfig
  584. default "$preconfig{$preconfig}->{$cfg}->{default}"
  585. EOF
  586. }
  587. }
  588. print "source \"package/*/image-config.in\"\n";
  589. if (scalar glob "package/feeds/*/*/image-config.in") {
  590. print "source \"package/feeds/*/*/image-config.in\"\n";
  591. }
  592. print_package_features();
  593. print_package_config_category 'Base system';
  594. foreach my $cat (sort {uc($a) cmp uc($b)} keys %category) {
  595. print_package_config_category $cat;
  596. }
  597. print_package_overrides();
  598. }
  599. sub get_conditional_dep($$) {
  600. my $condition = shift;
  601. my $depstr = shift;
  602. if ($condition) {
  603. if ($condition =~ /^!(.+)/) {
  604. return "\$(if \$(CONFIG_$1),,$depstr)";
  605. } else {
  606. return "\$(if \$(CONFIG_$condition),$depstr)";
  607. }
  608. } else {
  609. return $depstr;
  610. }
  611. }
  612. sub gen_package_mk() {
  613. my %conf;
  614. my %dep;
  615. my %done;
  616. my $line;
  617. parse_package_metadata($ARGV[0]) or exit 1;
  618. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  619. my $config;
  620. my $pkg = $package{$name};
  621. my @srcdeps;
  622. next if defined $pkg->{vdepends};
  623. $config = "\$(CONFIG_PACKAGE_$name)";
  624. if ($config) {
  625. $pkg->{buildonly} and $config = "";
  626. print "package-$config += $pkg->{subdir}$pkg->{src}\n";
  627. if ($pkg->{variant}) {
  628. if (!defined($done{$pkg->{src}}) or $pkg->{variant_default}) {
  629. print "\$(curdir)/$pkg->{subdir}$pkg->{src}/default-variant := $pkg->{variant}\n";
  630. }
  631. print "\$(curdir)/$pkg->{subdir}$pkg->{src}/variants += \$(if $config,$pkg->{variant})\n"
  632. }
  633. $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
  634. }
  635. next if $done{$pkg->{src}};
  636. $done{$pkg->{src}} = 1;
  637. if (@{$pkg->{buildtypes}} > 0) {
  638. print "buildtypes-$pkg->{subdir}$pkg->{src} = ".join(' ', @{$pkg->{buildtypes}})."\n";
  639. }
  640. foreach my $spkg (@{$srcpackage{$pkg->{src}}}) {
  641. foreach my $dep (@{$spkg->{depends}}, @{$spkg->{builddepends}}) {
  642. $dep =~ /@/ or do {
  643. $dep =~ s/\+//g;
  644. push @srcdeps, $dep;
  645. };
  646. }
  647. }
  648. foreach my $type (@{$pkg->{buildtypes}}) {
  649. my @extra_deps;
  650. my %deplines;
  651. next unless $pkg->{"builddepends/$type"};
  652. foreach my $dep (@{$pkg->{"builddepends/$type"}}) {
  653. my $suffix = "";
  654. my $condition;
  655. if ($dep =~ /^(.+):(.+)/) {
  656. $condition = $1;
  657. $dep = $2;
  658. }
  659. if ($dep =~ /^(.+)(\/.+)/) {
  660. $dep = $1;
  661. $suffix = $2;
  662. }
  663. my $idx = "";
  664. my $pkg_dep = $package{$dep};
  665. if (defined($pkg_dep) && defined($pkg_dep->{src})) {
  666. $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
  667. } elsif (defined($srcpackage{$dep})) {
  668. $idx = $subdir{$dep}.$dep;
  669. } else {
  670. next;
  671. }
  672. my $depstr = "\$(curdir)/$idx$suffix/compile";
  673. my $depline = get_conditional_dep($condition, $depstr);
  674. if ($depline) {
  675. $deplines{$depline}++;
  676. }
  677. }
  678. my $depline = join(" ", sort keys %deplines);
  679. if ($depline) {
  680. $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/$type/compile += $depline\n";
  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. if ($deps =~ /^(.+):(.+)/) {
  691. $condition = $1;
  692. $deps = $2;
  693. }
  694. if ($deps =~ /^(.+)(\/.+)/) {
  695. $deps = $1;
  696. $suffix = $2;
  697. }
  698. my $pkg_dep = $package{$deps};
  699. my @deps;
  700. if ($pkg_dep->{vdepends}) {
  701. @deps = @{$pkg_dep->{vdepends}};
  702. } else {
  703. @deps = ($deps);
  704. }
  705. foreach my $dep (@deps) {
  706. $pkg_dep = $package{$deps};
  707. if (defined $pkg_dep->{src}) {
  708. ($pkg->{src} ne $pkg_dep->{src}.$suffix) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
  709. } elsif (defined($srcpackage{$dep})) {
  710. $idx = $subdir{$dep}.$dep;
  711. }
  712. undef $idx if $idx eq 'base-files';
  713. if ($idx) {
  714. $idx .= $suffix;
  715. my $depline;
  716. next if $pkg->{src} eq $pkg_dep->{src}.$suffix;
  717. next if $dep{$condition.":".$pkg->{src}."->".$idx};
  718. next if $dep{$pkg->{src}."->($dep)".$idx} and $pkg_dep->{vdepends};
  719. my $depstr;
  720. if ($pkg_dep->{vdepends}) {
  721. $depstr = "\$(if \$(CONFIG_PACKAGE_$dep),\$(curdir)/$idx/compile)";
  722. $dep{$pkg->{src}."->($dep)".$idx} = 1;
  723. } else {
  724. $depstr = "\$(curdir)/$idx/compile";
  725. $dep{$pkg->{src}."->".$idx} = 1;
  726. }
  727. $depline = get_conditional_dep($condition, $depstr);
  728. if ($depline) {
  729. $deplines{$depline}++;
  730. }
  731. }
  732. }
  733. }
  734. my $depline = join(" ", sort keys %deplines);
  735. if ($depline) {
  736. $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
  737. }
  738. }
  739. if ($line ne "") {
  740. print "\n$line";
  741. }
  742. foreach my $preconfig (keys %preconfig) {
  743. my $cmds;
  744. foreach my $cfg (keys %{$preconfig{$preconfig}}) {
  745. my $conf = $preconfig{$preconfig}->{$cfg}->{id};
  746. $conf =~ tr/\.-/__/;
  747. $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
  748. }
  749. next unless $cmds;
  750. print <<EOF
  751. ifndef DUMP_TARGET_DB
  752. \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
  753. ( \\
  754. $cmds \\
  755. ) > \$@
  756. ifneq (\$(IMAGEOPT)\$(CONFIG_IMAGEOPT),)
  757. package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
  758. endif
  759. endif
  760. EOF
  761. }
  762. }
  763. sub gen_package_source() {
  764. parse_package_metadata($ARGV[0]) or exit 1;
  765. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  766. my $pkg = $package{$name};
  767. if ($pkg->{name} && $pkg->{source}) {
  768. print "$pkg->{name}: ";
  769. print "$pkg->{source}\n";
  770. }
  771. }
  772. }
  773. sub gen_package_subdirs() {
  774. parse_package_metadata($ARGV[0]) or exit 1;
  775. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  776. my $pkg = $package{$name};
  777. if ($pkg->{name} && $pkg->{repository}) {
  778. print "Package/$name/subdir = $pkg->{repository}\n";
  779. }
  780. }
  781. }
  782. sub gen_package_license($) {
  783. my $level = shift;
  784. parse_package_metadata($ARGV[0]) or exit 1;
  785. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  786. my $pkg = $package{$name};
  787. if ($pkg->{name}) {
  788. if ($pkg->{license}) {
  789. print "$pkg->{name}: ";
  790. print "$pkg->{license}\n";
  791. if ($pkg->{licensefiles} && $level == 0) {
  792. print "\tFiles: $pkg->{licensefiles}\n";
  793. }
  794. } else {
  795. if ($level == 1) {
  796. print "$pkg->{name}: Missing license! ";
  797. print "Please fix $pkg->{makefile}\n";
  798. }
  799. }
  800. }
  801. }
  802. }
  803. sub gen_version_filtered_list() {
  804. foreach my $item (version_filter_list(@ARGV)) {
  805. print "$item\n";
  806. }
  807. }
  808. sub parse_command() {
  809. GetOptions("ignore=s", \@ignore);
  810. my $cmd = shift @ARGV;
  811. for ($cmd) {
  812. /^target_config$/ and return gen_target_config();
  813. /^package_mk$/ and return gen_package_mk();
  814. /^package_config$/ and return gen_package_config();
  815. /^kconfig/ and return gen_kconfig_overrides();
  816. /^package_source$/ and return gen_package_source();
  817. /^package_subdirs$/ and return gen_package_subdirs();
  818. /^package_license$/ and return gen_package_license(0);
  819. /^package_licensefull$/ and return gen_package_license(1);
  820. /^version_filter$/ and return gen_version_filtered_list();
  821. }
  822. print <<EOF
  823. Available Commands:
  824. $0 target_config [file] Target metadata in Kconfig format
  825. $0 package_mk [file] Package metadata in makefile format
  826. $0 package_config [file] Package metadata in Kconfig format
  827. $0 kconfig [file] [config] [patchver] Kernel config overrides
  828. $0 package_source [file] Package source file information
  829. $0 package_subdirs [file] Package subdir information in makefile format
  830. $0 package_license [file] Package license information
  831. $0 package_licensefull [file] Package license information (full list)
  832. $0 version_filter [patchver] [list...] Filter list of version tagged strings
  833. Options:
  834. --ignore <name> Ignore the source package <name>
  835. EOF
  836. }
  837. parse_command();