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';
23 MakeMaker::Test::Utils - Utility routines for testing MakeMaker
27 use MakeMaker::Test::Utils;
29 my $perl = which_perl;
32 my $makefile = makefile_name;
33 my $makefile_back = makefile_backup;
36 my $make_run = make_run;
37 make_macro($make, $targ, %macros);
39 my $mtime = calibrate_mtime;
43 A consolidation of little utility functions used through out the
48 The following are exported by default.
54 my $perl = which_perl;
56 Returns a path to perl which is safe to use in a command line, no
57 matter where you chdir to.
65 # VMS should have 'perl' aliased properly
66 return $perl if $Is_VMS;
68 $perl .= $Config{exe_ext} unless $perl =~ m/$Config{exe_ext}$/i;
70 my $perlpath = File::Spec->rel2abs( $perl );
71 unless( -x $perlpath ) {
72 # $^X was probably 'perl'
74 # When building in the core, *don't* go off and find
76 die "Can't find a perl to use (\$^X=$^X), (\$perlpath=$perlpath)"
79 foreach my $path (File::Spec->path) {
80 $perlpath = File::Spec->catfile($path, $perl);
92 Sets up environment variables so perl can find its libraries.
96 my $old5lib = $ENV{PERL5LIB};
97 my $had5lib = exists $ENV{PERL5LIB};
99 # perl-src/lib/ExtUtils/t/Foo
100 my $lib = $ENV{PERL_CORE} ? qq{../../../lib}
101 # ExtUtils-MakeMaker/t/Foo
103 $lib = File::Spec->rel2abs($lib);
105 push @libs, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
106 $ENV{PERL5LIB} = join($Config{path_sep}, @libs);
112 $ENV{PERL5LIB} = $old5lib;
115 delete $ENV{PERL5LIB};
120 =item B<makefile_name>
122 my $makefile = makefile_name;
124 MakeMaker doesn't always generate 'Makefile'. It returns what it
130 return $Is_VMS ? 'Descrip.MMS' : 'Makefile';
133 =item B<makefile_backup>
135 my $makefile_old = makefile_backup;
137 Returns the name MakeMaker will use for a backup of the current
142 sub makefile_backup {
143 my $makefile = makefile_name;
144 return $Is_VMS ? $makefile : "$makefile.old";
151 Returns a good guess at the make to run.
156 my $make = $Config{make};
157 $make = $ENV{MAKE} if exists $ENV{MAKE};
164 my $make_run = make_run;
166 Returns the make to run as with make() plus any necessary switches.
172 $make .= ' -nologo' if $make eq 'nmake';
179 my $make_cmd = make_macro($make, $target, %macros);
181 Returns the command necessary to run $make on the given $target using
184 my $make_test_verbose = make_macro(make_run(), 'test',
187 This is important because VMS's make utilities have a completely
188 different calling convention than Unix or Windows.
190 %macros is actually a list of tuples, so the order will be preserved.
195 my($make, $target) = (shift, shift);
197 my $is_mms = $make =~ /^MM(K|S)/i;
201 while( my($key,$val) = splice(@_, 0, 2) ) {
203 $macros .= qq{/macro="$key=$val"};
206 $macros .= qq{ $key=$val};
210 return $is_mms ? "$make$macros $target" : "$make $target $macros";
213 =item B<calibrate_mtime>
215 my $mtime = calibrate_mtime;
217 When building on NFS, file modification times can often lose touch
218 with reality. This returns the mtime of a file which has just been
223 sub calibrate_mtime {
224 open(FILE, ">calibrate_mtime.tmp") || die $!;
227 my($mtime) = (stat('calibrate_mtime.tmp'))[9];
228 unlink 'calibrate_mtime.tmp';
236 Michael G Schwern <schwern@pobox.com>