metadata.pl 18 KB

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