finish up package makefile
[openwrt/openwrt.git] / openwrt / scripts / gen_deps.pl
1 #!/usr/bin/perl
2 use strict;
3
4 my $name;
5 my $src;
6 my $makefile;
7 my %pkg;
8
9 my $line;
10 while ($line = <>) {
11 chomp $line;
12 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
13 $makefile = $1;
14 $src = $2;
15 };
16 $line =~ /^Package: \s*(.+)\s*$/ and do {
17 $name = $1;
18 defined $pkg{$name} or $pkg{$name} = {};
19 $pkg{$name}->{src} = $src;
20 };
21 $line =~ /^Depends: \s*(.+)\s*$/ and do {
22 my @dep = split /,\s*/, $1;
23 $pkg{$name}->{depends} = \@dep;
24 };
25 }
26
27 $line="";
28
29 foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
30 print "package-\$(CONFIG_PACKAGE_$name) += $pkg{$name}->{src}\n";
31
32 my $hasdeps = 0;
33 my $depline = "";
34 foreach my $dep (@{$pkg{$name}->{depends}}) {
35 if (defined $pkg{$dep}->{src} && $pkg{$name}->{src} ne $pkg{$dep}->{src}) {
36 $depline .= " $pkg{$dep}->{src}-compile";
37 }
38 }
39 if ($depline ne "") {
40 $line .= "$pkg{$name}->{src}-compile: $depline\n";
41 }
42 }
43
44 if ($line ne "") {
45 print "\n$line";
46 }