metadata.pl 21 KB

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