metadata.pl 20 KB

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