metadata.pl 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. }
  176. return $ret;
  177. }
  178. sub target_name($) {
  179. my $target = shift;
  180. my $parent = $target->{parent};
  181. if ($parent) {
  182. return $target->{parent}->{name}." - ".$target->{name};
  183. } else {
  184. return $target->{name};
  185. }
  186. }
  187. sub kver($) {
  188. my $v = shift;
  189. $v =~ tr/\./_/;
  190. if (substr($v,0,2) eq "2_") {
  191. $v =~ /(\d+_\d+_\d+)(_\d+)?/ and $v = $1;
  192. } else {
  193. $v =~ /(\d+_\d+)(_\d+)?/ and $v = $1;
  194. }
  195. return $v;
  196. }
  197. sub print_target($) {
  198. my $target = shift;
  199. my $features = target_config_features(@{$target->{features}});
  200. my $help = $target->{desc};
  201. my $confstr;
  202. chomp $features;
  203. $features .= "\n";
  204. if ($help =~ /\w+/) {
  205. $help =~ s/^\s*/\t /mg;
  206. $help = "\thelp\n$help";
  207. } else {
  208. undef $help;
  209. }
  210. my $v = kver($target->{version});
  211. if (@{$target->{subtargets}} == 0) {
  212. $confstr = <<EOF;
  213. config TARGET_$target->{conf}
  214. bool "$target->{name}"
  215. select LINUX_$v
  216. EOF
  217. }
  218. else {
  219. $confstr = <<EOF;
  220. config TARGET_$target->{conf}
  221. bool "$target->{name}"
  222. EOF
  223. }
  224. if ($target->{subtarget}) {
  225. $confstr .= "\tdepends on TARGET_$target->{boardconf}\n";
  226. }
  227. if (@{$target->{subtargets}} > 0) {
  228. $confstr .= "\tselect HAS_SUBTARGETS\n";
  229. grep { /broken/ } @{$target->{features}} and $confstr .= "\tdepends on BROKEN\n";
  230. } else {
  231. $confstr .= $features;
  232. }
  233. if ($target->{arch} =~ /\w/) {
  234. $confstr .= "\tselect $target->{arch}\n";
  235. }
  236. foreach my $dep (@{$target->{depends}}) {
  237. my $mode = "depends on";
  238. my $flags;
  239. my $name;
  240. $dep =~ /^([@\+\-]+)(.+)$/;
  241. $flags = $1;
  242. $name = $2;
  243. next if $name =~ /:/;
  244. $flags =~ /-/ and $mode = "deselect";
  245. $flags =~ /\+/ and $mode = "select";
  246. $flags =~ /@/ and $confstr .= "\t$mode $name\n";
  247. }
  248. $confstr .= "$help\n\n";
  249. print $confstr;
  250. }
  251. sub gen_target_config() {
  252. my @target = parse_target_metadata();
  253. my %defaults;
  254. my @target_sort = sort {
  255. target_name($a) cmp target_name($b);
  256. } @target;
  257. print <<EOF;
  258. choice
  259. prompt "Target System"
  260. default TARGET_ar71xx
  261. reset if !DEVEL
  262. EOF
  263. foreach my $target (@target_sort) {
  264. next if $target->{subtarget};
  265. print_target($target);
  266. }
  267. print <<EOF;
  268. endchoice
  269. choice
  270. prompt "Subtarget" if HAS_SUBTARGETS
  271. EOF
  272. foreach my $target (@target) {
  273. next unless $target->{def_subtarget};
  274. print <<EOF;
  275. default TARGET_$target->{conf}_$target->{def_subtarget} if TARGET_$target->{conf}
  276. EOF
  277. }
  278. print <<EOF;
  279. EOF
  280. foreach my $target (@target) {
  281. next unless $target->{subtarget};
  282. print_target($target);
  283. }
  284. print <<EOF;
  285. endchoice
  286. choice
  287. prompt "Target Profile"
  288. EOF
  289. foreach my $target (@target) {
  290. my $profiles = $target->{profiles};
  291. foreach my $profile (@$profiles) {
  292. print <<EOF;
  293. config TARGET_$target->{conf}_$profile->{id}
  294. bool "$profile->{name}"
  295. depends on TARGET_$target->{conf}
  296. $profile->{config}
  297. EOF
  298. $profile->{kconfig} and print "\tselect PROFILE_KCONFIG\n";
  299. my @pkglist = merge_package_lists($target->{packages}, $profile->{packages});
  300. foreach my $pkg (@pkglist) {
  301. print "\tselect DEFAULT_$pkg\n";
  302. $defaults{$pkg} = 1;
  303. }
  304. my $help = $profile->{desc};
  305. if ($help =~ /\w+/) {
  306. $help =~ s/^\s*/\t /mg;
  307. $help = "\thelp\n$help";
  308. } else {
  309. undef $help;
  310. }
  311. print "$help\n";
  312. }
  313. }
  314. print <<EOF;
  315. endchoice
  316. config HAS_SUBTARGETS
  317. bool
  318. config TARGET_BOARD
  319. string
  320. EOF
  321. foreach my $target (@target) {
  322. $target->{subtarget} or print "\t\tdefault \"".$target->{board}."\" if TARGET_".$target->{conf}."\n";
  323. }
  324. print <<EOF;
  325. config TARGET_ARCH_PACKAGES
  326. string
  327. EOF
  328. foreach my $target (@target) {
  329. next if @{$target->{subtargets}} > 0;
  330. print "\t\tdefault \"".($target->{arch_packages} || $target->{board})."\" if TARGET_".$target->{conf}."\n";
  331. }
  332. print <<EOF;
  333. config DEFAULT_TARGET_OPTIMIZATION
  334. string
  335. EOF
  336. foreach my $target (@target) {
  337. next if @{$target->{subtargets}} > 0;
  338. print "\tdefault \"".$target->{cflags}."\" if TARGET_".$target->{conf}."\n";
  339. }
  340. print "\tdefault \"-Os -pipe -funit-at-a-time\"\n";
  341. print <<EOF;
  342. config CPU_TYPE
  343. string
  344. EOF
  345. foreach my $target (@target) {
  346. next if @{$target->{subtargets}} > 0;
  347. print "\tdefault \"".$target->{cputype}."\" if TARGET_".$target->{conf}."\n";
  348. }
  349. print "\tdefault \"\"\n";
  350. my %kver;
  351. foreach my $target (@target) {
  352. my $v = kver($target->{version});
  353. next if $kver{$v};
  354. $kver{$v} = 1;
  355. print <<EOF;
  356. config LINUX_$v
  357. bool
  358. EOF
  359. }
  360. foreach my $def (sort keys %defaults) {
  361. print "\tconfig DEFAULT_".$def."\n";
  362. print "\t\tbool\n\n";
  363. }
  364. }
  365. my %dep_check;
  366. sub __find_package_dep($$) {
  367. my $pkg = shift;
  368. my $name = shift;
  369. my $deps = ($pkg->{vdepends} or $pkg->{depends});
  370. return 0 unless defined $deps;
  371. foreach my $dep (@{$deps}) {
  372. next if $dep_check{$dep};
  373. $dep_check{$dep} = 1;
  374. return 1 if $dep eq $name;
  375. return 1 if ($package{$dep} and (__find_package_dep($package{$dep},$name) == 1));
  376. }
  377. return 0;
  378. }
  379. # wrapper to avoid infinite recursion
  380. sub find_package_dep($$) {
  381. my $pkg = shift;
  382. my $name = shift;
  383. %dep_check = ();
  384. return __find_package_dep($pkg, $name);
  385. }
  386. sub package_depends($$) {
  387. my $a = shift;
  388. my $b = shift;
  389. my $ret;
  390. return 0 if ($a->{submenu} ne $b->{submenu});
  391. if (find_package_dep($a, $b->{name}) == 1) {
  392. $ret = 1;
  393. } elsif (find_package_dep($b, $a->{name}) == 1) {
  394. $ret = -1;
  395. } else {
  396. return 0;
  397. }
  398. return $ret;
  399. }
  400. sub mconf_depends {
  401. my $pkgname = shift;
  402. my $depends = shift;
  403. my $only_dep = shift;
  404. my $res;
  405. my $dep = shift;
  406. my $seen = shift;
  407. my $parent_condition = shift;
  408. $dep or $dep = {};
  409. $seen or $seen = {};
  410. my @t_depends;
  411. $depends or return;
  412. my @depends = @$depends;
  413. foreach my $depend (@depends) {
  414. my $m = "depends on";
  415. my $flags = "";
  416. $depend =~ s/^([@\+]+)// and $flags = $1;
  417. my $vdep;
  418. my $condition = $parent_condition;
  419. next if $condition eq $depend;
  420. next if $seen->{"$parent_condition:$depend"};
  421. next if $seen->{":$depend"};
  422. $seen->{"$parent_condition:$depend"} = 1;
  423. if ($depend =~ /^(.+):(.+)$/) {
  424. if ($1 ne "PACKAGE_$pkgname") {
  425. if ($condition) {
  426. $condition = "$condition && $1";
  427. } else {
  428. $condition = $1;
  429. }
  430. }
  431. $depend = $2;
  432. }
  433. next if $package{$depend} and $package{$depend}->{buildonly};
  434. if ($vdep = $package{$depend}->{vdepends}) {
  435. $depend = join("||", map { "PACKAGE_".$_ } @$vdep);
  436. } else {
  437. $flags =~ /\+/ and do {
  438. # Menuconfig will not treat 'select FOO' as a real dependency
  439. # thus if FOO depends on other config options, these dependencies
  440. # will not be checked. To fix this, we simply emit all of FOO's
  441. # depends here as well.
  442. $package{$depend} and push @t_depends, [ $package{$depend}->{depends}, $condition ];
  443. $m = "select";
  444. next if $only_dep;
  445. };
  446. $flags =~ /@/ or $depend = "PACKAGE_$depend";
  447. if ($condition) {
  448. if ($m =~ /select/) {
  449. next if $depend eq $condition;
  450. $depend = "$depend if $condition";
  451. } else {
  452. $depend = "!($condition) || $depend";
  453. }
  454. }
  455. }
  456. $dep->{$depend} =~ /select/ or $dep->{$depend} = $m;
  457. }
  458. foreach my $tdep (@t_depends) {
  459. mconf_depends($pkgname, $tdep->[0], 1, $dep, $seen, $tdep->[1]);
  460. }
  461. foreach my $depend (keys %$dep) {
  462. my $m = $dep->{$depend};
  463. $res .= "\t\t$m $depend\n";
  464. }
  465. return $res;
  466. }
  467. sub print_package_config_category($) {
  468. my $cat = shift;
  469. my %menus;
  470. my %menu_dep;
  471. return unless $category{$cat};
  472. print "menu \"$cat\"\n\n";
  473. my %spkg = %{$category{$cat}};
  474. foreach my $spkg (sort {uc($a) cmp uc($b)} keys %spkg) {
  475. foreach my $pkg (@{$spkg{$spkg}}) {
  476. next if $pkg->{buildonly};
  477. my $menu = $pkg->{submenu};
  478. if ($menu) {
  479. $menu_dep{$menu} or $menu_dep{$menu} = $pkg->{submenudep};
  480. } else {
  481. $menu = 'undef';
  482. }
  483. $menus{$menu} or $menus{$menu} = [];
  484. push @{$menus{$menu}}, $pkg;
  485. }
  486. }
  487. my @menus = sort {
  488. ($a eq 'undef' ? 1 : 0) or
  489. ($b eq 'undef' ? -1 : 0) or
  490. ($a cmp $b)
  491. } keys %menus;
  492. foreach my $menu (@menus) {
  493. my @pkgs = sort {
  494. package_depends($a, $b) or
  495. ($a->{name} cmp $b->{name})
  496. } @{$menus{$menu}};
  497. if ($menu ne 'undef') {
  498. $menu_dep{$menu} and print "if $menu_dep{$menu}\n";
  499. print "menu \"$menu\"\n";
  500. }
  501. foreach my $pkg (@pkgs) {
  502. my $title = $pkg->{name};
  503. my $c = (72 - length($pkg->{name}) - length($pkg->{title}));
  504. if ($c > 0) {
  505. $title .= ("." x $c). " ". $pkg->{title};
  506. }
  507. $title = "\"$title\"";
  508. print "\t";
  509. $pkg->{menu} and print "menu";
  510. print "config PACKAGE_".$pkg->{name}."\n";
  511. $pkg->{hidden} and $title = "";
  512. print "\t\t".($pkg->{tristate} ? 'tristate' : 'bool')." $title\n";
  513. print "\t\tdefault y if DEFAULT_".$pkg->{name}."\n";
  514. unless ($pkg->{hidden}) {
  515. $pkg->{default} ||= "m if ALL";
  516. }
  517. if ($pkg->{default}) {
  518. foreach my $default (split /\s*,\s*/, $pkg->{default}) {
  519. print "\t\tdefault $default\n";
  520. }
  521. }
  522. print mconf_depends($pkg->{name}, $pkg->{depends}, 0);
  523. print mconf_depends($pkg->{name}, $pkg->{mdepends}, 0);
  524. print "\t\thelp\n";
  525. print $pkg->{description};
  526. print "\n";
  527. $pkg->{config} and print $pkg->{config}."\n";
  528. }
  529. if ($menu ne 'undef') {
  530. print "endmenu\n";
  531. $menu_dep{$menu} and print "endif\n";
  532. }
  533. }
  534. print "endmenu\n\n";
  535. undef $category{$cat};
  536. }
  537. sub print_package_features() {
  538. keys %features > 0 or return;
  539. print "menu \"Package features\"\n";
  540. foreach my $n (keys %features) {
  541. my @features = sort { $b->{priority} <=> $a->{priority} or $a->{title} cmp $b->{title} } @{$features{$n}};
  542. print <<EOF;
  543. choice
  544. prompt "$features[0]->{target_title}"
  545. default FEATURE_$features[0]->{name}
  546. EOF
  547. foreach my $feature (@features) {
  548. print <<EOF;
  549. config FEATURE_$feature->{name}
  550. bool "$feature->{title}"
  551. EOF
  552. $feature->{description} =~ /\w/ and do {
  553. print "\t\thelp\n".$feature->{description}."\n";
  554. };
  555. }
  556. print "endchoice\n"
  557. }
  558. print "endmenu\n\n";
  559. }
  560. sub gen_package_config() {
  561. parse_package_metadata($ARGV[0]) or exit 1;
  562. print "menuconfig IMAGEOPT\n\tbool \"Image configuration\"\n\tdefault n\n";
  563. foreach my $preconfig (keys %preconfig) {
  564. foreach my $cfg (keys %{$preconfig{$preconfig}}) {
  565. my $conf = $preconfig{$preconfig}->{$cfg}->{id};
  566. $conf =~ tr/\.-/__/;
  567. print <<EOF
  568. config UCI_PRECONFIG_$conf
  569. string "$preconfig{$preconfig}->{$cfg}->{label}" if IMAGEOPT
  570. depends on PACKAGE_$preconfig
  571. default "$preconfig{$preconfig}->{$cfg}->{default}"
  572. EOF
  573. }
  574. }
  575. print "source \"package/*/image-config.in\"\n";
  576. if (scalar glob "package/feeds/*/*/image-config.in") {
  577. print "source \"package/feeds/*/*/image-config.in\"\n";
  578. }
  579. print_package_features();
  580. print_package_config_category 'Base system';
  581. foreach my $cat (sort {uc($a) cmp uc($b)} keys %category) {
  582. print_package_config_category $cat;
  583. }
  584. }
  585. sub get_conditional_dep($$) {
  586. my $condition = shift;
  587. my $depstr = shift;
  588. if ($condition) {
  589. if ($condition =~ /^!(.+)/) {
  590. return "\$(if \$(CONFIG_$1),,$depstr)";
  591. } else {
  592. return "\$(if \$(CONFIG_$condition),$depstr)";
  593. }
  594. } else {
  595. return $depstr;
  596. }
  597. }
  598. sub gen_package_mk() {
  599. my %conf;
  600. my %dep;
  601. my %done;
  602. my $line;
  603. parse_package_metadata($ARGV[0]) or exit 1;
  604. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  605. my $config;
  606. my $pkg = $package{$name};
  607. my @srcdeps;
  608. next if defined $pkg->{vdepends};
  609. $config = "\$(CONFIG_PACKAGE_$name)";
  610. if ($config) {
  611. $pkg->{buildonly} and $config = "";
  612. print "package-$config += $pkg->{subdir}$pkg->{src}\n";
  613. if ($pkg->{variant}) {
  614. if (!defined($done{$pkg->{src}})) {
  615. print "\$(curdir)/$pkg->{subdir}$pkg->{src}/default-variant := $pkg->{variant}\n";
  616. }
  617. print "\$(curdir)/$pkg->{subdir}$pkg->{src}/variants += \$(if $config,$pkg->{variant})\n"
  618. }
  619. $pkg->{prereq} and print "prereq-$config += $pkg->{subdir}$pkg->{src}\n";
  620. }
  621. next if $done{$pkg->{src}};
  622. $done{$pkg->{src}} = 1;
  623. if (@{$pkg->{buildtypes}} > 0) {
  624. print "buildtypes-$pkg->{subdir}$pkg->{src} = ".join(' ', @{$pkg->{buildtypes}})."\n";
  625. }
  626. foreach my $spkg (@{$srcpackage{$pkg->{src}}}) {
  627. foreach my $dep (@{$spkg->{depends}}, @{$spkg->{builddepends}}) {
  628. $dep =~ /@/ or do {
  629. $dep =~ s/\+//g;
  630. push @srcdeps, $dep;
  631. };
  632. }
  633. }
  634. foreach my $type (@{$pkg->{buildtypes}}) {
  635. my @extra_deps;
  636. my %deplines;
  637. next unless $pkg->{"builddepends/$type"};
  638. foreach my $dep (@{$pkg->{"builddepends/$type"}}) {
  639. my $suffix = "";
  640. my $condition;
  641. if ($dep =~ /^(.+):(.+)/) {
  642. $condition = $1;
  643. $dep = $2;
  644. }
  645. if ($dep =~ /^(.+)(\/.+)/) {
  646. $dep = $1;
  647. $suffix = $2;
  648. }
  649. my $idx = "";
  650. my $pkg_dep = $package{$dep};
  651. if (defined($pkg_dep) && defined($pkg_dep->{src})) {
  652. $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
  653. } elsif (defined($srcpackage{$dep})) {
  654. $idx = $subdir{$dep}.$dep;
  655. } else {
  656. next;
  657. }
  658. my $depstr = "\$(curdir)/$idx$suffix/compile";
  659. my $depline = get_conditional_dep($condition, $depstr);
  660. if ($depline) {
  661. $deplines{$depline}++;
  662. }
  663. }
  664. my $depline = join(" ", sort keys %deplines);
  665. if ($depline) {
  666. $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/$type/compile += $depline\n";
  667. }
  668. }
  669. my $hasdeps = 0;
  670. my %deplines;
  671. foreach my $deps (@srcdeps) {
  672. my $idx;
  673. my $condition;
  674. my $prefix = "";
  675. my $suffix = "";
  676. if ($deps =~ /^(.+):(.+)/) {
  677. $condition = $1;
  678. $deps = $2;
  679. }
  680. if ($deps =~ /^(.+)(\/.+)/) {
  681. $deps = $1;
  682. $suffix = $2;
  683. }
  684. my $pkg_dep = $package{$deps};
  685. my @deps;
  686. if ($pkg_dep->{vdepends}) {
  687. @deps = @{$pkg_dep->{vdepends}};
  688. } else {
  689. @deps = ($deps);
  690. }
  691. foreach my $dep (@deps) {
  692. $pkg_dep = $package{$deps};
  693. if (defined $pkg_dep->{src}) {
  694. ($pkg->{src} ne $pkg_dep->{src}.$suffix) and $idx = $pkg_dep->{subdir}.$pkg_dep->{src};
  695. } elsif (defined($srcpackage{$dep})) {
  696. $idx = $subdir{$dep}.$dep;
  697. }
  698. undef $idx if $idx eq 'base-files';
  699. if ($idx) {
  700. $idx .= $suffix;
  701. my $depline;
  702. next if $pkg->{src} eq $pkg_dep->{src}.$suffix;
  703. next if $dep{$condition.":".$pkg->{src}."->".$idx};
  704. next if $dep{$pkg->{src}."->($dep)".$idx} and $pkg_dep->{vdepends};
  705. my $depstr;
  706. if ($pkg_dep->{vdepends}) {
  707. $depstr = "\$(if \$(CONFIG_PACKAGE_$dep),\$(curdir)/$idx/compile)";
  708. $dep{$pkg->{src}."->($dep)".$idx} = 1;
  709. } else {
  710. $depstr = "\$(curdir)/$idx/compile";
  711. $dep{$pkg->{src}."->".$idx} = 1;
  712. }
  713. $depline = get_conditional_dep($condition, $depstr);
  714. if ($depline) {
  715. $deplines{$depline}++;
  716. }
  717. }
  718. }
  719. }
  720. my $depline = join(" ", sort keys %deplines);
  721. if ($depline) {
  722. $line .= "\$(curdir)/".$pkg->{subdir}."$pkg->{src}/compile += $depline\n";
  723. }
  724. }
  725. if ($line ne "") {
  726. print "\n$line";
  727. }
  728. foreach my $preconfig (keys %preconfig) {
  729. my $cmds;
  730. foreach my $cfg (keys %{$preconfig{$preconfig}}) {
  731. my $conf = $preconfig{$preconfig}->{$cfg}->{id};
  732. $conf =~ tr/\.-/__/;
  733. $cmds .= "\techo \"uci set '$preconfig{$preconfig}->{$cfg}->{id}=\$(subst \",,\$(CONFIG_UCI_PRECONFIG_$conf))'\"; \\\n";
  734. }
  735. next unless $cmds;
  736. print <<EOF
  737. ifndef DUMP_TARGET_DB
  738. \$(TARGET_DIR)/etc/uci-defaults/$preconfig: FORCE
  739. ( \\
  740. $cmds \\
  741. ) > \$@
  742. ifneq (\$(IMAGEOPT)\$(CONFIG_IMAGEOPT),)
  743. package/preconfig: \$(TARGET_DIR)/etc/uci-defaults/$preconfig
  744. endif
  745. endif
  746. EOF
  747. }
  748. }
  749. sub gen_package_source() {
  750. parse_package_metadata($ARGV[0]) or exit 1;
  751. foreach my $name (sort {uc($a) cmp uc($b)} keys %package) {
  752. my $pkg = $package{$name};
  753. if ($pkg->{name} && $pkg->{source}) {
  754. print "$pkg->{name}: ";
  755. print "$pkg->{source}\n";
  756. }
  757. }
  758. }
  759. sub parse_command() {
  760. my $cmd = shift @ARGV;
  761. for ($cmd) {
  762. /^target_config$/ and return gen_target_config();
  763. /^package_mk$/ and return gen_package_mk();
  764. /^package_config$/ and return gen_package_config();
  765. /^kconfig/ and return gen_kconfig_overrides();
  766. /^package_source$/ and return gen_package_source();
  767. }
  768. print <<EOF
  769. Available Commands:
  770. $0 target_config [file] Target metadata in Kconfig format
  771. $0 package_mk [file] Package metadata in makefile format
  772. $0 package_config [file] Package metadata in Kconfig format
  773. $0 kconfig [file] [config] Kernel config overrides
  774. $0 package_source [file] Package source file information
  775. EOF
  776. }
  777. parse_command();