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