gen_deps.pl 2.2 KB

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