metadata.pl 18 KB

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