Updating ExtUtils-ParseXS to 2.20
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Any.pm
CommitLineData
f6d6199c 1package ExtUtils::MM_Any;
2
3use strict;
c0956255 4our $VERSION = '6.53_02';
f6d6199c 5
2977d345 6use Carp;
f6d6199c 7use File::Spec;
5bdf71cc 8use File::Basename;
a592ba15 9BEGIN { our @ISA = qw(File::Spec); }
7292dc67 10
11# We need $Verbose
12use ExtUtils::MakeMaker qw($Verbose);
13
14use ExtUtils::MakeMaker::Config;
15
16
17# So we don't have to keep calling the methods over and over again,
18# we have these globals to cache the values. Faster and shrtr.
19my $Curdir = __PACKAGE__->curdir;
20my $Rootdir = __PACKAGE__->rootdir;
21my $Updir = __PACKAGE__->updir;
f6d6199c 22
23
24=head1 NAME
25
30361541 26ExtUtils::MM_Any - Platform-agnostic MM methods
f6d6199c 27
28=head1 SYNOPSIS
29
30 FOR INTERNAL USE ONLY!
31
32 package ExtUtils::MM_SomeOS;
33
34 # Temporarily, you have to subclass both. Put MM_Any first.
35 require ExtUtils::MM_Any;
36 require ExtUtils::MM_Unix;
37 @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);
38
39=head1 DESCRIPTION
40
41B<FOR INTERNAL USE ONLY!>
42
43ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
44modules. It contains methods which are either inherently
45cross-platform or are written in a cross-platform manner.
46
47Subclass off of ExtUtils::MM_Any I<and> ExtUtils::MM_Unix. This is a
48temporary solution.
49
50B<THIS MAY BE TEMPORARY!>
51
f6d6199c 52
7292dc67 53=head1 METHODS
f6d6199c 54
7292dc67 55Any methods marked I<Abstract> must be implemented by subclasses.
dedf98bc 56
5e719f03 57
7292dc67 58=head2 Cross-platform helper methods
5e719f03 59
7292dc67 60These are methods which help writing cross-platform code.
5e719f03 61
5e719f03 62
5e719f03 63
7292dc67 64=head3 os_flavor I<Abstract>
65
66 my @os_flavor = $mm->os_flavor;
67
68@os_flavor is the style of operating system this is, usually
69corresponding to the MM_*.pm file we're using.
70
71The first element of @os_flavor is the major family (ie. Unix,
72Windows, VMS, OS/2, etc...) and the rest are sub families.
73
74Some examples:
75
76 Cygwin98 ('Unix', 'Cygwin', 'Cygwin9x')
77 Windows NT ('Win32', 'WinNT')
78 Win98 ('Win32', 'Win9x')
79 Linux ('Unix', 'Linux')
80 MacOS X ('Unix', 'Darwin', 'MacOS', 'MacOS X')
81 OS/2 ('OS/2')
82
83This is used to write code for styles of operating system.
84See os_flavor_is() for use.
85
dedf98bc 86
7292dc67 87=head3 os_flavor_is
88
89 my $is_this_flavor = $mm->os_flavor_is($this_flavor);
90 my $is_this_flavor = $mm->os_flavor_is(@one_of_these_flavors);
dedf98bc 91
92Checks to see if the current operating system is one of the given flavors.
93
94This is useful for code like:
95
96 if( $mm->os_flavor_is('Unix') ) {
97 $out = `foo 2>&1`;
98 }
99 else {
100 $out = `foo`;
101 }
102
103=cut
104
105sub os_flavor_is {
106 my $self = shift;
107 my %flavors = map { ($_ => 1) } $self->os_flavor;
108 return (grep { $flavors{$_} } @_) ? 1 : 0;
109}
110
5dca256e 111
c0956255 112=head3 can_load_xs
113
114 my $can_load_xs = $self->can_load_xs;
115
116Returns true if we have the ability to load XS.
117
118This is important because miniperl, used to build XS modules in the
119core, can not load XS.
120
121=cut
122
123sub can_load_xs {
124 return defined &DynaLoader::boot_DynaLoader ? 1 : 0;
125}
126
127
7292dc67 128=head3 split_command
479d2113 129
130 my @cmds = $MM->split_command($cmd, @args);
131
132Most OS have a maximum command length they can execute at once. Large
133modules can easily generate commands well past that limit. Its
134necessary to split long commands up into a series of shorter commands.
135
7292dc67 136C<split_command> will return a series of @cmds each processing part of
479d2113 137the args. Collectively they will process all the arguments. Each
138individual line in @cmds will not be longer than the
139$self->max_exec_len being careful to take into account macro expansion.
140
141$cmd should include any switches and repeated initial arguments.
142
143If no @args are given, no @cmds will be returned.
144
145Pairs of arguments will always be preserved in a single command, this
146is a heuristic for things like pm_to_blib and pod2man which work on
147pairs of arguments. This makes things like this safe:
148
149 $self->split_command($cmd, %pod2man);
150
f6d6199c 151
152=cut
153
479d2113 154sub split_command {
155 my($self, $cmd, @args) = @_;
156
157 my @cmds = ();
158 return(@cmds) unless @args;
159
160 # If the command was given as a here-doc, there's probably a trailing
161 # newline.
162 chomp $cmd;
163
a592ba15 164 # set aside 30% for macro expansion.
165 my $len_left = int($self->max_exec_len * 0.70);
479d2113 166 $len_left -= length $self->_expand_macros($cmd);
167
168 do {
169 my $arg_str = '';
170 my @next_args;
171 while( @next_args = splice(@args, 0, 2) ) {
172 # Two at a time to preserve pairs.
173 my $next_arg_str = "\t ". join ' ', @next_args, "\n";
174
175 if( !length $arg_str ) {
176 $arg_str .= $next_arg_str
177 }
178 elsif( length($arg_str) + length($next_arg_str) > $len_left ) {
179 unshift @args, @next_args;
180 last;
181 }
182 else {
183 $arg_str .= $next_arg_str;
184 }
185 }
186 chop $arg_str;
187
a7d1454b 188 push @cmds, $self->escape_newlines("$cmd \n$arg_str");
479d2113 189 } while @args;
190
191 return @cmds;
f6d6199c 192}
193
479d2113 194
195sub _expand_macros {
196 my($self, $cmd) = @_;
197
198 $cmd =~ s{\$\((\w+)\)}{
199 defined $self->{$1} ? $self->{$1} : "\$($1)"
200 }e;
201 return $cmd;
202}
203
204
7292dc67 205=head3 echo
479d2113 206
207 my @commands = $MM->echo($text);
208 my @commands = $MM->echo($text, $file);
209 my @commands = $MM->echo($text, $file, $appending);
210
211Generates a set of @commands which print the $text to a $file.
212
213If $file is not given, output goes to STDOUT.
214
215If $appending is true the $file will be appended to rather than
216overwritten.
f6d6199c 217
218=cut
219
479d2113 220sub echo {
221 my($self, $text, $file, $appending) = @_;
222 $appending ||= 0;
223
224 my @cmds = map { '$(NOECHO) $(ECHO) '.$self->quote_literal($_) }
225 split /\n/, $text;
226 if( $file ) {
227 my $redirect = $appending ? '>>' : '>';
228 $cmds[0] .= " $redirect $file";
229 $_ .= " >> $file" foreach @cmds[1..$#cmds];
230 }
231
232 return @cmds;
f6d6199c 233}
234
479d2113 235
7292dc67 236=head3 wraplist
479d2113 237
7292dc67 238 my $args = $mm->wraplist(@list);
479d2113 239
7292dc67 240Takes an array of items and turns them into a well-formatted list of
241arguments. In most cases this is simply something like:
479d2113 242
7292dc67 243 FOO \
244 BAR \
245 BAZ
479d2113 246
7292dc67 247=cut
479d2113 248
7292dc67 249sub wraplist {
250 my $self = shift;
251 return join " \\\n\t", @_;
252}
479d2113 253
479d2113 254
6d6be53e 255=head3 maketext_filter
256
257 my $filter_make_text = $mm->maketext_filter($make_text);
258
259The text of the Makefile is run through this method before writing to
260disk. It allows systems a chance to make portability fixes to the
261Makefile.
262
263By default it does nothing.
264
265This method is protected and not intended to be called outside of
266MakeMaker.
267
268=cut
269
270sub maketext_filter { return $_[1] }
271
272
7292dc67 273=head3 cd I<Abstract>
479d2113 274
7292dc67 275 my $subdir_cmd = $MM->cd($subdir, @cmds);
479d2113 276
7292dc67 277This will generate a make fragment which runs the @cmds in the given
278$dir. The rough equivalent to this, except cross platform.
479d2113 279
7292dc67 280 cd $subdir && $cmd
479d2113 281
7292dc67 282Currently $dir can only go down one level. "foo" is fine. "foo/bar" is
283not. "../foo" is right out.
479d2113 284
7292dc67 285The resulting $subdir_cmd has no leading tab nor trailing newline. This
286makes it easier to embed in a make string. For example.
479d2113 287
7292dc67 288 my $make = sprintf <<'CODE', $subdir_cmd;
289 foo :
290 $(ECHO) what
291 %s
292 $(ECHO) mouche
293 CODE
f6d6199c 294
f6d6199c 295
7292dc67 296=head3 oneliner I<Abstract>
479d2113 297
7292dc67 298 my $oneliner = $MM->oneliner($perl_code);
299 my $oneliner = $MM->oneliner($perl_code, \@switches);
479d2113 300
7292dc67 301This will generate a perl one-liner safe for the particular platform
302you're on based on the given $perl_code and @switches (a -e is
303assumed) suitable for using in a make target. It will use the proper
304shell quoting and escapes.
479d2113 305
7292dc67 306$(PERLRUN) will be used as perl.
479d2113 307
7292dc67 308Any newlines in $perl_code will be escaped. Leading and trailing
309newlines will be stripped. Makes this idiom much easier:
479d2113 310
7292dc67 311 my $code = $MM->oneliner(<<'CODE', [...switches...]);
312some code here
313another line here
314CODE
479d2113 315
7292dc67 316Usage might be something like:
479d2113 317
7292dc67 318 # an echo emulation
319 $oneliner = $MM->oneliner('print "Foo\n"');
320 $make = '$oneliner > somefile';
479d2113 321
7292dc67 322All dollar signs must be doubled in the $perl_code if you expect them
323to be interpreted normally, otherwise it will be considered a make
324macro. Also remember to quote make macros else it might be used as a
325bareword. For example:
479d2113 326
7292dc67 327 # Assign the value of the $(VERSION_FROM) make macro to $vf.
328 $oneliner = $MM->oneliner('$$vf = "$(VERSION_FROM)"');
f6d6199c 329
7292dc67 330Its currently very simple and may be expanded sometime in the figure
331to include more flexible code and switches.
479d2113 332
479d2113 333
7292dc67 334=head3 quote_literal I<Abstract>
f6d6199c 335
7292dc67 336 my $safe_text = $MM->quote_literal($text);
f6d6199c 337
7292dc67 338This will quote $text so it is interpreted literally in the shell.
f6d6199c 339
7292dc67 340For example, on Unix this would escape any single-quotes in $text and
341put single-quotes around the whole thing.
479d2113 342
f6d6199c 343
7292dc67 344=head3 escape_newlines I<Abstract>
f6d6199c 345
7292dc67 346 my $escaped_text = $MM->escape_newlines($text);
479d2113 347
7292dc67 348Shell escapes newlines in $text.
479d2113 349
479d2113 350
7292dc67 351=head3 max_exec_len I<Abstract>
479d2113 352
7292dc67 353 my $max_exec_len = $MM->max_exec_len;
479d2113 354
7292dc67 355Calculates the maximum command size the OS can exec. Effectively,
356this is the max size of a shell command line.
479d2113 357
7292dc67 358=for _private
359$self->{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.
f6d6199c 360
479d2113 361
2977d345 362=head3 make
479d2113 363
2977d345 364 my $make = $MM->make;
365
366Returns the make variant we're generating the Makefile for. This attempts
367to do some normalization on the information from %Config or the user.
368
369=cut
370
371sub make {
372 my $self = shift;
373
1487aac6 374 my $make = lc $self->{MAKE};
2977d345 375
376 # Truncate anything like foomake6 to just foomake.
377 $make =~ s/^(\w+make).*/$1/;
378
379 # Turn gnumake into gmake.
380 $make =~ s/^gnu/g/;
381
382 return $make;
383}
479d2113 384
f6d6199c 385
7292dc67 386=head2 Targets
f6d6199c 387
7292dc67 388These are methods which produce make targets.
479d2113 389
479d2113 390
7292dc67 391=head3 all_target
479d2113 392
7292dc67 393Generate the default target 'all'.
479d2113 394
7292dc67 395=cut
479d2113 396
7292dc67 397sub all_target {
398 my $self = shift;
479d2113 399
7292dc67 400 return <<'MAKE_EXT';
401all :: pure_all
402 $(NOECHO) $(NOOP)
403MAKE_EXT
479d2113 404
f6d6199c 405}
406
479d2113 407
7292dc67 408=head3 blibdirs_target
479d2113 409
7292dc67 410 my $make_frag = $mm->blibdirs_target;
479d2113 411
7292dc67 412Creates the blibdirs target which creates all the directories we use
413in blib/.
f6d6199c 414
7292dc67 415The blibdirs.ts target is deprecated. Depend on blibdirs instead.
f6d6199c 416
479d2113 417
7292dc67 418=cut
419
420sub blibdirs_target {
421 my $self = shift;
422
423 my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
424 autodir archautodir
425 bin script
426 man1dir man3dir
427 );
f6d6199c 428
7292dc67 429 my @exists = map { $_.'$(DFSEP).exists' } @dirs;
479d2113 430
7292dc67 431 my $make = sprintf <<'MAKE', join(' ', @exists);
432blibdirs : %s
433 $(NOECHO) $(NOOP)
479d2113 434
7292dc67 435# Backwards compat with 6.18 through 6.25
436blibdirs.ts : blibdirs
437 $(NOECHO) $(NOOP)
479d2113 438
7292dc67 439MAKE
440
441 $make .= $self->dir_target(@dirs);
442
443 return $make;
444}
445
446
447=head3 clean (o)
448
449Defines the clean target.
f6d6199c 450
451=cut
452
7292dc67 453sub clean {
454# --- Cleanup and Distribution Sections ---
479d2113 455
7292dc67 456 my($self, %attribs) = @_;
457 my @m;
458 push(@m, '
459# Delete temporary files but do not touch installed files. We don\'t delete
460# the Makefile here so a later make realclean still has a makefile to use.
461
462clean :: clean_subdirs
463');
464
465 my @files = values %{$self->{XS}}; # .c files from *.xs files
466 my @dirs = qw(blib);
467
468 # Normally these are all under blib but they might have been
469 # redefined.
470 # XXX normally this would be a good idea, but the Perl core sets
471 # INST_LIB = ../../lib rather than actually installing the files.
472 # So a "make clean" in an ext/ directory would blow away lib.
473 # Until the core is adjusted let's leave this out.
474# push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
475# $(INST_BIN) $(INST_SCRIPT)
476# $(INST_MAN1DIR) $(INST_MAN3DIR)
477# $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
478# $(INST_STATIC) $(INST_DYNAMIC) $(INST_BOOT)
479# );
480
481
482 if( $attribs{FILES} ) {
483 # Use @dirs because we don't know what's in here.
484 push @dirs, ref $attribs{FILES} ?
485 @{$attribs{FILES}} :
486 split /\s+/, $attribs{FILES} ;
487 }
479d2113 488
7292dc67 489 push(@files, qw[$(MAKE_APERL_FILE)
490 perlmain.c tmon.out mon.out so_locations
491 blibdirs.ts pm_to_blib pm_to_blib.ts
492 *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
493 $(BOOTSTRAP) $(BASEEXT).bso
494 $(BASEEXT).def lib$(BASEEXT).def
495 $(BASEEXT).exp $(BASEEXT).x
496 ]);
479d2113 497
7292dc67 498 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
499 push(@files, $self->catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));
479d2113 500
7292dc67 501 # core files
502 push(@files, qw[core core.*perl.*.? *perl.core]);
503 push(@files, map { "core." . "[0-9]"x$_ } (1..5));
479d2113 504
7292dc67 505 # OS specific things to clean up. Use @dirs since we don't know
506 # what might be in here.
507 push @dirs, $self->extra_clean_files;
f6d6199c 508
7292dc67 509 # Occasionally files are repeated several times from different sources
510 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
511 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
f6d6199c 512
7292dc67 513 push @m, map "\t$_\n", $self->split_command('- $(RM_F)', @files);
514 push @m, map "\t$_\n", $self->split_command('- $(RM_RF)', @dirs);
f6d6199c 515
7292dc67 516 # Leave Makefile.old around for realclean
517 push @m, <<'MAKE';
518 - $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
519MAKE
479d2113 520
7292dc67 521 push(@m, "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
479d2113 522
7292dc67 523 join("", @m);
524}
525
526
527=head3 clean_subdirs_target
528
529 my $make_frag = $MM->clean_subdirs_target;
530
531Returns the clean_subdirs target. This is used by the clean target to
532call clean on any subdirectories which contain Makefiles.
479d2113 533
534=cut
535
7292dc67 536sub clean_subdirs_target {
537 my($self) = shift;
479d2113 538
7292dc67 539 # No subdirectories, no cleaning.
540 return <<'NOOP_FRAG' unless @{$self->{DIR}};
541clean_subdirs :
542 $(NOECHO) $(NOOP)
543NOOP_FRAG
544
545
546 my $clean = "clean_subdirs :\n";
547
548 for my $dir (@{$self->{DIR}}) {
549 my $subclean = $self->oneliner(sprintf <<'CODE', $dir);
550chdir '%s'; system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
551CODE
552
553 $clean .= "\t$subclean\n";
554 }
555
556 return $clean;
479d2113 557}
f6d6199c 558
f6d6199c 559
7292dc67 560=head3 dir_target
f6d6199c 561
7292dc67 562 my $make_frag = $mm->dir_target(@directories);
f6d6199c 563
7292dc67 564Generates targets to create the specified directories and set its
5bdf71cc 565permission to PERM_DIR.
f6d6199c 566
7292dc67 567Because depending on a directory to just ensure it exists doesn't work
568too well (the modified time changes too often) dir_target() creates a
569.exists file in the created directory. It is this you should depend on.
570For portability purposes you should use the $(DIRFILESEP) macro rather
571than a '/' to seperate the directory from the file.
572
573 yourdirectory$(DIRFILESEP).exists
f6d6199c 574
575=cut
576
7292dc67 577sub dir_target {
578 my($self, @dirs) = @_;
f6d6199c 579
7292dc67 580 my $make = '';
581 foreach my $dir (@dirs) {
582 $make .= sprintf <<'MAKE', ($dir) x 7;
087dded7 583%s$(DFSEP).exists :: Makefile.PL
7292dc67 584 $(NOECHO) $(MKPATH) %s
5bdf71cc 585 $(NOECHO) $(CHMOD) $(PERM_DIR) %s
7292dc67 586 $(NOECHO) $(TOUCH) %s$(DFSEP).exists
f6d6199c 587
7292dc67 588MAKE
f6d6199c 589
7292dc67 590 }
f6d6199c 591
7292dc67 592 return $make;
593}
f6d6199c 594
7292dc67 595
596=head3 distdir
597
598Defines the scratch directory target that will hold the distribution
599before tar-ing (or shar-ing).
f6d6199c 600
601=cut
602
7292dc67 603# For backwards compatibility.
604*dist_dir = *distdir;
f6d6199c 605
7292dc67 606sub distdir {
607 my($self) = shift;
479d2113 608
7292dc67 609 my $meta_target = $self->{NO_META} ? '' : 'distmeta';
610 my $sign_target = !$self->{SIGN} ? '' : 'distsignature';
479d2113 611
7292dc67 612 return sprintf <<'MAKE_FRAG', $meta_target, $sign_target;
613create_distdir :
614 $(RM_RF) $(DISTVNAME)
615 $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
616 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
479d2113 617
7292dc67 618distdir : create_distdir %s %s
619 $(NOECHO) $(NOOP)
620
621MAKE_FRAG
622
623}
624
625
626=head3 dist_test
627
628Defines a target that produces the distribution in the
629scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
630subdirectory.
479d2113 631
632=cut
633
7292dc67 634sub dist_test {
635 my($self) = shift;
636
637 my $mpl_args = join " ", map qq["$_"], @ARGV;
638
639 my $test = $self->cd('$(DISTVNAME)',
640 '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
641 '$(MAKE) $(PASTHRU)',
642 '$(MAKE) test $(PASTHRU)'
643 );
644
645 return sprintf <<'MAKE_FRAG', $test;
646disttest : distdir
647 %s
648
649MAKE_FRAG
650
479d2113 651
479d2113 652}
653
479d2113 654
7292dc67 655=head3 dynamic (o)
656
657Defines the dynamic target.
479d2113 658
659=cut
660
7292dc67 661sub dynamic {
662# --- Dynamic Loading Sections ---
479d2113 663
7292dc67 664 my($self) = shift;
665 '
666dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT)
667 $(NOECHO) $(NOOP)
668';
669}
479d2113 670
479d2113 671
7292dc67 672=head3 makemakerdflt_target
673
674 my $make_frag = $mm->makemakerdflt_target
675
676Returns a make fragment with the makemakerdeflt_target specified.
677This target is the first target in the Makefile, is the default target
678and simply points off to 'all' just in case any make variant gets
679confused or something gets snuck in before the real 'all' target.
479d2113 680
7292dc67 681=cut
682
683sub makemakerdflt_target {
684 return <<'MAKE_FRAG';
3a0105ce 685makemakerdflt : all
7292dc67 686 $(NOECHO) $(NOOP)
479d2113 687MAKE_FRAG
688
689}
690
691
7292dc67 692=head3 manifypods_target
479d2113 693
7292dc67 694 my $manifypods_target = $self->manifypods_target;
695
696Generates the manifypods target. This target generates man pages from
697all POD files in MAN1PODS and MAN3PODS.
479d2113 698
699=cut
700
7292dc67 701sub manifypods_target {
702 my($self) = shift;
479d2113 703
7292dc67 704 my $man1pods = '';
705 my $man3pods = '';
706 my $dependencies = '';
707
708 # populate manXpods & dependencies:
709 foreach my $name (keys %{$self->{MAN1PODS}}, keys %{$self->{MAN3PODS}}) {
710 $dependencies .= " \\\n\t$name";
711 }
712
7292dc67 713 my $manify = <<END;
714manifypods : pure_all $dependencies
715END
716
717 my @man_cmds;
718 foreach my $section (qw(1 3)) {
719 my $pods = $self->{"MAN${section}PODS"};
720 push @man_cmds, $self->split_command(<<CMD, %$pods);
721 \$(NOECHO) \$(POD2MAN) --section=$section --perm_rw=\$(PERM_RW)
722CMD
723 }
724
725 $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
726 $manify .= join '', map { "$_\n" } @man_cmds;
479d2113 727
7292dc67 728 return $manify;
479d2113 729}
730
731
7292dc67 732=head3 metafile_target
479d2113 733
734 my $target = $mm->metafile_target;
735
736Generate the metafile target.
737
7292dc67 738Writes the file META.yml YAML encoded meta-data about the module in
739the distdir. The format follows Module::Build's as closely as
562c8117 740possible.
479d2113 741
742=cut
743
744sub metafile_target {
745 my $self = shift;
746
431b0fc4 747 return <<'MAKE_FRAG' if $self->{NO_META};
3a0105ce 748metafile :
431b0fc4 749 $(NOECHO) $(NOOP)
750MAKE_FRAG
751
2e65e370 752 my @metadata = $self->metafile_data(
753 $self->{META_ADD} || {},
754 $self->{META_MERGE} || {},
755 );
756 my $meta = $self->metafile_file(@metadata);
757 my @write_meta = $self->echo($meta, 'META_new.yml');
758
759 return sprintf <<'MAKE_FRAG', join("\n\t", @write_meta);
760metafile : create_distdir
761 $(NOECHO) $(ECHO) Generating META.yml
762 %s
763 -$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
764MAKE_FRAG
765
766}
767
768
769=begin private
770
771=head3 _sort_pairs
772
773 my @pairs = _sort_pairs($sort_sub, \%hash);
774
775Sorts the pairs of a hash based on keys ordered according
776to C<$sort_sub>.
777
778=end private
779
780=cut
781
782sub _sort_pairs {
783 my $sort = shift;
784 my $pairs = shift;
785 return map { $_ => $pairs->{$_} }
786 sort $sort
787 keys %$pairs;
788}
789
790
791# Taken from Module::Build::Base
792sub _hash_merge {
793 my ($self, $h, $k, $v) = @_;
794 if (ref $h->{$k} eq 'ARRAY') {
795 push @{$h->{$k}}, ref $v ? @$v : $v;
796 } elsif (ref $h->{$k} eq 'HASH') {
797 $self->_hash_merge($h->{$k}, $_, $v->{$_}) foreach keys %$v;
798 } else {
799 $h->{$k} = $v;
479d2113 800 }
2e65e370 801}
a7d1454b 802
c8d65f10 803
2e65e370 804=head3 metafile_data
805
806 my @metadata_pairs = $mm->metafile_data(\%meta_add, \%meta_merge);
807
808Returns the data which MakeMaker turns into the META.yml file.
809
810Values of %meta_add will overwrite any existing metadata in those
811keys. %meta_merge will be merged with them.
812
813=cut
814
815sub metafile_data {
816 my $self = shift;
817 my($meta_add, $meta_merge) = @_;
818
819 # The order in which standard meta keys should be written.
820 my @meta_order = qw(
821 name
822 version
823 abstract
824 author
825 license
826 distribution_type
827
828 configure_requires
829 build_requires
830 requires
831
832 resources
833
834 provides
835 no_index
836
837 generated_by
838 meta-spec
839 );
840
5bdf71cc 841 my $configure_requires;
842 if( $self->{CONFIGURE_REQUIRES} and ref($self->{CONFIGURE_REQUIRES}) eq 'HASH' ) {
843 $configure_requires = $self->{CONFIGURE_REQUIRES};
844 } else {
845 $configure_requires = {
846 'ExtUtils::MakeMaker' => 0,
847 };
848 }
849
2e65e370 850 my %meta = (
2977d345 851 name => $self->{DISTNAME},
852 version => $self->{VERSION},
853 abstract => $self->{ABSTRACT},
2e65e370 854 license => $self->{LICENSE} || 'unknown',
2977d345 855 distribution_type => $self->{PM} ? 'module' : 'script',
2e65e370 856
5bdf71cc 857 configure_requires => $configure_requires,
2e65e370 858
1487aac6 859 build_requires => {
860 'ExtUtils::MakeMaker' => 0
861 },
862
2e65e370 863 no_index => {
864 directory => [qw(t inc)]
865 },
866
867 generated_by => "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
868 'meta-spec' => {
869 url => 'http://module-build.sourceforge.net/META-spec-v1.4.html',
870 version => 1.4
871 },
2977d345 872 );
bf87a6a1 873
874 # The author key is required and it takes a list.
2e65e370 875 $meta{author} = defined $self->{AUTHOR} ? [$self->{AUTHOR}] : [];
bf87a6a1 876
2e65e370 877 $meta{requires} = $self->{PREREQ_PM} if defined $self->{PREREQ_PM};
bf87a6a1 878 $meta{requires}{perl} = $self->{MIN_PERL_VERSION} if $self->{MIN_PERL_VERSION};
2977d345 879
2e65e370 880 while( my($key, $val) = each %$meta_add ) {
881 $meta{$key} = $val;
882 }
2977d345 883
2e65e370 884 while( my($key, $val) = each %$meta_merge ) {
885 $self->_hash_merge(\%meta, $key, $val);
886 }
2977d345 887
2e65e370 888 my @meta_pairs;
889
890 # Put the standard keys first in the proper order.
891 for my $key (@meta_order) {
892 next unless exists $meta{$key};
893
894 push @meta_pairs, $key, delete $meta{$key};
895 }
896
897 # Then tack everything else onto the end, alpha sorted.
898 for my $key (sort {lc $a cmp lc $b} keys %meta) {
899 push @meta_pairs, $key, $meta{$key};
900 }
901
902 return @meta_pairs
903}
2977d345 904
2e65e370 905=begin private
906
907=head3 _dump_hash
908
909 $yaml = _dump_hash(\%options, %hash);
910
911Implements a fake YAML dumper for a hash given
912as a list of pairs. No quoting/escaping is done. Keys
913are supposed to be strings. Values are undef, strings,
914hash refs or array refs of strings.
915
916Supported options are:
917
918 delta => STR - indentation delta
919 use_header => BOOL - whether to include a YAML header
920 indent => STR - a string of spaces
921 default: ''
922
923 max_key_length => INT - maximum key length used to align
924 keys and values of the same hash
925 default: 20
926 key_sort => CODE - a sort sub
927 It may be undef, which means no sorting by keys
928 default: sub { lc $a cmp lc $b }
929
930 customs => HASH - special options for certain keys
931 (whose values are hashes themselves)
932 may contain: max_key_length, key_sort, customs
933
934=end private
935
936=cut
937
938sub _dump_hash {
939 croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH';
940 my $options = shift;
941 my %hash = @_;
942
943 # Use a list to preserve order.
944 my @pairs;
945
946 my $k_sort
947 = exists $options->{key_sort} ? $options->{key_sort}
948 : sub { lc $a cmp lc $b };
949 if ($k_sort) {
950 croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE';
951 @pairs = _sort_pairs($k_sort, \%hash);
952 } else { # list of pairs, no sorting
953 @pairs = @_;
954 }
955
956 my $yaml = $options->{use_header} ? "--- #YAML:1.0\n" : '';
957 my $indent = $options->{indent} || '';
958 my $k_length = min(
959 ($options->{max_key_length} || 20),
960 max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash)
961 );
962 my $customs = $options->{customs} || {};
963
964 # printf format for key
965 my $k_format = "%-${k_length}s";
966
967 while( @pairs ) {
968 my($key, $val) = splice @pairs, 0, 2;
969 $val = '~' unless defined $val;
970 if(ref $val eq 'HASH') {
971 if ( keys %$val ) {
972 my %k_options = ( # options for recursive call
973 delta => $options->{delta},
974 use_header => 0,
975 indent => $indent . $options->{delta},
976 );
977 if (exists $customs->{$key}) {
978 my %k_custom = %{$customs->{$key}};
979 foreach my $k qw(key_sort max_key_length customs) {
980 $k_options{$k} = $k_custom{$k} if exists $k_custom{$k};
981 }
982 }
983 $yaml .= $indent . "$key:\n"
984 . _dump_hash(\%k_options, %$val);
985 }
986 else {
987 $yaml .= $indent . "$key: {}\n";
988 }
989 }
990 elsif (ref $val eq 'ARRAY') {
991 if( @$val ) {
992 $yaml .= $indent . "$key:\n";
993
994 for (@$val) {
995 croak "only nested arrays of non-refs are supported" if ref $_;
996 $yaml .= $indent . $options->{delta} . "- $_\n";
997 }
998 }
999 else {
1000 $yaml .= $indent . "$key: []\n";
1001 }
1002 }
1003 elsif( ref $val and !blessed($val) ) {
1004 croak "only nested hashes, arrays and objects are supported";
1005 }
1006 else { # if it's an object, just stringify it
1007 $yaml .= $indent . sprintf "$k_format %s\n", "$key:", $val;
1008 }
2977d345 1009 };
1010
2e65e370 1011 return $yaml;
479d2113 1012
2e65e370 1013}
2977d345 1014
2e65e370 1015sub blessed {
1016 return eval { $_[0]->isa("UNIVERSAL"); };
1017}
a7d1454b 1018
2e65e370 1019sub max {
1020 return (sort { $b <=> $a } @_)[0];
1021}
1022
1023sub min {
1024 return (sort { $a <=> $b } @_)[0];
1025}
1026
1027=head3 metafile_file
1028
1029 my $meta_yml = $mm->metafile_file(@metadata_pairs);
1030
1031Turns the @metadata_pairs into YAML.
1032
1033This method does not implement a complete YAML dumper, being limited
1034to dump a hash with values which are strings, undef's or nested hashes
1035and arrays of strings. No quoting/escaping is done.
1036
1037=cut
1038
1039sub metafile_file {
1040 my $self = shift;
1041
1042 my %dump_options = (
1043 use_header => 1,
1044 delta => ' ' x 4,
1045 key_sort => undef,
1046 );
1047 return _dump_hash(\%dump_options, @_);
479d2113 1048
1049}
1050
1051
7292dc67 1052=head3 distmeta_target
bb68fe9e 1053
7292dc67 1054 my $make_frag = $mm->distmeta_target;
bb68fe9e 1055
7292dc67 1056Generates the distmeta target to add META.yml to the MANIFEST in the
1057distdir.
bb68fe9e 1058
1059=cut
1060
7292dc67 1061sub distmeta_target {
bb68fe9e 1062 my $self = shift;
1063
7292dc67 1064 my $add_meta = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1065eval { maniadd({q{META.yml} => q{Module meta-data (added by MakeMaker)}}) }
1066 or print "Could not add META.yml to MANIFEST: $${'@'}\n"
1067CODE
bb68fe9e 1068
7292dc67 1069 my $add_meta_to_distdir = $self->cd('$(DISTVNAME)', $add_meta);
bb68fe9e 1070
7292dc67 1071 return sprintf <<'MAKE', $add_meta_to_distdir;
1072distmeta : create_distdir metafile
1073 $(NOECHO) %s
1074
1075MAKE
bb68fe9e 1076
7292dc67 1077}
bb68fe9e 1078
479d2113 1079
7292dc67 1080=head3 realclean (o)
479d2113 1081
7292dc67 1082Defines the realclean target.
479d2113 1083
1084=cut
1085
7292dc67 1086sub realclean {
1087 my($self, %attribs) = @_;
479d2113 1088
7292dc67 1089 my @dirs = qw($(DISTVNAME));
1090 my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));
431b0fc4 1091
76ca89ed 1092 # Special exception for the perl core where INST_* is not in blib.
1093 # This cleans up the files built from the ext/ directory (all XS).
1094 if( $self->{PERL_CORE} ) {
7292dc67 1095 push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
76ca89ed 1096 push @files, values %{$self->{PM}};
7292dc67 1097 }
479d2113 1098
7292dc67 1099 if( $self->has_link_code ){
1100 push @files, qw($(OBJECT));
1101 }
1102
1103 if( $attribs{FILES} ) {
1104 if( ref $attribs{FILES} ) {
1105 push @dirs, @{ $attribs{FILES} };
1106 }
1107 else {
1108 push @dirs, split /\s+/, $attribs{FILES};
1109 }
1110 }
1111
1112 # Occasionally files are repeated several times from different sources
1113 { my(%f) = map { ($_ => 1) } @files; @files = keys %f; }
1114 { my(%d) = map { ($_ => 1) } @dirs; @dirs = keys %d; }
1115
1116 my $rm_cmd = join "\n\t", map { "$_" }
1117 $self->split_command('- $(RM_F)', @files);
1118 my $rmf_cmd = join "\n\t", map { "$_" }
1119 $self->split_command('- $(RM_RF)', @dirs);
1120
1121 my $m = sprintf <<'MAKE', $rm_cmd, $rmf_cmd;
1122# Delete temporary files (via clean) and also delete dist files
1123realclean purge :: clean realclean_subdirs
1124 %s
1125 %s
1126MAKE
1127
1128 $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};
479d2113 1129
7292dc67 1130 return $m;
479d2113 1131}
1132
1133
7292dc67 1134=head3 realclean_subdirs_target
bb68fe9e 1135
7292dc67 1136 my $make_frag = $MM->realclean_subdirs_target;
bb68fe9e 1137
7292dc67 1138Returns the realclean_subdirs target. This is used by the realclean
1139target to call realclean on any subdirectories which contain Makefiles.
bb68fe9e 1140
1141=cut
1142
7292dc67 1143sub realclean_subdirs_target {
bb68fe9e 1144 my $self = shift;
1145
7292dc67 1146 return <<'NOOP_FRAG' unless @{$self->{DIR}};
1147realclean_subdirs :
bb68fe9e 1148 $(NOECHO) $(NOOP)
7292dc67 1149NOOP_FRAG
bb68fe9e 1150
7292dc67 1151 my $rclean = "realclean_subdirs :\n";
1152
1153 foreach my $dir (@{$self->{DIR}}) {
1154 foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
1155 my $subrclean .= $self->oneliner(sprintf <<'CODE', $dir, ($makefile) x 2);
1156chdir '%s'; system '$(MAKE) $(USEMAKEFILE) %s realclean' if -f '%s';
bb68fe9e 1157CODE
1158
7292dc67 1159 $rclean .= sprintf <<'RCLEAN', $subrclean;
1160 - %s
1161RCLEAN
bb68fe9e 1162
7292dc67 1163 }
1164 }
bb68fe9e 1165
7292dc67 1166 return $rclean;
1167}
bb68fe9e 1168
479d2113 1169
7292dc67 1170=head3 signature_target
479d2113 1171
7292dc67 1172 my $target = $mm->signature_target;
479d2113 1173
7292dc67 1174Generate the signature target.
479d2113 1175
7292dc67 1176Writes the file SIGNATURE with "cpansign -s".
479d2113 1177
7292dc67 1178=cut
479d2113 1179
7292dc67 1180sub signature_target {
1181 my $self = shift;
479d2113 1182
7292dc67 1183 return <<'MAKE_FRAG';
1184signature :
1185 cpansign -s
1186MAKE_FRAG
479d2113 1187
7292dc67 1188}
479d2113 1189
7292dc67 1190
1191=head3 distsignature_target
1192
1193 my $make_frag = $mm->distsignature_target;
1194
1195Generates the distsignature target to add SIGNATURE to the MANIFEST in the
1196distdir.
1197
1198=cut
1199
1200sub distsignature_target {
1201 my $self = shift;
1202
1203 my $add_sign = $self->oneliner(<<'CODE', ['-MExtUtils::Manifest=maniadd']);
1204eval { maniadd({q{SIGNATURE} => q{Public-key signature (added by MakeMaker)}}) }
1205 or print "Could not add SIGNATURE to MANIFEST: $${'@'}\n"
479d2113 1206CODE
1207
7292dc67 1208 my $sign_dist = $self->cd('$(DISTVNAME)' => 'cpansign -s');
479d2113 1209
7292dc67 1210 # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
1211 # exist
1212 my $touch_sig = $self->cd('$(DISTVNAME)' => '$(TOUCH) SIGNATURE');
1213 my $add_sign_to_dist = $self->cd('$(DISTVNAME)' => $add_sign );
479d2113 1214
7292dc67 1215 return sprintf <<'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
1216distsignature : create_distdir
1217 $(NOECHO) %s
1218 $(NOECHO) %s
1219 %s
479d2113 1220
7292dc67 1221MAKE
479d2113 1222
7292dc67 1223}
479d2113 1224
1225
7292dc67 1226=head3 special_targets
479d2113 1227
7292dc67 1228 my $make_frag = $mm->special_targets
479d2113 1229
7292dc67 1230Returns a make fragment containing any targets which have special
1231meaning to make. For example, .SUFFIXES and .PHONY.
479d2113 1232
7292dc67 1233=cut
479d2113 1234
7292dc67 1235sub special_targets {
1236 my $make_frag = <<'MAKE_FRAG';
1237.SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)
479d2113 1238
7292dc67 1239.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir
479d2113 1240
7292dc67 1241MAKE_FRAG
479d2113 1242
7292dc67 1243 $make_frag .= <<'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
1244.NO_CONFIG_REC: Makefile
479d2113 1245
7292dc67 1246MAKE_FRAG
479d2113 1247
7292dc67 1248 return $make_frag;
1249}
479d2113 1250
479d2113 1251
479d2113 1252
479d2113 1253
7292dc67 1254=head2 Init methods
1255
1256Methods which help initialize the MakeMaker object and macros.
1257
1258
2977d345 1259=head3 init_ABSTRACT
1260
1261 $mm->init_ABSTRACT
1262
1263=cut
1264
1265sub init_ABSTRACT {
1266 my $self = shift;
1267
1268 if( $self->{ABSTRACT_FROM} and $self->{ABSTRACT} ) {
1269 warn "Both ABSTRACT_FROM and ABSTRACT are set. ".
1270 "Ignoring ABSTRACT_FROM.\n";
1271 return;
1272 }
1273
1274 if ($self->{ABSTRACT_FROM}){
1275 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
1276 carp "WARNING: Setting ABSTRACT via file ".
1277 "'$self->{ABSTRACT_FROM}' failed\n";
1278 }
1279}
1280
7292dc67 1281=head3 init_INST
1282
1283 $mm->init_INST;
1284
1285Called by init_main. Sets up all INST_* variables except those related
1286to XS code. Those are handled in init_xs.
1287
1288=cut
1289
1290sub init_INST {
1291 my($self) = shift;
1292
1293 $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1294 $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
1295
1296 # INST_LIB typically pre-set if building an extension after
1297 # perl has been built and installed. Setting INST_LIB allows
1298 # you to build directly into, say $Config{privlibexp}.
1299 unless ($self->{INST_LIB}){
1300 if ($self->{PERL_CORE}) {
1301 if (defined $Cross::platform) {
1302 $self->{INST_LIB} = $self->{INST_ARCHLIB} =
1303 $self->catdir($self->{PERL_LIB},"..","xlib",
1304 $Cross::platform);
1305 }
1306 else {
1307 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1308 }
1309 } else {
1310 $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
1311 }
1312 }
1313
1314 my @parentdir = split(/::/, $self->{PARENT_NAME});
1315 $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1316 $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1317 $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1318 '$(FULLEXT)');
1319 $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1320 '$(FULLEXT)');
1321
1322 $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
1323
1324 $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1325 $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
1326
1327 return 1;
1328}
1329
1330
1331=head3 init_INSTALL
1332
1333 $mm->init_INSTALL;
1334
1335Called by init_main. Sets up all INSTALL_* variables (except
1336INSTALLDIRS) and *PREFIX.
1337
1338=cut
1339
1340sub init_INSTALL {
1341 my($self) = shift;
1342
2977d345 1343 if( $self->{ARGS}{INSTALL_BASE} and $self->{ARGS}{PREFIX} ) {
1344 die "Only one of PREFIX or INSTALL_BASE can be given. Not both.\n";
7292dc67 1345 }
1346
2977d345 1347 if( $self->{ARGS}{INSTALL_BASE} ) {
1348 $self->init_INSTALL_from_INSTALL_BASE;
7292dc67 1349 }
1350 else {
1351 $self->init_INSTALL_from_PREFIX;
1352 }
1353}
1354
1355
1356=head3 init_INSTALL_from_PREFIX
1357
1358 $mm->init_INSTALL_from_PREFIX;
1359
1360=cut
1361
1362sub init_INSTALL_from_PREFIX {
1363 my $self = shift;
1364
1365 $self->init_lib2arch;
1366
1367 # There are often no Config.pm defaults for these new man variables so
1368 # we fall back to the old behavior which is to use installman*dir
1369 foreach my $num (1, 3) {
1370 my $k = 'installsiteman'.$num.'dir';
1371
1372 $self->{uc $k} ||= uc "\$(installman${num}dir)"
1373 unless $Config{$k};
1374 }
1375
1376 foreach my $num (1, 3) {
1377 my $k = 'installvendorman'.$num.'dir';
1378
1379 unless( $Config{$k} ) {
1380 $self->{uc $k} ||= $Config{usevendorprefix}
1381 ? uc "\$(installman${num}dir)"
1382 : '';
1383 }
1384 }
1385
1386 $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
1387 unless $Config{installsitebin};
002b9267 1388 $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
1389 unless $Config{installsitescript};
7292dc67 1390
1391 unless( $Config{installvendorbin} ) {
1392 $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
1393 ? $Config{installbin}
1394 : '';
1395 }
002b9267 1396 unless( $Config{installvendorscript} ) {
1397 $self->{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
1398 ? $Config{installscript}
1399 : '';
1400 }
7292dc67 1401
1402
1403 my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
1404 $Config{prefixexp} || $Config{prefix} || '';
1405 my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
1406 my $sprefix = $Config{siteprefixexp} || '';
1407
1408 # 5.005_03 doesn't have a siteprefix.
1409 $sprefix = $iprefix unless $sprefix;
1410
1411
1412 $self->{PREFIX} ||= '';
1413
1414 if( $self->{PREFIX} ) {
1415 @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
1416 ('$(PREFIX)') x 3;
1417 }
1418 else {
1419 $self->{PERLPREFIX} ||= $iprefix;
1420 $self->{SITEPREFIX} ||= $sprefix;
1421 $self->{VENDORPREFIX} ||= $vprefix;
1422
1423 # Lots of MM extension authors like to use $(PREFIX) so we
1424 # put something sensible in there no matter what.
1425 $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
1426 }
1427
1428 my $arch = $Config{archname};
1429 my $version = $Config{version};
1430
1431 # default style
1432 my $libstyle = $Config{installstyle} || 'lib/perl5';
1433 my $manstyle = '';
1434
1435 if( $self->{LIBSTYLE} ) {
1436 $libstyle = $self->{LIBSTYLE};
1437 $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
1438 }
1439
1440 # Some systems, like VOS, set installman*dir to '' if they can't
1441 # read man pages.
1442 for my $num (1, 3) {
1443 $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
1444 unless $Config{'installman'.$num.'dir'};
1445 }
1446
1447 my %bin_layouts =
1448 (
1449 bin => { s => $iprefix,
1450 t => 'perl',
1451 d => 'bin' },
1452 vendorbin => { s => $vprefix,
1453 t => 'vendor',
1454 d => 'bin' },
1455 sitebin => { s => $sprefix,
1456 t => 'site',
1457 d => 'bin' },
1458 script => { s => $iprefix,
1459 t => 'perl',
1460 d => 'bin' },
002b9267 1461 vendorscript=> { s => $vprefix,
1462 t => 'vendor',
1463 d => 'bin' },
1464 sitescript => { s => $sprefix,
1465 t => 'site',
1466 d => 'bin' },
7292dc67 1467 );
1468
1469 my %man_layouts =
1470 (
1471 man1dir => { s => $iprefix,
1472 t => 'perl',
1473 d => 'man/man1',
1474 style => $manstyle, },
1475 siteman1dir => { s => $sprefix,
1476 t => 'site',
1477 d => 'man/man1',
1478 style => $manstyle, },
1479 vendorman1dir => { s => $vprefix,
1480 t => 'vendor',
1481 d => 'man/man1',
1482 style => $manstyle, },
1483
1484 man3dir => { s => $iprefix,
1485 t => 'perl',
1486 d => 'man/man3',
1487 style => $manstyle, },
1488 siteman3dir => { s => $sprefix,
1489 t => 'site',
1490 d => 'man/man3',
1491 style => $manstyle, },
1492 vendorman3dir => { s => $vprefix,
1493 t => 'vendor',
1494 d => 'man/man3',
1495 style => $manstyle, },
1496 );
1497
1498 my %lib_layouts =
1499 (
1500 privlib => { s => $iprefix,
1501 t => 'perl',
1502 d => '',
1503 style => $libstyle, },
1504 vendorlib => { s => $vprefix,
1505 t => 'vendor',
1506 d => '',
1507 style => $libstyle, },
1508 sitelib => { s => $sprefix,
1509 t => 'site',
1510 d => 'site_perl',
1511 style => $libstyle, },
1512
1513 archlib => { s => $iprefix,
1514 t => 'perl',
1515 d => "$version/$arch",
1516 style => $libstyle },
1517 vendorarch => { s => $vprefix,
1518 t => 'vendor',
1519 d => "$version/$arch",
1520 style => $libstyle },
1521 sitearch => { s => $sprefix,
1522 t => 'site',
1523 d => "site_perl/$version/$arch",
1524 style => $libstyle },
1525 );
1526
1527
1528 # Special case for LIB.
1529 if( $self->{LIB} ) {
1530 foreach my $var (keys %lib_layouts) {
1531 my $Installvar = uc "install$var";
1532
1533 if( $var =~ /arch/ ) {
1534 $self->{$Installvar} ||=
1535 $self->catdir($self->{LIB}, $Config{archname});
1536 }
1537 else {
1538 $self->{$Installvar} ||= $self->{LIB};
1539 }
1540 }
1541 }
1542
1543 my %type2prefix = ( perl => 'PERLPREFIX',
1544 site => 'SITEPREFIX',
1545 vendor => 'VENDORPREFIX'
1546 );
1547
1548 my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
1549 while( my($var, $layout) = each(%layouts) ) {
1550 my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
1551 my $r = '$('.$type2prefix{$t}.')';
1552
1553 print STDERR "Prefixing $var\n" if $Verbose >= 2;
1554
1555 my $installvar = "install$var";
1556 my $Installvar = uc $installvar;
1557 next if $self->{$Installvar};
1558
1559 $d = "$style/$d" if $style;
1560 $self->prefixify($installvar, $s, $r, $d);
1561
1562 print STDERR " $Installvar == $self->{$Installvar}\n"
1563 if $Verbose >= 2;
1564 }
1565
1566 # Generate these if they weren't figured out.
1567 $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
1568 $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
1569
1570 return 1;
1571}
1572
1573
2977d345 1574=head3 init_from_INSTALL_BASE
7292dc67 1575
2977d345 1576 $mm->init_from_INSTALL_BASE
7292dc67 1577
1578=cut
1579
1580my %map = (
1581 lib => [qw(lib perl5)],
1582 arch => [('lib', 'perl5', $Config{archname})],
1583 bin => [qw(bin)],
1584 man1dir => [qw(man man1)],
1585 man3dir => [qw(man man3)]
1586 );
1587$map{script} = $map{bin};
1588
2977d345 1589sub init_INSTALL_from_INSTALL_BASE {
7292dc67 1590 my $self = shift;
1591
1592 @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
2977d345 1593 '$(INSTALL_BASE)';
7292dc67 1594
1595 my %install;
1596 foreach my $thing (keys %map) {
1597 foreach my $dir (('', 'SITE', 'VENDOR')) {
1598 my $uc_thing = uc $thing;
1599 my $key = "INSTALL".$dir.$uc_thing;
1600
1601 $install{$key} ||=
2977d345 1602 $self->catdir('$(INSTALL_BASE)', @{$map{$thing}});
7292dc67 1603 }
1604 }
1605
1606 # Adjust for variable quirks.
1607 $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
1608 $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};
7292dc67 1609
1610 foreach my $key (keys %install) {
1611 $self->{$key} ||= $install{$key};
1612 }
1613
1614 return 1;
1615}
1616
1617
1618=head3 init_VERSION I<Abstract>
1619
1620 $mm->init_VERSION
1621
1622Initialize macros representing versions of MakeMaker and other tools
1623
1624MAKEMAKER: path to the MakeMaker module.
1625
1626MM_VERSION: ExtUtils::MakeMaker Version
1627
1628MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
1629 compat)
1630
1631VERSION: version of your module
1632
1633VERSION_MACRO: which macro represents the version (usually 'VERSION')
1634
1635VERSION_SYM: like version but safe for use as an RCS revision number
1636
1637DEFINE_VERSION: -D line to set the module version when compiling
1638
1639XS_VERSION: version in your .xs file. Defaults to $(VERSION)
1640
1641XS_VERSION_MACRO: which macro represents the XS version.
1642
1643XS_DEFINE_VERSION: -D line to set the xs version when compiling.
1644
1645Called by init_main.
1646
1647=cut
1648
1649sub init_VERSION {
1650 my($self) = shift;
1651
1652 $self->{MAKEMAKER} = $ExtUtils::MakeMaker::Filename;
1653 $self->{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
1654 $self->{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
1655 $self->{VERSION_FROM} ||= '';
1656
1657 if ($self->{VERSION_FROM}){
1658 $self->{VERSION} = $self->parse_version($self->{VERSION_FROM});
1659 if( $self->{VERSION} eq 'undef' ) {
2977d345 1660 carp("WARNING: Setting VERSION via file ".
1661 "'$self->{VERSION_FROM}' failed\n");
7292dc67 1662 }
1663 }
1664
1665 # strip blanks
1666 if (defined $self->{VERSION}) {
1667 $self->{VERSION} =~ s/^\s+//;
1668 $self->{VERSION} =~ s/\s+$//;
1669 }
1670 else {
1671 $self->{VERSION} = '';
1672 }
1673
1674
1675 $self->{VERSION_MACRO} = 'VERSION';
1676 ($self->{VERSION_SYM} = $self->{VERSION}) =~ s/\W/_/g;
1677 $self->{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';
1678
1679
1680 # Graham Barr and Paul Marquess had some ideas how to ensure
1681 # version compatibility between the *.pm file and the
1682 # corresponding *.xs file. The bottomline was, that we need an
1683 # XS_VERSION macro that defaults to VERSION:
1684 $self->{XS_VERSION} ||= $self->{VERSION};
1685
1686 $self->{XS_VERSION_MACRO} = 'XS_VERSION';
1687 $self->{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';
1688
1689}
1690
1691
5bdf71cc 1692=head3 init_others
479d2113 1693
1694 $MM->init_others();
1695
1696Initializes the macro definitions used by tools_other() and places them
1697in the $MM object.
1698
1699If there is no description, its the same as the parameter to
1700WriteMakefile() documented in ExtUtils::MakeMaker.
1701
1702Defines at least these macros.
1703
1704 Macro Description
1705
dedf98bc 1706 NOOP Do nothing
1707 NOECHO Tell make not to display the command itself
479d2113 1708
1709 MAKEFILE
1710 FIRST_MAKEFILE
1711 MAKEFILE_OLD
1712 MAKE_APERL_FILE File used by MAKE_APERL
1713
2977d345 1714 SHELL Program used to run shell commands
479d2113 1715
dedf98bc 1716 ECHO Print text adding a newline on the end
479d2113 1717 RM_F Remove a file
1718 RM_RF Remove a directory
1719 TOUCH Update a file's timestamp
1720 TEST_F Test for a file's existence
1721 CP Copy a file
1722 MV Move a file
5bdf71cc 1723 CHMOD Change permissions on a file
1724 FALSE Exit with non-zero
1725 TRUE Exit with zero
479d2113 1726
1727 UMASK_NULL Nullify umask
3c4b39be 1728 DEV_NULL Suppress all command output
479d2113 1729
5bdf71cc 1730=cut
1731
1732sub init_others {
1733 my $self = shift;
1734
1735 $self->{ECHO} ||= $self->oneliner('print qq{@ARGV}', ['-l']);
1736 $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}');
1737
1738 $self->{TOUCH} ||= $self->oneliner('touch', ["-MExtUtils::Command"]);
1739 $self->{CHMOD} ||= $self->oneliner('chmod', ["-MExtUtils::Command"]);
1740 $self->{RM_F} ||= $self->oneliner('rm_f', ["-MExtUtils::Command"]);
1741 $self->{RM_RF} ||= $self->oneliner('rm_rf', ["-MExtUtils::Command"]);
1742 $self->{TEST_F} ||= $self->oneliner('test_f', ["-MExtUtils::Command"]);
1743 $self->{FALSE} ||= $self->oneliner('exit 1');
1744 $self->{TRUE} ||= $self->oneliner('exit 0');
1745
1746 $self->{MKPATH} ||= $self->oneliner('mkpath', ["-MExtUtils::Command"]);
1747
1748 $self->{CP} ||= $self->oneliner('cp', ["-MExtUtils::Command"]);
1749 $self->{MV} ||= $self->oneliner('mv', ["-MExtUtils::Command"]);
1750
1751 $self->{MOD_INSTALL} ||=
1752 $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
1753install([ from_to => {@ARGV}, verbose => '$(VERBINST)', uninstall_shadows => '$(UNINST)', dir_mode => '$(PERM_DIR)' ]);
1754CODE
1755 $self->{DOC_INSTALL} ||= $self->oneliner('perllocal_install', ["-MExtUtils::Command::MM"]);
1756 $self->{UNINSTALL} ||= $self->oneliner('uninstall', ["-MExtUtils::Command::MM"]);
1757 $self->{WARN_IF_OLD_PACKLIST} ||=
1758 $self->oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]);
1759 $self->{FIXIN} ||= $self->oneliner('MY->fixin(shift)', ["-MExtUtils::MY"]);
1760 $self->{EQUALIZE_TIMESTAMP} ||= $self->oneliner('eqtime', ["-MExtUtils::Command"]);
1761
1762 $self->{UNINST} ||= 0;
1763 $self->{VERBINST} ||= 0;
1764
1765 $self->{FIRST_MAKEFILE} ||= $self->{MAKEFILE} || 'Makefile';
1766 $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
1767 $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old';
1768 $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl';
1769
1770 # Not everybody uses -f to indicate "use this Makefile instead"
1771 $self->{USEMAKEFILE} ||= '-f';
1772
1773 # Some makes require a wrapper around macros passed in on the command
1774 # line.
1775 $self->{MACROSTART} ||= '';
1776 $self->{MACROEND} ||= '';
1777
1778 $self->{SHELL} ||= $Config{sh};
1779
1780 # UMASK_NULL is not used by MakeMaker but some CPAN modules
1781 # make use of it.
1782 $self->{UMASK_NULL} ||= "umask 0";
1783
1784 # Not the greatest default, but its something.
1785 $self->{DEV_NULL} ||= "> /dev/null 2>&1";
1786
1787 $self->{NOOP} ||= '$(TRUE)';
1788 $self->{NOECHO} = '@' unless defined $self->{NOECHO};
1789
1790 $self->{LD_RUN_PATH} = "";
1791
c0956255 1792 $self->{LIBS} = $self->_fix_libs($self->{LIBS});
5bdf71cc 1793
c0956255 1794 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
5bdf71cc 1795 foreach my $libs ( @{$self->{LIBS}} ){
1796 $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1797 my(@libs) = $self->extliblist($libs);
1798 if ($libs[0] or $libs[1] or $libs[2]){
1799 # LD_RUN_PATH now computed by ExtUtils::Liblist
1800 ($self->{EXTRALIBS}, $self->{BSLOADLIBS},
1801 $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
1802 last;
1803 }
1804 }
1805
1806 if ( $self->{OBJECT} ) {
1807 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1808 } else {
1809 # init_dirscan should have found out, if we have C files
1810 $self->{OBJECT} = "";
1811 $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1812 }
1813 $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1814
1815 $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1816 $self->{PERLMAINCC} ||= '$(CC)';
1817 $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1818
1819 # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1820 # the 'dynamic' section of MM. We don't have this problem with
1821 # 'static', since we either must use it (%Config says we can't
1822 # use dynamic loading) or the caller asked for it explicitly.
1823 if (!$self->{LINKTYPE}) {
1824 $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1825 ? 'static'
1826 : ($Config{usedl} ? 'dynamic' : 'static');
1827 }
1828
1829 return 1;
1830}
1831
1832
c0956255 1833# Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1834# undefined. In any case we turn it into an anon array
1835sub _fix_libs {
1836 my($self, $libs) = @_;
1837
1838 return !defined $libs ? [''] :
1839 !ref $libs ? [$libs] :
1840 !defined $libs->[0] ? [''] :
1841 $libs ;
1842}
1843
1844
5bdf71cc 1845=head3 tools_other
1846
1847 my $make_frag = $MM->tools_other;
1848
1849Returns a make fragment containing definitions for the macros init_others()
1850initializes.
1851
1852=cut
1853
1854sub tools_other {
1855 my($self) = shift;
1856 my @m;
1857
1858 # We set PM_FILTER as late as possible so it can see all the earlier
1859 # on macro-order sensitive makes such as nmake.
1860 for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH
1861 UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP
1862 FALSE TRUE
1863 ECHO ECHO_N
1864 UNINST VERBINST
1865 MOD_INSTALL DOC_INSTALL UNINSTALL
1866 WARN_IF_OLD_PACKLIST
1867 MACROSTART MACROEND
1868 USEMAKEFILE
1869 PM_FILTER
1870 FIXIN
1871 } )
1872 {
1873 next unless defined $self->{$tool};
1874 push @m, "$tool = $self->{$tool}\n";
1875 }
1876
1877 return join "", @m;
1878}
1879
7292dc67 1880
1881=head3 init_DIRFILESEP I<Abstract>
479d2113 1882
1883 $MM->init_DIRFILESEP;
1884 my $dirfilesep = $MM->{DIRFILESEP};
1885
1886Initializes the DIRFILESEP macro which is the seperator between the
1887directory and filename in a filepath. ie. / on Unix, \ on Win32 and
1888nothing on VMS.
1889
1890For example:
1891
1892 # instead of $(INST_ARCHAUTODIR)/extralibs.ld
1893 $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld
1894
1895Something of a hack but it prevents a lot of code duplication between
1896MM_* variants.
1897
1898Do not use this as a seperator between directories. Some operating
1899systems use different seperators between subdirectories as between
1900directories and filenames (for example: VOLUME:[dir1.dir2]file on VMS).
1901
7292dc67 1902=head3 init_linker I<Abstract>
479d2113 1903
1904 $mm->init_linker;
1905
1906Initialize macros which have to do with linking.
1907
1908PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
1909extensions.
1910
1911PERL_ARCHIVE_AFTER: path to a library which should be put on the
1912linker command line I<after> the external libraries to be linked to
1913dynamic extensions. This may be needed if the linker is one-pass, and
1914Perl includes some overrides for C RTL functions, such as malloc().
1915
1916EXPORT_LIST: name of a file that is passed to linker to define symbols
1917to be exported.
1918
1919Some OSes do not need these in which case leave it blank.
1920
1921
7292dc67 1922=head3 init_platform
479d2113 1923
1924 $mm->init_platform
1925
1926Initialize any macros which are for platform specific use only.
1927
1928A typical one is the version number of your OS specific mocule.
1929(ie. MM_Unix_VERSION or MM_VMS_VERSION).
1930
7292dc67 1931=cut
479d2113 1932
7292dc67 1933sub init_platform {
1934 return '';
1935}
479d2113 1936
7292dc67 1937
2977d345 1938=head3 init_MAKE
1939
1940 $mm->init_MAKE
7292dc67 1941
2977d345 1942Initialize MAKE from either a MAKE environment variable or $Config{make}.
1943
1944=cut
1945
1946sub init_MAKE {
1947 my $self = shift;
1948
1949 $self->{MAKE} ||= $ENV{MAKE} || $Config{make};
1950}
7292dc67 1951
1952
1953=head2 Tools
1954
1955A grab bag of methods to generate specific macros and commands.
1956
1957
1958
1959=head3 manifypods
1960
1961Defines targets and routines to translate the pods into manpages and
1962put them into the INST_* directories.
479d2113 1963
1964=cut
1965
7292dc67 1966sub manifypods {
1967 my $self = shift;
1968
1969 my $POD2MAN_macro = $self->POD2MAN_macro();
1970 my $manifypods_target = $self->manifypods_target();
1971
1972 return <<END_OF_TARGET;
1973
1974$POD2MAN_macro
1975
1976$manifypods_target
1977
1978END_OF_TARGET
1979
479d2113 1980}
1981
7292dc67 1982
1983=head3 POD2MAN_macro
1984
1985 my $pod2man_macro = $self->POD2MAN_macro
1986
1987Returns a definition for the POD2MAN macro. This is a program
1988which emulates the pod2man utility. You can add more switches to the
1989command by simply appending them on the macro.
1990
1991Typical usage:
1992
1993 $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...
1994
1995=cut
1996
1997sub POD2MAN_macro {
1998 my $self = shift;
1999
2000# Need the trailing '--' so perl stops gobbling arguments and - happens
2001# to be an alternative end of line seperator on VMS so we quote it
2002 return <<'END_OF_DEF';
2003POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
2004POD2MAN = $(POD2MAN_EXE)
2005END_OF_DEF
479d2113 2006}
2007
dedf98bc 2008
7292dc67 2009=head3 test_via_harness
dedf98bc 2010
7292dc67 2011 my $command = $mm->test_via_harness($perl, $tests);
dedf98bc 2012
7292dc67 2013Returns a $command line which runs the given set of $tests with
2014Test::Harness and the given $perl.
dedf98bc 2015
7292dc67 2016Used on the t/*.t files.
dedf98bc 2017
7292dc67 2018=cut
dedf98bc 2019
7292dc67 2020sub test_via_harness {
2021 my($self, $perl, $tests) = @_;
2022
2023 return qq{\t$perl "-MExtUtils::Command::MM" }.
2024 qq{"-e" "test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
2025}
2026
2027=head3 test_via_script
2028
2029 my $command = $mm->test_via_script($perl, $script);
2030
2031Returns a $command line which just runs a single test without
2032Test::Harness. No checks are done on the results, they're just
2033printed.
dedf98bc 2034
7292dc67 2035Used for test.pl, since they don't always follow Test::Harness
2036formatting.
2037
2038=cut
2039
2040sub test_via_script {
2041 my($self, $perl, $script) = @_;
2042 return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
2043}
2044
2045
2046=head3 tool_autosplit
2047
2048Defines a simple perl call that runs autosplit. May be deprecated by
2049pm_to_blib soon.
2050
2051=cut
2052
2053sub tool_autosplit {
2054 my($self, %attribs) = @_;
2055
2056 my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
2057 : '';
2058
2059 my $asplit = $self->oneliner(sprintf <<'PERL_CODE', $maxlen);
2060use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
2061PERL_CODE
2062
2063 return sprintf <<'MAKE_FRAG', $asplit;
2064# Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
2065AUTOSPLITFILE = %s
2066
2067MAKE_FRAG
2068
2069}
2070
2071
5bdf71cc 2072=head3 arch_check
2073
2074 my $arch_ok = $mm->arch_check(
2075 $INC{"Config.pm"},
2076 File::Spec->catfile($Config{archlibexp}, "Config.pm")
2077 );
2078
2079A sanity check that what Perl thinks the architecture is and what
2080Config thinks the architecture is are the same. If they're not it
2081will return false and show a diagnostic message.
2082
2083When building Perl it will always return true, as nothing is installed
2084yet.
2085
2086The interface is a bit odd because this is the result of a
2087quick refactoring. Don't rely on it.
2088
2089=cut
2090
2091sub arch_check {
2092 my $self = shift;
2093 my($pconfig, $cconfig) = @_;
2094
2095 return 1 if $self->{PERL_SRC};
2096
2097 my($pvol, $pthinks) = $self->splitpath($pconfig);
2098 my($cvol, $cthinks) = $self->splitpath($cconfig);
2099
2100 $pthinks = $self->canonpath($pthinks);
2101 $cthinks = $self->canonpath($cthinks);
2102
2103 my $ret = 1;
2104 if ($pthinks ne $cthinks) {
2105 print "Have $pthinks\n";
2106 print "Want $cthinks\n";
2107
2108 $ret = 0;
2109
2110 my $arch = (grep length, $self->splitdir($pthinks))[-1];
2111
2112 print STDOUT <<END unless $self->{UNINSTALLED_PERL};
2113Your perl and your Config.pm seem to have different ideas about the
2114architecture they are running on.
2115Perl thinks: [$arch]
2116Config says: [$Config{archname}]
2117This may or may not cause problems. Please check your installation of perl
2118if you have problems building this extension.
2119END
2120 }
2121
2122 return $ret;
2123}
2124
7292dc67 2125
2126
2127=head2 File::Spec wrappers
2128
2129ExtUtils::MM_Any is a subclass of File::Spec. The methods noted here
2130override File::Spec.
2131
2132
2133
2134=head3 catfile
2135
2136File::Spec <= 0.83 has a bug where the file part of catfile is not
2137canonicalized. This override fixes that bug.
2138
2139=cut
2140
2141sub catfile {
2142 my $self = shift;
2143 return $self->canonpath($self->SUPER::catfile(@_));
2144}
2145
2146
2147
2148=head2 Misc
2149
2150Methods I can't really figure out where they should go yet.
2151
2152
2153=head3 find_tests
2154
2155 my $test = $mm->find_tests;
2156
2157Returns a string suitable for feeding to the shell to return all
2158tests in t/*.t.
2159
2160=cut
2161
2162sub find_tests {
2163 my($self) = shift;
2164 return -d 't' ? 't/*.t' : '';
2165}
2166
2167
2168=head3 extra_clean_files
2169
2170 my @files_to_clean = $MM->extra_clean_files;
2171
2172Returns a list of OS specific files to be removed in the clean target in
2173addition to the usual set.
2174
2175=cut
2176
2177# An empty method here tickled a perl 5.8.1 bug and would return its object.
2178sub extra_clean_files {
2179 return;
2180}
2181
2182
2183=head3 installvars
2184
2185 my @installvars = $mm->installvars;
2186
2187A list of all the INSTALL* variables without the INSTALL prefix. Useful
2188for iteration or building related variable sets.
2189
2190=cut
2191
2192sub installvars {
2193 return qw(PRIVLIB SITELIB VENDORLIB
2194 ARCHLIB SITEARCH VENDORARCH
2195 BIN SITEBIN VENDORBIN
002b9267 2196 SCRIPT SITESCRIPT VENDORSCRIPT
7292dc67 2197 MAN1DIR SITEMAN1DIR VENDORMAN1DIR
2198 MAN3DIR SITEMAN3DIR VENDORMAN3DIR
2199 );
2200}
2201
2202
2203=head3 libscan
2204
2205 my $wanted = $self->libscan($path);
2206
2207Takes a path to a file or dir and returns an empty string if we don't
2208want to include this file in the library. Otherwise it returns the
2209the $path unchanged.
2210
2211Mainly used to exclude version control administrative directories from
2212installation.
2213
2214=cut
2215
2216sub libscan {
2217 my($self,$path) = @_;
2218 my($dirs,$file) = ($self->splitpath($path))[1,2];
2219 return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
2220 $self->splitdir($dirs), $file;
2221
2222 return $path;
2223}
2224
2225
2226=head3 platform_constants
2227
2228 my $make_frag = $mm->platform_constants
2229
2230Returns a make fragment defining all the macros initialized in
2231init_platform() rather than put them in constants().
2232
2233=cut
2234
2235sub platform_constants {
2236 return '';
2237}
479d2113 2238
f6d6199c 2239
2240=head1 AUTHOR
2241
479d2113 2242Michael G Schwern <schwern@pobox.com> and the denizens of
2243makemaker@perl.org with code from ExtUtils::MM_Unix and
2244ExtUtils::MM_Win32.
f6d6199c 2245
2246
2247=cut
2248
22491;