metadata.pl 19 KB

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