metadata.pl 20 KB

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