1 package MakeMaker::Test::Utils;
7 use vars qw($VERSION @ISA @EXPORT);
14 @EXPORT = qw(which_perl perl_lib makefile_name makefile_backup
15 make make_run make_macro calibrate_mtime
18 my $Is_VMS = $^O eq 'VMS';
19 my $Is_MacOS = $^O eq 'MacOS';
24 MakeMaker::Test::Utils - Utility routines for testing MakeMaker
28 use MakeMaker::Test::Utils;
30 my $perl = which_perl;
33 my $makefile = makefile_name;
34 my $makefile_back = makefile_backup;
37 my $make_run = make_run;
38 make_macro($make, $targ, %macros);
40 my $mtime = calibrate_mtime;
44 A consolidation of little utility functions used through out the
49 The following are exported by default.
55 my $perl = which_perl;
57 Returns a path to perl which is safe to use in a command line, no
58 matter where you chdir to.
66 # VMS should have 'perl' aliased properly
67 return $perl if $Is_VMS;
69 $perl .= $Config{exe_ext} unless $perl =~ m/$Config{exe_ext}$/i;
71 my $perlpath = File::Spec->rel2abs( $perl );
72 unless( $Is_MacOS || -x $perlpath ) {
73 # $^X was probably 'perl'
75 # When building in the core, *don't* go off and find
77 die "Can't find a perl to use (\$^X=$^X), (\$perlpath=$perlpath)"
80 foreach my $path (File::Spec->path) {
81 $perlpath = File::Spec->catfile($path, $perl);
93 Sets up environment variables so perl can find its libraries.
97 my $old5lib = $ENV{PERL5LIB};
98 my $had5lib = exists $ENV{PERL5LIB};
101 my $lib = $ENV{PERL_CORE} ? qq{../lib}
102 # ExtUtils-MakeMaker/t/
104 $lib = File::Spec->rel2abs($lib);
106 push @libs, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
107 $ENV{PERL5LIB} = join($Config{path_sep}, @libs);
113 $ENV{PERL5LIB} = $old5lib;
116 delete $ENV{PERL5LIB};
121 =item B<makefile_name>
123 my $makefile = makefile_name;
125 MakeMaker doesn't always generate 'Makefile'. It returns what it
131 return $Is_VMS ? 'Descrip.MMS' : 'Makefile';
134 =item B<makefile_backup>
136 my $makefile_old = makefile_backup;
138 Returns the name MakeMaker will use for a backup of the current
143 sub makefile_backup {
144 my $makefile = makefile_name;
145 return $Is_VMS ? $makefile : "$makefile.old";
152 Returns a good guess at the make to run.
157 my $make = $Config{make};
158 $make = $ENV{MAKE} if exists $ENV{MAKE};
165 my $make_run = make_run;
167 Returns the make to run as with make() plus any necessary switches.
173 $make .= ' -nologo' if $make eq 'nmake';
180 my $make_cmd = make_macro($make, $target, %macros);
182 Returns the command necessary to run $make on the given $target using
185 my $make_test_verbose = make_macro(make_run(), 'test',
188 This is important because VMS's make utilities have a completely
189 different calling convention than Unix or Windows.
191 %macros is actually a list of tuples, so the order will be preserved.
196 my($make, $target) = (shift, shift);
198 my $is_mms = $make =~ /^MM(K|S)/i;
202 while( my($key,$val) = splice(@_, 0, 2) ) {
204 $macros .= qq{/macro="$key=$val"};
207 $macros .= qq{ $key=$val};
211 return $is_mms ? "$make$macros $target" : "$make $target $macros";
214 =item B<calibrate_mtime>
216 my $mtime = calibrate_mtime;
218 When building on NFS, file modification times can often lose touch
219 with reality. This returns the mtime of a file which has just been
224 sub calibrate_mtime {
225 open(FILE, ">calibrate_mtime.tmp") || die $!;
228 my($mtime) = (stat('calibrate_mtime.tmp'))[9];
229 unlink 'calibrate_mtime.tmp';
237 Michael G Schwern <schwern@pobox.com>