fix lxdialog cc/ldflags check script for darwin/osx
[openwrt/staging/dedeckeh.git] / openwrt / 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 %dep;
17 my %options;
18 my $opt;
19
20 while ($opt = shift @ARGV) {
21 $opt =~ /^-s/ and $options{SDK} = 1;
22 }
23
24 my $line;
25 while ($line = <>) {
26 chomp $line;
27 $line =~ /^Source-Makefile: \s*(.+\/([^\/]+)\/Makefile)\s*$/ and do {
28 $makefile = $1;
29 $src = $2;
30 };
31 $line =~ /^Package: \s*(.+)\s*$/ and do {
32 $name = $1;
33 defined $pkg{$name} or $pkg{$name} = {};
34 $pkg{$name}->{src} = $src;
35 };
36 $line =~ /^(Build-)?Depends: \s*(.+)\s*$/ and do {
37 $pkg{$name}->{depends} ||= [];
38 foreach my $v (split /\s+/, $2) {
39 next if $v =~ /^[\+]?@/;
40 $v =~ s/^\+//;
41 push @{$pkg{$name}->{depends}}, $v;
42 }
43 };
44 }
45
46 $line="";
47
48 foreach $name (sort {uc($a) cmp uc($b)} keys %pkg) {
49 if ($options{SDK}) {
50 $conf{$pkg{$name}->{src}} or print "package-m += $pkg{$name}->{src}\n";
51 $conf{$pkg{$name}->{src}} = 1;
52 } else {
53 print "package-\$(CONFIG_PACKAGE_$name) += $pkg{$name}->{src}\n";
54 }
55
56 my $hasdeps = 0;
57 my $depline = "";
58 foreach my $dep (@{$pkg{$name}->{depends}}) {
59 my $idx;
60 if (defined $pkg{$dep}->{src}) {
61 ($pkg{$name}->{src} ne $pkg{$dep}->{src}) and $idx = $pkg{$dep}->{src};
62 } elsif (defined($pkg{$dep}) && !$options{SDK}) {
63 $idx = $dep;
64 }
65 if ($idx) {
66 next if $dep{$pkg{$name}->{src}."->".$idx};
67 $depline .= " $idx\-compile";
68 $dep{$pkg{$name}->{src}."->".$idx} = 1;
69 }
70 }
71 if ($depline ne "") {
72 $line .= "$pkg{$name}->{src}-compile: $depline\n";
73 }
74 }
75
76 if ($line ne "") {
77 print "\n$line";
78 }