metadata.pl 24 KB

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