metadata.pl 20 KB

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