metadata.pl 18 KB

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