adjust searchdict.t for EBCDIC (still needs documenting)
[p5sagit/p5-mst-13.2.git] / utils / perlcc.PL
index af7488f..b214645 100644 (file)
@@ -2,6 +2,7 @@
  
 use Config;
 use File::Basename qw(&basename &dirname);
+use Cwd;
  
 # List explicitly here the variables you want Configure to
 # generate.  Metaconfig only looks for shell variables, so you
@@ -13,6 +14,7 @@ use File::Basename qw(&basename &dirname);
  
 # This forces PL files to create target in same directory as PL file.
 # This is so that make depend always knows where to find PL derivatives.
+$origdir = cwd;
 chdir dirname($0);
 $file = basename($0, '.PL');
 $file .= '.com' if $^O eq 'VMS';
@@ -38,6 +40,7 @@ use Config;
 use strict;
 use FileHandle;
 use File::Basename qw(&basename &dirname);
+use Cwd;
 
 use Getopt::Long;
 
@@ -121,9 +124,10 @@ sub _doit
 
         $obj =         ($options->{'o'})?    $options->{'o'} :
                                             _getExecutable($file, $module_ext);
-        $so = "$obj.so";
+        $so = "$obj.$Config{so}";
         $type = 'sharedlib';
         return() if (!$obj);
+        $objfile = ($options->{'C'}) ?     $options->{'C'} : "$file.c";
     }
     else
     {
@@ -140,7 +144,7 @@ sub _doit
                                                                 if ($errcode);
 
         _print("Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
-        my $errcode = _compileCode($file, $objfile, $obj) 
+        $errcode = _compileCode($file, $objfile, $obj) 
                                             if (!$options->{'gen'});
 
         if ($errcode)
@@ -160,9 +164,10 @@ sub _doit
 
         _removeCode($file) if ($options->{'e'}); 
 
-        _removeCode($obj) if (($options->{'e'} && 
-                                ((!$options->{'sav'}) || !$options->{'o'})) || 
-                                ($options->{'run'} && (!$options->{'sav'})));
+        _removeCode($obj) if (($options->{'e'}
+                              && !$options->{'sav'}
+                              && !$options->{'o'})
+                             || ($options->{'run'} && !$options->{'sav'}));
     }
     else
     {
@@ -171,7 +176,7 @@ sub _doit
         (_print( "ERROR: In generating code for $file!\n", -1), return()) 
                                                                 if ($errcode);
     
-        _print( "Compiling C($obj) for $file!\n", 36 ) if (!$options->{'gen'});
+        _print( "Compiling C($so) for $file!\n", 36 ) if (!$options->{'gen'});
 
         my $errorcode = 
             _compileCode($file, $objfile, $obj, $so ) if (!$options->{'gen'});
@@ -240,18 +245,19 @@ sub _compileCode
     if (@_ == 3)                            # just compiling a program 
     {
         $return[0] = 
-        _ccharness($sourceprog, "-o", $output_executable, $generated_cfile);  
+        _ccharness('static', $sourceprog, "-o", $output_executable, $generated_cfile);  
         $return[0];
     }
     else
     {
         my $object_file = $generated_cfile;
-        $object_file =~ s"\.c$"\.o";   
+        $object_file =~ s"\.c$"$Config{_o}";   
 
-        $return[0] = _ccharness($sourceprog, "-c", $generated_cfile);
+        $return[0] = _ccharness('compile', $sourceprog, "-c", $generated_cfile);
         $return[1] = _ccharness
                             (
-                                $sourceprog, "-shared","-o", 
+                               'dynamic', 
+                                $sourceprog, "-o", 
                                 $shared_object, $object_file 
                             );
         return(1) if (grep ($_, @return));
@@ -274,6 +280,7 @@ sub _removeCode
 
 sub _ccharness
 {
+    my $type = shift;
     my (@args) = @_;
     local($") = " ";
 
@@ -287,24 +294,26 @@ sub _ccharness
     }
     else
     {
-        $libdir = "-L.."; 
-        $incdir = "-I..";
+        $libdir = "-L.. -L."; 
+        $incdir = "-I.. -I.";
     }
 
     $libdir .= " -L$options->{L}" if (defined($options->{L}));
     $incdir .= " -I$options->{L}" if (defined($options->{L}));
 
-    my $linkargs;
+    my $linkargs = '';
 
-    if (!grep(/^-[cS]$/, @ARGV))
+    if (!grep(/^-[cS]$/, @args))
     {
-        $linkargs = sprintf("%s $libdir -lperl %s",@Config{qw(ldflags libs)});
+       my $lperl = $^O eq 'os2' ? '-llibperl' : '-lperl';
+       my $flags = $type eq 'dynamic' ? $Config{lddlflags} : $Config{ldflags};
+        $linkargs = "$flags $libdir $lperl @Config{libs}";
     }
 
     my @sharedobjects = _getSharedObjects($sourceprog); 
 
     my $cccmd = 
-        "$Config{cc} $Config{ccflags} $incdir @sharedobjects @args $linkargs";
+        "$Config{cc} @Config{qw(ccflags optimize)} $incdir @sharedobjects @args $linkargs";
 
 
     _print ("$cccmd\n", 36);
@@ -354,7 +363,7 @@ EOF
     _print("$\18 -I@INC $tmpfile\n", 36);
     _run("$\18 -I@INC $tmpfile", 9 );
 
-    my $fd = new FileHandle ("$incfile"); 
+    $fd = new FileHandle ("$incfile"); 
     my @lines = <$fd>;    
 
     unlink($tmpfile);
@@ -455,9 +464,9 @@ sub _mungeRegexp
 {
     my ($regexp) = @_;
 
-    grep(s"(^|[^\\])\."$1\x0\\."g, @$regexp);
-    grep(s"(^|[^\x0])\\\."$1\."g,  @$regexp);
-    grep(s"\x0""g,                 @$regexp);
+    grep(s:(^|[^\\])\.:$1\x00\\.:g, @$regexp);
+    grep(s:(^|[^\x00])\\\.:$1\.:g,  @$regexp);
+    grep(s:\x00::g,                 @$regexp);
 }
 
 
@@ -933,3 +942,4 @@ by perl5.005.
 close OUT or die "Can't close $file: $!";
 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
+chdir $origdir;