Regen Glossary et al.
[p5sagit/p5-mst-13.2.git] / wince / makedist.pl
CommitLineData
2e64bfdb 1use strict;
2use Cwd;
3use File::Path;
4use File::Find;
5
6my %opts = (
7 #defaults
c96f74ce 8 'verbose' => 1, # verbose level, in range from 0 to 2
2e64bfdb 9 'distdir' => 'distdir',
10 'unicode' => 1, # include unicode by default
11 'minimal' => 0, # minimal possible distribution.
12 # actually this is just perl.exe and perlXX.dll
13 # but can be extended by additional exts
14 # ... (as soon as this will be implemented :)
15 'include-modules' => '', # TODO
16 'exclude-modules' => '', # TODO
17 #??? 'only-modules' => '', # TODO
c96f74ce 18 'cross-name' => 'wince',
2e64bfdb 19 'strip-pod' => 0, # TODO strip POD from perl modules
20 'adaptation' => 0, # TODO do some adaptation, such as stripping such
21 # occurences as "if ($^O eq 'VMS'){...}" for certain modules
c96f74ce 22 'zip' => 0, # perform zip
2e64bfdb 23 'clean-exts' => 0,
24 #options itself
25 (map {/^--([\-_\w]+)=(.*)$/} @ARGV), # --opt=smth
26 (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV), # --opt --no-opt --noopt
27 );
28
c96f74ce 29# TODO
30# -- error checking. When something goes wrong, just exit with rc!=0
31# -- may be '--zip' option should be made differently?
2e64bfdb 32
33my $cwd = cwd;
34
35if ($opts{'clean-exts'}) {
36 # unfortunately, unlike perl58.dll and like, extensions for different
37 # platforms are built in same directory, therefore we must be able to clean
38 # them often
39 unlink '../config.sh'; # delete cache config file, which remembers our previous config
40 chdir '../ext';
41 find({no_chdir=>1,wanted => sub{
42 unlink if /((?:\.obj|\/makefile|\/errno\.pm))$/i;
43 }
44 },'.');
45 exit;
46}
47
c96f74ce 48# zip
49if ($opts{'zip'}) {
50 if ($opts{'verbose'} >=1) {
51 print STDERR "zipping...\n";
52 }
53 chdir $opts{'distdir'};
54 unlink <*.zip>;
55 `zip -R perl-$opts{'cross-name'} *`;
56 exit;
57}
58
2e64bfdb 59my (%libexclusions, %extexclusions);
60my @lfiles;
61sub copy($$);
62
63# lib
64chdir '../lib';
65find({no_chdir=>1,wanted=>sub{push @lfiles, $_ if /\.p[lm]$/}},'.');
66chdir $cwd;
67# exclusions
68@lfiles = grep {!exists $libexclusions{$_}} @lfiles;
69#inclusions
70#...
71#copy them
c96f74ce 72if ($opts{'verbose'} >=1) {
73 print STDERR "Copying perl lib files...\n";
74}
2e64bfdb 75for (@lfiles) {
76 /^(.*)\/[^\/]+$/;
77 mkpath "$opts{distdir}/lib/$1";
78 copy "../lib/$_", "$opts{distdir}/lib/$_";
79}
80
81#ext
82my @efiles;
83chdir '../ext';
84find({no_chdir=>1,wanted=>sub{push @efiles, $_ if /\.pm$/}},'.');
85chdir $cwd;
86# exclusions
87#...
88#inclusions
89#...
90#copy them
91#{s[/(\w+)/\1\.pm][/$1.pm]} @efiles;
c96f74ce 92if ($opts{'verbose'} >=1) {
93 print STDERR "Copying perl core extensions...\n";
94}
2e64bfdb 95for (@efiles) {
96 /^(.*)\/([^\/]+)\/([^\/]+)$/;
97 copy "../ext/$_", "$opts{distdir}/lib/$1/$3";
98}
99
c96f74ce 100# Config.pm, perl binaries
101if ($opts{'verbose'} >=1) {
102 print STDERR "Copying Config.pm, perl.dll and perl.exe...\n";
103}
104copy "../xlib/$opts{'cross-name'}/Config.pm", "$opts{distdir}/lib/Config.pm";
105copy "$opts{'cross-name'}/perl.exe", "$opts{distdir}/bin/perl.exe";
106copy "$opts{'cross-name'}/perl.dll", "$opts{distdir}/bin/perl.dll";
107# how do we know exact name of perl.dll?)
2e64bfdb 108
109# auto
110my @afiles;
c96f74ce 111chdir "../xlib/$opts{'cross-name'}/auto";
2e64bfdb 112find({no_chdir=>1,wanted=>sub{push @afiles, $_ if /\.(dll|bs)$/}},'.');
113chdir $cwd;
c96f74ce 114if ($opts{'verbose'} >=1) {
115 print STDERR "Copying binaries for perl core extensions...\n";
116}
2e64bfdb 117for (@afiles) {
c96f74ce 118 copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$_";
2e64bfdb 119}
120
c96f74ce 121sub copy($$) {
2e64bfdb 122 my ($fnfrom, $fnto) = @_;
c96f74ce 123 open my $fh, "<$fnfrom" or die "can not open $fnfrom: $!";
124 binmode $fh;
125 local $/;
126 my $ffrom = <$fh>;
2e64bfdb 127 if ($opts{'strip-pod'}) {
128 # actually following regexp is suspicious to not work everywhere.
129 # but we've checked on our set of modules, and it's fit for our purposes
130 $ffrom =~ s/^=\w+.*?^=cut(?:\n|\Z)//msg;
131 # $ffrom =~ s/^__END__.*\Z//msg; # TODO -- deal with Autoload
132 }
133 mkpath $1 if $fnto=~/^(.*)\/([^\/]+)$/;
134 open my $fhout, ">$fnto";
c96f74ce 135 binmode $fhout;
2e64bfdb 136 print $fhout $ffrom;
c96f74ce 137 if ($opts{'verbose'} >=2) {
138 print STDERR "copying $fnfrom=>$fnto\n";
139 }
2e64bfdb 140}
141
142BEGIN {
143%libexclusions = map {$_=>1} split/\s/, <<"EOS";
144abbrev.pl bigfloat.pl bigint.pl bigrat.pl cacheout.pl complete.pl ctime.pl
145dotsh.pl exceptions.pl fastcwd.pl flush.pl ftp.pl getcwd.pl getopt.pl
146getopts.pl hostname.pl look.pl newgetopt.pl pwd.pl termcap.pl
147EOS
148%extexclusions = map {$_=>1} split/\s/, <<"EOS";
149EOS
150
151}
152