More WinCE tweaking for Vadim Konovalov.
[p5sagit/p5-mst-13.2.git] / wince / makedist.pl
index 5729922..be447e8 100644 (file)
@@ -5,6 +5,7 @@ use File::Find;
 
 my %opts = (
   #defaults
+    'verbose' => 1, # verbose level, in range from 0 to 2
     'distdir' => 'distdir',
     'unicode' => 1, # include unicode by default
     'minimal' => 0, # minimal possible distribution.
@@ -14,18 +15,20 @@ my %opts = (
     'include-modules' => '', # TODO
     'exclude-modules' => '', # TODO
     #??? 'only-modules' => '', # TODO
-    'platform' => 'wince',
+    'cross-name' => 'wince',
     'strip-pod' => 0, # TODO strip POD from perl modules
     'adaptation' => 0, # TODO do some adaptation, such as stripping such
                        # occurences as "if ($^O eq 'VMS'){...}" for certain modules
-    'zip' => 0,     # perform zip (TODO)
+    'zip' => 0,     # perform zip
     'clean-exts' => 0,
   #options itself
     (map {/^--([\-_\w]+)=(.*)$/} @ARGV),                            # --opt=smth
     (map {/^no-?(.*)$/i?($1=>0):($_=>1)} map {/^--([\-_\w]+)$/} @ARGV),  # --opt --no-opt --noopt
   );
 
-# TODO -- error checking. When something goes wrong, just exit with rc!=0
+# TODO
+#   -- error checking. When something goes wrong, just exit with rc!=0
+#   -- may be '--zip' option should be made differently?
 
 my $cwd = cwd;
 
@@ -42,6 +45,17 @@ if ($opts{'clean-exts'}) {
   exit;
 }
 
+# zip
+if ($opts{'zip'}) {
+  if ($opts{'verbose'} >=1) {
+    print STDERR "zipping...\n";
+  }
+  chdir $opts{'distdir'};
+  unlink <*.zip>;
+  `zip -R perl-$opts{'cross-name'} *`;
+  exit;
+}
+
 my (%libexclusions, %extexclusions);
 my @lfiles;
 sub copy($$);
@@ -55,6 +69,9 @@ chdir $cwd;
 #inclusions
 #...
 #copy them
+if ($opts{'verbose'} >=1) {
+  print STDERR "Copying perl lib files...\n";
+}
 for (@lfiles) {
   /^(.*)\/[^\/]+$/;
   mkpath "$opts{distdir}/lib/$1";
@@ -72,26 +89,41 @@ chdir $cwd;
 #...
 #copy them
 #{s[/(\w+)/\1\.pm][/$1.pm]} @efiles;
+if ($opts{'verbose'} >=1) {
+  print STDERR "Copying perl core extensions...\n";
+}
 for (@efiles) {
   /^(.*)\/([^\/]+)\/([^\/]+)$/;
   copy "../ext/$_", "$opts{distdir}/lib/$1/$3";
 }
 
-# Config.pm
-copy "../xlib/$opts{platform}/Config.pm", "$opts{distdir}/lib/Config.pm";
+# Config.pm, perl binaries
+if ($opts{'verbose'} >=1) {
+  print STDERR "Copying Config.pm, perl.dll and perl.exe...\n";
+}
+copy "../xlib/$opts{'cross-name'}/Config.pm", "$opts{distdir}/lib/Config.pm";
+copy "$opts{'cross-name'}/perl.exe", "$opts{distdir}/bin/perl.exe";
+copy "$opts{'cross-name'}/perl.dll", "$opts{distdir}/bin/perl.dll";
+# how do we know exact name of perl.dll?)
 
 # auto
 my @afiles;
-chdir "../xlib/$opts{platform}/auto";
+chdir "../xlib/$opts{'cross-name'}/auto";
 find({no_chdir=>1,wanted=>sub{push @afiles, $_ if /\.(dll|bs)$/}},'.');
 chdir $cwd;
+if ($opts{'verbose'} >=1) {
+  print STDERR "Copying binaries for perl core extensions...\n";
+}
 for (@afiles) {
-  copy "../xlib/$opts{platform}/auto/$_", "$opts{distdir}/lib/auto/$_";
+  copy "../xlib/$opts{'cross-name'}/auto/$_", "$opts{distdir}/lib/auto/$_";
 }
 
-sub copy {
+sub copy($$) {
   my ($fnfrom, $fnto) = @_;
-  my $ffrom = do {local (@ARGV,$/) = $fnfrom; <>};
+  open my $fh, "<$fnfrom" or die "can not open $fnfrom: $!";
+  binmode $fh;
+  local $/;
+  my $ffrom = <$fh>;
   if ($opts{'strip-pod'}) {
     # actually following regexp is suspicious to not work everywhere.
     # but we've checked on our set of modules, and it's fit for our purposes
@@ -100,7 +132,11 @@ sub copy {
   }
   mkpath $1 if $fnto=~/^(.*)\/([^\/]+)$/;
   open my $fhout, ">$fnto";
+  binmode $fhout;
   print $fhout $ffrom;
+  if ($opts{'verbose'} >=2) {
+    print STDERR "copying $fnfrom=>$fnto\n";
+  }
 }
 
 BEGIN {