metadata.pl 21 KB

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