1 package ExtUtils::Install;
4 use vars qw(@ISA @EXPORT $VERSION $MUST_REBOOT %Config);
8 use Config qw(%Config);
11 use ExtUtils::Packlist;
12 use File::Basename qw(dirname);
13 use File::Compare qw(compare);
15 use File::Find qw(find);
21 @EXPORT = ('install','uninstall','pm_to_blib', 'install_default');
27 ExtUtils::Install - install files from here to there
31 use ExtUtils::Install;
33 install({ 'blib/lib' => 'some/install/dir' } );
37 pm_to_blib({ 'lib/Foo/Bar.pm' => 'blib/lib/Foo/Bar.pm' });
46 $VERSION = eval $VERSION;
52 Handles the installing and uninstalling of perl modules, scripts, man
55 Both install() and uninstall() are specific to the way
56 ExtUtils::MakeMaker handles the installation and deinstallation of
57 perl modules. They are not designed as general purpose tools.
59 On some operating systems such as Win32 installation may not be possible
60 until after a reboot has occured. This can have varying consequences:
61 removing an old DLL does not impact programs using the new one, but if
62 a new DLL cannot be installed properly until reboot then anything
63 depending on it must wait. The package variable
65 $ExtUtils::Install::MUST_REBOOT
67 is used to store this status.
69 If this variable is true then such an operation has occured and
70 anything depending on this module cannot proceed until a reboot
73 If this value is defined but false then such an operation has
74 ocurred, but should not impact later operations.
80 Wrapper to chmod() for debugging and error trapping.
84 Warns about something only once.
88 Dies with a special message.
94 my $Is_VMS = $^O eq 'VMS';
95 my $Is_MacPerl = $^O eq 'MacOS';
96 my $Is_Win32 = $^O eq 'MSWin32';
97 my $Is_cygwin = $^O eq 'cygwin';
98 my $CanMoveAtBoot = ($Is_Win32 || $Is_cygwin);
100 # *note* CanMoveAtBoot is only incidentally the same condition as below
101 # this needs not hold true in the future.
102 my $Has_Win32API_File = ($Is_Win32 || $Is_cygwin)
103 ? (eval {require Win32API::File; 1} || 0)
107 my $Inc_uninstall_warn_handler;
109 # install relative to here
111 my $INSTALL_ROOT = $ENV{PERL_INSTALL_ROOT};
113 my $Curdir = File::Spec->curdir;
114 my $Updir = File::Spec->updir;
117 return join "\n",'!' x 72,@_,'!' x 72,'';
123 my $msg=_estr "WARNING: $first",@_;
124 warn $msg unless $warned{$msg}++;
129 my $msg=_estr "ERROR: $first",@_;
135 my ( $mode, $item, $verbose )=@_;
137 if (chmod $mode, $item) {
138 print "chmod($mode, $item)\n" if $verbose > 1;
141 _warnonce "WARNING: Failed chmod($mode, $item): $err\n"
148 =item _move_file_at_boot( $file, $target, $moan )
150 OS-Specific, Win32/Cygwin
152 Schedules a file to be moved/renamed/deleted at next boot.
153 $file should be a filespec of an existing file
154 $target should be a ref to an array if the file is to be deleted
155 otherwise it should be a filespec for a rename. If the file is existing
158 Sets $MUST_REBOOT to 0 to indicate a deletion operation has occured
159 and sets it to 1 to indicate that a move operation has been requested.
161 returns 1 on success, on failure if $moan is false errors are fatal.
162 If $moan is true then returns 0 on error and warns instead of dies.
170 sub _move_file_at_boot { #XXX OS-SPECIFIC
171 my ( $file, $target, $moan )= @_;
172 Carp::confess("Panic: Can't _move_file_at_boot on this platform!")
173 unless $CanMoveAtBoot;
175 my $descr= ref $target
176 ? "'$file' for deletion"
177 : "'$file' for installation as '$target'";
179 if ( ! $Has_Win32API_File ) {
182 "Cannot schedule $descr at reboot.",
183 "Try installing Win32API::File to allow operations on locked files",
184 "to be scheduled during reboot. Or try to perform the operation by",
185 "hand yourself. (You may need to close other perl processes first)"
187 if ( $moan ) { _warnonce(@msg) } else { _choke(@msg) }
190 my $opts= Win32API::File::MOVEFILE_DELAY_UNTIL_REBOOT();
191 $opts= $opts | Win32API::File::MOVEFILE_REPLACE_EXISTING()
194 _chmod( 0666, $file );
195 _chmod( 0666, $target ) unless ref $target;
197 if (Win32API::File::MoveFileEx( $file, $target, $opts )) {
198 $MUST_REBOOT ||= ref $target ? 0 : 1;
202 "MoveFileEx $descr at reboot failed: $^E",
203 "You may try to perform the operation by hand yourself. ",
204 "(You may need to close other perl processes first).",
206 if ( $moan ) { _warnonce(@msg) } else { _choke(@msg) }
214 =item _unlink_or_rename( $file, $tryhard, $installing )
216 OS-Specific, Win32/Cygwin
218 Tries to get a file out of the way by unlinking it or renaming it. On
219 some OS'es (Win32 based) DLL files can end up locked such that they can
220 be renamed but not deleted. Likewise sometimes a file can be locked such
221 that it cant even be renamed or changed except at reboot. To handle
222 these cases this routine finds a tempfile name that it can either rename
223 the file out of the way or use as a proxy for the install so that the
224 rename can happen later (at reboot).
226 $file : the file to remove.
227 $tryhard : should advanced tricks be used for deletion
228 $installing : we are not merely deleting but we want to overwrite
230 When $tryhard is not true if the unlink fails its fatal. When $tryhard
231 is true then the file is attempted to be renamed. The renamed file is
232 then scheduled for deletion. If the rename fails then $installing
233 governs what happens. If it is false the failure is fatal. If it is true
234 then an attempt is made to schedule installation at boot using a
235 temporary file to hold the new file. If this fails then a fatal error is
236 thrown, if it succeeds it returns the temporary file name (which will be
237 a derivative of the original in the same directory) so that the caller can
238 use it to install under. In all other cases of success returns $file.
239 On failure throws a fatal error.
247 sub _unlink_or_rename { #XXX OS-SPECIFIC
248 my ( $file, $tryhard, $installing )= @_;
250 _chmod( 0666, $file );
251 my $unlink_count = 0;
252 while (unlink $file) { $unlink_count++; }
253 return $file if $unlink_count > 0;
256 _choke("Cannot unlink '$file': $!")
257 unless $CanMoveAtBoot && $tryhard;
260 ++$tmp while -e "$file.$tmp";
263 warn "WARNING: Unable to unlink '$file': $error\n",
264 "Going to try to rename it to '$tmp'.\n";
266 if ( rename $file, $tmp ) {
267 warn "Rename succesful. Scheduling '$tmp'\nfor deletion at reboot.\n";
268 # when $installing we can set $moan to true.
269 # IOW, if we cant delete the renamed file at reboot its
270 # not the end of the world. The other cases are more serious
271 # and need to be fatal.
272 _move_file_at_boot( $tmp, [], $installing );
274 } elsif ( $installing ) {
275 _warnonce("Rename failed: $!. Scheduling '$tmp'\nfor".
276 " installation as '$file' at reboot.\n");
277 _move_file_at_boot( $tmp, $file );
280 _choke("Rename failed:$!", "Cannot procede.");
292 =item _get_install_skip
294 Handles loading the INSTALL.SKIP file. Returns an array of patterns to use.
300 sub _get_install_skip {
301 my ( $skip, $verbose )= @_;
302 if ($ENV{EU_INSTALL_IGNORE_SKIP}) {
303 print "EU_INSTALL_IGNORE_SKIP is set, ignore skipfile settings\n"
307 if ( ! defined $skip ) {
308 print "Looking for install skip list\n"
310 for my $file ( 'INSTALL.SKIP', $ENV{EU_INSTALL_SITE_SKIPFILE} ) {
312 print "\tChecking for $file\n"
320 if ($skip && !ref $skip) {
321 print "Reading skip patterns from '$skip'.\n"
323 if (open my $fh,$skip ) {
327 next if /^\s*(?:#|$)/;
328 print "\tSkip pattern: $_\n" if $verbose>3;
333 warn "Can't read skip file:'$skip':$!\n";
336 } elsif ( UNIVERSAL::isa($skip,'ARRAY') ) {
337 print "Using array for skip list\n"
340 print "No skip list found.\n"
344 warn "Got @{[0+@$skip]} skip patterns.\n"
351 =item _have_write_access
353 Abstract a -w check that tries to use POSIX::access() if possible.
359 sub _have_write_access {
361 unless (defined $has_posix) {
362 $has_posix= (!$Is_cygwin && !$Is_Win32
363 && eval 'local $^W; require POSIX; 1') || 0;
366 return POSIX::access($dir, POSIX::W_OK());
375 =item _can_write_dir(C<$dir>)
377 Checks whether a given directory is writable, taking account
378 the possibility that the directory might not exist and would have to
381 Returns a list, containing: C<($writable, $determined_by, @create)>
383 C<$writable> says whether whether the directory is (hypothetically) writable
385 C<$determined_by> is the directory the status was determined from. It will be
386 either the C<$dir>, or one of its parents.
388 C<@create> is a list of directories that would probably have to be created
389 to make the requested directory. It may not actually be correct on
390 relative paths with C<..> in them. But for our purposes it should work ok
398 unless defined $dir and length $dir;
400 my ($vol, $dirs, $file) = File::Spec->splitpath($dir,1);
401 my @dirs = File::Spec->splitdir($dirs);
402 unshift @dirs, File::Spec->curdir
403 unless File::Spec->file_name_is_absolute($dir);
409 $dir = File::Spec->catdir($vol,@dirs);
412 $dir = File::Spec->catdir(@dirs);
413 $dir = File::Spec->catpath($vol,$dir,'')
414 if defined $vol and length $vol;
416 next if ( $dir eq $path );
421 if ( _have_write_access($dir) ) {
434 =item _mkpath($dir,$show,$mode,$verbose,$dry_run)
436 Wrapper around File::Path::mkpath() to handle errors.
438 If $verbose is true and >1 then additional diagnostics will be produced, also
439 this will force $show to true.
441 If $dry_run is true then the directory will not be created but a check will be
442 made to see whether it would be possible to write to the directory, or that
443 it would be possible to create the directory.
445 If $dry_run is not true dies if the directory can not be created or is not
451 my ($dir,$show,$mode,$verbose,$dry_run)=@_;
452 if ( $verbose && $verbose > 1 && ! -d $dir) {
454 printf "mkpath(%s,%d,%#o)\n", $dir, $show, $mode;
457 if ( ! eval { File::Path::mkpath($dir,$show,$mode); 1 } ) {
458 _choke("Can't create '$dir'","$@");
462 my ($can,$root,@make)=_can_write_dir($dir);
465 "Can't create '$dir'",
466 $root ? "Do not have write permissions on '$root'"
474 } elsif ($show and $dry_run) {
475 print "$_\n" for @make;
482 =item _copy($from,$to,$verbose,$dry_run)
484 Wrapper around File::Copy::copy to handle errors.
486 If $verbose is true and >1 then additional dignostics will be emitted.
488 If $dry_run is true then the copy will not actually occur.
490 Dies if the copy fails.
496 my ( $from, $to, $verbose, $dry_run)=@_;
497 if ($verbose && $verbose>1) {
498 printf "copy(%s,%s)\n", $from, $to;
501 File::Copy::copy($from,$to)
502 or Carp::croak( _estr "ERROR: Cannot copy '$from' to '$to': $!" );
510 Wrapper around chdir to catch errors.
512 If not called in void context returns the cwd from before the chdir.
521 if (defined wantarray) {
525 or _choke("Couldn't chdir to '$dir': $!");
539 install(\%from_to, $verbose, $dry_run, $uninstall_shadows,
540 $skip, $always_copy, \%result);
542 # recommended form as of 1.47
544 from_to => \%from_to,
547 uninstall_shadows => 1,
550 result => \%install_results,
554 Copies each directory tree of %from_to to its corresponding value
555 preserving timestamps and permissions.
557 There are two keys with a special meaning in the hash: "read" and
558 "write". These contain packlist files. After the copying is done,
559 install() will write the list of target files to $from_to{write}. If
560 $from_to{read} is given the contents of this file will be merged into
561 the written file. The read and the written file may be identical, but
562 on AFS it is quite likely that people are installing to a different
563 directory than the one where the files later appear.
565 If $verbose is true, will print out each file removed. Default is
566 false. This is "make install VERBINST=1". $verbose values going
567 up to 5 show increasingly more diagnostics output.
569 If $dry_run is true it will only print what it was going to do
570 without actually doing it. Default is false.
572 If $uninstall_shadows is true any differing versions throughout @INC
573 will be uninstalled. This is "make install UNINST=1"
575 As of 1.37_02 install() supports the use of a list of patterns to filter out
576 files that shouldn't be installed. If $skip is omitted or undefined then
577 install will try to read the list from INSTALL.SKIP in the CWD. This file is
578 a list of regular expressions and is just like the MANIFEST.SKIP file used
579 by L<ExtUtils::Manifest>.
581 A default site INSTALL.SKIP may be provided by setting then environment
582 variable EU_INSTALL_SITE_SKIPFILE, this will only be used when there isn't a
583 distribution specific INSTALL.SKIP. If the environment variable
584 EU_INSTALL_IGNORE_SKIP is true then no install file filtering will be
587 If $skip is undefined then the skip file will be autodetected and used if it
588 is found. If $skip is a reference to an array then it is assumed the array
589 contains the list of patterns, if $skip is a true non reference it is
590 assumed to be the filename holding the list of patterns, any other value of
591 $skip is taken to mean that no install filtering should occur.
593 B<Changes As of Version 1.47>
595 As of version 1.47 the following additions were made to the install interface.
596 Note that the new argument style and use of the %result hash is recommended.
598 The $always_copy parameter which when true causes files to be updated
599 regardles as to whether they have changed, if it is defined but false then
600 copies are made only if the files have changed, if it is undefined then the
601 value of the environment variable EU_INSTALL_ALWAYS_COPY is used as default.
603 The %result hash will be populated with the various keys/subhashes reflecting
604 the install. Currently these keys and their structure are:
606 install => { $target => $source },
607 install_fail => { $target => $source },
608 install_unchanged => { $target => $source },
610 install_filtered => { $source => $pattern },
612 uninstall => { $uninstalled => $source },
613 uninstall_fail => { $uninstalled => $source },
615 where C<$source> is the filespec of the file being installed. C<$target> is where
616 it is being installed to, and C<$uninstalled> is any shadow file that is in C<@INC>
617 or C<$ENV{PERL5LIB}> or other standard locations, and C<$pattern> is the pattern that
618 caused a source file to be skipped. In future more keys will be added, such as to
619 show created directories, however this requires changes in other modules and must
622 These keys will be populated before any exceptions are thrown should there be an
625 Note that all updates of the %result are additive, the hash will not be
626 cleared before use, thus allowing status results of many installs to be easily
629 B<NEW ARGUMENT STYLE>
631 If there is only one argument and it is a reference to an array then
632 the array is assumed to contain a list of key-value pairs specifying
633 the options. In this case the option "from_to" is mandatory. This style
634 means that you dont have to supply a cryptic list of arguments and can
635 use a self documenting argument list that is easier to understand.
637 This is now the recommended interface to install().
641 If all actions were successful install will return a hashref of the results
642 as described above for the $result parameter. If any action is a failure
643 then install will die, therefore it is recommended to pass in the $result
644 parameter instead of using the return value. If the result parameter is
645 provided then the returned hashref will be the passed in hashref.
649 sub install { #XXX OS-SPECIFIC
650 my($from_to,$verbose,$dry_run,$uninstall_shadows,$skip,$always_copy,$result) = @_;
651 if (@_==1 and eval { 1+@$from_to }) {
652 my %opts = @$from_to;
653 $from_to = $opts{from_to}
654 or Carp::confess("from_to is a mandatory parameter");
655 $verbose = $opts{verbose};
656 $dry_run = $opts{dry_run};
657 $uninstall_shadows = $opts{uninstall_shadows};
659 $always_copy = $opts{always_copy};
660 $result = $opts{result};
667 $skip= _get_install_skip($skip,$verbose);
668 $always_copy = $ENV{EU_INSTALL_ALWAYS_COPY}
669 || $ENV{EU_ALWAYS_COPY}
671 unless defined $always_copy;
673 my(%from_to) = %$from_to;
674 my(%pack, $dir, %warned);
675 my($packlist) = ExtUtils::Packlist->new();
678 for (qw/read write/) {
679 $pack{$_}=$from_to{$_};
682 my $tmpfile = install_rooted_file($pack{"read"});
683 $packlist->read($tmpfile) if (-f $tmpfile);
688 MOD_INSTALL: foreach my $source (sort keys %from_to) {
689 #copy the tree to the target directory without altering
690 #timestamp and permission and remember for the .packlist
691 #file. The packlist file contains the absolute paths of the
692 #install locations. AFS users may call this a bug. We'll have
693 #to reconsider how to add the means to satisfy AFS users also.
695 #October 1997: we want to install .pm files into archlib if
696 #there are any files in arch. So we depend on having ./blib/arch
699 my $targetroot = install_rooted_dir($from_to{$source});
701 my $blib_lib = File::Spec->catdir('blib', 'lib');
702 my $blib_arch = File::Spec->catdir('blib', 'arch');
703 if ($source eq $blib_lib and
704 exists $from_to{$blib_arch} and
705 directory_not_empty($blib_arch)
707 $targetroot = install_rooted_dir($from_to{$blib_arch});
708 print "Files found in $blib_arch: installing files in $blib_lib into architecture dependent library tree\n";
711 next unless -d $source;
713 # 5.5.3's File::Find missing no_chdir option
715 # File::Find seems to always be Unixy except on MacPerl :(
716 my $current_directory= $Is_MacPerl ? $Curdir : '.';
718 my ($mode,$size,$atime,$mtime) = (stat)[2,7,8,9];
723 return if $origfile eq ".exists";
724 my $targetdir = File::Spec->catdir($targetroot, $File::Find::dir);
725 my $targetfile = File::Spec->catfile($targetdir, $origfile);
726 my $sourcedir = File::Spec->catdir($source, $File::Find::dir);
727 my $sourcefile = File::Spec->catfile($sourcedir, $origfile);
729 for my $pat (@$skip) {
730 if ( $sourcefile=~/$pat/ ) {
731 print "Skipping $targetfile (filtered)\n"
733 $result->{install_filtered}{$sourcefile} = $pat;
737 # we have to do this for back compat with old File::Finds
738 # and because the target is relative
739 my $save_cwd = _chdir($cwd);
741 # XXX: I wonder how useful this logic is actually -- demerphq
742 if ( $always_copy or !-f $targetfile or -s $targetfile != $size) {
745 # we might not need to copy this file
746 $diff = compare($sourcefile, $targetfile);
748 $check_dirs{$targetdir}++
749 unless -w $targetfile;
752 [ $diff, $File::Find::dir, $origfile,
753 $mode, $size, $atime, $mtime,
754 $targetdir, $targetfile, $sourcedir, $sourcefile,
757 #restore the original directory we were in when File::Find
758 #called us so that it doesnt get horribly confused.
760 }, $current_directory );
763 foreach my $targetdir (sort keys %check_dirs) {
764 _mkpath( $targetdir, 0, 0755, $verbose, $dry_run );
766 foreach my $found (@found_files) {
767 my ($diff, $ffd, $origfile, $mode, $size, $atime, $mtime,
768 $targetdir, $targetfile, $sourcedir, $sourcefile)= @$found;
770 my $realtarget= $targetfile;
773 if (-f $targetfile) {
774 print "_unlink_or_rename($targetfile)\n" if $verbose>1;
775 $targetfile= _unlink_or_rename( $targetfile, 'tryhard', 'install' )
777 } elsif ( ! -d $targetdir ) {
778 _mkpath( $targetdir, 0, 0755, $verbose, $dry_run );
780 print "Installing $targetfile\n";
782 _copy( $sourcefile, $targetfile, $verbose, $dry_run, );
786 print "utime($atime,$mtime,$targetfile)\n" if $verbose>1;
787 utime($atime,$mtime + $Is_VMS,$targetfile) unless $dry_run>1;
790 $mode = 0444 | ( $mode & 0111 ? 0111 : 0 );
792 if $realtarget ne $targetfile;
793 _chmod( $mode, $targetfile, $verbose );
794 $result->{install}{$targetfile} = $sourcefile;
797 $result->{install_fail}{$targetfile} = $sourcefile;
801 $result->{install_unchanged}{$targetfile} = $sourcefile;
802 print "Skipping $targetfile (unchanged)\n" if $verbose;
805 if ( $uninstall_shadows ) {
806 inc_uninstall($sourcefile,$ffd, $verbose,
808 $realtarget ne $targetfile ? $realtarget : "",
812 # Record the full pathname.
813 $packlist->{$targetfile}++;
816 if ($pack{'write'}) {
817 $dir = install_rooted_dir(dirname($pack{'write'}));
818 _mkpath( $dir, 0, 0755, $verbose, $dry_run );
819 print "Writing $pack{'write'}\n";
820 $packlist->write(install_rooted_file($pack{'write'})) unless $dry_run;
823 _do_cleanup($verbose);
831 Standardize finish event for after another instruction has occured.
832 Handles converting $MUST_REBOOT to a die for instance.
841 die _estr "Operation not completed! ",
842 "You must reboot to complete the installation.",
844 } elsif (defined $MUST_REBOOT & $verbose) {
845 warn _estr "Installation will be completed at the next reboot.\n",
846 "However it is not necessary to reboot immediately.\n";
852 =item install_rooted_file( $file )
854 Returns $file, or catfile($INSTALL_ROOT,$file) if $INSTALL_ROOT
857 =item install_rooted_dir( $dir )
859 Returns $dir, or catdir($INSTALL_ROOT,$dir) if $INSTALL_ROOT
867 sub install_rooted_file {
868 if (defined $INSTALL_ROOT) {
869 File::Spec->catfile($INSTALL_ROOT, $_[0]);
876 sub install_rooted_dir {
877 if (defined $INSTALL_ROOT) {
878 File::Spec->catdir($INSTALL_ROOT, $_[0]);
886 =item forceunlink( $file, $tryhard )
888 Tries to delete a file. If $tryhard is true then we will use whatever
889 devious tricks we can to delete the file. Currently this only applies to
890 Win32 in that it will try to use Win32API::File to schedule a delete at
891 reboot. A wrapper for _unlink_or_rename().
899 my ( $file, $tryhard )= @_; #XXX OS-SPECIFIC
900 _unlink_or_rename( $file, $tryhard, not("installing") );
905 =item directory_not_empty( $dir )
907 Returns 1 if there is an .exists file somewhere in a directory tree.
908 Returns 0 if there is not.
914 sub directory_not_empty ($) {
918 return if $_ eq ".exists";
920 $File::Find::prune++;
929 =item B<install_default> I<DISCOURAGED>
932 install_default($fullext);
934 Calls install() with arguments to copy a module from blib/ to the
935 default site installation location.
937 $fullext is the name of the module converted to a directory
938 (ie. Foo::Bar would be Foo/Bar). If $fullext is not specified, it
939 will attempt to read it from @ARGV.
941 This is primarily useful for install scripts.
943 B<NOTE> This function is not really useful because of the hard-coded
944 install location with no way to control site vs core vs vendor
945 directories and the strange way in which the module name is given.
946 Consider its use discouraged.
950 sub install_default {
951 @_ < 2 or Carp::croak("install_default should be called with 0 or 1 argument");
952 my $FULLEXT = @_ ? shift : $ARGV[0];
953 defined $FULLEXT or die "Do not know to where to write install log";
954 my $INST_LIB = File::Spec->catdir($Curdir,"blib","lib");
955 my $INST_ARCHLIB = File::Spec->catdir($Curdir,"blib","arch");
956 my $INST_BIN = File::Spec->catdir($Curdir,'blib','bin');
957 my $INST_SCRIPT = File::Spec->catdir($Curdir,'blib','script');
958 my $INST_MAN1DIR = File::Spec->catdir($Curdir,'blib','man1');
959 my $INST_MAN3DIR = File::Spec->catdir($Curdir,'blib','man3');
961 read => "$Config{sitearchexp}/auto/$FULLEXT/.packlist",
962 write => "$Config{installsitearch}/auto/$FULLEXT/.packlist",
963 $INST_LIB => (directory_not_empty($INST_ARCHLIB)) ?
964 $Config{installsitearch} :
965 $Config{installsitelib},
966 $INST_ARCHLIB => $Config{installsitearch},
967 $INST_BIN => $Config{installbin} ,
968 $INST_SCRIPT => $Config{installscript},
969 $INST_MAN1DIR => $Config{installman1dir},
970 $INST_MAN3DIR => $Config{installman3dir},
977 uninstall($packlist_file);
978 uninstall($packlist_file, $verbose, $dont_execute);
980 Removes the files listed in a $packlist_file.
982 If $verbose is true, will print out each file removed. Default is
985 If $dont_execute is true it will only print what it was going to do
986 without actually doing it. Default is false.
991 my($fil,$verbose,$dry_run) = @_;
995 die _estr "ERROR: no packlist file found: '$fil'"
997 # my $my_req = $self->catfile(qw(auto ExtUtils Install forceunlink.al));
998 # require $my_req; # Hairy, but for the first
999 my ($packlist) = ExtUtils::Packlist->new($fil);
1000 foreach (sort(keys(%$packlist))) {
1002 print "unlink $_\n" if $verbose;
1003 forceunlink($_,'tryhard') unless $dry_run;
1005 print "unlink $fil\n" if $verbose;
1006 forceunlink($fil, 'tryhard') unless $dry_run;
1007 _do_cleanup($verbose);
1010 =begin _undocumented
1012 =item inc_uninstall($filepath,$libdir,$verbose,$dry_run,$ignore,$results)
1014 Remove shadowed files. If $ignore is true then it is assumed to hold
1015 a filename to ignore. This is used to prevent spurious warnings from
1016 occuring when doing an install at reboot.
1018 We now only die when failing to remove a file that has precedence over
1019 our own, when our install has precedence we only warn.
1021 $results is assumed to contain a hashref which will have the keys
1022 'uninstall' and 'uninstall_fail' populated with keys for the files
1023 removed and values of the source files they would shadow.
1030 my($filepath,$libdir,$verbose,$dry_run,$ignore,$results) = @_;
1033 my $file = (File::Spec->splitpath($filepath))[2];
1036 my @PERL_ENV_LIB = split $Config{path_sep}, defined $ENV{'PERL5LIB'}
1037 ? $ENV{'PERL5LIB'} : $ENV{'PERLLIB'} || '';
1039 my @dirs=( @PERL_ENV_LIB,
1041 @Config{qw(archlibexp
1046 #warn join "\n","---",@dirs,"---";
1048 foreach $dir ( @dirs ) {
1049 my $canonpath = $Is_VMS ? $dir : File::Spec->canonpath($dir);
1050 next if $canonpath eq $Curdir;
1051 next if $seen_dir{$canonpath}++;
1052 my $targetfile = File::Spec->catfile($canonpath,$libdir,$file);
1053 next unless -f $targetfile;
1055 # The reason why we compare file's contents is, that we cannot
1056 # know, which is the file we just installed (AFS). So we leave
1057 # an identical file in place
1059 if ( -f $targetfile && -s _ == -s $filepath) {
1060 # We have a good chance, we can skip this one
1061 $diff = compare($filepath,$targetfile);
1065 print "#$file and $targetfile differ\n" if $diff && $verbose > 1;
1067 if (!$diff or $targetfile eq $ignore) {
1072 $results->{uninstall}{$targetfile} = $filepath;
1074 $Inc_uninstall_warn_handler ||= ExtUtils::Install::Warn->new();
1075 $libdir =~ s|^\./||s ; # That's just cosmetics, no need to port. It looks prettier.
1076 $Inc_uninstall_warn_handler->add(
1077 File::Spec->catfile($libdir, $file),
1081 # if not verbose, we just say nothing
1083 print "Unlinking $targetfile (shadowing?)\n" if $verbose;
1085 die "Fake die for testing"
1086 if $ExtUtils::Install::Testing and
1087 ucase(File::Spec->canonpath($ExtUtils::Install::Testing)) eq ucase($targetfile);
1088 forceunlink($targetfile,'tryhard');
1089 $results->{uninstall}{$targetfile} = $filepath;
1092 $results->{fail_uninstall}{$targetfile} = $filepath;
1094 warn "Failed to remove probably harmless shadow file '$targetfile'\n";
1103 =begin _undocumented
1105 =item run_filter($cmd,$src,$dest)
1107 Filter $src using $cmd into $dest.
1114 my ($cmd, $src, $dest) = @_;
1116 open(CMD, "|$cmd >$dest") || die "Cannot fork: $!";
1117 open(SRC, $src) || die "Cannot open $src: $!";
1120 while (my $len = sysread(SRC, $buf, $sz)) {
1121 syswrite(CMD, $buf, $len);
1124 close CMD or die "Filter command '$cmd' failed for $src";
1131 pm_to_blib(\%from_to, $autosplit_dir);
1132 pm_to_blib(\%from_to, $autosplit_dir, $filter_cmd);
1134 Copies each key of %from_to to its corresponding value efficiently.
1135 Filenames with the extension .pm are autosplit into the $autosplit_dir.
1136 Any destination directories are created.
1138 $filter_cmd is an optional shell command to run each .pm file through
1139 prior to splitting and copying. Input is the contents of the module,
1140 output the new module contents.
1142 You can have an environment variable PERL_INSTALL_ROOT set which will
1143 be prepended as a directory to each installed file (and directory).
1148 my($fromto,$autodir,$pm_filter) = @_;
1150 _mkpath($autodir,0,0755);
1151 while(my($from, $to) = each %$fromto) {
1152 if( -f $to && -s $from == -s $to && -M $to < -M $from ) {
1153 print "Skip $to (unchanged)\n";
1157 # When a pm_filter is defined, we need to pre-process the source first
1158 # to determine whether it has changed or not. Therefore, only perform
1159 # the comparison check when there's no filter to be ran.
1160 # -- RAM, 03/01/2001
1162 my $need_filtering = defined $pm_filter && length $pm_filter &&
1165 if (!$need_filtering && 0 == compare($from,$to)) {
1166 print "Skip $to (unchanged)\n";
1170 # we wont try hard here. its too likely to mess things up.
1173 _mkpath(dirname($to),0,0755);
1175 if ($need_filtering) {
1176 run_filter($pm_filter, $from, $to);
1177 print "$pm_filter <$from >$to\n";
1179 _copy( $from, $to );
1180 print "cp $from $to\n";
1182 my($mode,$atime,$mtime) = (stat $from)[2,8,9];
1183 utime($atime,$mtime+$Is_VMS,$to);
1184 _chmod(0444 | ( $mode & 0111 ? 0111 : 0 ),$to);
1185 next unless $from =~ /\.pm$/;
1186 _autosplit($to,$autodir);
1195 From 1.0307 back, AutoSplit will sometimes leave an open filehandle to
1196 the file being split. This causes problems on systems with mandatory
1197 locking (ie. Windows). So we wrap it and close the filehandle.
1203 sub _autosplit { #XXX OS-SPECIFIC
1204 my $retval = autosplit(@_);
1205 close *AutoSplit::IN if defined *AutoSplit::IN{IO};
1211 package ExtUtils::Install::Warn;
1213 sub new { bless {}, shift }
1216 my($self,$file,$targetfile) = @_;
1217 push @{$self->{$file}}, $targetfile;
1221 unless(defined $INSTALL_ROOT) {
1223 my($file,$i,$plural);
1224 foreach $file (sort keys %$self) {
1225 $plural = @{$self->{$file}} > 1 ? "s" : "";
1226 print "## Differing version$plural of $file found. You might like to\n";
1227 for (0..$#{$self->{$file}}) {
1228 print "rm ", $self->{$file}[$_], "\n";
1232 $plural = $i>1 ? "all those files" : "this file";
1233 my $inst = (_invokant() eq 'ExtUtils::MakeMaker')
1234 ? ( $Config::Config{make} || 'make' ).' install'
1235 . ( $Is_VMS ? '/MACRO="UNINST"=1' : ' UNINST=1' )
1236 : './Build install uninst=1';
1237 print "## Running '$inst' will unlink $plural for you.\n";
1245 Does a heuristic on the stack to see who called us for more intelligent
1246 error messages. Currently assumes we will be called only by Module::Build
1247 or by ExtUtils::MakeMaker.
1256 while (my $file = (caller($frame++))[1]) {
1257 push @stack, (File::Spec->splitpath($file))[2];
1261 my $top = pop @stack;
1262 if ($top =~ /^Build/i || exists($INC{'Module/Build.pm'})) {
1263 $builder = 'Module::Build';
1265 $builder = 'ExtUtils::MakeMaker';
1278 =item B<PERL_INSTALL_ROOT>
1280 Will be prepended to each install path.
1282 =item B<EU_INSTALL_IGNORE_SKIP>
1284 Will prevent the automatic use of INSTALL.SKIP as the install skip file.
1286 =item B<EU_INSTALL_SITE_SKIPFILE>
1288 If there is no INSTALL.SKIP file in the make directory then this value
1289 can be used to provide a default.
1291 =item B<EU_INSTALL_ALWAYS_COPY>
1293 If this environment variable is true then normal install processes will
1294 always overwrite older identical files during the install process.
1296 Note that the alias EU_ALWAYS_COPY will be supported if EU_INSTALL_ALWAYS_COPY
1297 is not defined until at least the 1.50 release. Please ensure you use the
1298 correct EU_INSTALL_ALWAYS_COPY.
1304 Original author lost in the mists of time. Probably the same as Makemaker.
1306 Production release currently maintained by demerphq C<yves at cpan.org>,
1307 extensive changes by Michael G. Schwern.
1309 Send bug reports via http://rt.cpan.org/. Please send your
1310 generated Makefile along with your report.
1314 This program is free software; you can redistribute it and/or
1315 modify it under the same terms as Perl itself.
1317 See L<http://www.perl.com/perl/misc/Artistic.html>