This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update CPANPLUS-Dist-Build to CPAN version 0.52
[perl5.git] / symbian / xsbuild.pl
index ff743bd..939b569 100644 (file)
@@ -6,11 +6,24 @@ use Getopt::Long;
 use File::Basename;
 use Cwd;
 
-do "sanity.pl";
+unshift @INC, dirname $0 || '.';
+do "sanity.pl" or die $@;
 
 my $CoreBuild = -d "ext" && -f "perl.h" && -d "symbian" && -f "perl.c";
 
-my $SymbianVersion = $ENV{XSBUILD_SYMBIAN_VERSION};
+my $SymbianVersion;
+
+if (exists $ENV{EPOCROOT}) {
+    if ($ENV{EPOCROOT} =~ m!\\Symbian\\UIQ_21\\$!i) {
+       $SymbianVersion = '7.0s'; # TODO: other UIQ versions
+    } elsif ($ENV{EPOCROOT} =~ m!\\Symbian\\(.+?)\\!i) {
+       $SymbianVersion = $1;
+    }
+}
+
+$SymbianVersion = $ENV{XSBUILD_SYMBIAN_VERSION}
+  if exists $ENV{XSBUILD_SYMBIAN_VERSION};
+
 my $PerlVersion    = $ENV{XSBUILD_PERL_VERSION};
 my $CSuffix        = '.c';
 my $CPlusPlus;
@@ -23,8 +36,9 @@ my $Sis;
 sub usage {
     die <<__EOF__;
 $0: Usage: $0 [--symbian=version] [--perl=version]
-              [--csuffix=csuffix] [--cplusplus]
-             [--win=win] [--arm=arm]
+              [--extversion=x.y]
+              [--csuffix=csuffix] [--cplusplus|--cpp]
+              [--win=win] [--arm=arm]
               [--config|--build|--clean|--distclean|--sis] ext
 __EOF__
 }
@@ -34,9 +48,9 @@ my $SDK;
 my $VERSION;
 my $R_V_SV;
 my $PERLSDK;
-my $WIN;
-my $ARM;
-my $HOME = getcwd();
+my $WIN = 'wins';
+my $ARM = 'thumb';
+my $BUILDROOT = getcwd();
 
 if ( !defined $PerlVersion && $0 =~ m:\\symbian\\perl\\(.+)\\bin\\xsbuild.pl:i )
 {
@@ -44,37 +58,38 @@ if ( !defined $PerlVersion && $0 =~ m:\\symbian\\perl\\(.+)\\bin\\xsbuild.pl:i )
 }
 
 if ( !defined $SymbianVersion) {
-    ($SymbianVersion) = ($ENV{PATH} =~ m!C:\\Symbian\\(.+?)\\!i);
+    ($SymbianVersion) = ($ENV{PATH} =~ m!\\Symbian\\(.+?)\\!i);
 }
 
-my $S60SDK;
+my ($SYMBIAN_ROOT, $SYMBIAN_VERSION, $SDK_NAME, $SDK_VARIANT, $SDK_VERSION);
 
 if ($CoreBuild) {
-    unshift @INC, "symbian";
-    do "sanity.pl";
-    my %VERSION = %{ do "version.pl" };
-    $SDK     = do "sdk.pl";
+    do "sanity.pl" or die $@;
+    my %VERSION = %{ do "version.pl" or die $@ };
+    ($SYMBIAN_ROOT, $SYMBIAN_VERSION, $SDK_NAME, $SDK_VARIANT, $SDK_VERSION) =
+      @{ do "sdk.pl" or die $@ };
     $VERSION = "$VERSION{REVISION}$VERSION{VERSION}$VERSION{SUBVERSION}";
     $R_V_SV  = "$VERSION{REVISION}.$VERSION{VERSION}.$VERSION{SUBVERSION}";
-    $HOME    = do "cwd.pl";
-    $SymbianVersion = $1 if $SDK =~ m:\\Symbian\\([^\\]+):;
+    $BUILDROOT    = do "cwd.pl" or die $@;
     $PerlVersion    = $R_V_SV;
-    $S60SDK = $ENV{S60SDK}; # from sdk.pl
 }
 
+my %CONF;
+
 usage()
   unless GetOptions(
-    'symbian=s' => \$SymbianVersion,
-    'perl=s'    => \$PerlVersion,
-    'csuffix=s' => \$CSuffix,
-    'cplusplus' => \$CPlusPlus,
-    'win=s'     => \$WIN,
-    'arm=s'     => \$ARM,
-    'config'    => \$Config,
-    'build'     => \$Build,
-    'clean'     => \$Clean,
-    'distclean' => \$DistClean,
-    'sis'       => \$Sis
+    'symbian=s'     => \$SymbianVersion,
+    'perl=s'        => \$PerlVersion,
+    'extversion=s'  => \$CONF{EXTVERSION},
+    'csuffix=s'     => \$CSuffix,
+    'cplusplus|cpp' => \$CPlusPlus,
+    'win=s'         => \$WIN,
+    'arm=s'         => \$ARM,
+    'config'        => \$Config,
+    'build'         => \$Build,
+    'clean'         => \$Clean,
+    'distclean'     => \$DistClean,
+    'sis'           => \$Sis
   );
 
 usage() unless @ARGV;
@@ -86,32 +101,37 @@ die "$0: Symbian version undefined\n" unless defined $SymbianVersion;
 
 $SymbianVersion =~ s:/:\\:g;
 
-die "$0: Symbian version '$SymbianVersion' not found\n"
-  unless -d "\\Symbian\\$SymbianVersion";
+#die "$0: Symbian version '$SymbianVersion' not found\n"
+#  unless -d "\\Symbian\\$SymbianVersion";
 
 die "$0: Perl version undefined\n" unless defined $PerlVersion;
 
+$PERLSDK = "$SYMBIAN_ROOT\\Perl\\$PerlVersion";
+
 die "$0: Perl version '$PerlVersion' not found\n"
-  if !$CoreBuild && !-d "\\Symbian\\Perl\\$PerlVersion";
+  if !$CoreBuild && !-d $PERLSDK;
 
 print "Configuring with Symbian $SymbianVersion and Perl $PerlVersion...\n";
 
-$SDK     = "\\Symbian\\$SymbianVersion" unless defined $SDK;
-$PERLSDK = "\\Symbian\\Perl\\$PerlVersion";
-
 $R_V_SV = $PerlVersion;
 
-$VERSION =~ tr/.//d;
+$VERSION = $PerlVersion unless defined $VERSION;
 
-$ENV{SDK}   = $SDK;    # For the Errno extension
-$ENV{CROSS} = 1;       # For the Encode extension
+$VERSION =~ tr/.//d if defined $VERSION;
 
-my $UREL = $ENV{UREL}; # from sdk.pl
-$UREL =~ s/-ARM-/$ARM/;
-my $UARM = $ENV{UARM}; # from sdk.pl
-my $SRCDBG = $UARM eq 'udeb' ? "SRCDBG" : "";
+$ENV{SDK}   = $SYMBIAN_ROOT;    # For the Errno extension
+$ENV{CROSS} = 1;                # For the Encode extension (unbuilt now)
+
+my $UARM = 'urel';
+my $UREL = "$SYMBIAN_ROOT\\epoc32\\release\\-ARM-\\$UARM";
+my $SRCDBG;
+if (exists $ENV{UREL}) {
+    $UREL = $ENV{UREL}; # from sdk.pl
+    $UREL =~ s/-ARM-/$ARM/;
+    $UARM = $ENV{UARM}; # from sdk.pl
+    $SRCDBG = $UARM eq 'udeb' ? "SRCDBG" : "";
+}
 
-my %CONF;
 my %EXTCFG;
 
 sub write_bld_inf {
@@ -143,20 +163,9 @@ sub run_PL {
         print "\t(Running $dir\\$PL)\n";
     }
     my $cmd;
-    if ($CoreBuild) {
-        # Problem: the Config.pm we have in $HOME\\lib carries the
-        # version number of the Perl we are building, while the Perl
-        # we are running might have some other version.  Solution:
-        # temporarily replace the Config.pm with a patched version.
-        my $V = sprintf "%vd", $^V;
-        unlink("$HOME\\lib\\Config.pm.bak");
-       system_echo("perl -pi.bak -e \"s:\\Q$R_V_SV:$V:\" $HOME\\lib\\Config.pm");
-    }
-    system_echo("perl -I$HOME\\lib -I$HOME\\xlib\\symbian $PL") == 0
+    $ENV{PERL_CORE} = 1 if $CoreBuild;
+    system_echo("perl -I$BUILDROOT\\lib -I$BUILDROOT\\xlib\\symbian -I$BUILDROOT\\t\\lib $PL") == 0
       or warn "$0: $PL failed.\n";
-    if ($CoreBuild) {
-        system_echo("copy $HOME\\lib\\Config.pm.bak $HOME\\lib\\Config.pm");
-    }
     if ( defined $file ) { -s $file or die "$0: No $file created.\n" }
 }
 
@@ -198,28 +207,34 @@ sub read_mmp {
 }
 
 sub write_mmp {
-    my ( $base, $userinclude, @src ) = @_;
+    my ( $ext, $base, $userinclude, @src ) = @_;
+
+    my $extdash = $ext; $extdash =~ s!\\!-!g;
 
     print "\t$base.mmp\n";
-    $CONF{TARGET}        = "$base.dll";
+    $CONF{TARGET}        = "perl$VERSION-$extdash.dll";
     $CONF{TARGETPATH}    = "\\System\\Libs\\Perl\\$R_V_SV";
     $CONF{SOURCE}        = [@src];
-    $CONF{SOURCEPATH}    = [ $CWD, $HOME ];
-    $CONF{USERINCLUDE}   = [ $CWD, $HOME ];
+    $CONF{SOURCEPATH}    = [ $CWD, $BUILDROOT ];
+    $CONF{USERINCLUDE}   = [ $CWD, $BUILDROOT ];
     $CONF{SYSTEMINCLUDE} = ["$PERLSDK\\include"] unless $CoreBuild;
-    $CONF{SYSTEMINCLUDE} = [ $HOME ] if $CoreBuild;
+    $CONF{SYSTEMINCLUDE} = [ $BUILDROOT, "$BUILDROOT\\symbian" ] if $CoreBuild;
     $CONF{LIBRARY}       = [];
     $CONF{MACRO}         = [];
     read_mmp( \%CONF, "_init.mmp" );
     read_mmp( \%CONF, "$base.mmp" );
 
+    if ($base eq 'Zlib') {
+       push @{$CONF{USERINCLUDE}}, "$CWD\\zlib-src";
+    }
+
     for my $ui ( @{$userinclude} ) {
         $ui =~ s!/!\\!g;
         if ( $ui =~ m!^(?:[CD]:)?\\! ) {
             push @{ $CONF{USERINCLUDE} }, $ui;
         }
         else {
-            push @{ $CONF{USERINCLUDE} }, "$HOME\\$ui";
+            push @{ $CONF{USERINCLUDE} }, "$BUILDROOT\\$ui";
         }
     }
     push @{ $CONF{SYSTEMINCLUDE} }, "\\epoc32\\include";
@@ -234,6 +249,23 @@ sub write_mmp {
     push @{ $CONF{MACRO} },         "PERL_GLOBAL_STRUCT";
     push @{ $CONF{MACRO} },         "PERL_GLOBAL_STRUCT_PRIVATE";
 
+    if ($SDK_VARIANT eq 'S60') {
+      push @{ $CONF{MACRO} }, '__SERIES60__'
+       unless grep { $_ eq '__SERIES60__' } @{ $CONF{MACRO} };
+    }
+    if ($SDK_VARIANT eq 'S80') {
+      push @{ $CONF{MACRO} }, '__SERIES80__'
+       unless grep { $_ eq '__SERIES80__' } @{ $CONF{MACRO} };
+    }
+    if ($SDK_VARIANT eq 'S90') {
+      push @{ $CONF{MACRO} }, '__SERIES90__'
+       unless grep { $_ eq '__SERIES90__' } @{ $CONF{MACRO} };
+    }
+    if ($SDK_VARIANT eq 'UIQ') {
+      push @{ $CONF{MACRO} }, '__UIQ__'
+       unless grep { $_ eq '__UIQ__' } @{ $CONF{MACRO} };
+    }
+
     for my $u (qw(SOURCE SOURCEPATH SYSTEMINCLUDE USERINCLUDE LIBRARY MACRO)) {
         $CONF{$u} = uniquefy_filenames( $CONF{$u} );
     }
@@ -255,9 +287,12 @@ __EOF__
     print BASE_MMP <<__EOF__;
 LIBRARY                @{$CONF{LIBRARY}}
 MACRO          @{$CONF{MACRO}}
-// OPTION      MSVC /P
-// OPTION      GCC -E
+// OPTION      MSVC /P // Uncomment for creating .i (cpp'ed .cpp)
+// OPTION      GCC -E  // Uncomment for creating .i (cpp'ed .cpp)
 __EOF__
+#    if (-f "$base.rss") {
+#        print BASE_MMP "RESOURCE\t$base.rss\n";
+#    }
     close(BASE_MMP);
 
 }
@@ -267,12 +302,12 @@ sub write_makefile {
 
     print "\tMakefile\n";
 
-    my $windef1 = "$SDK\\Epoc32\\Build$CWD\\$base\\$WIN\\$base.def";
+    my $windef1 = "$SYMBIAN_ROOT\\Epoc32\\Build$CWD\\$base\\$WIN\\$base.def";
     my $windef2 = "..\\BWINS\\${base}u.def";
-    my $armdef1 = "$SDK\\Epoc32\\Build$CWD\\$base\\$ARM\\$base.def";
+    my $armdef1 = "$SYMBIAN_ROOT\\Epoc32\\Build$CWD\\$base\\$ARM\\$base.def";
     my $armdef2 = "..\\BMARM\\${base}u.def";
 
-    my $wrap = $SDK && $S60SDK eq '1.2' && $SDK !~ /_CW$/;
+    my $wrap = $SYMBIAN_ROOT && defined $SDK_VARIANT eq 'S60' && $SDK_VERSION eq '1.2' && $SYMBIAN_ROOT !~ /_CW$/;
     my $ABLD = $wrap ? 'perl b.pl' : 'abld';
 
     open( MAKEFILE, ">Makefile" ) or die "$0: Makefile: $!\n";
@@ -356,7 +391,7 @@ delete $ENV{MFLAGS};
 delete $ENV{MAKEFLAGS};
 
 print "abld @ARGV\n";
-system("abld @ARGV");
+system_echo("abld @ARGV");
 __EOF__
             close(B);
        } else {
@@ -372,11 +407,56 @@ sub update_dir {
     print getcwd(), "]\n";
 }
 
+sub patch_config {
+    # Problem: the Config.pm we have in $BUILDROOT\\lib carries the
+    # version number of the Perl we are building, while the Perl
+    # we are running might have some other version.  Solution:
+    # temporarily replace the Config.pm with a patched version.
+    #
+    # Reverse patch will be done with this special script
+    my $config_restore_script = "$BUILDROOT\\lib\\symbian_config_restore.pl";
+    # make sure the patch script was not left from previous run
+    unlink $config_restore_script;
+    return unless $CoreBuild;
+    my $V = sprintf "%vd", $^V;
+    # create reverse patch script
+    if (open(RSCRIPT, ">$config_restore_script")) {
+        print RSCRIPT <<__EOF__;
+#!perl -pi.bak
+s:\\Q$V:$R_V_SV:
+__EOF__
+        close RSCRIPT;
+    } else {
+        die "$0: Cannot create $config_restore_script: $!";
+    }
+    # patch the config
+    unlink("$BUILDROOT\\lib\\Config.pm.bak");
+    print "(patching $BUILDROOT\\lib\\Config.pm)\n";
+    system_echo("perl -pi.bak -e \"s:\\Q$R_V_SV:$V:\" $BUILDROOT\\lib\\Config.pm");
+}
+
+sub restore_config {
+    my $config_restore_script = "$BUILDROOT\\lib\\symbian_config_restore.pl";
+    # this function should always return True
+    # because it's commonly used in error handling blocks as
+    #   &restore_config and die
+    return 1 unless -f $config_restore_script;
+    unlink("$BUILDROOT\\lib\\Config.pm.bak");
+    print "(restoring $BUILDROOT\\lib\\Config.pm)\n";
+    system_echo("perl -pi.bak $config_restore_script $BUILDROOT\\lib\\Config.pm");
+    unlink "$BUILDROOT\\lib\\Config.pm.bak", $config_restore_script;
+    # above command should always return 2 already,
+    # but i want to be absolutely sure that return value is True
+    return 1;
+}
+
 sub xsconfig {
     my ( $ext, $dir ) = @_;
-    print "Configuring for $ext, directory $dir...\n";
-    my $extu = $CoreBuild ? "$HOME\\lib\\ExtUtils" : "$PERLSDK\\lib\\ExtUtils";
+    print "Configuring for $ext, directory '$dir'...\n";
+    my $extu = $CoreBuild ? "$BUILDROOT\\lib\\ExtUtils" : "$PERLSDK\\lib\\ExtUtils";
     update_dir($dir) or die "$0: chdir '$dir': $!\n";
+    &patch_config;
+
     my $build  = dirname($ext);
     my $base   = basename($ext);
     my $basexs = "$base.xs";
@@ -398,8 +478,10 @@ sub xsconfig {
 
     $extdirdir = $extdirdir eq "." ? "" : "$extdirdir\\";
 
+    my $extdash = $ext; $extdash =~ s!\\!-!g;
+
     my %lst;
-    $lst{"$UREL\\$base.dll"} =
+    $lst{"$UREL\\perl$VERSION-$extdash.dll"} =
       "$targetroot\\$ARM-symbian\\$base.dll"
       if -f $basexs;
     $lst{"$dir\\$base.pm"} = "$targetroot\\$extdirdir$base.pm"
@@ -412,6 +494,7 @@ sub xsconfig {
         my @found;
         find( sub { push @found, $File::Find::name if -f $_ }, 'lib' );
         for my $found (@found) {
+           next if $found =~ /\.bak$/i; # Zlib
             my ($short) = ( $found =~ m/^lib.(.+)/ );
             $short =~ s!/!\\!g;
             $found =~ s!/!\\!g;
@@ -426,12 +509,14 @@ sub xsconfig {
         }
     }
     if ( my @c = glob("*.c *.cpp */*.c */*.cpp") ) {
+       map { s:^zlib-src/:: } @c if $ext eq 'ext\Compress\Raw\Zlib';
         for my $c (@c) {
             $c =~ s:/:\\:g;
             $src{$c}++;
         }
     }
     if ( my @h = glob("*.h */*.h") ) {
+        map { s:^zlib-src/:: } @h if $ext eq 'ext\Compress\Raw\Zlib';
         for my $h (@h) {
             $h =~ s:/:\\:g;
             $h = dirname($h);
@@ -492,7 +577,7 @@ sub xsconfig {
     }
     elsif ( $dir eq "ext\\Encode" ) {
         system_echo("perl bin\\enc2xs -Q -O -o def_t.c -f def_t.fnm") == 0
-          or die "$0: running enc2xs failed: $!\n";
+          or &restore_config and die "$0: running enc2xs failed: $!\n";
     }
 
     my @lst = sort keys %lst;
@@ -530,7 +615,7 @@ sub xsconfig {
             print "\tUsing $EXTVERSION for version...\n";
             $MM{VERSION} = $MM{XS_VERSION} = $EXTVERSION;
         }
-        die "VERSION or XS_VERSION undefined\n"
+        (&restore_config and die "$0: VERSION or XS_VERSION undefined\n")
           unless defined $MM{VERSION} && defined $MM{XS_VERSION};
         if ( open( BASE_C, ">$basec" ) ) {
             print BASE_C <<__EOF__;
@@ -547,17 +632,19 @@ __EOF__
             warn "$0: $basec: $!";
         }
         unless (
-            system(
-"perl -I$PERLSDK\\lib $extu\\xsubpp -C++ -csuffix .cpp -typemap $extu\\typemap -noprototypes $basexs >> $basec"
+            system_echo(
+"perl -I$BUILDROOT\\lib -I$PERLSDK\\lib $extu\\xsubpp -csuffix .cpp -typemap $extu\\typemap -noprototypes $basexs >> $basec"
             ) == 0
             && -s $basec
           )
         {
+            &restore_config;
             die "$0: perl xsubpp failed: $!\n";
         }
 
         print "\t_init.c\n";
-        open( _INIT_C, ">_init.c" ) or die "$!: _init.c: $!\n";
+        open( _INIT_C, ">_init.c" )
+            or &restore_config and die "$!: _init.c: $!\n";
         print _INIT_C <<__EOF__;
     #include "EXTERN.h"
     #include "perl.h"
@@ -578,7 +665,7 @@ __EOF__
                         while (<SUBMF>) {
                             next if 1 .. /postamble/;
                             if (m!^(\w+_t)\.c : !) {
-                                system(
+                                system_echo(
                                     "perl ..\\bin\\enc2xs -Q -o $1.c -f $1.fnm")
                                   == 0
                                   or warn "$0: enc2xs: $!\n";
@@ -589,18 +676,19 @@ __EOF__
                         unlink($submf);
                         my $subbase = $d;
                         $subbase =~ s!/!::!g;
-                        write_mmp( $subbase, ["..\\Encode"], "$subbase.c",
+                        write_mmp( $ext, $subbase, ["..\\Encode"], "$subbase.c",
                             @subsrc );
                         write_makefile( $subbase, $build );
                         write_bld_inf($subbase);
 
                         unless (
-                            system(
-"perl -I$HOME\\lib ..\\$extu\\xsubpp -C++ -csuffix .cpp -typemap ..\\$extu\\typemap -noprototypes $subbase.xs > $subbase.c"
+                            system_echo(
+"perl -I$BUILDROOT\\lib ..\\$extu\\xsubpp -csuffix .cpp -typemap ..\\$extu\\typemap -noprototypes $subbase.xs > $subbase.c"
                             ) == 0
                             && -s "$subbase.c"
                           )
                         {
+                            &restore_config;
                             die "$0: perl xsubpp failed: $!\n";
                         }
                         update_dir("..");
@@ -616,15 +704,17 @@ __EOF__
             print "Configuring Encode...\n";
         }
 
-        write_mmp( $base, [ keys %incdir ], @src );
+        write_mmp( $ext, $base, [ keys %incdir ], @src );
         write_makefile( $base, $build );
     }
+    &restore_config;
+
     my $lstname = $ext;
     $lstname =~ s:^ext\\::;
     $lstname =~ s:\\:-:g;
     print "\t$lstname.lst\n";
     my $lstout =
-      $CoreBuild ? "$HOME/symbian/$lstname.lst" : "$HOME/$lstname.lst";
+      $CoreBuild ? "$BUILDROOT/symbian/$lstname.lst" : "$BUILDROOT/$lstname.lst";
     if ( open( my $lst, ">$lstout" ) ) {
         for my $f (@lst) { print $lst qq["$f"-"!:$lst{$f}"\n] }
         close($lst);
@@ -632,18 +722,25 @@ __EOF__
     else {
         die "$0: $lstout: $!\n";
     }
-    update_dir($HOME);
+    update_dir($BUILDROOT);
 }
 
 sub update_cwd {
     $CWD = getcwd();
-    $CWD =~ s!^[CD]:!!i;
+    $CWD =~ s!^[A-Z]:!!i;
     $CWD =~ s!/!\\!g;
 }
 
+if (grep /^(Compress::Raw::Zlib|Cwd|Data::Dumper|Digest::SHA|Sys::Syslog|Time::HiRes)$/, @ARGV) {
+    &patch_config;
+    system_echo("perl -I$BUILDROOT\\lib -I$PERLSDK\\lib $BUILDROOT\\mkppport");
+    &restore_config;
+}
+
 for my $ext (@ARGV) {
 
     $ext =~ s!::!\\!g;
+    my $extdash = $ext =~ /ext\\/ ? $ext : "ext\\$ext"; $extdash =~ s!\\!-!g;
     $ext =~ s!/!\\!g;
 
     my $cfg;
@@ -709,6 +806,11 @@ for my $ext (@ARGV) {
         next if $Config;
     }
 
+    if ($dir eq ".") {
+       warn "$0: No directory for $ext, skipping...\n";
+       next;
+    }
+
     my $chdir = $ext eq "ext\\XSLoader" ? "ext\\DynaLoader" : $dir;
     die "$0: no directory '$chdir'\n" unless -d $chdir;
     update_dir($chdir) or die "$0: chdir '$chdir' failed: $!\n";
@@ -735,8 +837,8 @@ for my $ext (@ARGV) {
      # (2) With the rest and the _init.c to get ordinals for the rest.
      # (3) With an updated _init.c that carries the symbols from step (2).
 
-        system("make clean");
-        system("make defrost") == 0 or die "$0: make defrost failed\n";
+        system_echo("make clean");
+        system_echo("make defrost") == 0 or warn "$0: make defrost failed\n";
 
         my @TARGET;
 
@@ -745,19 +847,21 @@ for my $ext (@ARGV) {
         # Compile #1.
         # Hide all but the _init.c.
         print "\n*** $ext - Compile 1 of 3.\n\n";
+       print "(patching $base.mmp)\n";
         system(
 "perl -pi.bak -e \"s:^SOURCE\\s+_init.c:SOURCE\\t_init.c // :\" $base.mmp"
         );
-       system("bldmake bldfiles");
-        system("make @TARGET") == 0 or die "$0: make #1 failed\n";
+       system_echo("bldmake bldfiles");
+        system_echo("make @TARGET") == 0 or die "$0: make #1 failed\n";
 
         # Compile #2.
         # Reveal the rest again.
         print "\n*** $ext - Compile 2 of 3.\n\n";
+       print "(patching $base.mmp)\n";
         system(
 "perl -pi.bak -e \"s:^SOURCE\\t_init.c // :SOURCE\\t_init.c :\" $base.mmp"
         );
-        system("make @TARGET") == 0 or die "$0: make #2 failed\n";
+        system_echo("make @TARGET") == 0 or die "$0: make #2 failed\n";
         unlink("$base.mmp.bak");
 
         open( _INIT_C, ">_init.c" ) or die "$0: _init.c: $!\n";
@@ -778,8 +882,8 @@ __EOF__
         my %symbol;
        my $def;
        my $basef;
-        for my $f ("$SDK\\Epoc32\\Build$CWD\\$base\\WINS\\$base.def",
-                  "..\\BMARM\\${base}u.def") {
+        for my $f ("$SYMBIAN_ROOT\\Epoc32\\Build$CWD\\$base\\WINS\\perl$VERSION-$extdash.def",
+                  "..\\BMARM\\perl$VERSION-${extdash}u.def") {
            print "\t($f - ";
            if ( open( $def, $f ) ) {
                print "OK)\n";
@@ -828,7 +932,7 @@ __EOF__
 
         # Compile #3.  This is for real.
         print "\n*** $ext - Compile 3 of 3.\n\n";
-        system("make @TARGET") == 0 or die "$0: make #3 failed\n";
+        system_echo("make @TARGET") == 0 or die "$0: make #3 failed\n";
 
     }
     elsif ( $Clean || $DistClean ) {
@@ -838,22 +942,33 @@ __EOF__
         else {
             if ( -f "Makefile" ) {
                 if ($Clean) {
-                    system("make clean") == 0 or die "$0: make clean failed\n";
+                    system_echo("make clean") == 0 or die "$0: make clean failed\n";
                 }
                 elsif ($DistClean) {
-                    system("make distclean") == 0
+                    system_echo("make distclean") == 0
                       or die "$0: make distclean failed\n";
                 }
             }
+           if ( $ext eq "ext\\Compress\\Raw\\Zlib" ) {
+               my @bak;
+               find( sub { push @bak, $File::Find::name if /\.bak$/ }, "." );
+               unlink(@bak) if @bak;
+               my @src;
+               find( sub { push @src, $_ if -f $_ }, "zlib-src" );
+               unlink(@src) if @src;
+               unlink("constants.xs");
+           }
             if ( $ext eq "ext\\Devel\\PPPort" ) {
                 unlink("ppport.h");
             }
         }
+       my @D = glob("../BMARM/*.def ../BWINS/*.def");
+       unlink(@D) if @D;
         my @B = glob("ext/BWINS ext/BMARM ext/*/BWINS ext/*/BMARM Makefile");
         rmdir(@B) if @B;
     }
 
-    update_dir($HOME);
+    update_dir($BUILDROOT);
 
 }    # for my $ext