gen_deps.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) 2006 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. use strict;
  9. my $name;
  10. my $src;
  11. my $makefile;
  12. my %conf;
  13. my %pkg;
  14. my %prereq;
  15. my %dep;
  16. my %options;
  17. my $opt;
  18. while ($opt = shift @ARGV) {
  19. $opt =~ /^-s/ and $options{SDK} = 1;
  20. }
  21. my $line;
  22. while ($line = <>) {
  23. chomp $line;
  24. $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
  25. $makefile = $1;
  26. $src = $2;
  27. };
  28. $line =~ /^Package: \s*(.+)\s*$/ and do {
  29. $name = $1;
  30. defined $pkg{$name} or $pkg{$name} = {};
  31. $pkg{$name}->{src} = $src;
  32. };
  33. $line =~ /^Prereq-Check:/ and !defined $prereq{$src} and do {
  34. $pkg{$name}->{prereq} = 1;
  35. };
  36. $line =~ /^(Build-)?Depends: \s*(.+)\s*$/ and do {
  37. $pkg{$name}->{depends} ||= [];
  38. foreach my $v (split /\s+/, $2) {
  39. next if $v =~ /^[\+]?@/;
  40. $v =~ s/^\+//;
  41. push @{$pkg{$name}->{depends}}, $v;
  42. }
  43. };
  44. }
  45. $line="";
  46. foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
  47. my $config;
  48. if ($options{SDK}) {
  49. $conf{$pkg{$name}->{src}} or do {
  50. $config = 'm';
  51. $conf{$pkg{$name}->{src}} = 1;
  52. };
  53. } else {
  54. $config = "\$(CONFIG_PACKAGE_$name)"
  55. }
  56. if ($config) {
  57. print "package-$config += $pkg{$name}->{src}\n";
  58. $pkg{$name}->{prereq} and print "prereq-$config += $pkg{$name}->{src}\n";
  59. }
  60. my $hasdeps = 0;
  61. my $depline = "";
  62. foreach my $dep (@{$pkg{$name}->{depends}}) {
  63. my $idx;
  64. if (defined $pkg{$dep}->{src}) {
  65. ($pkg{$name}->{src} ne $pkg{$dep}->{src}) and $idx = $pkg{$dep}->{src};
  66. } elsif (defined($pkg{$dep}) && !$options{SDK}) {
  67. $idx = $dep;
  68. }
  69. undef $idx if $idx =~ /^(kernel)|(base-files)$/;
  70. if ($idx) {
  71. next if $dep{$pkg{$name}->{src}."->".$idx};
  72. $depline .= " $idx\-compile";
  73. $dep{$pkg{$name}->{src}."->".$idx} = 1;
  74. }
  75. }
  76. if ($depline ne "") {
  77. $line .= "$pkg{$name}->{src}-compile: $depline\n";
  78. }
  79. }
  80. if ($line ne "") {
  81. print "\n$line";
  82. }