speed up package prereq check (only run make on those directories that actually conta...
[openwrt.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 $prereq;
18 my %dep;
19 my %options;
20 my $opt;
21
22 while ($opt = shift @ARGV) {
23         $opt =~ /^-s/ and $options{SDK} = 1;
24 }
25
26 my $line;
27 while ($line = <>) {
28         chomp $line;
29         $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
30                 $makefile = $1;
31                 $src = $2;
32         };
33         $line =~ /^Package: \s*(.+)\s*$/ and do {
34                 $name = $1;
35                 defined $pkg{$name} or $pkg{$name} = {};
36                 $pkg{$name}->{src} = $src;
37         };
38         $line =~ /^Prereq-Check:/ and !defined $prereq{$src} and do {
39                 $prereq{$src} = 1;
40                 $prereq .= "package-prereq += $src\n";
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
52 $line="";
53
54 foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
55         if ($options{SDK}) {
56                 $conf{$pkg{$name}->{src}} or print "package-m += $pkg{$name}->{src}\n";
57                 $conf{$pkg{$name}->{src}} = 1;
58         } else {
59                 print "package-\$(CONFIG_PACKAGE_$name) += $pkg{$name}->{src}\n";
60         }
61
62         my $hasdeps = 0;
63         my $depline = "";
64         foreach my $dep (@{$pkg{$name}->{depends}}) {
65                 my $idx;
66                 if (defined $pkg{$dep}->{src}) {
67                         ($pkg{$name}->{src} ne $pkg{$dep}->{src}) and $idx = $pkg{$dep}->{src};
68                 } elsif (defined($pkg{$dep}) && !$options{SDK}) {
69                         $idx = $dep;
70                 }
71                 undef $idx if $idx =~ /^(kernel)|(base-files)$/;
72                 if ($idx) {
73                         next if $dep{$pkg{$name}->{src}."->".$idx};
74                         $depline .= " $idx\-compile";
75                         $dep{$pkg{$name}->{src}."->".$idx} = 1;
76                 }
77         }
78         if ($depline ne "") {
79                 $line .= "$pkg{$name}->{src}-compile: $depline\n";
80         }
81 }
82
83 if ($line ne "") {
84         print "\n$line\n$prereq";
85 }