metadata.pl 19 KB

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