8 'verbose' => 1, # verbose level, in range from 0 to 2
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 'cross-name' => 'wince',
16 'strip-pod' => 0, # strip POD from perl modules
17 'adaptation' => 1, # do some adaptation, such as stripping such
18 # occurences as "if ($^O eq 'VMS'){...}" for Dynaloader.pm
19 'zip' => 0, # perform zip
22 (map {/^--([\-_\w]+)=(.*)$/} @ARGV), # --opt=smth
23 (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV), # --opt --no-opt --noopt
27 # -- error checking. When something goes wrong, just exit with rc!=0
28 # -- may be '--zip' option should be made differently?
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
36 unlink '../config.sh'; # delete cache config file, which remembers our previous config
38 find({no_chdir=>1,wanted => sub{
39 unlink if /((?:\.obj|\/makefile|\/errno\.pm))$/i;
47 if ($opts{'verbose'} >=1) {
48 print STDERR "zipping...\n";
50 chdir $opts{'distdir'};
52 `zip -R perl-$opts{'cross-name'} *`;
56 my (%libexclusions, %extexclusions);
62 find({no_chdir=>1,wanted=>sub{push @lfiles, $_ if /\.p[lm]$/}},'.');
65 @lfiles = grep {!exists $libexclusions{$_}} @lfiles;
69 if ($opts{'verbose'} >=1) {
70 print STDERR "Copying perl lib files...\n";
74 mkpath "$opts{distdir}/lib/$1";
75 copy "../lib/$_", "$opts{distdir}/lib/$_";
81 find({no_chdir=>1,wanted=>sub{push @efiles, $_ if /\.pm$/}},'.');
88 #{s[/(\w+)/\1\.pm][/$1.pm]} @efiles;
89 if ($opts{'verbose'} >=1) {
90 print STDERR "Copying perl core extensions...\n";
93 if (m#^.*?/lib/(.*)$#) {
94 copy "../ext/$_", "$opts{distdir}/lib/$1";
97 /^(.*)\/([^\/]+)\/([^\/]+)$/;
98 copy "../ext/$_", "$opts{distdir}/lib/$1/$3";
102 if ($opts{adaptation}) {
103 # let's copy our Dynaloader.pm (make this optional?)
104 open my $fhdyna, ">$opts{distdir}/lib/Dynaloader.pm";
105 print $fhdyna $dynaloader_pm;
109 # Config.pm, perl binaries
110 if ($opts{'verbose'} >=1) {
111 print STDERR "Copying Config.pm, perl.dll and perl.exe...\n";
113 copy "../xlib/$opts{'cross-name'}/Config.pm", "$opts{distdir}/lib/Config.pm";
114 copy "$opts{'cross-name'}/perl.exe", "$opts{distdir}/bin/perl.exe";
115 copy "$opts{'cross-name'}/perl.dll", "$opts{distdir}/bin/perl.dll";
116 # how do we know exact name of perl.dll?
119 my %aexcl = (socket=>'Socket_1');
120 # Socket.dll and may be some other conflict with same file in \windows dir
121 # on WinCE, %aexcl needed to replace it with a different name that however
122 # will be found by Dynaloader
124 chdir "../xlib/$opts{'cross-name'}/auto";
125 find({no_chdir=>1,wanted=>sub{push @afiles, $_ if /\.(dll|bs)$/}},'.');
127 if ($opts{'verbose'} >=1) {
128 print STDERR "Copying binaries for perl core extensions...\n";
131 if (/^(.*)\/(\w+)\.dll$/i && exists $aexcl{lc($2)}) {
132 copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$1/$aexcl{lc($2)}.dll";
135 copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$_";
140 my ($fnfrom, $fnto) = @_;
141 open my $fh, "<$fnfrom" or die "can not open $fnfrom: $!";
145 if ($opts{'strip-pod'}) {
146 # actually following regexp is suspicious to not work everywhere.
147 # but we've checked on our set of modules, and it's fit for our purposes
148 $ffrom =~ s/^=\w+.*?^=cut(?:\n|\Z)//msg;
149 unless ($ffrom=~/\bAutoLoader\b/) {
150 # this logic actually strip less than could be stripped, but we're
151 # not risky. Just strip only of no mention of AutoLoader
152 $ffrom =~ s/^__END__.*\Z//msg;
155 mkpath $1 if $fnto=~/^(.*)\/([^\/]+)$/;
156 open my $fhout, ">$fnto";
159 if ($opts{'verbose'} >=2) {
160 print STDERR "copying $fnfrom=>$fnto\n";
165 %libexclusions = map {$_=>1} split/\s/, <<"EOS";
166 abbrev.pl bigfloat.pl bigint.pl bigrat.pl cacheout.pl complete.pl ctime.pl
167 dotsh.pl exceptions.pl fastcwd.pl flush.pl ftp.pl getcwd.pl getopt.pl
168 getopts.pl hostname.pl look.pl newgetopt.pl pwd.pl termcap.pl
170 %extexclusions = map {$_=>1} split/\s/, <<"EOS";
172 $dynaloader_pm=<<'EOS';
173 # This module designed *only* for WinCE
174 # if you encounter a problem with this file, try using original Dynaloader.pm
175 # from perl distribution, it's larger but essentially the same.
181 @dl_require_symbols = (); # names of symbols we need
183 #@dl_librefs = (); # things we have loaded
184 #@dl_modules = (); # Modules we have loaded
186 boot_DynaLoader('DynaLoader') if defined(&boot_DynaLoader) && !defined(&dl_error);
188 print STDERR "DynaLoader not linked into this perl\n"
189 unless defined(&boot_DynaLoader);
191 1; # End of main code
193 sub croak{require Carp;Carp::croak(@_)}
194 sub bootstrap_inherit {
196 local *isa = *{"$module\::ISA"};
197 local @isa = (@isa, 'DynaLoader');
201 # use local vars to enable $module.bs script to edit values
203 local($module) = $args[0];
208 Carp::confess("Usage: DynaLoader::bootstrap(module)");
211 croak("Can't load module $module, dynamic loading not available in this perl.\n")
212 unless defined(&dl_load_file);
214 my @modparts = split(/::/,$module);
215 my $modfname = $modparts[-1];
216 my $modpname = join('/',@modparts);
219 my $dir = "$_/auto/$modpname";
221 my $try = "$dir/$modfname.dll";
222 last if $file = ( (-f $try) && $try);
224 $try = "$dir/${modfname}_1.dll";
225 last if $file = ( (-f $try) && $try);
228 $file = dl_findfile(map("-L$_",@dirs,@INC), $modfname) unless $file;
230 croak("Can't locate loadable object for module $module in \@INC (\@INC contains: @INC)")
233 (my $bootname = "boot_$module") =~ s/\W/_/g;
234 @dl_require_symbols = ($bootname);
236 # optional '.bootstrap' perl script
238 $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/;
239 if (-s $bs) { # only read file if it's not empty
241 warn "$bs: $@\n" if $@;
244 my $libref = dl_load_file($file, 0) or
245 croak("Can't load '$file' for module $module: ".dl_error());
247 push(@dl_librefs,$libref); # record loaded object
249 my @unresolved = dl_undef_symbols();
252 Carp::carp("Undefined symbols present after loading $file: @unresolved\n");
255 my $boot_symbol_ref = dl_find_symbol($libref, $bootname) or
256 croak("Can't find '$bootname' symbol in $file\n");
258 push(@dl_modules, $module);
261 my $xs = dl_install_xsub("${module}::bootstrap", $boot_symbol_ref, $file);
270 arg: foreach(@args) {
273 last arg unless wantarray;
277 if (s:^-L::) {push(@dirs, $_); next;}
278 if (m:/: && -d $_) {push(@dirs, $_); next;}
282 for my $name (/\.dll$/i?($_):("$_.dll",$_)) {
283 print STDERR " checking in $dir for $name\n" if $dl_debug;
284 if (-f "$dir/$name") {
285 push(@found, "$dir/$name");
291 return $found[0] unless wantarray;