1package ExtUtils::MM_Unix; 2 3require 5.006; 4 5use strict; 6 7use Carp; 8use ExtUtils::MakeMaker::Config; 9use File::Basename qw(basename dirname); 10use DirHandle; 11 12our %Config_Override; 13 14use ExtUtils::MakeMaker qw($Verbose neatvalue); 15 16# If we make $VERSION an our variable parse_version() breaks 17use vars qw($VERSION); 18$VERSION = '6.63_02'; 19$VERSION = eval $VERSION; 20 21require ExtUtils::MM_Any; 22our @ISA = qw(ExtUtils::MM_Any); 23 24my %Is; 25BEGIN { 26 $Is{OS2} = $^O eq 'os2'; 27 $Is{Win32} = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare'; 28 $Is{Dos} = $^O eq 'dos'; 29 $Is{VMS} = $^O eq 'VMS'; 30 $Is{OSF} = $^O eq 'dec_osf'; 31 $Is{IRIX} = $^O eq 'irix'; 32 $Is{NetBSD} = $^O eq 'netbsd'; 33 $Is{Interix} = $^O eq 'interix'; 34 $Is{SunOS4} = $^O eq 'sunos'; 35 $Is{Solaris} = $^O eq 'solaris'; 36 $Is{SunOS} = $Is{SunOS4} || $Is{Solaris}; 37 $Is{BSD} = ($^O =~ /^(?:free|net|open)bsd$/ or 38 grep( $^O eq $_, qw(bsdos interix dragonfly) ) 39 ); 40} 41 42BEGIN { 43 if( $Is{VMS} ) { 44 # For things like vmsify() 45 require VMS::Filespec; 46 VMS::Filespec->import; 47 } 48} 49 50 51=head1 NAME 52 53ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker 54 55=head1 SYNOPSIS 56 57C<require ExtUtils::MM_Unix;> 58 59=head1 DESCRIPTION 60 61The methods provided by this package are designed to be used in 62conjunction with ExtUtils::MakeMaker. When MakeMaker writes a 63Makefile, it creates one or more objects that inherit their methods 64from a package C<MM>. MM itself doesn't provide any methods, but it 65ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating 66specific packages take the responsibility for all the methods provided 67by MM_Unix. We are trying to reduce the number of the necessary 68overrides by defining rather primitive operations within 69ExtUtils::MM_Unix. 70 71If you are going to write a platform specific MM package, please try 72to limit the necessary overrides to primitive methods, and if it is not 73possible to do so, let's work out how to achieve that gain. 74 75If you are overriding any of these methods in your Makefile.PL (in the 76MY class), please report that to the makemaker mailing list. We are 77trying to minimize the necessary method overrides and switch to data 78driven Makefile.PLs wherever possible. In the long run less methods 79will be overridable via the MY class. 80 81=head1 METHODS 82 83The following description of methods is still under 84development. Please refer to the code for not suitably documented 85sections and complain loudly to the makemaker@perl.org mailing list. 86Better yet, provide a patch. 87 88Not all of the methods below are overridable in a 89Makefile.PL. Overridable methods are marked as (o). All methods are 90overridable by a platform specific MM_*.pm file. 91 92Cross-platform methods are being moved into MM_Any. If you can't find 93something that used to be in here, look in MM_Any. 94 95=cut 96 97# So we don't have to keep calling the methods over and over again, 98# we have these globals to cache the values. Faster and shrtr. 99my $Curdir = __PACKAGE__->curdir; 100my $Rootdir = __PACKAGE__->rootdir; 101my $Updir = __PACKAGE__->updir; 102 103 104=head2 Methods 105 106=over 4 107 108=item os_flavor 109 110Simply says that we're Unix. 111 112=cut 113 114sub os_flavor { 115 return('Unix'); 116} 117 118 119=item c_o (o) 120 121Defines the suffix rules to compile different flavors of C files to 122object files. 123 124=cut 125 126sub c_o { 127# --- Translation Sections --- 128 129 my($self) = shift; 130 return '' unless $self->needs_linking(); 131 my(@m); 132 133 my $command = '$(CCCMD)'; 134 my $flags = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)'; 135 136 if (my $cpp = $Config{cpprun}) { 137 my $cpp_cmd = $self->const_cccmd; 138 $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/; 139 push @m, qq{ 140.c.i: 141 $cpp_cmd $flags \$*.c > \$*.i 142}; 143 } 144 145 push @m, qq{ 146.c.s: 147 $command -S $flags \$*.c 148 149.c\$(OBJ_EXT): 150 $command $flags \$*.c 151 152.cpp\$(OBJ_EXT): 153 $command $flags \$*.cpp 154 155.cxx\$(OBJ_EXT): 156 $command $flags \$*.cxx 157 158.cc\$(OBJ_EXT): 159 $command $flags \$*.cc 160}; 161 162 push @m, qq{ 163.C\$(OBJ_EXT): 164 $command $flags \$*.C 165} if !$Is{OS2} and !$Is{Win32} and !$Is{Dos}; #Case-specific 166 167 return join "", @m; 168} 169 170=item cflags (o) 171 172Does very much the same as the cflags script in the perl 173distribution. It doesn't return the whole compiler command line, but 174initializes all of its parts. The const_cccmd method then actually 175returns the definition of the CCCMD macro which uses these parts. 176 177=cut 178 179#' 180 181sub cflags { 182 my($self,$libperl)=@_; 183 return $self->{CFLAGS} if $self->{CFLAGS}; 184 return '' unless $self->needs_linking(); 185 186 my($prog, $uc, $perltype, %cflags); 187 $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ; 188 $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/; 189 190 @cflags{qw(cc ccflags optimize shellflags)} 191 = @Config{qw(cc ccflags optimize shellflags)}; 192 my($optdebug) = ""; 193 194 $cflags{shellflags} ||= ''; 195 196 my(%map) = ( 197 D => '-DDEBUGGING', 198 E => '-DEMBED', 199 DE => '-DDEBUGGING -DEMBED', 200 M => '-DEMBED -DMULTIPLICITY', 201 DM => '-DDEBUGGING -DEMBED -DMULTIPLICITY', 202 ); 203 204 if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){ 205 $uc = uc($1); 206 } else { 207 $uc = ""; # avoid warning 208 } 209 $perltype = $map{$uc} ? $map{$uc} : ""; 210 211 if ($uc =~ /^D/) { 212 $optdebug = "-g"; 213 } 214 215 216 my($name); 217 ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ; 218 if ($prog = $Config{$name}) { 219 # Expand hints for this extension via the shell 220 print STDOUT "Processing $name hint:\n" if $Verbose; 221 my(@o)=`cc=\"$cflags{cc}\" 222 ccflags=\"$cflags{ccflags}\" 223 optimize=\"$cflags{optimize}\" 224 perltype=\"$cflags{perltype}\" 225 optdebug=\"$cflags{optdebug}\" 226 eval '$prog' 227 echo cc=\$cc 228 echo ccflags=\$ccflags 229 echo optimize=\$optimize 230 echo perltype=\$perltype 231 echo optdebug=\$optdebug 232 `; 233 foreach my $line (@o){ 234 chomp $line; 235 if ($line =~ /(.*?)=\s*(.*)\s*$/){ 236 $cflags{$1} = $2; 237 print STDOUT " $1 = $2\n" if $Verbose; 238 } else { 239 print STDOUT "Unrecognised result from hint: '$line'\n"; 240 } 241 } 242 } 243 244 if ($optdebug) { 245 $cflags{optimize} = $optdebug; 246 } 247 248 for (qw(ccflags optimize perltype)) { 249 $cflags{$_} ||= ''; 250 $cflags{$_} =~ s/^\s+//; 251 $cflags{$_} =~ s/\s+/ /g; 252 $cflags{$_} =~ s/\s+$//; 253 $self->{uc $_} ||= $cflags{$_}; 254 } 255 256 if ($self->{POLLUTE}) { 257 $self->{CCFLAGS} .= ' -DPERL_POLLUTE '; 258 } 259 260 my $pollute = ''; 261 if ($Config{usemymalloc} and not $Config{bincompat5005} 262 and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/ 263 and $self->{PERL_MALLOC_OK}) { 264 $pollute = '$(PERL_MALLOC_DEF)'; 265 } 266 267 $self->{CCFLAGS} = quote_paren($self->{CCFLAGS}); 268 $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE}); 269 270 return $self->{CFLAGS} = qq{ 271CCFLAGS = $self->{CCFLAGS} 272OPTIMIZE = $self->{OPTIMIZE} 273PERLTYPE = $self->{PERLTYPE} 274MPOLLUTE = $pollute 275}; 276 277} 278 279 280=item const_cccmd (o) 281 282Returns the full compiler call for C programs and stores the 283definition in CONST_CCCMD. 284 285=cut 286 287sub const_cccmd { 288 my($self,$libperl)=@_; 289 return $self->{CONST_CCCMD} if $self->{CONST_CCCMD}; 290 return '' unless $self->needs_linking(); 291 return $self->{CONST_CCCMD} = 292 q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\ 293 $(CCFLAGS) $(OPTIMIZE) \\ 294 $(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\ 295 $(XS_DEFINE_VERSION)}; 296} 297 298=item const_config (o) 299 300Defines a couple of constants in the Makefile that are imported from 301%Config. 302 303=cut 304 305sub const_config { 306# --- Constants Sections --- 307 308 my($self) = shift; 309 my @m = <<"END"; 310 311# These definitions are from config.sh (via $INC{'Config.pm'}). 312# They may have been overridden via Makefile.PL or on the command line. 313END 314 315 my(%once_only); 316 foreach my $key (@{$self->{CONFIG}}){ 317 # SITE*EXP macros are defined in &constants; avoid duplicates here 318 next if $once_only{$key}; 319 $self->{uc $key} = quote_paren($self->{uc $key}); 320 push @m, uc($key) , ' = ' , $self->{uc $key}, "\n"; 321 $once_only{$key} = 1; 322 } 323 join('', @m); 324} 325 326=item const_loadlibs (o) 327 328Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See 329L<ExtUtils::Liblist> for details. 330 331=cut 332 333sub const_loadlibs { 334 my($self) = shift; 335 return "" unless $self->needs_linking; 336 my @m; 337 push @m, qq{ 338# $self->{NAME} might depend on some other libraries: 339# See ExtUtils::Liblist for details 340# 341}; 342 for my $tmp (qw/ 343 EXTRALIBS LDLOADLIBS BSLOADLIBS 344 /) { 345 next unless defined $self->{$tmp}; 346 push @m, "$tmp = $self->{$tmp}\n"; 347 } 348 # don't set LD_RUN_PATH if empty 349 for my $tmp (qw/ 350 LD_RUN_PATH 351 /) { 352 next unless $self->{$tmp}; 353 push @m, "$tmp = $self->{$tmp}\n"; 354 } 355 return join "", @m; 356} 357 358=item constants (o) 359 360 my $make_frag = $mm->constants; 361 362Prints out macros for lots of constants. 363 364=cut 365 366sub constants { 367 my($self) = @_; 368 my @m = (); 369 370 $self->{DFSEP} = '$(DIRFILESEP)'; # alias for internal use 371 372 for my $macro (qw( 373 374 AR_STATIC_ARGS DIRFILESEP DFSEP 375 NAME NAME_SYM 376 VERSION VERSION_MACRO VERSION_SYM DEFINE_VERSION 377 XS_VERSION XS_VERSION_MACRO XS_DEFINE_VERSION 378 INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB 379 INST_MAN1DIR INST_MAN3DIR 380 MAN1EXT MAN3EXT 381 INSTALLDIRS INSTALL_BASE DESTDIR PREFIX 382 PERLPREFIX SITEPREFIX VENDORPREFIX 383 ), 384 (map { ("INSTALL".$_, 385 "DESTINSTALL".$_) 386 } $self->installvars), 387 qw( 388 PERL_LIB 389 PERL_ARCHLIB 390 LIBPERL_A MYEXTLIB 391 FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE 392 PERLMAINCC PERL_SRC PERL_INC 393 PERL FULLPERL ABSPERL 394 PERLRUN FULLPERLRUN ABSPERLRUN 395 PERLRUNINST FULLPERLRUNINST ABSPERLRUNINST 396 PERL_CORE 397 PERM_DIR PERM_RW PERM_RWX 398 399 ) ) 400 { 401 next unless defined $self->{$macro}; 402 403 # pathnames can have sharp signs in them; escape them so 404 # make doesn't think it is a comment-start character. 405 $self->{$macro} =~ s/#/\\#/g; 406 push @m, "$macro = $self->{$macro}\n"; 407 } 408 409 push @m, qq{ 410MAKEMAKER = $self->{MAKEMAKER} 411MM_VERSION = $self->{MM_VERSION} 412MM_REVISION = $self->{MM_REVISION} 413}; 414 415 push @m, q{ 416# FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle). 417# BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle) 418# PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar) 419# DLBASE = Basename part of dynamic library. May be just equal BASEEXT. 420}; 421 422 for my $macro (qw/ 423 MAKE 424 FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT 425 LDFROM LINKTYPE BOOTDEP 426 / ) 427 { 428 next unless defined $self->{$macro}; 429 push @m, "$macro = $self->{$macro}\n"; 430 } 431 432 push @m, " 433# Handy lists of source code files: 434XS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})." 435C_FILES = ".$self->wraplist(@{$self->{C}})." 436O_FILES = ".$self->wraplist(@{$self->{O_FILES}})." 437H_FILES = ".$self->wraplist(@{$self->{H}})." 438MAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})." 439MAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})." 440"; 441 442 443 push @m, q{ 444# Where is the Config information that we are using/depend on 445CONFIGDEP = $(PERL_ARCHLIB)$(DFSEP)Config.pm $(PERL_INC)$(DFSEP)config.h 446}; 447 448 449 push @m, qq{ 450# Where to build things 451INST_LIBDIR = $self->{INST_LIBDIR} 452INST_ARCHLIBDIR = $self->{INST_ARCHLIBDIR} 453 454INST_AUTODIR = $self->{INST_AUTODIR} 455INST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR} 456 457INST_STATIC = $self->{INST_STATIC} 458INST_DYNAMIC = $self->{INST_DYNAMIC} 459INST_BOOT = $self->{INST_BOOT} 460}; 461 462 463 push @m, qq{ 464# Extra linker info 465EXPORT_LIST = $self->{EXPORT_LIST} 466PERL_ARCHIVE = $self->{PERL_ARCHIVE} 467PERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER} 468}; 469 470 push @m, " 471 472TO_INST_PM = ".$self->wraplist(sort keys %{$self->{PM}})." 473 474PM_TO_BLIB = ".$self->wraplist(%{$self->{PM}})." 475"; 476 477 join('',@m); 478} 479 480 481=item depend (o) 482 483Same as macro for the depend attribute. 484 485=cut 486 487sub depend { 488 my($self,%attribs) = @_; 489 my(@m,$key,$val); 490 while (($key,$val) = each %attribs){ 491 last unless defined $key; 492 push @m, "$key : $val\n"; 493 } 494 join "", @m; 495} 496 497 498=item init_DEST 499 500 $mm->init_DEST 501 502Defines the DESTDIR and DEST* variables paralleling the INSTALL*. 503 504=cut 505 506sub init_DEST { 507 my $self = shift; 508 509 # Initialize DESTDIR 510 $self->{DESTDIR} ||= ''; 511 512 # Make DEST variables. 513 foreach my $var ($self->installvars) { 514 my $destvar = 'DESTINSTALL'.$var; 515 $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')'; 516 } 517} 518 519 520=item init_dist 521 522 $mm->init_dist; 523 524Defines a lot of macros for distribution support. 525 526 macro description default 527 528 TAR tar command to use tar 529 TARFLAGS flags to pass to TAR cvf 530 531 ZIP zip command to use zip 532 ZIPFLAGS flags to pass to ZIP -r 533 534 COMPRESS compression command to gzip --best 535 use for tarfiles 536 SUFFIX suffix to put on .gz 537 compressed files 538 539 SHAR shar command to use shar 540 541 PREOP extra commands to run before 542 making the archive 543 POSTOP extra commands to run after 544 making the archive 545 546 TO_UNIX a command to convert linefeeds 547 to Unix style in your archive 548 549 CI command to checkin your ci -u 550 sources to version control 551 RCS_LABEL command to label your sources rcs -Nv$(VERSION_SYM): -q 552 just after CI is run 553 554 DIST_CP $how argument to manicopy() best 555 when the distdir is created 556 557 DIST_DEFAULT default target to use to tardist 558 create a distribution 559 560 DISTVNAME name of the resulting archive $(DISTNAME)-$(VERSION) 561 (minus suffixes) 562 563=cut 564 565sub init_dist { 566 my $self = shift; 567 568 $self->{TAR} ||= 'tar'; 569 $self->{TARFLAGS} ||= 'cvf'; 570 $self->{ZIP} ||= 'zip'; 571 $self->{ZIPFLAGS} ||= '-r'; 572 $self->{COMPRESS} ||= 'gzip --best'; 573 $self->{SUFFIX} ||= '.gz'; 574 $self->{SHAR} ||= 'shar'; 575 $self->{PREOP} ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST 576 $self->{POSTOP} ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir 577 $self->{TO_UNIX} ||= '$(NOECHO) $(NOOP)'; 578 579 $self->{CI} ||= 'ci -u'; 580 $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q'; 581 $self->{DIST_CP} ||= 'best'; 582 $self->{DIST_DEFAULT} ||= 'tardist'; 583 584 ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME}; 585 $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION}; 586 587} 588 589=item dist (o) 590 591 my $dist_macros = $mm->dist(%overrides); 592 593Generates a make fragment defining all the macros initialized in 594init_dist. 595 596%overrides can be used to override any of the above. 597 598=cut 599 600sub dist { 601 my($self, %attribs) = @_; 602 603 my $make = ''; 604 foreach my $key (qw( 605 TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR 606 PREOP POSTOP TO_UNIX 607 CI RCS_LABEL DIST_CP DIST_DEFAULT 608 DISTNAME DISTVNAME 609 )) 610 { 611 my $value = $attribs{$key} || $self->{$key}; 612 $make .= "$key = $value\n"; 613 } 614 615 return $make; 616} 617 618=item dist_basics (o) 619 620Defines the targets distclean, distcheck, skipcheck, manifest, veryclean. 621 622=cut 623 624sub dist_basics { 625 my($self) = shift; 626 627 return <<'MAKE_FRAG'; 628distclean :: realclean distcheck 629 $(NOECHO) $(NOOP) 630 631distcheck : 632 $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck 633 634skipcheck : 635 $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck 636 637manifest : 638 $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest 639 640veryclean : realclean 641 $(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old 642 643MAKE_FRAG 644 645} 646 647=item dist_ci (o) 648 649Defines a check in target for RCS. 650 651=cut 652 653sub dist_ci { 654 my($self) = shift; 655 return q{ 656ci : 657 $(PERLRUN) "-MExtUtils::Manifest=maniread" \\ 658 -e "@all = keys %{ maniread() };" \\ 659 -e "print(qq{Executing $(CI) @all\n}); system(qq{$(CI) @all});" \\ 660 -e "print(qq{Executing $(RCS_LABEL) ...\n}); system(qq{$(RCS_LABEL) @all});" 661}; 662} 663 664=item dist_core (o) 665 666 my $dist_make_fragment = $MM->dist_core; 667 668Puts the targets necessary for 'make dist' together into one make 669fragment. 670 671=cut 672 673sub dist_core { 674 my($self) = shift; 675 676 my $make_frag = ''; 677 foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile 678 shdist)) 679 { 680 my $method = $target.'_target'; 681 $make_frag .= "\n"; 682 $make_frag .= $self->$method(); 683 } 684 685 return $make_frag; 686} 687 688 689=item B<dist_target> 690 691 my $make_frag = $MM->dist_target; 692 693Returns the 'dist' target to make an archive for distribution. This 694target simply checks to make sure the Makefile is up-to-date and 695depends on $(DIST_DEFAULT). 696 697=cut 698 699sub dist_target { 700 my($self) = shift; 701 702 my $date_check = $self->oneliner(<<'CODE', ['-l']); 703print 'Warning: Makefile possibly out of date with $(VERSION_FROM)' 704 if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)'; 705CODE 706 707 return sprintf <<'MAKE_FRAG', $date_check; 708dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE) 709 $(NOECHO) %s 710MAKE_FRAG 711} 712 713=item B<tardist_target> 714 715 my $make_frag = $MM->tardist_target; 716 717Returns the 'tardist' target which is simply so 'make tardist' works. 718The real work is done by the dynamically named tardistfile_target() 719method, tardist should have that as a dependency. 720 721=cut 722 723sub tardist_target { 724 my($self) = shift; 725 726 return <<'MAKE_FRAG'; 727tardist : $(DISTVNAME).tar$(SUFFIX) 728 $(NOECHO) $(NOOP) 729MAKE_FRAG 730} 731 732=item B<zipdist_target> 733 734 my $make_frag = $MM->zipdist_target; 735 736Returns the 'zipdist' target which is simply so 'make zipdist' works. 737The real work is done by the dynamically named zipdistfile_target() 738method, zipdist should have that as a dependency. 739 740=cut 741 742sub zipdist_target { 743 my($self) = shift; 744 745 return <<'MAKE_FRAG'; 746zipdist : $(DISTVNAME).zip 747 $(NOECHO) $(NOOP) 748MAKE_FRAG 749} 750 751=item B<tarfile_target> 752 753 my $make_frag = $MM->tarfile_target; 754 755The name of this target is the name of the tarball generated by 756tardist. This target does the actual work of turning the distdir into 757a tarball. 758 759=cut 760 761sub tarfile_target { 762 my($self) = shift; 763 764 return <<'MAKE_FRAG'; 765$(DISTVNAME).tar$(SUFFIX) : distdir 766 $(PREOP) 767 $(TO_UNIX) 768 $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME) 769 $(RM_RF) $(DISTVNAME) 770 $(COMPRESS) $(DISTVNAME).tar 771 $(POSTOP) 772MAKE_FRAG 773} 774 775=item zipfile_target 776 777 my $make_frag = $MM->zipfile_target; 778 779The name of this target is the name of the zip file generated by 780zipdist. This target does the actual work of turning the distdir into 781a zip file. 782 783=cut 784 785sub zipfile_target { 786 my($self) = shift; 787 788 return <<'MAKE_FRAG'; 789$(DISTVNAME).zip : distdir 790 $(PREOP) 791 $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME) 792 $(RM_RF) $(DISTVNAME) 793 $(POSTOP) 794MAKE_FRAG 795} 796 797=item uutardist_target 798 799 my $make_frag = $MM->uutardist_target; 800 801Converts the tarfile into a uuencoded file 802 803=cut 804 805sub uutardist_target { 806 my($self) = shift; 807 808 return <<'MAKE_FRAG'; 809uutardist : $(DISTVNAME).tar$(SUFFIX) 810 uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu 811MAKE_FRAG 812} 813 814 815=item shdist_target 816 817 my $make_frag = $MM->shdist_target; 818 819Converts the distdir into a shell archive. 820 821=cut 822 823sub shdist_target { 824 my($self) = shift; 825 826 return <<'MAKE_FRAG'; 827shdist : distdir 828 $(PREOP) 829 $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar 830 $(RM_RF) $(DISTVNAME) 831 $(POSTOP) 832MAKE_FRAG 833} 834 835 836=item dlsyms (o) 837 838Used by some OS' to define DL_FUNCS and DL_VARS and write the *.exp files. 839 840Normally just returns an empty string. 841 842=cut 843 844sub dlsyms { 845 return ''; 846} 847 848 849=item dynamic_bs (o) 850 851Defines targets for bootstrap files. 852 853=cut 854 855sub dynamic_bs { 856 my($self, %attribs) = @_; 857 return ' 858BOOTSTRAP = 859' unless $self->has_link_code(); 860 861 my $target = $Is{VMS} ? '$(MMS$TARGET)' : '$@'; 862 863 return sprintf <<'MAKE_FRAG', ($target) x 5; 864BOOTSTRAP = $(BASEEXT).bs 865 866# As Mkbootstrap might not write a file (if none is required) 867# we use touch to prevent make continually trying to remake it. 868# The DynaLoader only reads a non-empty file. 869$(BOOTSTRAP) : $(FIRST_MAKEFILE) $(BOOTDEP) $(INST_ARCHAUTODIR)$(DFSEP).exists 870 $(NOECHO) $(ECHO) "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))" 871 $(NOECHO) $(PERLRUN) \ 872 "-MExtUtils::Mkbootstrap" \ 873 -e "Mkbootstrap('$(BASEEXT)','$(BSLOADLIBS)');" 874 $(NOECHO) $(TOUCH) %s 875 $(CHMOD) $(PERM_RW) %s 876 877$(INST_BOOT) : $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists 878 $(NOECHO) $(RM_RF) %s 879 - $(CP) $(BOOTSTRAP) %s 880 $(CHMOD) $(PERM_RW) %s 881MAKE_FRAG 882} 883 884=item dynamic_lib (o) 885 886Defines how to produce the *.so (or equivalent) files. 887 888=cut 889 890sub dynamic_lib { 891 my($self, %attribs) = @_; 892 return '' unless $self->needs_linking(); #might be because of a subdir 893 894 return '' unless $self->has_link_code; 895 896 my($otherldflags) = $attribs{OTHERLDFLAGS} || ""; 897 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || ""; 898 my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":"; 899 my($ldfrom) = '$(LDFROM)'; 900 $armaybe = 'ar' if ($Is{OSF} and $armaybe eq ':'); 901 my(@m); 902 my $ld_opt = $Is{OS2} ? '$(OPTIMIZE) ' : ''; # Useful on other systems too? 903 my $ld_fix = $Is{OS2} ? '|| ( $(RM_F) $@ && sh -c false )' : ''; 904 push(@m,' 905# This section creates the dynamically loadable $(INST_DYNAMIC) 906# from $(OBJECT) and possibly $(MYEXTLIB). 907ARMAYBE = '.$armaybe.' 908OTHERLDFLAGS = '.$ld_opt.$otherldflags.' 909INST_DYNAMIC_DEP = '.$inst_dynamic_dep.' 910INST_DYNAMIC_FIX = '.$ld_fix.' 911 912$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) 913'); 914 if ($armaybe ne ':'){ 915 $ldfrom = 'tmp$(LIB_EXT)'; 916 push(@m,' $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n"); 917 push(@m,' $(RANLIB) '."$ldfrom\n"); 918 } 919 $ldfrom = "-all $ldfrom -none" if $Is{OSF}; 920 921 # The IRIX linker doesn't use LD_RUN_PATH 922 my $ldrun = $Is{IRIX} && $self->{LD_RUN_PATH} ? 923 qq{-rpath "$self->{LD_RUN_PATH}"} : ''; 924 925 # For example in AIX the shared objects/libraries from previous builds 926 # linger quite a while in the shared dynalinker cache even when nobody 927 # is using them. This is painful if one for instance tries to restart 928 # a failed build because the link command will fail unnecessarily 'cos 929 # the shared object/library is 'busy'. 930 push(@m,' $(RM_F) $@ 931'); 932 933 my $libs = '$(LDLOADLIBS)'; 934 935 if (($Is{NetBSD} || $Is{Interix}) && $Config{'useshrplib'} eq 'true') { 936 # Use nothing on static perl platforms, and to the flags needed 937 # to link against the shared libperl library on shared perl 938 # platforms. We peek at lddlflags to see if we need -Wl,-R 939 # or -R to add paths to the run-time library search path. 940 if ($Config{'lddlflags'} =~ /-Wl,-R/) { 941 $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -Wl,-R$(PERL_ARCHLIB)/CORE -lperl'; 942 } elsif ($Config{'lddlflags'} =~ /-R/) { 943 $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -R$(PERL_ARCHLIB)/CORE -lperl'; 944 } 945 } 946 947 my $ld_run_path_shell = ""; 948 if ($self->{LD_RUN_PATH} ne "") { 949 $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" '; 950 } 951 952 push @m, sprintf <<'MAKE', $ld_run_path_shell, $ldrun, $ldfrom, $libs; 953 %s$(LD) %s $(LDDLFLAGS) %s $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) \ 954 $(PERL_ARCHIVE) %s $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST) \ 955 $(INST_DYNAMIC_FIX) 956MAKE 957 958 push @m, <<'MAKE'; 959 $(CHMOD) $(PERM_RWX) $@ 960MAKE 961 962 return join('',@m); 963} 964 965=item exescan 966 967Deprecated method. Use libscan instead. 968 969=cut 970 971sub exescan { 972 my($self,$path) = @_; 973 $path; 974} 975 976=item extliblist 977 978Called by init_others, and calls ext ExtUtils::Liblist. See 979L<ExtUtils::Liblist> for details. 980 981=cut 982 983sub extliblist { 984 my($self,$libs) = @_; 985 require ExtUtils::Liblist; 986 $self->ext($libs, $Verbose); 987} 988 989=item find_perl 990 991Finds the executables PERL and FULLPERL 992 993=cut 994 995sub find_perl { 996 my($self, $ver, $names, $dirs, $trace) = @_; 997 998 if ($trace >= 2){ 999 print "Looking for perl $ver by these names: 1000@$names 1001in these dirs: 1002@$dirs 1003"; 1004 } 1005 1006 my $stderr_duped = 0; 1007 local *STDERR_COPY; 1008 1009 unless ($Is{BSD}) { 1010 # >& and lexical filehandles together give 5.6.2 indigestion 1011 if( open(STDERR_COPY, '>&STDERR') ) { ## no critic 1012 $stderr_duped = 1; 1013 } 1014 else { 1015 warn <<WARNING; 1016find_perl() can't dup STDERR: $! 1017You might see some garbage while we search for Perl 1018WARNING 1019 } 1020 } 1021 1022 foreach my $name (@$names){ 1023 foreach my $dir (@$dirs){ 1024 next unless defined $dir; # $self->{PERL_SRC} may be undefined 1025 my ($abs, $val); 1026 if ($self->file_name_is_absolute($name)) { # /foo/bar 1027 $abs = $name; 1028 } elsif ($self->canonpath($name) eq 1029 $self->canonpath(basename($name))) { # foo 1030 $abs = $self->catfile($dir, $name); 1031 } else { # foo/bar 1032 $abs = $self->catfile($Curdir, $name); 1033 } 1034 print "Checking $abs\n" if ($trace >= 2); 1035 next unless $self->maybe_command($abs); 1036 print "Executing $abs\n" if ($trace >= 2); 1037 1038 my $version_check = qq{$abs -le "require $ver; print qq{VER_OK}"}; 1039 $version_check = "$Config{run} $version_check" 1040 if defined $Config{run} and length $Config{run}; 1041 1042 # To avoid using the unportable 2>&1 to suppress STDERR, 1043 # we close it before running the command. 1044 # However, thanks to a thread library bug in many BSDs 1045 # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 ) 1046 # we cannot use the fancier more portable way in here 1047 # but instead need to use the traditional 2>&1 construct. 1048 if ($Is{BSD}) { 1049 $val = `$version_check 2>&1`; 1050 } else { 1051 close STDERR if $stderr_duped; 1052 $val = `$version_check`; 1053 1054 # 5.6.2's 3-arg open doesn't work with >& 1055 open STDERR, ">&STDERR_COPY" ## no critic 1056 if $stderr_duped; 1057 } 1058 1059 if ($val =~ /^VER_OK/m) { 1060 print "Using PERL=$abs\n" if $trace; 1061 return $abs; 1062 } elsif ($trace >= 2) { 1063 print "Result: '$val' ".($? >> 8)."\n"; 1064 } 1065 } 1066 } 1067 print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n"; 1068 0; # false and not empty 1069} 1070 1071 1072=item fixin 1073 1074 $mm->fixin(@files); 1075 1076Inserts the sharpbang or equivalent magic number to a set of @files. 1077 1078=cut 1079 1080sub fixin { # stolen from the pink Camel book, more or less 1081 my ( $self, @files ) = @_; 1082 1083 for my $file (@files) { 1084 my $file_new = "$file.new"; 1085 my $file_bak = "$file.bak"; 1086 1087 open( my $fixin, '<', $file ) or croak "Can't process '$file': $!"; 1088 local $/ = "\n"; 1089 chomp( my $line = <$fixin> ); 1090 next unless $line =~ s/^\s*\#!\s*//; # Not a shbang file. 1091 1092 my $shb = $self->_fixin_replace_shebang( $file, $line ); 1093 next unless defined $shb; 1094 1095 open( my $fixout, ">", "$file_new" ) or do { 1096 warn "Can't create new $file: $!\n"; 1097 next; 1098 }; 1099 1100 # Print out the new #! line (or equivalent). 1101 local $\; 1102 local $/; 1103 print $fixout $shb, <$fixin>; 1104 close $fixin; 1105 close $fixout; 1106 1107 chmod 0666, $file_bak; 1108 unlink $file_bak; 1109 unless ( _rename( $file, $file_bak ) ) { 1110 warn "Can't rename $file to $file_bak: $!"; 1111 next; 1112 } 1113 unless ( _rename( $file_new, $file ) ) { 1114 warn "Can't rename $file_new to $file: $!"; 1115 unless ( _rename( $file_bak, $file ) ) { 1116 warn "Can't rename $file_bak back to $file either: $!"; 1117 warn "Leaving $file renamed as $file_bak\n"; 1118 } 1119 next; 1120 } 1121 unlink $file_bak; 1122 } 1123 continue { 1124 system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':'; 1125 } 1126} 1127 1128 1129sub _rename { 1130 my($old, $new) = @_; 1131 1132 foreach my $file ($old, $new) { 1133 if( $Is{VMS} and basename($file) !~ /\./ ) { 1134 # rename() in 5.8.0 on VMS will not rename a file if it 1135 # does not contain a dot yet it returns success. 1136 $file = "$file."; 1137 } 1138 } 1139 1140 return rename($old, $new); 1141} 1142 1143sub _fixin_replace_shebang { 1144 my ( $self, $file, $line ) = @_; 1145 1146 # Now figure out the interpreter name. 1147 my ( $cmd, $arg ) = split ' ', $line, 2; 1148 $cmd =~ s!^.*/!!; 1149 1150 # Now look (in reverse) for interpreter in absolute PATH (unless perl). 1151 my $interpreter; 1152 if ( $cmd =~ m{^perl(?:\z|[^a-z])} ) { 1153 if ( $Config{startperl} =~ m,^\#!.*/perl, ) { 1154 $interpreter = $Config{startperl}; 1155 $interpreter =~ s,^\#!,,; 1156 } 1157 else { 1158 $interpreter = $Config{perlpath}; 1159 } 1160 } 1161 else { 1162 my (@absdirs) 1163 = reverse grep { $self->file_name_is_absolute($_) } $self->path; 1164 $interpreter = ''; 1165 1166 foreach my $dir (@absdirs) { 1167 if ( $self->maybe_command($cmd) ) { 1168 warn "Ignoring $interpreter in $file\n" 1169 if $Verbose && $interpreter; 1170 $interpreter = $self->catfile( $dir, $cmd ); 1171 } 1172 } 1173 } 1174 1175 # Figure out how to invoke interpreter on this machine. 1176 1177 my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/; 1178 my ($shb) = ""; 1179 if ($interpreter) { 1180 print STDOUT "Changing sharpbang in $file to $interpreter" 1181 if $Verbose; 1182 # this is probably value-free on DOSISH platforms 1183 if ($does_shbang) { 1184 $shb .= "$Config{'sharpbang'}$interpreter"; 1185 $shb .= ' ' . $arg if defined $arg; 1186 $shb .= "\n"; 1187 } 1188 $shb .= qq{ 1189eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}' 1190 if 0; # not running under some shell 1191} unless $Is{Win32}; # this won't work on win32, so don't 1192 } 1193 else { 1194 warn "Can't find $cmd in PATH, $file unchanged" 1195 if $Verbose; 1196 return undef; 1197 } 1198 return $shb 1199} 1200 1201=item force (o) 1202 1203Writes an empty FORCE: target. 1204 1205=cut 1206 1207sub force { 1208 my($self) = shift; 1209 '# Phony target to force checking subdirectories. 1210FORCE : 1211 $(NOECHO) $(NOOP) 1212'; 1213} 1214 1215=item guess_name 1216 1217Guess the name of this package by examining the working directory's 1218name. MakeMaker calls this only if the developer has not supplied a 1219NAME attribute. 1220 1221=cut 1222 1223# '; 1224 1225sub guess_name { 1226 my($self) = @_; 1227 use Cwd 'cwd'; 1228 my $name = basename(cwd()); 1229 $name =~ s|[\-_][\d\.\-]+\z||; # this is new with MM 5.00, we 1230 # strip minus or underline 1231 # followed by a float or some such 1232 print "Warning: Guessing NAME [$name] from current directory name.\n"; 1233 $name; 1234} 1235 1236=item has_link_code 1237 1238Returns true if C, XS, MYEXTLIB or similar objects exist within this 1239object that need a compiler. Does not descend into subdirectories as 1240needs_linking() does. 1241 1242=cut 1243 1244sub has_link_code { 1245 my($self) = shift; 1246 return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE}; 1247 if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){ 1248 $self->{HAS_LINK_CODE} = 1; 1249 return 1; 1250 } 1251 return $self->{HAS_LINK_CODE} = 0; 1252} 1253 1254 1255=item init_dirscan 1256 1257Scans the directory structure and initializes DIR, XS, XS_FILES, 1258C, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES. 1259 1260Called by init_main. 1261 1262=cut 1263 1264sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc) 1265 my($self) = @_; 1266 my(%dir, %xs, %c, %h, %pl_files, %pm); 1267 1268 my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t); 1269 1270 # ignore the distdir 1271 $Is{VMS} ? $ignore{"$self->{DISTVNAME}.dir"} = 1 1272 : $ignore{$self->{DISTVNAME}} = 1; 1273 1274 @ignore{map lc, keys %ignore} = values %ignore if $Is{VMS}; 1275 1276 foreach my $name ($self->lsdir($Curdir)){ 1277 next if $name =~ /\#/; 1278 next if $name eq $Curdir or $name eq $Updir or $ignore{$name}; 1279 next unless $self->libscan($name); 1280 if (-d $name){ 1281 next if -l $name; # We do not support symlinks at all 1282 next if $self->{NORECURS}; 1283 $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL")); 1284 } elsif ($name =~ /\.xs\z/){ 1285 my($c); ($c = $name) =~ s/\.xs\z/.c/; 1286 $xs{$name} = $c; 1287 $c{$c} = 1; 1288 } elsif ($name =~ /\.c(pp|xx|c)?\z/i){ # .c .C .cpp .cxx .cc 1289 $c{$name} = 1 1290 unless $name =~ m/perlmain\.c/; # See MAP_TARGET 1291 } elsif ($name =~ /\.h\z/i){ 1292 $h{$name} = 1; 1293 } elsif ($name =~ /\.PL\z/) { 1294 ($pl_files{$name} = $name) =~ s/\.PL\z// ; 1295 } elsif (($Is{VMS} || $Is{Dos}) && $name =~ /[._]pl$/i) { 1296 # case-insensitive filesystem, one dot per name, so foo.h.PL 1297 # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos 1298 local($/); open(my $pl, '<', $name); my $txt = <$pl>; close $pl; 1299 if ($txt =~ /Extracting \S+ \(with variable substitutions/) { 1300 ($pl_files{$name} = $name) =~ s/[._]pl\z//i ; 1301 } 1302 else { 1303 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name); 1304 } 1305 } elsif ($name =~ /\.(p[ml]|pod)\z/){ 1306 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name); 1307 } 1308 } 1309 1310 $self->{PL_FILES} ||= \%pl_files; 1311 $self->{DIR} ||= [sort keys %dir]; 1312 $self->{XS} ||= \%xs; 1313 $self->{C} ||= [sort keys %c]; 1314 $self->{H} ||= [sort keys %h]; 1315 $self->{PM} ||= \%pm; 1316 1317 my @o_files = @{$self->{C}}; 1318 $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files]; 1319} 1320 1321 1322=item init_MANPODS 1323 1324Determines if man pages should be generated and initializes MAN1PODS 1325and MAN3PODS as appropriate. 1326 1327=cut 1328 1329sub init_MANPODS { 1330 my $self = shift; 1331 1332 # Set up names of manual pages to generate from pods 1333 foreach my $man (qw(MAN1 MAN3)) { 1334 if ( $self->{"${man}PODS"} 1335 or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/ 1336 ) { 1337 $self->{"${man}PODS"} ||= {}; 1338 } 1339 else { 1340 my $init_method = "init_${man}PODS"; 1341 $self->$init_method(); 1342 } 1343 } 1344} 1345 1346 1347sub _has_pod { 1348 my($self, $file) = @_; 1349 1350 my($ispod)=0; 1351 if (open( my $fh, '<', $file )) { 1352 while (<$fh>) { 1353 if (/^=(?:head\d+|item|pod)\b/) { 1354 $ispod=1; 1355 last; 1356 } 1357 } 1358 close $fh; 1359 } else { 1360 # If it doesn't exist yet, we assume, it has pods in it 1361 $ispod = 1; 1362 } 1363 1364 return $ispod; 1365} 1366 1367 1368=item init_MAN1PODS 1369 1370Initializes MAN1PODS from the list of EXE_FILES. 1371 1372=cut 1373 1374sub init_MAN1PODS { 1375 my($self) = @_; 1376 1377 if ( exists $self->{EXE_FILES} ) { 1378 foreach my $name (@{$self->{EXE_FILES}}) { 1379 next unless $self->_has_pod($name); 1380 1381 $self->{MAN1PODS}->{$name} = 1382 $self->catfile("\$(INST_MAN1DIR)", 1383 basename($name).".\$(MAN1EXT)"); 1384 } 1385 } 1386} 1387 1388 1389=item init_MAN3PODS 1390 1391Initializes MAN3PODS from the list of PM files. 1392 1393=cut 1394 1395sub init_MAN3PODS { 1396 my $self = shift; 1397 1398 my %manifypods = (); # we collect the keys first, i.e. the files 1399 # we have to convert to pod 1400 1401 foreach my $name (keys %{$self->{PM}}) { 1402 if ($name =~ /\.pod\z/ ) { 1403 $manifypods{$name} = $self->{PM}{$name}; 1404 } elsif ($name =~ /\.p[ml]\z/ ) { 1405 if( $self->_has_pod($name) ) { 1406 $manifypods{$name} = $self->{PM}{$name}; 1407 } 1408 } 1409 } 1410 1411 my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}}; 1412 1413 # Remove "Configure.pm" and similar, if it's not the only pod listed 1414 # To force inclusion, just name it "Configure.pod", or override 1415 # MAN3PODS 1416 foreach my $name (keys %manifypods) { 1417 if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) { 1418 delete $manifypods{$name}; 1419 next; 1420 } 1421 my($manpagename) = $name; 1422 $manpagename =~ s/\.p(od|m|l)\z//; 1423 # everything below lib is ok 1424 unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) { 1425 $manpagename = $self->catfile( 1426 split(/::/,$self->{PARENT_NAME}),$manpagename 1427 ); 1428 } 1429 $manpagename = $self->replace_manpage_separator($manpagename); 1430 $self->{MAN3PODS}->{$name} = 1431 $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)"); 1432 } 1433} 1434 1435 1436=item init_PM 1437 1438Initializes PMLIBDIRS and PM from PMLIBDIRS. 1439 1440=cut 1441 1442sub init_PM { 1443 my $self = shift; 1444 1445 # Some larger extensions often wish to install a number of *.pm/pl 1446 # files into the library in various locations. 1447 1448 # The attribute PMLIBDIRS holds an array reference which lists 1449 # subdirectories which we should search for library files to 1450 # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ]. We 1451 # recursively search through the named directories (skipping any 1452 # which don't exist or contain Makefile.PL files). 1453 1454 # For each *.pm or *.pl file found $self->libscan() is called with 1455 # the default installation path in $_[1]. The return value of 1456 # libscan defines the actual installation location. The default 1457 # libscan function simply returns the path. The file is skipped 1458 # if libscan returns false. 1459 1460 # The default installation location passed to libscan in $_[1] is: 1461 # 1462 # ./*.pm => $(INST_LIBDIR)/*.pm 1463 # ./xyz/... => $(INST_LIBDIR)/xyz/... 1464 # ./lib/... => $(INST_LIB)/... 1465 # 1466 # In this way the 'lib' directory is seen as the root of the actual 1467 # perl library whereas the others are relative to INST_LIBDIR 1468 # (which includes PARENT_NAME). This is a subtle distinction but one 1469 # that's important for nested modules. 1470 1471 unless( $self->{PMLIBDIRS} ) { 1472 if( $Is{VMS} ) { 1473 # Avoid logical name vs directory collisions 1474 $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"]; 1475 } 1476 else { 1477 $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}]; 1478 } 1479 } 1480 1481 #only existing directories that aren't in $dir are allowed 1482 1483 # Avoid $_ wherever possible: 1484 # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}}; 1485 my (@pmlibdirs) = @{$self->{PMLIBDIRS}}; 1486 @{$self->{PMLIBDIRS}} = (); 1487 my %dir = map { ($_ => $_) } @{$self->{DIR}}; 1488 foreach my $pmlibdir (@pmlibdirs) { 1489 -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir; 1490 } 1491 1492 unless( $self->{PMLIBPARENTDIRS} ) { 1493 @{$self->{PMLIBPARENTDIRS}} = ('lib'); 1494 } 1495 1496 return if $self->{PM} and $self->{ARGS}{PM}; 1497 1498 if (@{$self->{PMLIBDIRS}}){ 1499 print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n" 1500 if ($Verbose >= 2); 1501 require File::Find; 1502 File::Find::find(sub { 1503 if (-d $_){ 1504 unless ($self->libscan($_)){ 1505 $File::Find::prune = 1; 1506 } 1507 return; 1508 } 1509 return if /\#/; 1510 return if /~$/; # emacs temp files 1511 return if /,v$/; # RCS files 1512 return if m{\.swp$}; # vim swap files 1513 1514 my $path = $File::Find::name; 1515 my $prefix = $self->{INST_LIBDIR}; 1516 my $striplibpath; 1517 1518 my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}}; 1519 $prefix = $self->{INST_LIB} 1520 if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W} 1521 {$1}i; 1522 1523 my($inst) = $self->catfile($prefix,$striplibpath); 1524 local($_) = $inst; # for backwards compatibility 1525 $inst = $self->libscan($inst); 1526 print "libscan($path) => '$inst'\n" if ($Verbose >= 2); 1527 return unless $inst; 1528 $self->{PM}{$path} = $inst; 1529 }, @{$self->{PMLIBDIRS}}); 1530 } 1531} 1532 1533 1534=item init_DIRFILESEP 1535 1536Using / for Unix. Called by init_main. 1537 1538=cut 1539 1540sub init_DIRFILESEP { 1541 my($self) = shift; 1542 1543 $self->{DIRFILESEP} = '/'; 1544} 1545 1546 1547=item init_main 1548 1549Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE, 1550EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*, 1551INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME, 1552OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB, 1553PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION, 1554VERSION_SYM, XS_VERSION. 1555 1556=cut 1557 1558sub init_main { 1559 my($self) = @_; 1560 1561 # --- Initialize Module Name and Paths 1562 1563 # NAME = Foo::Bar::Oracle 1564 # FULLEXT = Foo/Bar/Oracle 1565 # BASEEXT = Oracle 1566 # PARENT_NAME = Foo::Bar 1567### Only UNIX: 1568### ($self->{FULLEXT} = 1569### $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket 1570 $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME}); 1571 1572 1573 # Copied from DynaLoader: 1574 1575 my(@modparts) = split(/::/,$self->{NAME}); 1576 my($modfname) = $modparts[-1]; 1577 1578 # Some systems have restrictions on files names for DLL's etc. 1579 # mod2fname returns appropriate file base name (typically truncated) 1580 # It may also edit @modparts if required. 1581 if (defined &DynaLoader::mod2fname) { 1582 $modfname = &DynaLoader::mod2fname(\@modparts); 1583 } 1584 1585 ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ; 1586 $self->{PARENT_NAME} ||= ''; 1587 1588 if (defined &DynaLoader::mod2fname) { 1589 # As of 5.001m, dl_os2 appends '_' 1590 $self->{DLBASE} = $modfname; 1591 } else { 1592 $self->{DLBASE} = '$(BASEEXT)'; 1593 } 1594 1595 1596 # --- Initialize PERL_LIB, PERL_SRC 1597 1598 # *Real* information: where did we get these two from? ... 1599 my $inc_config_dir = dirname($INC{'Config.pm'}); 1600 my $inc_carp_dir = dirname($INC{'Carp.pm'}); 1601 1602 unless ($self->{PERL_SRC}){ 1603 foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting 1604 my $dir = $self->catdir(($Updir) x $dir_count); 1605 1606 if (-f $self->catfile($dir,"config_h.SH") && 1607 -f $self->catfile($dir,"perl.h") && 1608 -f $self->catfile($dir,"lib","strict.pm") 1609 ) { 1610 $self->{PERL_SRC}=$dir ; 1611 last; 1612 } 1613 } 1614 } 1615 1616 warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if 1617 $self->{PERL_CORE} and !$self->{PERL_SRC}; 1618 1619 if ($self->{PERL_SRC}){ 1620 $self->{PERL_LIB} ||= $self->catdir("$self->{PERL_SRC}","lib"); 1621 1622 if (defined $Cross::platform) { 1623 $self->{PERL_ARCHLIB} = 1624 $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform); 1625 $self->{PERL_INC} = 1626 $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform, 1627 $Is{Win32}?("CORE"):()); 1628 } 1629 else { 1630 $self->{PERL_ARCHLIB} = $self->{PERL_LIB}; 1631 $self->{PERL_INC} = ($Is{Win32}) ? 1632 $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC}; 1633 } 1634 1635 # catch a situation that has occurred a few times in the past: 1636 unless ( 1637 -s $self->catfile($self->{PERL_SRC},'cflags') 1638 or 1639 $Is{VMS} 1640 && 1641 -s $self->catfile($self->{PERL_SRC},'vmsish.h') 1642 or 1643 $Is{Win32} 1644 ){ 1645 warn qq{ 1646You cannot build extensions below the perl source tree after executing 1647a 'make clean' in the perl source tree. 1648 1649To rebuild extensions distributed with the perl source you should 1650simply Configure (to include those extensions) and then build perl as 1651normal. After installing perl the source tree can be deleted. It is 1652not needed for building extensions by running 'perl Makefile.PL' 1653usually without extra arguments. 1654 1655It is recommended that you unpack and build additional extensions away 1656from the perl source tree. 1657}; 1658 } 1659 } else { 1660 # we should also consider $ENV{PERL5LIB} here 1661 my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC}; 1662 $self->{PERL_LIB} ||= $Config{privlibexp}; 1663 $self->{PERL_ARCHLIB} ||= $Config{archlibexp}; 1664 $self->{PERL_INC} = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now 1665 my $perl_h; 1666 1667 if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h")) 1668 and not $old){ 1669 # Maybe somebody tries to build an extension with an 1670 # uninstalled Perl outside of Perl build tree 1671 my $lib; 1672 for my $dir (@INC) { 1673 $lib = $dir, last if -e $self->catfile($dir, "Config.pm"); 1674 } 1675 if ($lib) { 1676 # Win32 puts its header files in /perl/src/lib/CORE. 1677 # Unix leaves them in /perl/src. 1678 my $inc = $Is{Win32} ? $self->catdir($lib, "CORE" ) 1679 : dirname $lib; 1680 if (-e $self->catfile($inc, "perl.h")) { 1681 $self->{PERL_LIB} = $lib; 1682 $self->{PERL_ARCHLIB} = $lib; 1683 $self->{PERL_INC} = $inc; 1684 $self->{UNINSTALLED_PERL} = 1; 1685 print STDOUT <<EOP; 1686... Detected uninstalled Perl. Trying to continue. 1687EOP 1688 } 1689 } 1690 } 1691 } 1692 1693 # We get SITELIBEXP and SITEARCHEXP directly via 1694 # Get_from_Config. When we are running standard modules, these 1695 # won't matter, we will set INSTALLDIRS to "perl". Otherwise we 1696 # set it to "site". I prefer that INSTALLDIRS be set from outside 1697 # MakeMaker. 1698 $self->{INSTALLDIRS} ||= "site"; 1699 1700 $self->{MAN1EXT} ||= $Config{man1ext}; 1701 $self->{MAN3EXT} ||= $Config{man3ext}; 1702 1703 # Get some stuff out of %Config if we haven't yet done so 1704 print STDOUT "CONFIG must be an array ref\n" 1705 if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY'); 1706 $self->{CONFIG} = [] unless (ref $self->{CONFIG}); 1707 push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config); 1708 push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags}; 1709 my(%once_only); 1710 foreach my $m (@{$self->{CONFIG}}){ 1711 next if $once_only{$m}; 1712 print STDOUT "CONFIG key '$m' does not exist in Config.pm\n" 1713 unless exists $Config{$m}; 1714 $self->{uc $m} ||= $Config{$m}; 1715 $once_only{$m} = 1; 1716 } 1717 1718# This is too dangerous: 1719# if ($^O eq "next") { 1720# $self->{AR} = "libtool"; 1721# $self->{AR_STATIC_ARGS} = "-o"; 1722# } 1723# But I leave it as a placeholder 1724 1725 $self->{AR_STATIC_ARGS} ||= "cr"; 1726 1727 # These should never be needed 1728 $self->{OBJ_EXT} ||= '.o'; 1729 $self->{LIB_EXT} ||= '.a'; 1730 1731 $self->{MAP_TARGET} ||= "perl"; 1732 1733 $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}"; 1734 1735 # make a simple check if we find strict 1736 warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory 1737 (strict.pm not found)" 1738 unless -f $self->catfile("$self->{PERL_LIB}","strict.pm") || 1739 $self->{NAME} eq "ExtUtils::MakeMaker"; 1740} 1741 1742=item init_tools 1743 1744Initializes tools to use their common (and faster) Unix commands. 1745 1746=cut 1747 1748sub init_tools { 1749 my $self = shift; 1750 1751 $self->{ECHO} ||= 'echo'; 1752 $self->{ECHO_N} ||= 'echo -n'; 1753 $self->{RM_F} ||= "rm -f"; 1754 $self->{RM_RF} ||= "rm -rf"; 1755 $self->{TOUCH} ||= "touch"; 1756 $self->{TEST_F} ||= "test -f"; 1757 $self->{CP} ||= "cp"; 1758 $self->{MV} ||= "mv"; 1759 $self->{CHMOD} ||= "chmod"; 1760 $self->{FALSE} ||= 'false'; 1761 $self->{TRUE} ||= 'true'; 1762 1763 $self->{LD} ||= 'ld'; 1764 1765 return $self->SUPER::init_tools(@_); 1766 1767 # After SUPER::init_tools so $Config{shell} has a 1768 # chance to get set. 1769 $self->{SHELL} ||= '/bin/sh'; 1770 1771 return; 1772} 1773 1774 1775=item init_linker 1776 1777Unix has no need of special linker flags. 1778 1779=cut 1780 1781sub init_linker { 1782 my($self) = shift; 1783 $self->{PERL_ARCHIVE} ||= ''; 1784 $self->{PERL_ARCHIVE_AFTER} ||= ''; 1785 $self->{EXPORT_LIST} ||= ''; 1786} 1787 1788 1789=begin _protected 1790 1791=item init_lib2arch 1792 1793 $mm->init_lib2arch 1794 1795=end _protected 1796 1797=cut 1798 1799sub init_lib2arch { 1800 my($self) = shift; 1801 1802 # The user who requests an installation directory explicitly 1803 # should not have to tell us an architecture installation directory 1804 # as well. We look if a directory exists that is named after the 1805 # architecture. If not we take it as a sign that it should be the 1806 # same as the requested installation directory. Otherwise we take 1807 # the found one. 1808 for my $libpair ({l=>"privlib", a=>"archlib"}, 1809 {l=>"sitelib", a=>"sitearch"}, 1810 {l=>"vendorlib", a=>"vendorarch"}, 1811 ) 1812 { 1813 my $lib = "install$libpair->{l}"; 1814 my $Lib = uc $lib; 1815 my $Arch = uc "install$libpair->{a}"; 1816 if( $self->{$Lib} && ! $self->{$Arch} ){ 1817 my($ilib) = $Config{$lib}; 1818 1819 $self->prefixify($Arch,$ilib,$self->{$Lib}); 1820 1821 unless (-d $self->{$Arch}) { 1822 print STDOUT "Directory $self->{$Arch} not found\n" 1823 if $Verbose; 1824 $self->{$Arch} = $self->{$Lib}; 1825 } 1826 print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose; 1827 } 1828 } 1829} 1830 1831 1832=item init_PERL 1833 1834 $mm->init_PERL; 1835 1836Called by init_main. Sets up ABSPERL, PERL, FULLPERL and all the 1837*PERLRUN* permutations. 1838 1839 PERL is allowed to be miniperl 1840 FULLPERL must be a complete perl 1841 1842 ABSPERL is PERL converted to an absolute path 1843 1844 *PERLRUN contains everything necessary to run perl, find it's 1845 libraries, etc... 1846 1847 *PERLRUNINST is *PERLRUN + everything necessary to find the 1848 modules being built. 1849 1850=cut 1851 1852sub init_PERL { 1853 my($self) = shift; 1854 1855 my @defpath = (); 1856 foreach my $component ($self->{PERL_SRC}, $self->path(), 1857 $Config{binexp}) 1858 { 1859 push @defpath, $component if defined $component; 1860 } 1861 1862 # Build up a set of file names (not command names). 1863 my $thisperl = $self->canonpath($^X); 1864 $thisperl .= $Config{exe_ext} unless 1865 # VMS might have a file version # at the end 1866 $Is{VMS} ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i 1867 : $thisperl =~ m/$Config{exe_ext}$/i; 1868 1869 # We need a relative path to perl when in the core. 1870 $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE}; 1871 1872 my @perls = ($thisperl); 1873 push @perls, map { "$_$Config{exe_ext}" } 1874 ('perl', 'perl5', "perl$Config{version}"); 1875 1876 # miniperl has priority over all but the cannonical perl when in the 1877 # core. Otherwise its a last resort. 1878 my $miniperl = "miniperl$Config{exe_ext}"; 1879 if( $self->{PERL_CORE} ) { 1880 splice @perls, 1, 0, $miniperl; 1881 } 1882 else { 1883 push @perls, $miniperl; 1884 } 1885 1886 $self->{PERL} ||= 1887 $self->find_perl(5.0, \@perls, \@defpath, $Verbose ); 1888 # don't check if perl is executable, maybe they have decided to 1889 # supply switches with perl 1890 1891 # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe. 1892 my $perl_name = 'perl'; 1893 $perl_name = 'ndbgperl' if $Is{VMS} && 1894 defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define'; 1895 1896 # XXX This logic is flawed. If "miniperl" is anywhere in the path 1897 # it will get confused. It should be fixed to work only on the filename. 1898 # Define 'FULLPERL' to be a non-miniperl (used in test: target) 1899 ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/$perl_name/i 1900 unless $self->{FULLPERL}; 1901 1902 # Little hack to get around VMS's find_perl putting "MCR" in front 1903 # sometimes. 1904 $self->{ABSPERL} = $self->{PERL}; 1905 my $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//; 1906 if( $self->file_name_is_absolute($self->{ABSPERL}) ) { 1907 $self->{ABSPERL} = '$(PERL)'; 1908 } 1909 else { 1910 $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL}); 1911 1912 # Quote the perl command if it contains whitespace 1913 $self->{ABSPERL} = $self->quote_literal($self->{ABSPERL}) 1914 if $self->{ABSPERL} =~ /\s/; 1915 1916 $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr; 1917 } 1918 1919 # Are we building the core? 1920 $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE}; 1921 $self->{PERL_CORE} = 0 unless defined $self->{PERL_CORE}; 1922 1923 # How do we run perl? 1924 foreach my $perl (qw(PERL FULLPERL ABSPERL)) { 1925 my $run = $perl.'RUN'; 1926 1927 $self->{$run} = "\$($perl)"; 1928 1929 # Make sure perl can find itself before it's installed. 1930 $self->{$run} .= q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} 1931 if $self->{UNINSTALLED_PERL} || $self->{PERL_CORE}; 1932 1933 $self->{$perl.'RUNINST'} = 1934 sprintf q{$(%sRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"}, $perl; 1935 } 1936 1937 return 1; 1938} 1939 1940 1941=item init_platform 1942 1943=item platform_constants 1944 1945Add MM_Unix_VERSION. 1946 1947=cut 1948 1949sub init_platform { 1950 my($self) = shift; 1951 1952 $self->{MM_Unix_VERSION} = $VERSION; 1953 $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '. 1954 '-Dfree=Perl_mfree -Drealloc=Perl_realloc '. 1955 '-Dcalloc=Perl_calloc'; 1956 1957} 1958 1959sub platform_constants { 1960 my($self) = shift; 1961 my $make_frag = ''; 1962 1963 foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF)) 1964 { 1965 next unless defined $self->{$macro}; 1966 $make_frag .= "$macro = $self->{$macro}\n"; 1967 } 1968 1969 return $make_frag; 1970} 1971 1972 1973=item init_PERM 1974 1975 $mm->init_PERM 1976 1977Called by init_main. Initializes PERL_* 1978 1979=cut 1980 1981sub init_PERM { 1982 my($self) = shift; 1983 1984 $self->{PERM_DIR} = 755 unless defined $self->{PERM_DIR}; 1985 $self->{PERM_RW} = 644 unless defined $self->{PERM_RW}; 1986 $self->{PERM_RWX} = 755 unless defined $self->{PERM_RWX}; 1987 1988 return 1; 1989} 1990 1991 1992=item init_xs 1993 1994 $mm->init_xs 1995 1996Sets up macros having to do with XS code. Currently just INST_STATIC, 1997INST_DYNAMIC and INST_BOOT. 1998 1999=cut 2000 2001sub init_xs { 2002 my $self = shift; 2003 2004 if ($self->has_link_code()) { 2005 $self->{INST_STATIC} = 2006 $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)'); 2007 $self->{INST_DYNAMIC} = 2008 $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)'); 2009 $self->{INST_BOOT} = 2010 $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs'); 2011 } else { 2012 $self->{INST_STATIC} = ''; 2013 $self->{INST_DYNAMIC} = ''; 2014 $self->{INST_BOOT} = ''; 2015 } 2016} 2017 2018=item install (o) 2019 2020Defines the install target. 2021 2022=cut 2023 2024sub install { 2025 my($self, %attribs) = @_; 2026 my(@m); 2027 2028 push @m, q{ 2029install :: pure_install doc_install 2030 $(NOECHO) $(NOOP) 2031 2032install_perl :: pure_perl_install doc_perl_install 2033 $(NOECHO) $(NOOP) 2034 2035install_site :: pure_site_install doc_site_install 2036 $(NOECHO) $(NOOP) 2037 2038install_vendor :: pure_vendor_install doc_vendor_install 2039 $(NOECHO) $(NOOP) 2040 2041pure_install :: pure_$(INSTALLDIRS)_install 2042 $(NOECHO) $(NOOP) 2043 2044doc_install :: doc_$(INSTALLDIRS)_install 2045 $(NOECHO) $(NOOP) 2046 2047pure__install : pure_site_install 2048 $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site 2049 2050doc__install : doc_site_install 2051 $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site 2052 2053pure_perl_install :: all 2054 $(NOECHO) $(MOD_INSTALL) \ 2055 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \ 2056 write }.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \ 2057 $(INST_LIB) $(DESTINSTALLPRIVLIB) \ 2058 $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \ 2059 $(INST_BIN) $(DESTINSTALLBIN) \ 2060 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \ 2061 $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \ 2062 $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR) 2063 $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ 2064 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{ 2065 2066 2067pure_site_install :: all 2068 $(NOECHO) $(MOD_INSTALL) \ 2069 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \ 2070 write }.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \ 2071 $(INST_LIB) $(DESTINSTALLSITELIB) \ 2072 $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \ 2073 $(INST_BIN) $(DESTINSTALLSITEBIN) \ 2074 $(INST_SCRIPT) $(DESTINSTALLSITESCRIPT) \ 2075 $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \ 2076 $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR) 2077 $(NOECHO) $(WARN_IF_OLD_PACKLIST) \ 2078 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{ 2079 2080pure_vendor_install :: all 2081 $(NOECHO) $(MOD_INSTALL) \ 2082 read }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \ 2083 write }.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{ \ 2084 $(INST_LIB) $(DESTINSTALLVENDORLIB) \ 2085 $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \ 2086 $(INST_BIN) $(DESTINSTALLVENDORBIN) \ 2087 $(INST_SCRIPT) $(DESTINSTALLVENDORSCRIPT) \ 2088 $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \ 2089 $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR) 2090 2091doc_perl_install :: all 2092 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod 2093 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) 2094 -$(NOECHO) $(DOC_INSTALL) \ 2095 "Module" "$(NAME)" \ 2096 "installed into" "$(INSTALLPRIVLIB)" \ 2097 LINKTYPE "$(LINKTYPE)" \ 2098 VERSION "$(VERSION)" \ 2099 EXE_FILES "$(EXE_FILES)" \ 2100 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{ 2101 2102doc_site_install :: all 2103 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod 2104 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) 2105 -$(NOECHO) $(DOC_INSTALL) \ 2106 "Module" "$(NAME)" \ 2107 "installed into" "$(INSTALLSITELIB)" \ 2108 LINKTYPE "$(LINKTYPE)" \ 2109 VERSION "$(VERSION)" \ 2110 EXE_FILES "$(EXE_FILES)" \ 2111 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{ 2112 2113doc_vendor_install :: all 2114 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod 2115 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) 2116 -$(NOECHO) $(DOC_INSTALL) \ 2117 "Module" "$(NAME)" \ 2118 "installed into" "$(INSTALLVENDORLIB)" \ 2119 LINKTYPE "$(LINKTYPE)" \ 2120 VERSION "$(VERSION)" \ 2121 EXE_FILES "$(EXE_FILES)" \ 2122 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{ 2123 2124}; 2125 2126 push @m, q{ 2127uninstall :: uninstall_from_$(INSTALLDIRS)dirs 2128 $(NOECHO) $(NOOP) 2129 2130uninstall_from_perldirs :: 2131 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ 2132 2133uninstall_from_sitedirs :: 2134 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ 2135 2136uninstall_from_vendordirs :: 2137 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{ 2138}; 2139 2140 join("",@m); 2141} 2142 2143=item installbin (o) 2144 2145Defines targets to make and to install EXE_FILES. 2146 2147=cut 2148 2149sub installbin { 2150 my($self) = shift; 2151 2152 return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY"; 2153 my @exefiles = @{$self->{EXE_FILES}}; 2154 return "" unless @exefiles; 2155 2156 @exefiles = map vmsify($_), @exefiles if $Is{VMS}; 2157 2158 my %fromto; 2159 for my $from (@exefiles) { 2160 my($path)= $self->catfile('$(INST_SCRIPT)', basename($from)); 2161 2162 local($_) = $path; # for backwards compatibility 2163 my $to = $self->libscan($path); 2164 print "libscan($from) => '$to'\n" if ($Verbose >=2); 2165 2166 $to = vmsify($to) if $Is{VMS}; 2167 $fromto{$from} = $to; 2168 } 2169 my @to = values %fromto; 2170 2171 my @m; 2172 push(@m, qq{ 2173EXE_FILES = @exefiles 2174 2175pure_all :: @to 2176 \$(NOECHO) \$(NOOP) 2177 2178realclean :: 2179}); 2180 2181 # realclean can get rather large. 2182 push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to); 2183 push @m, "\n"; 2184 2185 2186 # A target for each exe file. 2187 while (my($from,$to) = each %fromto) { 2188 last unless defined $from; 2189 2190 push @m, sprintf <<'MAKE', $to, $from, $to, $from, $to, $to, $to; 2191%s : %s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists 2192 $(NOECHO) $(RM_F) %s 2193 $(CP) %s %s 2194 $(FIXIN) %s 2195 -$(NOECHO) $(CHMOD) $(PERM_RWX) %s 2196 2197MAKE 2198 2199 } 2200 2201 join "", @m; 2202} 2203 2204 2205=item linkext (o) 2206 2207Defines the linkext target which in turn defines the LINKTYPE. 2208 2209=cut 2210 2211sub linkext { 2212 my($self, %attribs) = @_; 2213 # LINKTYPE => static or dynamic or '' 2214 my($linktype) = defined $attribs{LINKTYPE} ? 2215 $attribs{LINKTYPE} : '$(LINKTYPE)'; 2216 " 2217linkext :: $linktype 2218 \$(NOECHO) \$(NOOP) 2219"; 2220} 2221 2222=item lsdir 2223 2224Takes as arguments a directory name and a regular expression. Returns 2225all entries in the directory that match the regular expression. 2226 2227=cut 2228 2229sub lsdir { 2230 my($self) = shift; 2231 my($dir, $regex) = @_; 2232 my(@ls); 2233 my $dh = new DirHandle; 2234 $dh->open($dir || ".") or return (); 2235 @ls = $dh->read; 2236 $dh->close; 2237 @ls = grep(/$regex/, @ls) if $regex; 2238 @ls; 2239} 2240 2241=item macro (o) 2242 2243Simple subroutine to insert the macros defined by the macro attribute 2244into the Makefile. 2245 2246=cut 2247 2248sub macro { 2249 my($self,%attribs) = @_; 2250 my(@m,$key,$val); 2251 while (($key,$val) = each %attribs){ 2252 last unless defined $key; 2253 push @m, "$key = $val\n"; 2254 } 2255 join "", @m; 2256} 2257 2258=item makeaperl (o) 2259 2260Called by staticmake. Defines how to write the Makefile to produce a 2261static new perl. 2262 2263By default the Makefile produced includes all the static extensions in 2264the perl library. (Purified versions of library files, e.g., 2265DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.) 2266 2267=cut 2268 2269sub makeaperl { 2270 my($self, %attribs) = @_; 2271 my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) = 2272 @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)}; 2273 my(@m); 2274 push @m, " 2275# --- MakeMaker makeaperl section --- 2276MAP_TARGET = $target 2277FULLPERL = $self->{FULLPERL} 2278"; 2279 return join '', @m if $self->{PARENT}; 2280 2281 my($dir) = join ":", @{$self->{DIR}}; 2282 2283 unless ($self->{MAKEAPERL}) { 2284 push @m, q{ 2285$(MAP_TARGET) :: static $(MAKE_APERL_FILE) 2286 $(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@ 2287 2288$(MAKE_APERL_FILE) : $(FIRST_MAKEFILE) pm_to_blib 2289 $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET) 2290 $(NOECHO) $(PERLRUNINST) \ 2291 Makefile.PL DIR=}, $dir, q{ \ 2292 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \ 2293 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=}; 2294 2295 foreach (@ARGV){ 2296 if( /\s/ ){ 2297 s/=(.*)/='$1'/; 2298 } 2299 push @m, " \\\n\t\t$_"; 2300 } 2301# push @m, map( " \\\n\t\t$_", @ARGV ); 2302 push @m, "\n"; 2303 2304 return join '', @m; 2305 } 2306 2307 2308 2309 my($cccmd, $linkcmd, $lperl); 2310 2311 2312 $cccmd = $self->const_cccmd($libperl); 2313 $cccmd =~ s/^CCCMD\s*=\s*//; 2314 $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /; 2315 $cccmd .= " $Config{cccdlflags}" 2316 if ($Config{useshrplib} eq 'true'); 2317 $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/; 2318 2319 # The front matter of the linkcommand... 2320 $linkcmd = join ' ', "\$(CC)", 2321 grep($_, @Config{qw(ldflags ccdlflags)}); 2322 $linkcmd =~ s/\s+/ /g; 2323 $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,; 2324 2325 # Which *.a files could we make use of... 2326 my %static; 2327 require File::Find; 2328 File::Find::find(sub { 2329 return unless m/\Q$self->{LIB_EXT}\E$/; 2330 2331 # Skip perl's libraries. 2332 return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/; 2333 2334 # Skip purified versions of libraries 2335 # (e.g., DynaLoader_pure_p1_c0_032.a) 2336 return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure"; 2337 2338 if( exists $self->{INCLUDE_EXT} ){ 2339 my $found = 0; 2340 2341 (my $xx = $File::Find::name) =~ s,.*?/auto/,,s; 2342 $xx =~ s,/?$_,,; 2343 $xx =~ s,/,::,g; 2344 2345 # Throw away anything not explicitly marked for inclusion. 2346 # DynaLoader is implied. 2347 foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){ 2348 if( $xx eq $incl ){ 2349 $found++; 2350 last; 2351 } 2352 } 2353 return unless $found; 2354 } 2355 elsif( exists $self->{EXCLUDE_EXT} ){ 2356 (my $xx = $File::Find::name) =~ s,.*?/auto/,,s; 2357 $xx =~ s,/?$_,,; 2358 $xx =~ s,/,::,g; 2359 2360 # Throw away anything explicitly marked for exclusion 2361 foreach my $excl (@{$self->{EXCLUDE_EXT}}){ 2362 return if( $xx eq $excl ); 2363 } 2364 } 2365 2366 # don't include the installed version of this extension. I 2367 # leave this line here, although it is not necessary anymore: 2368 # I patched minimod.PL instead, so that Miniperl.pm won't 2369 # enclude duplicates 2370 2371 # Once the patch to minimod.PL is in the distribution, I can 2372 # drop it 2373 return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}\z:; 2374 use Cwd 'cwd'; 2375 $static{cwd() . "/" . $_}++; 2376 }, grep( -d $_, @{$searchdirs || []}) ); 2377 2378 # We trust that what has been handed in as argument, will be buildable 2379 $static = [] unless $static; 2380 @static{@{$static}} = (1) x @{$static}; 2381 2382 $extra = [] unless $extra && ref $extra eq 'ARRAY'; 2383 for (sort keys %static) { 2384 next unless /\Q$self->{LIB_EXT}\E\z/; 2385 $_ = dirname($_) . "/extralibs.ld"; 2386 push @$extra, $_; 2387 } 2388 2389 s/^(.*)/"-I$1"/ for @{$perlinc || []}; 2390 2391 $target ||= "perl"; 2392 $tmp ||= "."; 2393 2394# MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we 2395# regenerate the Makefiles, MAP_STATIC and the dependencies for 2396# extralibs.all are computed correctly 2397 push @m, " 2398MAP_LINKCMD = $linkcmd 2399MAP_PERLINC = @{$perlinc || []} 2400MAP_STATIC = ", 2401join(" \\\n\t", reverse sort keys %static), " 2402 2403MAP_PRELIBS = $Config{perllibs} $Config{cryptlib} 2404"; 2405 2406 if (defined $libperl) { 2407 ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/; 2408 } 2409 unless ($libperl && -f $lperl) { # Ilya's code... 2410 my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE"; 2411 $dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL}; 2412 $libperl ||= "libperl$self->{LIB_EXT}"; 2413 $libperl = "$dir/$libperl"; 2414 $lperl ||= "libperl$self->{LIB_EXT}"; 2415 $lperl = "$dir/$lperl"; 2416 2417 if (! -f $libperl and ! -f $lperl) { 2418 # We did not find a static libperl. Maybe there is a shared one? 2419 if ($Is{SunOS}) { 2420 $lperl = $libperl = "$dir/$Config{libperl}"; 2421 # SUNOS ld does not take the full path to a shared library 2422 $libperl = '' if $Is{SunOS4}; 2423 } 2424 } 2425 2426 print STDOUT "Warning: $libperl not found 2427 If you're going to build a static perl binary, make sure perl is installed 2428 otherwise ignore this warning\n" 2429 unless (-f $lperl || defined($self->{PERL_SRC})); 2430 } 2431 2432 # SUNOS ld does not take the full path to a shared library 2433 my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl'; 2434 2435 push @m, " 2436MAP_LIBPERL = $libperl 2437LLIBPERL = $llibperl 2438"; 2439 2440 push @m, ' 2441$(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).' 2442 $(NOECHO) $(RM_F) $@ 2443 $(NOECHO) $(TOUCH) $@ 2444'; 2445 2446 foreach my $catfile (@$extra){ 2447 push @m, "\tcat $catfile >> \$\@\n"; 2448 } 2449 2450push @m, " 2451\$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all 2452 \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(LDFROM) \$(MAP_STATIC) \$(LLIBPERL) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS) 2453 \$(NOECHO) \$(ECHO) 'To install the new \"\$(MAP_TARGET)\" binary, call' 2454 \$(NOECHO) \$(ECHO) ' \$(MAKE) \$(USEMAKEFILE) $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)' 2455 \$(NOECHO) \$(ECHO) 'To remove the intermediate files say' 2456 \$(NOECHO) \$(ECHO) ' \$(MAKE) \$(USEMAKEFILE) $makefilename map_clean' 2457 2458$tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c 2459"; 2460 push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n"; 2461 2462 push @m, qq{ 2463$tmp/perlmain.c: $makefilename}, q{ 2464 $(NOECHO) $(ECHO) Writing $@ 2465 $(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \\ 2466 -e "writemain(grep s#.*/auto/##s, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@ 2467 2468}; 2469 push @m, "\t", q{$(NOECHO) $(PERL) $(INSTALLSCRIPT)/fixpmain 2470} if (defined (&Dos::UseLFN) && Dos::UseLFN()==0); 2471 2472 2473 push @m, q{ 2474doc_inst_perl : 2475 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod 2476 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB) 2477 -$(NOECHO) $(DOC_INSTALL) \ 2478 "Perl binary" "$(MAP_TARGET)" \ 2479 MAP_STATIC "$(MAP_STATIC)" \ 2480 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \ 2481 MAP_LIBPERL "$(MAP_LIBPERL)" \ 2482 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{ 2483 2484}; 2485 2486 push @m, q{ 2487inst_perl : pure_inst_perl doc_inst_perl 2488 2489pure_inst_perl : $(MAP_TARGET) 2490 }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{ 2491 2492clean :: map_clean 2493 2494map_clean : 2495 }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all 2496}; 2497 2498 join '', @m; 2499} 2500 2501=item makefile (o) 2502 2503Defines how to rewrite the Makefile. 2504 2505=cut 2506 2507sub makefile { 2508 my($self) = shift; 2509 my $m; 2510 # We do not know what target was originally specified so we 2511 # must force a manual rerun to be sure. But as it should only 2512 # happen very rarely it is not a significant problem. 2513 $m = ' 2514$(OBJECT) : $(FIRST_MAKEFILE) 2515 2516' if $self->{OBJECT}; 2517 2518 my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?'; 2519 my $mpl_args = join " ", map qq["$_"], @ARGV; 2520 2521 $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $mpl_args; 2522# We take a very conservative approach here, but it's worth it. 2523# We move Makefile to Makefile.old here to avoid gnu make looping. 2524$(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP) 2525 $(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s" 2526 $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..." 2527 -$(NOECHO) $(RM_F) $(MAKEFILE_OLD) 2528 -$(NOECHO) $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) 2529 - $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL) 2530 $(PERLRUN) Makefile.PL %s 2531 $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <==" 2532 $(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command. <==" 2533 $(FALSE) 2534 2535MAKE_FRAG 2536 2537 return $m; 2538} 2539 2540 2541=item maybe_command 2542 2543Returns true, if the argument is likely to be a command. 2544 2545=cut 2546 2547sub maybe_command { 2548 my($self,$file) = @_; 2549 return $file if -x $file && ! -d $file; 2550 return; 2551} 2552 2553 2554=item needs_linking (o) 2555 2556Does this module need linking? Looks into subdirectory objects (see 2557also has_link_code()) 2558 2559=cut 2560 2561sub needs_linking { 2562 my($self) = shift; 2563 2564 my $caller = (caller(0))[3]; 2565 confess("needs_linking called too early") if 2566 $caller =~ /^ExtUtils::MakeMaker::/; 2567 return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING}; 2568 if ($self->has_link_code or $self->{MAKEAPERL}){ 2569 $self->{NEEDS_LINKING} = 1; 2570 return 1; 2571 } 2572 foreach my $child (keys %{$self->{CHILDREN}}) { 2573 if ($self->{CHILDREN}->{$child}->needs_linking) { 2574 $self->{NEEDS_LINKING} = 1; 2575 return 1; 2576 } 2577 } 2578 return $self->{NEEDS_LINKING} = 0; 2579} 2580 2581 2582=item parse_abstract 2583 2584parse a file and return what you think is the ABSTRACT 2585 2586=cut 2587 2588sub parse_abstract { 2589 my($self,$parsefile) = @_; 2590 my $result; 2591 2592 local $/ = "\n"; 2593 open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!"; 2594 my $inpod = 0; 2595 my $package = $self->{DISTNAME}; 2596 $package =~ s/-/::/g; 2597 while (<$fh>) { 2598 $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; 2599 next if !$inpod; 2600 chop; 2601 next unless /^($package(?:\.pm)? \s+ -+ \s+)(.*)/x; 2602 $result = $2; 2603 last; 2604 } 2605 close $fh; 2606 2607 return $result; 2608} 2609 2610=item parse_version 2611 2612 my $version = MM->parse_version($file); 2613 2614Parse a $file and return what $VERSION is set to by the first assignment. 2615It will return the string "undef" if it can't figure out what $VERSION 2616is. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION 2617are okay, but C<my $VERSION> is not. 2618 2619C<<package Foo VERSION>> is also checked for. The first version 2620declaration found is used, but this may change as it differs from how 2621Perl does it. 2622 2623parse_version() will try to C<use version> before checking for 2624C<$VERSION> so the following will work. 2625 2626 $VERSION = qv(1.2.3); 2627 2628=cut 2629 2630sub parse_version { 2631 my($self,$parsefile) = @_; 2632 my $result; 2633 2634 local $/ = "\n"; 2635 local $_; 2636 open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!"; 2637 my $inpod = 0; 2638 while (<$fh>) { 2639 $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; 2640 next if $inpod || /^\s*#/; 2641 chop; 2642 next if /^\s*(if|unless|elsif)/; 2643 if ( m{^ \s* package \s+ \w[\w\:\']* \s+ (v?[0-9._]+) \s* ; }x ) { 2644 local $^W = 0; 2645 $result = $1; 2646 } 2647 elsif ( m{(?<!\\) ([\$*]) (([\w\:\']*) \bVERSION)\b .* =}x ) { 2648 my $eval = qq{ 2649 package ExtUtils::MakeMaker::_version; 2650 no strict; 2651 BEGIN { eval { 2652 # Ensure any version() routine which might have leaked 2653 # into this package has been deleted. Interferes with 2654 # version->import() 2655 undef *version; 2656 require version; 2657 "version"->import; 2658 } } 2659 2660 local $1$2; 2661 \$$2=undef; 2662 do { 2663 $_ 2664 }; 2665 \$$2; 2666 }; 2667 local $^W = 0; 2668 $result = eval($eval); ## no critic 2669 warn "Could not eval '$eval' in $parsefile: $@" if $@; 2670 } 2671 else { 2672 next; 2673 } 2674 last if defined $result; 2675 } 2676 close $fh; 2677 2678 $result = "undef" unless defined $result; 2679 return $result; 2680} 2681 2682 2683=item pasthru (o) 2684 2685Defines the string that is passed to recursive make calls in 2686subdirectories. 2687 2688=cut 2689 2690sub pasthru { 2691 my($self) = shift; 2692 my(@m); 2693 2694 my(@pasthru); 2695 my($sep) = $Is{VMS} ? ',' : ''; 2696 $sep .= "\\\n\t"; 2697 2698 foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE 2699 PREFIX INSTALL_BASE) 2700 ) 2701 { 2702 next unless defined $self->{$key}; 2703 push @pasthru, "$key=\"\$($key)\""; 2704 } 2705 2706 foreach my $key (qw(DEFINE INC)) { 2707 next unless defined $self->{$key}; 2708 push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\""; 2709 } 2710 2711 push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n"; 2712 join "", @m; 2713} 2714 2715=item perl_script 2716 2717Takes one argument, a file name, and returns the file name, if the 2718argument is likely to be a perl script. On MM_Unix this is true for 2719any ordinary, readable file. 2720 2721=cut 2722 2723sub perl_script { 2724 my($self,$file) = @_; 2725 return $file if -r $file && -f _; 2726 return; 2727} 2728 2729=item perldepend (o) 2730 2731Defines the dependency from all *.h files that come with the perl 2732distribution. 2733 2734=cut 2735 2736sub perldepend { 2737 my($self) = shift; 2738 my(@m); 2739 2740 my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm'); 2741 2742 push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC}; 2743# Check for unpropogated config.sh changes. Should never happen. 2744# We do NOT just update config.h because that is not sufficient. 2745# An out of date config.h is not fatal but complains loudly! 2746$(PERL_INC)/config.h: $(PERL_SRC)/config.sh 2747 -$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; $(FALSE) 2748 2749$(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh 2750 $(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh" 2751 %s 2752MAKE_FRAG 2753 2754 return join "", @m unless $self->needs_linking; 2755 2756 push @m, q{ 2757PERL_HDRS = \ 2758 $(PERL_INC)/EXTERN.h \ 2759 $(PERL_INC)/INTERN.h \ 2760 $(PERL_INC)/XSUB.h \ 2761 $(PERL_INC)/av.h \ 2762 $(PERL_INC)/config.h \ 2763 $(PERL_INC)/cop.h \ 2764 $(PERL_INC)/cv.h \ 2765 $(PERL_INC)/dosish.h \ 2766 $(PERL_INC)/embed.h \ 2767 $(PERL_INC)/embedvar.h \ 2768 $(PERL_INC)/fakethr.h \ 2769 $(PERL_INC)/form.h \ 2770 $(PERL_INC)/gv.h \ 2771 $(PERL_INC)/handy.h \ 2772 $(PERL_INC)/hv.h \ 2773 $(PERL_INC)/intrpvar.h \ 2774 $(PERL_INC)/iperlsys.h \ 2775 $(PERL_INC)/keywords.h \ 2776 $(PERL_INC)/mg.h \ 2777 $(PERL_INC)/nostdio.h \ 2778 $(PERL_INC)/op.h \ 2779 $(PERL_INC)/opcode.h \ 2780 $(PERL_INC)/patchlevel.h \ 2781 $(PERL_INC)/perl.h \ 2782 $(PERL_INC)/perlio.h \ 2783 $(PERL_INC)/perlsdio.h \ 2784 $(PERL_INC)/perlsfio.h \ 2785 $(PERL_INC)/perlvars.h \ 2786 $(PERL_INC)/perly.h \ 2787 $(PERL_INC)/pp.h \ 2788 $(PERL_INC)/pp_proto.h \ 2789 $(PERL_INC)/proto.h \ 2790 $(PERL_INC)/regcomp.h \ 2791 $(PERL_INC)/regexp.h \ 2792 $(PERL_INC)/regnodes.h \ 2793 $(PERL_INC)/scope.h \ 2794 $(PERL_INC)/sv.h \ 2795 $(PERL_INC)/thread.h \ 2796 $(PERL_INC)/unixish.h \ 2797 $(PERL_INC)/util.h 2798 2799$(OBJECT) : $(PERL_HDRS) 2800} if $self->{OBJECT}; 2801 2802 push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n" if %{$self->{XS}}; 2803 2804 join "\n", @m; 2805} 2806 2807 2808=item pm_to_blib 2809 2810Defines target that copies all files in the hash PM to their 2811destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION> 2812 2813=cut 2814 2815sub pm_to_blib { 2816 my $self = shift; 2817 my($autodir) = $self->catdir('$(INST_LIB)','auto'); 2818 my $r = q{ 2819pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM) 2820}; 2821 2822 # VMS will swallow '' and PM_FILTER is often empty. So use q[] 2823 my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']); 2824pm_to_blib({\@ARGV}, '$autodir', q[\$(PM_FILTER)], '\$(PERM_DIR)') 2825CODE 2826 2827 my @cmds = $self->split_command($pm_to_blib, %{$self->{PM}}); 2828 2829 $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds; 2830 $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n}; 2831 2832 return $r; 2833} 2834 2835=item post_constants (o) 2836 2837Returns an empty string per default. Dedicated to overrides from 2838within Makefile.PL after all constants have been defined. 2839 2840=cut 2841 2842sub post_constants{ 2843 ""; 2844} 2845 2846=item post_initialize (o) 2847 2848Returns an empty string per default. Used in Makefile.PLs to add some 2849chunk of text to the Makefile after the object is initialized. 2850 2851=cut 2852 2853sub post_initialize { 2854 ""; 2855} 2856 2857=item postamble (o) 2858 2859Returns an empty string. Can be used in Makefile.PLs to write some 2860text to the Makefile at the end. 2861 2862=cut 2863 2864sub postamble { 2865 ""; 2866} 2867 2868# transform dot-separated version string into comma-separated quadruple 2869# examples: '1.2.3.4.5' => '1,2,3,4' 2870# '1.2.3' => '1,2,3,0' 2871sub _ppd_version { 2872 my ($self, $string) = @_; 2873 return join ',', ((split /\./, $string), (0) x 4)[0..3]; 2874} 2875 2876=item ppd 2877 2878Defines target that creates a PPD (Perl Package Description) file 2879for a binary distribution. 2880 2881=cut 2882 2883sub ppd { 2884 my($self) = @_; 2885 2886 my $abstract = $self->{ABSTRACT} || ''; 2887 $abstract =~ s/\n/\\n/sg; 2888 $abstract =~ s/</</g; 2889 $abstract =~ s/>/>/g; 2890 2891 my $author = join(', ',@{$self->{AUTHOR} || []}); 2892 $author =~ s/</</g; 2893 $author =~ s/>/>/g; 2894 2895 my $ppd_file = '$(DISTNAME).ppd'; 2896 2897 my @ppd_cmds = $self->echo(<<'PPD_HTML', $ppd_file, { append => 0, allow_variables => 1 }); 2898<SOFTPKG NAME="$(DISTNAME)" VERSION="$(VERSION)"> 2899PPD_HTML 2900 2901 my $ppd_xml = sprintf <<'PPD_HTML', $abstract, $author; 2902 <ABSTRACT>%s</ABSTRACT> 2903 <AUTHOR>%s</AUTHOR> 2904PPD_HTML 2905 2906 $ppd_xml .= " <IMPLEMENTATION>\n"; 2907 if ( $self->{MIN_PERL_VERSION} ) { 2908 my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION}); 2909 $ppd_xml .= sprintf <<'PPD_PERLVERS', $min_perl_version; 2910 <PERLCORE VERSION="%s" /> 2911PPD_PERLVERS 2912 2913 } 2914 2915 # Don't add "perl" to requires. perl dependencies are 2916 # handles by ARCHITECTURE. 2917 my %prereqs = %{$self->{PREREQ_PM}}; 2918 delete $prereqs{perl}; 2919 2920 # Build up REQUIRE 2921 foreach my $prereq (sort keys %prereqs) { 2922 my $name = $prereq; 2923 $name .= '::' unless $name =~ /::/; 2924 my $version = $prereqs{$prereq}+0; # force numification 2925 2926 my %attrs = ( NAME => $name ); 2927 $attrs{VERSION} = $version if $version; 2928 my $attrs = join " ", map { qq[$_="$attrs{$_}"] } keys %attrs; 2929 $ppd_xml .= qq( <REQUIRE $attrs />\n); 2930 } 2931 2932 my $archname = $Config{archname}; 2933 if ($] >= 5.008) { 2934 # archname did not change from 5.6 to 5.8, but those versions may 2935 # not be not binary compatible so now we append the part of the 2936 # version that changes when binary compatibility may change 2937 $archname .= "-$Config{PERL_REVISION}.$Config{PERL_VERSION}"; 2938 } 2939 $ppd_xml .= sprintf <<'PPD_OUT', $archname; 2940 <ARCHITECTURE NAME="%s" /> 2941PPD_OUT 2942 2943 if ($self->{PPM_INSTALL_SCRIPT}) { 2944 if ($self->{PPM_INSTALL_EXEC}) { 2945 $ppd_xml .= sprintf qq{ <INSTALL EXEC="%s">%s</INSTALL>\n}, 2946 $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT}; 2947 } 2948 else { 2949 $ppd_xml .= sprintf qq{ <INSTALL>%s</INSTALL>\n}, 2950 $self->{PPM_INSTALL_SCRIPT}; 2951 } 2952 } 2953 2954 my ($bin_location) = $self->{BINARY_LOCATION} || ''; 2955 $bin_location =~ s/\\/\\\\/g; 2956 2957 $ppd_xml .= sprintf <<'PPD_XML', $bin_location; 2958 <CODEBASE HREF="%s" /> 2959 </IMPLEMENTATION> 2960</SOFTPKG> 2961PPD_XML 2962 2963 push @ppd_cmds, $self->echo($ppd_xml, $ppd_file, { append => 1 }); 2964 2965 return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds; 2966# Creates a PPD (Perl Package Description) for a binary distribution. 2967ppd : 2968 %s 2969PPD_OUT 2970 2971} 2972 2973=item prefixify 2974 2975 $MM->prefixify($var, $prefix, $new_prefix, $default); 2976 2977Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to 2978replace it's $prefix with a $new_prefix. 2979 2980Should the $prefix fail to match I<AND> a PREFIX was given as an 2981argument to WriteMakefile() it will set it to the $new_prefix + 2982$default. This is for systems whose file layouts don't neatly fit into 2983our ideas of prefixes. 2984 2985This is for heuristics which attempt to create directory structures 2986that mirror those of the installed perl. 2987 2988For example: 2989 2990 $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1'); 2991 2992this will attempt to remove '/usr' from the front of the 2993$MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir} 2994if necessary) and replace it with '/home/foo'. If this fails it will 2995simply use '/home/foo/man/man1'. 2996 2997=cut 2998 2999sub prefixify { 3000 my($self,$var,$sprefix,$rprefix,$default) = @_; 3001 3002 my $path = $self->{uc $var} || 3003 $Config_Override{lc $var} || $Config{lc $var} || ''; 3004 3005 $rprefix .= '/' if $sprefix =~ m|/$|; 3006 3007 print STDERR " prefixify $var => $path\n" if $Verbose >= 2; 3008 print STDERR " from $sprefix to $rprefix\n" if $Verbose >= 2; 3009 3010 if( $self->{ARGS}{PREFIX} && 3011 $path !~ s{^\Q$sprefix\E\b}{$rprefix}s ) 3012 { 3013 3014 print STDERR " cannot prefix, using default.\n" if $Verbose >= 2; 3015 print STDERR " no default!\n" if !$default && $Verbose >= 2; 3016 3017 $path = $self->catdir($rprefix, $default) if $default; 3018 } 3019 3020 print " now $path\n" if $Verbose >= 2; 3021 return $self->{uc $var} = $path; 3022} 3023 3024 3025=item processPL (o) 3026 3027Defines targets to run *.PL files. 3028 3029=cut 3030 3031sub processPL { 3032 my $self = shift; 3033 my $pl_files = $self->{PL_FILES}; 3034 3035 return "" unless $pl_files; 3036 3037 my $m = ''; 3038 foreach my $plfile (sort keys %$pl_files) { 3039 my $list = ref($pl_files->{$plfile}) 3040 ? $pl_files->{$plfile} 3041 : [$pl_files->{$plfile}]; 3042 3043 foreach my $target (@$list) { 3044 if( $Is{VMS} ) { 3045 $plfile = vmsify($self->eliminate_macros($plfile)); 3046 $target = vmsify($self->eliminate_macros($target)); 3047 } 3048 3049 # Normally a .PL file runs AFTER pm_to_blib so it can have 3050 # blib in its @INC and load the just built modules. BUT if 3051 # the generated module is something in $(TO_INST_PM) which 3052 # pm_to_blib depends on then it can't depend on pm_to_blib 3053 # else we have a dependency loop. 3054 my $pm_dep; 3055 my $perlrun; 3056 if( defined $self->{PM}{$target} ) { 3057 $pm_dep = ''; 3058 $perlrun = 'PERLRUN'; 3059 } 3060 else { 3061 $pm_dep = 'pm_to_blib'; 3062 $perlrun = 'PERLRUNINST'; 3063 } 3064 3065 $m .= <<MAKE_FRAG; 3066 3067all :: $target 3068 \$(NOECHO) \$(NOOP) 3069 3070$target :: $plfile $pm_dep 3071 \$($perlrun) $plfile $target 3072MAKE_FRAG 3073 3074 } 3075 } 3076 3077 return $m; 3078} 3079 3080=item quote_paren 3081 3082Backslashes parentheses C<()> in command line arguments. 3083Doesn't handle recursive Makefile C<$(...)> constructs, 3084but handles simple ones. 3085 3086=cut 3087 3088sub quote_paren { 3089 my $arg = shift; 3090 $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g; # protect $(...) 3091 $arg =~ s{(?<!\\)([()])}{\\$1}g; # quote unprotected 3092 $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g; # unprotect $(...) 3093 return $arg; 3094} 3095 3096=item replace_manpage_separator 3097 3098 my $man_name = $MM->replace_manpage_separator($file_path); 3099 3100Takes the name of a package, which may be a nested package, in the 3101form 'Foo/Bar.pm' and replaces the slash with C<::> or something else 3102safe for a man page file name. Returns the replacement. 3103 3104=cut 3105 3106sub replace_manpage_separator { 3107 my($self,$man) = @_; 3108 3109 $man =~ s,/+,::,g; 3110 return $man; 3111} 3112 3113 3114=item cd 3115 3116=cut 3117 3118sub cd { 3119 my($self, $dir, @cmds) = @_; 3120 3121 # No leading tab and no trailing newline makes for easier embedding 3122 my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds; 3123 3124 return $make_frag; 3125} 3126 3127=item oneliner 3128 3129=cut 3130 3131sub oneliner { 3132 my($self, $cmd, $switches) = @_; 3133 $switches = [] unless defined $switches; 3134 3135 # Strip leading and trailing newlines 3136 $cmd =~ s{^\n+}{}; 3137 $cmd =~ s{\n+$}{}; 3138 3139 my @cmds = split /\n/, $cmd; 3140 $cmd = join " \n\t -e ", map $self->quote_literal($_), @cmds; 3141 $cmd = $self->escape_newlines($cmd); 3142 3143 $switches = join ' ', @$switches; 3144 3145 return qq{\$(ABSPERLRUN) $switches -e $cmd --}; 3146} 3147 3148 3149=item quote_literal 3150 3151=cut 3152 3153sub quote_literal { 3154 my($self, $text, $opts) = @_; 3155 $opts->{allow_variables} = 1 unless defined $opts->{allow_variables}; 3156 3157 # Quote single quotes 3158 $text =~ s{'}{'\\''}g; 3159 3160 $text = $opts->{allow_variables} 3161 ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text); 3162 3163 return "'$text'"; 3164} 3165 3166 3167=item escape_newlines 3168 3169=cut 3170 3171sub escape_newlines { 3172 my($self, $text) = @_; 3173 3174 $text =~ s{\n}{\\\n}g; 3175 3176 return $text; 3177} 3178 3179 3180=item max_exec_len 3181 3182Using POSIX::ARG_MAX. Otherwise falling back to 4096. 3183 3184=cut 3185 3186sub max_exec_len { 3187 my $self = shift; 3188 3189 if (!defined $self->{_MAX_EXEC_LEN}) { 3190 if (my $arg_max = eval { require POSIX; &POSIX::ARG_MAX }) { 3191 $self->{_MAX_EXEC_LEN} = $arg_max; 3192 } 3193 else { # POSIX minimum exec size 3194 $self->{_MAX_EXEC_LEN} = 4096; 3195 } 3196 } 3197 3198 return $self->{_MAX_EXEC_LEN}; 3199} 3200 3201 3202=item static (o) 3203 3204Defines the static target. 3205 3206=cut 3207 3208sub static { 3209# --- Static Loading Sections --- 3210 3211 my($self) = shift; 3212 ' 3213## $(INST_PM) has been moved to the all: target. 3214## It remains here for awhile to allow for old usage: "make static" 3215static :: $(FIRST_MAKEFILE) $(INST_STATIC) 3216 $(NOECHO) $(NOOP) 3217'; 3218} 3219 3220=item static_lib (o) 3221 3222Defines how to produce the *.a (or equivalent) files. 3223 3224=cut 3225 3226sub static_lib { 3227 my($self) = @_; 3228 return '' unless $self->has_link_code; 3229 3230 my(@m); 3231 push(@m, <<'END'); 3232 3233$(INST_STATIC) : $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists 3234 $(RM_RF) $@ 3235END 3236 3237 # If this extension has its own library (eg SDBM_File) 3238 # then copy that to $(INST_STATIC) and add $(OBJECT) into it. 3239 push(@m, <<'MAKE_FRAG') if $self->{MYEXTLIB}; 3240 $(CP) $(MYEXTLIB) $@ 3241MAKE_FRAG 3242 3243 my $ar; 3244 if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) { 3245 # Prefer the absolute pathed ar if available so that PATH 3246 # doesn't confuse us. Perl itself is built with the full_ar. 3247 $ar = 'FULL_AR'; 3248 } else { 3249 $ar = 'AR'; 3250 } 3251 push @m, sprintf <<'MAKE_FRAG', $ar; 3252 $(%s) $(AR_STATIC_ARGS) $@ $(OBJECT) && $(RANLIB) $@ 3253 $(CHMOD) $(PERM_RWX) $@ 3254 $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld 3255MAKE_FRAG 3256 3257 # Old mechanism - still available: 3258 push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS}; 3259 $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs 3260MAKE_FRAG 3261 3262 join('', @m); 3263} 3264 3265=item staticmake (o) 3266 3267Calls makeaperl. 3268 3269=cut 3270 3271sub staticmake { 3272 my($self, %attribs) = @_; 3273 my(@static); 3274 3275 my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP}, $self->{INST_ARCHLIB}); 3276 3277 # And as it's not yet built, we add the current extension 3278 # but only if it has some C code (or XS code, which implies C code) 3279 if (@{$self->{C}}) { 3280 @static = $self->catfile($self->{INST_ARCHLIB}, 3281 "auto", 3282 $self->{FULLEXT}, 3283 "$self->{BASEEXT}$self->{LIB_EXT}" 3284 ); 3285 } 3286 3287 # Either we determine now, which libraries we will produce in the 3288 # subdirectories or we do it at runtime of the make. 3289 3290 # We could ask all subdir objects, but I cannot imagine, why it 3291 # would be necessary. 3292 3293 # Instead we determine all libraries for the new perl at 3294 # runtime. 3295 my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB}); 3296 3297 $self->makeaperl(MAKE => $self->{MAKEFILE}, 3298 DIRS => \@searchdirs, 3299 STAT => \@static, 3300 INCL => \@perlinc, 3301 TARGET => $self->{MAP_TARGET}, 3302 TMP => "", 3303 LIBPERL => $self->{LIBPERL_A} 3304 ); 3305} 3306 3307=item subdir_x (o) 3308 3309Helper subroutine for subdirs 3310 3311=cut 3312 3313sub subdir_x { 3314 my($self, $subdir) = @_; 3315 3316 my $subdir_cmd = $self->cd($subdir, 3317 '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)' 3318 ); 3319 return sprintf <<'EOT', $subdir_cmd; 3320 3321subdirs :: 3322 $(NOECHO) %s 3323EOT 3324 3325} 3326 3327=item subdirs (o) 3328 3329Defines targets to process subdirectories. 3330 3331=cut 3332 3333sub subdirs { 3334# --- Sub-directory Sections --- 3335 my($self) = shift; 3336 my(@m); 3337 # This method provides a mechanism to automatically deal with 3338 # subdirectories containing further Makefile.PL scripts. 3339 # It calls the subdir_x() method for each subdirectory. 3340 foreach my $dir (@{$self->{DIR}}){ 3341 push(@m, $self->subdir_x($dir)); 3342#### print "Including $dir subdirectory\n"; 3343 } 3344 if (@m){ 3345 unshift(@m, " 3346# The default clean, realclean and test targets in this Makefile 3347# have automatically been given entries for each subdir. 3348 3349"); 3350 } else { 3351 push(@m, "\n# none") 3352 } 3353 join('',@m); 3354} 3355 3356=item test (o) 3357 3358Defines the test targets. 3359 3360=cut 3361 3362sub test { 3363# --- Test and Installation Sections --- 3364 3365 my($self, %attribs) = @_; 3366 my $tests = $attribs{TESTS} || ''; 3367 if (!$tests && -d 't') { 3368 $tests = $self->find_tests; 3369 } 3370 # note: 'test.pl' name is also hardcoded in init_dirscan() 3371 my(@m); 3372 push(@m," 3373TEST_VERBOSE=0 3374TEST_TYPE=test_\$(LINKTYPE) 3375TEST_FILE = test.pl 3376TEST_FILES = $tests 3377TESTDB_SW = -d 3378 3379testdb :: testdb_\$(LINKTYPE) 3380 3381test :: \$(TEST_TYPE) subdirs-test 3382 3383subdirs-test :: 3384 \$(NOECHO) \$(NOOP) 3385 3386"); 3387 3388 foreach my $dir (@{ $self->{DIR} }) { 3389 my $test = $self->cd($dir, '$(MAKE) test $(PASTHRU)'); 3390 3391 push @m, <<END 3392subdirs-test :: 3393 \$(NOECHO) $test 3394 3395END 3396 } 3397 3398 push(@m, "\t\$(NOECHO) \$(ECHO) 'No tests defined for \$(NAME) extension.'\n") 3399 unless $tests or -f "test.pl" or @{$self->{DIR}}; 3400 push(@m, "\n"); 3401 3402 push(@m, "test_dynamic :: pure_all\n"); 3403 push(@m, $self->test_via_harness('$(FULLPERLRUN)', '$(TEST_FILES)')) 3404 if $tests; 3405 push(@m, $self->test_via_script('$(FULLPERLRUN)', '$(TEST_FILE)')) 3406 if -f "test.pl"; 3407 push(@m, "\n"); 3408 3409 push(@m, "testdb_dynamic :: pure_all\n"); 3410 push(@m, $self->test_via_script('$(FULLPERLRUN) $(TESTDB_SW)', 3411 '$(TEST_FILE)')); 3412 push(@m, "\n"); 3413 3414 # Occasionally we may face this degenerate target: 3415 push @m, "test_ : test_dynamic\n\n"; 3416 3417 if ($self->needs_linking()) { 3418 push(@m, "test_static :: pure_all \$(MAP_TARGET)\n"); 3419 push(@m, $self->test_via_harness('./$(MAP_TARGET)', '$(TEST_FILES)')) if $tests; 3420 push(@m, $self->test_via_script('./$(MAP_TARGET)', '$(TEST_FILE)')) if -f "test.pl"; 3421 push(@m, "\n"); 3422 push(@m, "testdb_static :: pure_all \$(MAP_TARGET)\n"); 3423 push(@m, $self->test_via_script('./$(MAP_TARGET) $(TESTDB_SW)', '$(TEST_FILE)')); 3424 push(@m, "\n"); 3425 } else { 3426 push @m, "test_static :: test_dynamic\n"; 3427 push @m, "testdb_static :: testdb_dynamic\n"; 3428 } 3429 join("", @m); 3430} 3431 3432=item test_via_harness (override) 3433 3434For some reason which I forget, Unix machines like to have 3435PERL_DL_NONLAZY set for tests. 3436 3437=cut 3438 3439sub test_via_harness { 3440 my($self, $perl, $tests) = @_; 3441 return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests); 3442} 3443 3444=item test_via_script (override) 3445 3446Again, the PERL_DL_NONLAZY thing. 3447 3448=cut 3449 3450sub test_via_script { 3451 my($self, $perl, $script) = @_; 3452 return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script); 3453} 3454 3455 3456=item tool_xsubpp (o) 3457 3458Determines typemaps, xsubpp version, prototype behaviour. 3459 3460=cut 3461 3462sub tool_xsubpp { 3463 my($self) = shift; 3464 return "" unless $self->needs_linking; 3465 3466 my $xsdir; 3467 my @xsubpp_dirs = @INC; 3468 3469 # Make sure we pick up the new xsubpp if we're building perl. 3470 unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE}; 3471 3472 foreach my $dir (@xsubpp_dirs) { 3473 $xsdir = $self->catdir($dir, 'ExtUtils'); 3474 if( -r $self->catfile($xsdir, "xsubpp") ) { 3475 last; 3476 } 3477 } 3478 3479 my $tmdir = File::Spec->catdir($self->{PERL_LIB},"ExtUtils"); 3480 my(@tmdeps) = $self->catfile($tmdir,'typemap'); 3481 if( $self->{TYPEMAPS} ){ 3482 foreach my $typemap (@{$self->{TYPEMAPS}}){ 3483 if( ! -f $typemap ) { 3484 warn "Typemap $typemap not found.\n"; 3485 } 3486 else { 3487 push(@tmdeps, $typemap); 3488 } 3489 } 3490 } 3491 push(@tmdeps, "typemap") if -f "typemap"; 3492 my(@tmargs) = map("-typemap $_", @tmdeps); 3493 if( exists $self->{XSOPT} ){ 3494 unshift( @tmargs, $self->{XSOPT} ); 3495 } 3496 3497 if ($Is{VMS} && 3498 $Config{'ldflags'} && 3499 $Config{'ldflags'} =~ m!/Debug!i && 3500 (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/) 3501 ) 3502 { 3503 unshift(@tmargs,'-nolinenumbers'); 3504 } 3505 3506 3507 $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG}; 3508 3509 return qq{ 3510XSUBPPDIR = $xsdir 3511XSUBPP = \$(XSUBPPDIR)\$(DFSEP)xsubpp 3512XSUBPPRUN = \$(PERLRUN) \$(XSUBPP) 3513XSPROTOARG = $self->{XSPROTOARG} 3514XSUBPPDEPS = @tmdeps \$(XSUBPP) 3515XSUBPPARGS = @tmargs 3516XSUBPP_EXTRA_ARGS = 3517}; 3518}; 3519 3520 3521=item all_target 3522 3523Build man pages, too 3524 3525=cut 3526 3527sub all_target { 3528 my $self = shift; 3529 3530 return <<'MAKE_EXT'; 3531all :: pure_all manifypods 3532 $(NOECHO) $(NOOP) 3533MAKE_EXT 3534} 3535 3536=item top_targets (o) 3537 3538Defines the targets all, subdirs, config, and O_FILES 3539 3540=cut 3541 3542sub top_targets { 3543# --- Target Sections --- 3544 3545 my($self) = shift; 3546 my(@m); 3547 3548 push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'}; 3549 3550 push @m, ' 3551pure_all :: config pm_to_blib subdirs linkext 3552 $(NOECHO) $(NOOP) 3553 3554subdirs :: $(MYEXTLIB) 3555 $(NOECHO) $(NOOP) 3556 3557config :: $(FIRST_MAKEFILE) blibdirs 3558 $(NOECHO) $(NOOP) 3559'; 3560 3561 push @m, ' 3562$(O_FILES): $(H_FILES) 3563' if @{$self->{O_FILES} || []} && @{$self->{H} || []}; 3564 3565 push @m, q{ 3566help : 3567 perldoc ExtUtils::MakeMaker 3568}; 3569 3570 join('',@m); 3571} 3572 3573=item writedoc 3574 3575Obsolete, deprecated method. Not used since Version 5.21. 3576 3577=cut 3578 3579sub writedoc { 3580# --- perllocal.pod section --- 3581 my($self,$what,$name,@attribs)=@_; 3582 my $time = localtime; 3583 print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n"; 3584 print join "\n\n=item *\n\n", map("C<$_>",@attribs); 3585 print "\n\n=back\n\n"; 3586} 3587 3588=item xs_c (o) 3589 3590Defines the suffix rules to compile XS files to C. 3591 3592=cut 3593 3594sub xs_c { 3595 my($self) = shift; 3596 return '' unless $self->needs_linking(); 3597 ' 3598.xs.c: 3599 $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c 3600'; 3601} 3602 3603=item xs_cpp (o) 3604 3605Defines the suffix rules to compile XS files to C++. 3606 3607=cut 3608 3609sub xs_cpp { 3610 my($self) = shift; 3611 return '' unless $self->needs_linking(); 3612 ' 3613.xs.cpp: 3614 $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.cpp 3615'; 3616} 3617 3618=item xs_o (o) 3619 3620Defines suffix rules to go from XS to object files directly. This is 3621only intended for broken make implementations. 3622 3623=cut 3624 3625sub xs_o { # many makes are too dumb to use xs_c then c_o 3626 my($self) = shift; 3627 return '' unless $self->needs_linking(); 3628 ' 3629.xs$(OBJ_EXT): 3630 $(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc && $(MV) $*.xsc $*.c 3631 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c 3632'; 3633} 3634 3635 36361; 3637 3638=back 3639 3640=head1 SEE ALSO 3641 3642L<ExtUtils::MakeMaker> 3643 3644=cut 3645 3646__END__ 3647