metadata.pl 22 KB

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