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