gen_deps.pl 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 =~ /^Provides: \s*(.+)\s*$/ and do {
  34. foreach my $vpkg (split /\s+/, $1) {
  35. defined $pkg{$vpkg} or $pkg{$vpkg} = {};
  36. $pkg{$vpkg}->{virtual} = 1;
  37. }
  38. };
  39. $line =~ /^Prereq-Check:/ and !defined $prereq{$src} and do {
  40. $pkg{$name}->{prereq} = 1;
  41. };
  42. $line =~ /^(Build-)?Depends: \s*(.+)\s*$/ and do {
  43. $pkg{$name}->{depends} ||= [];
  44. foreach my $v (split /\s+/, $2) {
  45. next if $v =~ /^[\+]?@/;
  46. $v =~ s/^\+//;
  47. push @{$pkg{$name}->{depends}}, $v;
  48. }
  49. };
  50. }
  51. $line="";
  52. foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
  53. my $config;
  54. next if defined $pkg{$name}->{virtual};
  55. if ($options{SDK}) {
  56. $conf{$pkg{$name}->{src}} or do {
  57. $config = 'm';
  58. $conf{$pkg{$name}->{src}} = 1;
  59. };
  60. } else {
  61. $config = "\$(CONFIG_PACKAGE_$name)"
  62. }
  63. if ($config) {
  64. print "package-$config += $pkg{$name}->{src}\n";
  65. $pkg{$name}->{prereq} and print "prereq-$config += $pkg{$name}->{src}\n";
  66. }
  67. my $hasdeps = 0;
  68. my $depline = "";
  69. foreach my $dep (@{$pkg{$name}->{depends}}) {
  70. my $idx;
  71. next if defined $pkg{$dep}->{virtual};
  72. if (defined $pkg{$dep}->{src}) {
  73. ($pkg{$name}->{src} ne $pkg{$dep}->{src}) and $idx = $pkg{$dep}->{src};
  74. } elsif (defined($pkg{$dep}) && !$options{SDK}) {
  75. $idx = $dep;
  76. }
  77. undef $idx if $idx =~ /^(kernel)|(base-files)$/;
  78. if ($idx) {
  79. next if $dep{$pkg{$name}->{src}."->".$idx};
  80. $depline .= " $idx\-compile";
  81. $dep{$pkg{$name}->{src}."->".$idx} = 1;
  82. }
  83. }
  84. if ($depline ne "") {
  85. $line .= "$pkg{$name}->{src}-compile: $depline\n";
  86. }
  87. }
  88. if ($line ne "") {
  89. print "\n$line";
  90. }