[ANNOUNCE] Math::BigInt v1.69
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Unix.pm
index 43c5098..a1c21d2 100644 (file)
@@ -7,7 +7,7 @@ use strict;
 use Exporter ();
 use Carp;
 use Config         qw(%Config);
-use File::Basename qw(basename dirname fileparse);
+use File::Basename qw(basename dirname);
 use DirHandle;
 
 use vars qw($VERSION @ISA
@@ -20,7 +20,7 @@ use vars qw($VERSION @ISA
 
 use ExtUtils::MakeMaker qw($Verbose neatvalue);
 
-$VERSION = '1.42';
+$VERSION = '1.45';
 
 require ExtUtils::MM_Any;
 @ISA = qw(ExtUtils::MM_Any);
@@ -295,7 +295,8 @@ clean :: clean_subdirs
     push(@otherfiles, qw[./blib $(MAKE_APERL_FILE) 
                          $(INST_ARCHAUTODIR)/extralibs.all
                          $(INST_ARCHAUTODIR)/extralibs.ld
-                        perlmain.c tmon.out mon.out so_locations pm_to_blib
+                        perlmain.c tmon.out mon.out so_locations 
+                         blibdirs pm_to_blib
                         *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
                         $(BOOTSTRAP) $(BASEEXT).bso
                         $(BASEEXT).def lib$(BASEEXT).def
@@ -558,50 +559,73 @@ sub depend {
     join "", @m;
 }
 
-=item dir_target (o)
 
-Takes an array of directories that need to exist and returns a
-Makefile entry for a .exists file in these directories. Returns
-nothing, if the entry has already been processed. We're helpless
-though, if the same directory comes as $(FOO) _and_ as "bar". Both of
-them get an entry, that's why we use "::".
+=item dir_target B<DEPRECATED>
+
+    my $make_frag = $mm->dir_target(@directories);
+
+I<This function is deprecated> its use is no longer necessary and is I<only
+provided for backwards compatibility>.  blibdirs_target provides a much
+simpler mechanism and pm_to_blib() can create its own directories anyway.
+
+Returns a Makefile entry for a .exists file in each of the @directories.
+The purpose is to create a directory and provide a make target to depend on.
+The make target is a .exists file in each of those directories.
+
+For example
+
+    $mm->dir_target('$(INST_ARCHDIR)');
+
+would return the make target C<$(INST_ARCHDIR)/.exists> which would
+create $(INST_ARCHDIR) and touch .exists.  You would depend on this target
+to make sure $(INST_ARCHDIR) is created.
+
+Ignores directories which have already gone through dir_target() so you
+might wind up getting nothing.
 
 =cut
 
 sub dir_target {
-# --- Make-Directories section (internal method) ---
-# dir_target(@array) returns a Makefile entry for the file .exists in each
-# named directory. Returns nothing, if the entry has already been processed.
-# We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
-# Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the
-# prerequisite, because there has to be one, something that doesn't change
-# too often :)
-
-    my($self,@dirs) = @_;
-    my(@m,$dir,$targdir);
-    foreach $dir (@dirs) {
-       my($src) = $self->catfile($self->{PERL_INC},'perl.h');
-       my($targ) = $self->catfile($dir,'.exists');
-       # catfile may have adapted syntax of $dir to target OS, so...
-       if ($Is_VMS) { # Just remove file name; dirspec is often in macro
-           ($targdir = $targ) =~ s:/?\.exists\z::;
-       }
-       else { # while elsewhere we expect to see the dir separator in $targ
-           $targdir = dirname($targ);
-       }
-       next if $self->{DIR_TARGET}{$self}{$targdir}++;
-       push @m, qq{
-$targ :: $src
+    my($self, @dirs) = @_;
+
+    my @targs = ();
+    my $make = '';
+    foreach my $dir (@dirs) {
+        my $targ = $self->catfile($dir, '.exists');
+
+        my $targdir;
+        if ($Is_VMS) { # Just remove file name; dirspec is often in macro
+            ($targdir = $targ) =~ s:/?\.exists\z::;
+        }
+        else { # while elsewhere we expect to see the dir separator in $targ
+            $targdir = dirname($targ);
+        }
+
+        next if $self->{DIR_TARGET}{$self}{$targdir}++;
+
+        push @targs, $targ;
+        $make .= <<MAKE_FRAG;
+$targ ::
        \$(NOECHO) \$(MKPATH) $targdir
-       \$(NOECHO) \$(EQUALIZE_TIMESTAMP) $src $targ
-};
-       push(@m, qq{
-       -\$(NOECHO) \$(CHMOD) \$(PERM_RWX) $targdir
-}) unless $Is_VMS;
+       \$(NOECHO) \$(TOUCH) $targ
+       \$(NOECHO) \$(CHMOD) \$(PERM_RWX) $targdir
+
+MAKE_FRAG
+
     }
-    join "", @m;
+
+    # So these new .exists targets get called along with blibdirs.
+    my $blib_addition = '';
+    $blib_addition = <<MAKE_FRAG if @targs;
+blibdirs :: @targs
+       \$(NOECHO) \$(NOOP)
+
+MAKE_FRAG
+
+    return $blib_addition . $make;
 }
 
+
 =item init_DEST
 
   $mm->init_DEST
@@ -953,7 +977,7 @@ sub distdir {
     my($self) = shift;
 
     return <<'MAKE_FRAG';
-distdir : metafile metafile_addtomanifest signature signature_addtomanifest
+distdir : metafile metafile_addtomanifest signature
        $(RM_RF) $(DISTVNAME)
        $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
                -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
@@ -1054,7 +1078,7 @@ BOOTSTRAP = $(BASEEXT).bs
 # As Mkbootstrap might not write a file (if none is required)
 # we use touch to prevent make continually trying to remake it.
 # The DynaLoader only reads a non-empty file.
-$(BOOTSTRAP): $(FIRST_MAKEFILE) $(BOOTDEP) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists
+$(BOOTSTRAP): $(FIRST_MAKEFILE) $(BOOTDEP) blibdirs
        $(NOECHO) $(ECHO) "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
        $(NOECHO) $(PERLRUN) \
                "-MExtUtils::Mkbootstrap" \
@@ -1062,7 +1086,7 @@ $(BOOTSTRAP): $(FIRST_MAKEFILE) $(BOOTDEP) $(INST_ARCHAUTODIR)$(DIRFILESEP).exis
        $(NOECHO) $(TOUCH) $(BOOTSTRAP)
        $(CHMOD) $(PERM_RW) $@
 
-$(INST_BOOT): $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists
+$(INST_BOOT): $(BOOTSTRAP) blibdirs
        $(NOECHO) $(RM_RF) $(INST_BOOT)
        -$(CP) $(BOOTSTRAP) $(INST_BOOT)
        $(CHMOD) $(PERM_RW) $@
@@ -1097,7 +1121,7 @@ OTHERLDFLAGS = '.$ld_opt.$otherldflags.'
 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
 INST_DYNAMIC_FIX = '.$ld_fix.'
 
-$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
+$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) blibdirs $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
 ');
     if ($armaybe ne ':'){
        $ldfrom = 'tmp$(LIB_EXT)';
@@ -1120,18 +1144,16 @@ $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILE
 
     my $libs = '$(LDLOADLIBS)';
 
-    if ($Is_NetBSD) {
+    if ($Is_NetBSD && $Config{'useshrplib'}) {
        # Use nothing on static perl platforms, and to the flags needed
        # to link against the shared libperl library on shared perl
        # platforms.  We peek at lddlflags to see if we need -Wl,-R
        # or -R to add paths to the run-time library search path.
-       if ($Config{'useshrplib'}) {
-           if ($Config{'lddlflags'} =~ /-Wl,-R/) {
-               $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -lperl';
-           } elsif ($Config{'lddlflags'} =~ /-R/) {
-               $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -lperl';
-           }
-       }
+        if ($Config{'lddlflags'} =~ /-Wl,-R/) {
+            $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -Wl,-R$(PERL_ARCHLIB)/CORE -lperl';
+        } elsif ($Config{'lddlflags'} =~ /-R/) {
+            $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -R$(PERL_ARCHLIB)/CORE -lperl';
+        }
     }
 
     push(@m,
@@ -1141,7 +1163,6 @@ $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DIRFILE
        $(CHMOD) $(PERM_RWX) $@
 ';
 
-    push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
     join('',@m);
 }
 
@@ -1216,7 +1237,7 @@ WARNING
             next unless $self->maybe_command($abs);
             print "Executing $abs\n" if ($trace >= 2);
 
-            my $version_check = qq{$abs -e "require $ver; print qq{VER_OK\n}"};
+            my $version_check = qq{$abs -le "require $ver; print qq{VER_OK}"};
             # To avoid using the unportable 2>&1 to supress STDERR,
             # we close it before running the command.
             # However, thanks to a thread library bug in many BSDs
@@ -1814,25 +1835,7 @@ from the perl source tree.
 EOP
              }
            }
-       }
-       
-       unless(-f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h")))
-        {
-           die qq{
-Error: Unable to locate installed Perl libraries or Perl source code.
-
-It is recommended that you install perl in a standard location before
-building extensions. Some precompiled versions of perl do not contain
-these header files, so you cannot build extensions. In such a case,
-please build and install your perl from a fresh perl distribution. It
-usually solves this kind of problem.
-
-\(You get this message, because MakeMaker could not find "$perl_h"\)
-};
-       }
-#       print STDOUT "Using header files found in $self->{PERL_INC}\n"
-#           if $Verbose && $self->needs_linking();
-
+       }       
     }
 
     # We get SITELIBEXP and SITEARCHEXP directly via
@@ -1944,10 +1947,10 @@ sub init_others {       # --- Initialize Other Attributes
     $self->{NOOP}               ||= '$(SHELL) -c true';
     $self->{NOECHO}             = '@' unless defined $self->{NOECHO};
 
-    $self->{MAKEFILE}           ||= 'Makefile';
-    $self->{FIRST_MAKEFILE}     ||= $self->{MAKEFILE};
-    $self->{MAKEFILE_OLD}       ||= '$(FIRST_MAKEFILE).old';
-    $self->{MAKE_APERL_FILE}    ||= '$(FIRST_MAKEFILE).aperl';
+    $self->{FIRST_MAKEFILE}     ||= 'Makefile';
+    $self->{MAKEFILE}           ||= $self->{FIRST_MAKEFILE};
+    $self->{MAKEFILE_OLD}       ||= $self->{MAKEFILE}.'.old';
+    $self->{MAKE_APERL_FILE}    ||= $self->{MAKEFILE}.'.aperl';
 
     $self->{SHELL}              ||= $Config{sh} || '/bin/sh';
 
@@ -2046,17 +2049,35 @@ sub init_INSTALL {
 
     $self->init_lib2arch;
 
-    # Initialize installvendorman*dir if necessary
+    # There are often no Config.pm defaults for these new man variables so 
+    # we fall back to the old behavior which is to use installman*dir
+    foreach my $num (1, 3) {
+        my $k = 'installsiteman'.$num.'dir';
+
+        $self->{uc $k} ||= uc "\$(installman${num}dir)"
+          unless $Config{$k};
+    }
+
     foreach my $num (1, 3) {
         my $k = 'installvendorman'.$num.'dir';
 
-        unless ($Config{$k}) {
-            $Config_Override{$k} = $Config{usevendorprefix} ?
-                  $self->catdir($Config{vendorprefixexp}, 'man', "man$num") :
-                  '';
+        unless( $Config{$k} ) {
+            $self->{uc $k}  ||= $Config{usevendorprefix}
+                              ? uc "\$(installman${num}dir)"
+                              : '';
         }
     }
 
+    $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
+      unless $Config{installsitebin};
+
+    unless( $Config{installvendorbin} ) {
+        $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix} 
+                                    ? $Config{installbin}
+                                    : '';
+    }
+
+
     my $iprefix = $Config{installprefixexp} || $Config{installprefix} || 
                   $Config{prefixexp}        || $Config{prefix} || '';
     my $vprefix = $Config{usevendorprefix}  ? $Config{vendorprefixexp} : '';
@@ -2065,22 +2086,6 @@ sub init_INSTALL {
     # 5.005_03 doesn't have a siteprefix.
     $sprefix = $iprefix unless $sprefix;
 
-    # There are often no Config.pm defaults for these, but we can make
-    # it up.
-    unless( $Config{installsiteman1dir} ) {
-        $Config_Override{installsiteman1dir} = 
-          $self->catdir($sprefix, 'man', 'man1');
-    }
-
-    unless( $Config{installsiteman3dir} ) {
-        $Config_Override{installsiteman3dir} = 
-          $self->catdir($sprefix, 'man', 'man3');
-    }
-
-    unless( $Config{installsitebin} ) {
-        $Config_Override{installsitebin} =
-          $self->catdir($sprefix, 'bin');
-    }
 
     $self->{PREFIX}       ||= '';
 
@@ -2092,6 +2097,10 @@ sub init_INSTALL {
         $self->{PERLPREFIX}   ||= $iprefix;
         $self->{SITEPREFIX}   ||= $sprefix;
         $self->{VENDORPREFIX} ||= $vprefix;
+
+        # Lots of MM extension authors like to use $(PREFIX) so we
+        # put something sensible in there no matter what.
+        $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
     }
 
     my $arch    = $Config{archname};
@@ -2598,7 +2607,6 @@ sub installbin {
     return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
     return "" unless @{$self->{EXE_FILES}};
     my(@m, $from, $to, %fromto, @to);
-    push @m, $self->dir_target(qw[$(INST_SCRIPT)]);
     for $from (@{$self->{EXE_FILES}}) {
        my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
        local($_) = $path; # for backwards compatibility
@@ -2633,7 +2641,7 @@ realclean ::
        last unless defined $from;
        my $todir = dirname($to);
        push @m, "
-$to: $from \$(FIRST_MAKEFILE) " . $self->catdir($todir,'.exists') . "
+$to : $from \$(FIRST_MAKEFILE) blibdirs
        \$(NOECHO) \$(RM_F) $to
        \$(CP) $from $to
        \$(FIXIN) $to
@@ -2769,7 +2777,7 @@ $(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
     require File::Find;
     File::Find::find(sub {
        return unless m/\Q$self->{LIB_EXT}\E$/;
-       return if m/^libperl/;
+       return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
        # Skip purified versions of libraries (e.g., DynaLoader_pure_p1_c0_032.a)
        return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
 
@@ -2881,7 +2889,7 @@ LLIBPERL    = $llibperl
 ";
 
     push @m, "
-\$(INST_ARCHAUTODIR)/extralibs.all: \$(INST_ARCHAUTODIR)\$(DIRFILESEP).exists ".join(" \\\n\t", @$extra).'
+\$(INST_ARCHAUTODIR)/extralibs.all: blibdirs ".join(" \\\n\t", @$extra).'
        $(NOECHO) $(RM_F)  $@
        $(NOECHO) $(TOUCH) $@
 ';
@@ -2964,8 +2972,8 @@ $(OBJECT) : $(FIRST_MAKEFILE)
 $(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
        $(NOECHO) $(ECHO) "Makefile out-of-date with respect to $?"
        $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
-       $(NOECHO) $(RM_F) $(MAKEFILE_OLD)
-       $(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
+       -$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
+       -$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
        -$(MAKE) -f $(MAKEFILE_OLD) clean $(DEV_NULL) || $(NOOP)
        $(PERLRUN) Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
        $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
@@ -3076,6 +3084,7 @@ sub parse_version {
     my $result;
     local *FH;
     local $/ = "\n";
+    local $_;
     open(FH,$parsefile) or die "Could not open '$parsefile': $!";
     my $inpod = 0;
     while (<FH>) {
@@ -3429,7 +3438,9 @@ sub prefixify {
     print STDERR "  prefixify $var => $path\n" if $Verbose >= 2;
     print STDERR "    from $sprefix to $rprefix\n" if $Verbose >= 2;
 
-    if( $path !~ s{^\Q$sprefix\E\b}{$rprefix}s && $self->{ARGS}{PREFIX} ) {
+    if( $self->{ARGS}{PREFIX} && $self->file_name_is_absolute($path) && 
+        $path !~ s{^\Q$sprefix\E\b}{$rprefix}s ) 
+    {
 
         print STDERR "    cannot prefix, using default.\n" if $Verbose >= 2;
         print STDERR "    no default!\n" if !$default && $Verbose >= 2;
@@ -3687,7 +3698,7 @@ sub static_lib {
     my(@m);
     push(@m, <<'END');
 
-$(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DIRFILESEP).exists
+$(INST_STATIC): $(OBJECT) $(MYEXTLIB) blibdirs
        $(RM_RF) $@
 END
 
@@ -3716,7 +3727,6 @@ MAKE_FRAG
        $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
 MAKE_FRAG
 
-    push @m, "\n", $self->dir_target('$(INST_ARCHAUTODIR)');
     join('', @m);
 }
 
@@ -3835,7 +3845,7 @@ test :: \$(TEST_TYPE)
 ");
 
     if ($Is_Win95) {
-        push(@m, map(qq{\t\$(NOECHO) \$(PERLRUN) -e "exit unless -f shift; chdir '$_'; system q{\$(MAKE) test \$(PASTHRU)}" \$(FIRST_MAKEFILE)\n}, @{$self->{DIR}}));
+        push(@m, map(qq{\t\$(NOECHO) \$(PERLRUN) -e "exit unless -f shift; chdir '$_'; system q[\$(MAKE) test \$(PASTHRU)]" \$(FIRST_MAKEFILE)\n}, @{$self->{DIR}}));
     }
     else {
         push(@m, map("\t\$(NOECHO) cd $_ && \$(TEST_F) \$(FIRST_MAKEFILE) && \$(MAKE) test \$(PASTHRU)\n", @{$self->{DIR}}));
@@ -4012,7 +4022,7 @@ sub top_targets {
     my(@m);
 
     push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
-    
+
     push @m, '
 pure_all :: config pm_to_blib subdirs linkext
        $(NOECHO) $(NOOP)
@@ -4020,41 +4030,16 @@ pure_all :: config pm_to_blib subdirs linkext
 subdirs :: $(MYEXTLIB)
        $(NOECHO) $(NOOP)
 
-config :: $(FIRST_MAKEFILE) $(INST_LIBDIR)$(DIRFILESEP).exists
-       $(NOECHO) $(NOOP)
-
-config :: $(INST_ARCHAUTODIR)$(DIRFILESEP).exists
-       $(NOECHO) $(NOOP)
-
-config :: $(INST_AUTODIR)$(DIRFILESEP).exists
+config :: $(FIRST_MAKEFILE) blibdirs
        $(NOECHO) $(NOOP)
 ';
 
-    push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
-
-    if (%{$self->{MAN1PODS}}) {
-       push @m, q[
-config :: $(INST_MAN1DIR)$(DIRFILESEP).exists
-       $(NOECHO) $(NOOP)
-
-];
-       push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
-    }
-    if (%{$self->{MAN3PODS}}) {
-       push @m, q[
-config :: $(INST_MAN3DIR)$(DIRFILESEP).exists
-       $(NOECHO) $(NOOP)
-
-];
-       push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
-    }
-
     push @m, '
 $(O_FILES): $(H_FILES)
 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
 
     push @m, q{
-help:
+help :
        perldoc ExtUtils::MakeMaker
 };