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