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