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