source: packages/lang/perl/files/scan-perlbase.sh @ 11626

Last change on this file since 11626 was 11626, checked in by matteo, 8 years ago

packaged full perl, thanks Peter Colberg (closes #3708)

File size: 4.0 KB
Line 
1#!/bin/sh
2#
3# Generate perl base modules package definitions
4#
5# Copyright (C) 2007  Peter Colberg <peter@petercolberg.org>
6# Licensed under the terms of the GNU General Public License.
7#
8
9if [ $# -lt 1 ]; then
10    echo >&2 "Usage: $(basename $0) STAGING-DIR [OUTFILE]"
11    exit 1
12fi
13
14STAGING_DIR="$1"
15PERL_BIN="$STAGING_DIR/usr/bin/perl"
16PERL_LIB="$STAGING_DIR/usr/lib/perl5/5.10"
17INC_DIR="$(dirname $0)"
18shift
19
20"$PERL_BIN" -I"$INC_DIR" -I"$PERL_LIB" - "$PERL_LIB" "$@" <<'PERL_SCRIPT'
21use strict;
22use warnings;
23
24use Module::ScanDeps;
25use File::Find;
26use File::Basename;
27
28our $skipfiles = 'CORE vmsish.pm auto/sdbm';
29
30our %defmodules = (
31    'essential' => 'lib.pm vars.pm strict.pm warnings.pm warnings Carp Carp.pm Exporter Exporter.pm locale.pm subs.pm overload.pm constant.pm',
32    'getoptpl' => 'getopt.pl getopts.pl',
33    'utf8' => 'utf8_heavy.pl',
34    'Getopt' => 'newgetopt.pl',
35    'open' => 'open2.pl open3.pl',
36    'Config' => 'Config_heavy.pl',
37    'bytes' => 'bytes_heavy.pl',
38);
39
40our %defdepends = (
41    'DB_File' => 'libdb1-compat',
42    'GDBM_File' => 'libgdbm',
43);
44
45our $prefix = 'perlbase-';
46
47sub template ($) {
48    $_ = $_[0];
49    return <<TEMPLATE;
50define Package/$$_{package}
51SECTION:=lang
52CATEGORY:=Languages
53URL:=http://www.cpan.org/
54MAINTAINER:=Peter Colberg <peter\@petercolberg.org>
55TITLE:=$$_{module} perl module
56DEPENDS:=$$_{depends}
57endef
58
59define Package/$$_{package}/install
60\$(call perlmod/Install,\$(1),$$_{files},$$_{exclude})
61endef
62
63\$(eval \$(call BuildPackage,$$_{package}))
64
65
66TEMPLATE
67}
68
69
70sub scandeps ($) {
71    my $sitedir = shift;
72    my @result;
73
74    my ($mod, $file, @deps, $dep, %depends, $parent, $pkg);
75    our (%files, %modules);
76    my (%packages, %excludes);
77
78    for $mod (keys %defmodules) {
79        ($pkg = $prefix . $mod) =~ tr/A-Z_/a-z-/;
80        $modules{$pkg} = $mod;
81        for $file (split / /, $defmodules{$mod}) {
82            $files{$file} = $pkg;
83        }
84    }
85    for $file ('pod', 'Pod', split(/ /, $skipfiles)) {
86        $files{$file} = undef;
87    }
88
89    sub wanted {
90        s/^\.\///;
91        return if (/^(\.|auto)$/ or exists $files{$_});
92        if (/\.pod$/) {
93            $files{$_} = undef;
94        }
95        elsif (exists $files{dirname($_)}) {
96            $files{$_} = $files{dirname($_)};
97        }
98        elsif (m!^(?:auto/)?([^./]+)(?:\.(?:pl|pm)|/|$)!) {
99            (my $pkg = $prefix . $1) =~ tr/A-Z_/a-z-/;
100            $modules{$pkg} = $1;
101            $files{$_} = $pkg;
102        }
103        else {
104            $files{$_} = undef;
105        }
106    }
107    chdir($sitedir);
108    find({ wanted => \&wanted, no_chdir => 1}, '.');
109
110    for $pkg (keys %modules) {
111        $packages{$pkg} = [];
112        $excludes{$pkg} = [];
113        $depends{$pkg} = {};
114    }
115
116    for $file (keys %files) {
117        $mod = $files{$file};
118        $parent = $files{dirname($file)};
119
120        if (defined ($mod)) {
121            if (defined ($parent) and not ($parent eq $mod)) {
122                push @{$packages{$mod}}, $file;
123                push @{$excludes{$parent}}, $file;
124            }
125            elsif (not defined ($parent)) {
126                push @{$packages{$mod}}, $file;
127            }
128        }
129        elsif (defined ($parent)) {
130            push @{$excludes{$parent}}, $file;
131        }
132    }
133
134    for $mod (keys %defdepends) {
135        ($pkg = $prefix . $mod) =~ tr/A-Z_/a-z-/;
136        for $dep (split / /, $defdepends{$mod}) {
137            ${$depends{$pkg}}{$dep} = 1;
138        }
139    }
140
141    @INC = ('.');
142    for $file (grep { -f $_ and defined $files{$_} } keys %files) {
143        @deps = keys %{scan_deps(files => [ $file ], recurse => 0)};
144        $pkg = $files{$file};
145
146        for $dep (grep { not defined $files{$_} } @deps) {
147            warn "$file: could not resolve dependency: $dep\n";
148        }
149        for $dep (grep { defined $files{$_} } @deps) {
150            next if ($files{$dep} eq $pkg);
151            ${$depends{$pkg}}{$files{$dep}} = 1;
152        }
153    }
154
155    for $pkg (sort keys %packages) {
156        push @result, template({
157            package => $pkg,
158            module => $modules{$pkg},
159            depends => join(' ', 'perl', sort keys %{$depends{$pkg}}),
160            files => join(' ', sort @{$packages{$pkg}}),
161            exclude => join(' ', sort @{$excludes{$pkg}}),
162        });
163    }
164
165    return join('', @result);
166}
167
168
169if (@ARGV > 1) {
170    open FILE, ">$ARGV[1]" or die "$ARGV[1]: $!\n";
171    print FILE scandeps($ARGV[0]);
172    close FILE;
173}
174else {
175    print scandeps($ARGV[0] or '.');
176}
177PERL_SCRIPT
Note: See TracBrowser for help on using the repository browser.