metadata.pl 23 KB

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