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
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);
41 A consolidation of little utility functions used through out the
46 The following are exported by default.
52 my $perl = which_perl;
54 Returns a path to perl which is safe to use in a command line, no
55 matter where you chdir to.
63 # VMS should have 'perl' aliased properly
64 return $perl if $Is_VMS;
66 $perl = File::Spec->rel2abs( $perl );
69 # $^X was probably 'perl'
70 foreach my $path (File::Spec->path) {
71 $perl = File::Spec->catfile($path, $^X);
83 Sets up environment variables so perl can find its libraries.
87 my $old5lib = $ENV{PERL5LIB};
88 my $had5lib = exists $ENV{PERL5LIB};
90 # perl-src/lib/ExtUtils/t/Foo
91 my $lib = $ENV{PERL_CORE} ? qq{../../../lib}
92 # ExtUtils-MakeMaker/t/Foo
94 $lib = File::Spec->rel2abs($lib);
96 push @libs, $ENV{PERL5LIB} if exists $ENV{PERL5LIB};
97 $ENV{PERL5LIB} = join($Config{path_sep}, @libs);
103 $ENV{PERL5LIB} = $old5lib;
106 delete $ENV{PERL5LIB};
111 =item B<makefile_name>
113 my $makefile = makefile_name;
115 MakeMaker doesn't always generate 'Makefile'. It returns what it
121 return $Is_VMS ? 'Descrip.MMS' : 'Makefile';
124 =item B<makefile_backup>
126 my $makefile_old = makefile_backup;
128 Returns the name MakeMaker will use for a backup of the current
133 sub makefile_backup {
134 my $makefile = makefile_name;
135 return $Is_VMS ? $makefile : "$makefile.old";
142 Returns a good guess at the make to run.
147 my $make = $Config{make};
148 $make = $ENV{MAKE} if exists $ENV{MAKE};
155 my $make_run = make_run;
157 Returns the make to run as with make() plus any necessary switches.
163 $make .= ' -nologo' if $make eq 'nmake';
170 my $make_cmd = make_macro($make, $target, %macros);
172 Returns the command necessary to run $make on the given $target using
175 my $make_test_verbose = make_macro(make_run(), 'test',
178 This is important because VMS's make utilities have a completely
179 different calling convention than Unix or Windows.
181 %macros is actually a list of tuples, so the order will be preserved.
186 my($make, $target) = (shift, shift);
188 my $is_mms = $make =~ /^MM(K|S)/i;
192 while( my($key,$val) = splice(@_, 0, 2) ) {
194 $macros .= qq{/macro="$key=$val"};
197 $macros .= qq{ $key=$val};
201 return $is_mms ? "$make$macros $target" : "$make $target $macros";
208 Michael G Schwern <schwern@pobox.com>