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