Update perl shell configuration scripts with the new toolchain name and the switch...
[openwrt/svn-archive/archive.git] / lang / perl / files / perlmod-deps.sh
1 #!/bin/sh
2 #
3 # Generate perl module package dependencies
4 #
5 # Copyright (C) 2007 Peter Colberg <peter@petercolberg.org>
6 # Licensed under the terms of the GNU General Public License.
7 #
8
9 if [ $# -lt 3 ]; then
10 echo >&2 "Usage: $(basename $0) STAGING-DIR PERL-BUILD-DIR [FILES...] [DIRECTORIES...]"
11 exit 1
12 fi
13
14 STAGING_DIR="$1"
15 PERL_BIN="$STAGING_DIR/usr/bin/perl"
16 PERL_LIB="$STAGING_DIR/usr/lib/perl5/5.10"
17 INC_DIR="$(dirname $0)"
18 shift
19
20 "$PERL_BIN" -I"$INC_DIR" -I"$PERL_LIB" - "$@" <<'PERL_SCRIPT'
21 use strict;
22 use warnings;
23
24 use Module::ScanDeps;
25 use File::Find;
26 use Cwd;
27
28 our $sitelib = "/usr/lib/perl5/5.10";
29
30 sub scandeps {
31 my $builddir = Cwd::abs_path(shift);
32 my @scanpaths = @_;
33 my ($curdir, @pkgdirs, $dir, @deps, %depends, $file);
34 our ($pkg, %bundles, $path, @files);
35
36 @pkgdirs = glob($builddir . "/*/ipkg");
37 $curdir = getcwd();
38 @INC = ();
39 for $dir (@pkgdirs) {
40 chdir($dir) or die "$dir: $!";
41 for $pkg (glob("*")) {
42 chdir($dir . "/" . $pkg . $sitelib) or next;
43 push @INC, getcwd();
44 sub wanted {
45 return unless (-f $_);
46 s/^\.\///;
47 $bundles{$_} = $pkg;
48 }
49 find({ wanted => \&wanted, no_chdir => 1 }, ".");
50 }
51 }
52 chdir($curdir) or die "$curdir: $!\n";
53
54 for $path (@scanpaths) {
55 sub scan_wanted {
56 return unless (-f $_ and /\.(pl|pm)$/);
57 push @files, $_;
58 }
59 if (-f $path) {
60 push @files, $path;
61 }
62 elsif (-d $path) {
63 find({ wanted => \&scan_wanted, no_chdir => 1 }, $path);
64 }
65 }
66
67 @deps = keys %{scan_deps(files => \@files, recurse => 0)};
68 for $file (grep { not exists $bundles{$_} } @deps) {
69 warn "could not resolve dependency: $file\n";
70 }
71 %depends = map { $bundles{$_}, 1 } grep { exists $bundles{$_} } @deps;
72
73 if (%depends) {
74 print join(' ', 'perl', sort keys %depends), "\n";
75 }
76 }
77
78 if (@ARGV > 1) {
79 scandeps(@ARGV);
80 }
81 PERL_SCRIPT