metadata.pl 19 KB

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