sync whiterussian download.pl with trunk, allow the user to specify additional wget...
[openwrt/svn-archive/archive.git] / scripts / gen_deps.pl
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
9 use strict;
10
11 my $name;
12 my $src;
13 my $makefile;
14 my %conf;
15 my %pkg;
16 my %prereq;
17 my %dep;
18 my %options;
19 my $opt;
20
21 while ($opt = shift @ARGV) {
22 $opt =~ /^-s/ and $options{SDK} = 1;
23 }
24
25 my $line;
26 while ($line = <>) {
27 chomp $line;
28 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
29 $makefile = $1;
30 $src = $2;
31 };
32 $line =~ /^Package: \s*(.+)\s*$/ and do {
33 $name = $1;
34 defined $pkg{$name} or $pkg{$name} = {};
35 $pkg{$name}->{src} = $src;
36 };
37 $line =~ /^Prereq-Check:/ and !defined $prereq{$src} and do {
38 $pkg{$name}->{prereq} = 1;
39 };
40 $line =~ /^(Build-)?Depends: \s*(.+)\s*$/ and do {
41 $pkg{$name}->{depends} ||= [];
42 foreach my $v (split /\s+/, $2) {
43 next if $v =~ /^[\+]?@/;
44 $v =~ s/^\+//;
45 push @{$pkg{$name}->{depends}}, $v;
46 }
47 };
48 }
49
50 $line="";
51
52 foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
53 my $config;
54
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
68 my $hasdeps = 0;
69 my $depline = "";
70 foreach my $dep (@{$pkg{$name}->{depends}}) {
71 my $idx;
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
89 if ($line ne "") {
90 print "\n$line";
91 }