📄 makemaker.pm
字号:
# standard, we try to enable the next line again. It was # commented out until MM 5.23 next unless defined &{"${from}::$method"}; *{"${to}::$method"} = \&{"${from}::$method"}; # delete would do, if we were sure, nobody ever called # MY->makeaperl directly # delete $symtab->{$method}; # If we delete a method, then it will be undefined and cannot # be called. But as long as we have Makefile.PLs that rely on # %MY:: being intact, we have to fill the hole with an # inheriting method: eval "package MY; sub $method { shift->SUPER::$method(\@_); }"; } # We have to clean out %INC also, because the current directory is # changed frequently and Graham Barr prefers to get his version # out of a History.pl file which is "required" so woudn't get # loaded again in another extension requiring a History.pl # With perl5.002_01 the deletion of entries in %INC caused Tk-b11 # to core dump in the middle of a require statement. The required # file was Tk/MMutil.pm. The consequence is, we have to be # extremely careful when we try to give perl a reason to reload a # library with same name. The workaround prefers to drop nothing # from %INC and teach the writers not to use such libraries.# my $inc;# foreach $inc (keys %INC) {# #warn "***$inc*** deleted";# delete $INC{$inc};# }}sub skipcheck { my($self) = shift; my($section) = @_; if ($section eq 'dynamic') { print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets ", "in skipped section 'dynamic_bs'\n" if $self->{SKIPHASH}{dynamic_bs} && $Verbose; print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets ", "in skipped section 'dynamic_lib'\n" if $self->{SKIPHASH}{dynamic_lib} && $Verbose; } if ($section eq 'dynamic_lib') { print STDOUT "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on ", "targets in skipped section 'dynamic_bs'\n" if $self->{SKIPHASH}{dynamic_bs} && $Verbose; } if ($section eq 'static') { print STDOUT "Warning (non-fatal): Target 'static' depends on targets ", "in skipped section 'static_lib'\n" if $self->{SKIPHASH}{static_lib} && $Verbose; } return 'skipped' if $self->{SKIPHASH}{$section}; return '';}sub flush { my $self = shift; my($chunk); local *FH; my $finalname = $self->{MAKEFILE}; print STDOUT "Writing $finalname for $self->{NAME}\n"; unlink($finalname, "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : ()); open(FH,">MakeMaker.tmp") or die "Unable to open MakeMaker.tmp: $!"; for $chunk (@{$self->{RESULT}}) { print FH "$chunk\n"; } close FH; _rename("MakeMaker.tmp", $finalname) or warn "rename MakeMaker.tmp => $finalname: $!"; chmod 0644, $finalname unless $Is_VMS; my %keep = map { ($_ => 1) } qw(NEEDS_LINKING HAS_LINK_CODE); if ($self->{PARENT} && !$self->{_KEEP_AFTER_FLUSH}) { foreach (keys %$self) { # safe memory delete $self->{$_} unless $keep{$_}; } } system("$Config::Config{eunicefix} $finalname") unless $Config::Config{eunicefix} eq ":";}# This is a rename for OS's where the target must be unlinked first.sub _rename { my($src, $dest) = @_; chmod 0666, $dest; unlink $dest; return rename $src, $dest;}# This is an unlink for OS's where the target must be writable first.sub _unlink { my @files = @_; chmod 0666, @files; return unlink @files;}# The following mkbootstrap() is only for installations that are calling# the pre-4.1 mkbootstrap() from their old Makefiles. This MakeMaker# writes Makefiles, that use ExtUtils::Mkbootstrap directly.sub mkbootstrap { die <<END;!!! Your Makefile has been built such a long time ago, !!!!!! that is unlikely to work with current MakeMaker. !!!!!! Please rebuild your Makefile !!!END}# Ditto for mksymlists() as of MakeMaker 5.17sub mksymlists { die <<END;!!! Your Makefile has been built such a long time ago, !!!!!! that is unlikely to work with current MakeMaker. !!!!!! Please rebuild your Makefile !!!END}sub neatvalue { my($v) = @_; return "undef" unless defined $v; my($t) = ref $v; return "q[$v]" unless $t; if ($t eq 'ARRAY') { my(@m, @neat); push @m, "["; foreach my $elem (@$v) { push @neat, "q[$elem]"; } push @m, join ", ", @neat; push @m, "]"; return join "", @m; } return "$v" unless $t eq 'HASH'; my(@m, $key, $val); while (($key,$val) = each %$v){ last unless defined $key; # cautious programming in case (undef,undef) is true push(@m,"$key=>".neatvalue($val)) ; } return "{ ".join(', ',@m)." }";}sub selfdocument { my($self) = @_; my(@m); if ($Verbose){ push @m, "\n# Full list of MakeMaker attribute values:"; foreach my $key (sort keys %$self){ next if $key eq 'RESULT' || $key =~ /^[A-Z][a-z]/; my($v) = neatvalue($self->{$key}); $v =~ s/(CODE|HASH|ARRAY|SCALAR)\([\dxa-f]+\)/$1\(...\)/; $v =~ tr/\n/ /s; push @m, "# $key => $v"; } } join "\n", @m;}1;__END__=head1 NAMEExtUtils::MakeMaker - Create a module Makefile=head1 SYNOPSIS use ExtUtils::MakeMaker; WriteMakefile( ATTRIBUTE => VALUE [, ...] );=head1 DESCRIPTIONThis utility is designed to write a Makefile for an extension modulefrom a Makefile.PL. It is based on the Makefile.SH model provided byAndy Dougherty and the perl5-porters.It splits the task of generating the Makefile into several subroutinesthat can be individually overridden. Each subroutine returns the textit wishes to have written to the Makefile.MakeMaker is object oriented. Each directory below the currentdirectory that contains a Makefile.PL is treated as a separateobject. This makes it possible to write an unlimited number ofMakefiles with a single invocation of WriteMakefile().=head2 How To Write A Makefile.PLSee ExtUtils::MakeMaker::Tutorial.The long answer is the rest of the manpage :-)=head2 Default Makefile BehaviourThe generated Makefile enables the user of the extension to invoke perl Makefile.PL # optionally "perl Makefile.PL verbose" make make test # optionally set TEST_VERBOSE=1 make install # See belowThe Makefile to be produced may be altered by adding arguments of theform C<KEY=VALUE>. E.g. perl Makefile.PL INSTALL_BASE=~Other interesting targets in the generated Makefile are make config # to check if the Makefile is up-to-date make clean # delete local temp files (Makefile gets renamed) make realclean # delete derived files (including ./blib) make ci # check in all the files in the MANIFEST file make dist # see below the Distribution Support section=head2 make testMakeMaker checks for the existence of a file named F<test.pl> in thecurrent directory and if it exists it execute the script with theproper set of perl C<-I> options.MakeMaker also checks for any files matching glob("t/*.t"). It willexecute all matching files in alphabetical order via theL<Test::Harness> module with the C<-I> switches set correctly.If you'd like to see the raw output of your tests, set theC<TEST_VERBOSE> variable to true. make test TEST_VERBOSE=1=head2 make testdbA useful variation of the above is the target C<testdb>. It runs thetest under the Perl debugger (see L<perldebug>). If the fileF<test.pl> exists in the current directory, it is used for the test.If you want to debug some other testfile, set the C<TEST_FILE> variablethusly: make testdb TEST_FILE=t/mytest.tBy default the debugger is called using C<-d> option to perl. If youwant to specify some other option, set the C<TESTDB_SW> variable: make testdb TESTDB_SW=-Dx=head2 make installmake alone puts all relevant files into directories that are named bythe macros INST_LIB, INST_ARCHLIB, INST_SCRIPT, INST_MAN1DIR andINST_MAN3DIR. All these default to something below ./blib if you areI<not> building below the perl source directory. If you I<are>building below the perl source, INST_LIB and INST_ARCHLIB default to../../lib, and INST_SCRIPT is not defined.The I<install> target of the generated Makefile copies the files foundbelow each of the INST_* directories to their INSTALL*counterparts. Which counterparts are chosen depends on the setting ofINSTALLDIRS according to the following table: INSTALLDIRS set to perl site vendor PERLPREFIX SITEPREFIX VENDORPREFIX INST_ARCHLIB INSTALLARCHLIB INSTALLSITEARCH INSTALLVENDORARCH INST_LIB INSTALLPRIVLIB INSTALLSITELIB INSTALLVENDORLIB INST_BIN INSTALLBIN INSTALLSITEBIN INSTALLVENDORBIN INST_SCRIPT INSTALLSCRIPT INSTALLSITESCRIPT INSTALLVENDORSCRIPT INST_MAN1DIR INSTALLMAN1DIR INSTALLSITEMAN1DIR INSTALLVENDORMAN1DIR INST_MAN3DIR INSTALLMAN3DIR INSTALLSITEMAN3DIR INSTALLVENDORMAN3DIRThe INSTALL... macros in turn default to their %Config($Config{installprivlib}, $Config{installarchlib}, etc.) counterparts.You can check the values of these variables on your system with perl '-V:install.*'And to check the sequence in which the library directories aresearched by perl, run perl -le 'print join $/, @INC'Sometimes older versions of the module you're installing live in otherdirectories in @INC. Because Perl loads the first version of a module it finds, not the newest, you might accidentally get one of these olderversions even after installing a brand new version. To delete I<all otherversions of the module you're installing> (not simply older ones) set theC<UNINST> variable. make install UNINST=1=head2 INSTALL_BASEINSTALL_BASE can be passed into Makefile.PL to change where yourmodule will be installed. INSTALL_BASE is more like what everyoneelse calls "prefix" than PREFIX is.To have everything installed in your home directory, do the following. # Unix users, INSTALL_BASE=~ works fine perl Makefile.PL INSTALL_BASE=/path/to/your/home/dirLike PREFIX, it sets several INSTALL* attributes at once. UnlikePREFIX it is easy to predict where the module will end up. Theinstallation pattern looks like this: INSTALLARCHLIB INSTALL_BASE/lib/perl5/$Config{archname} INSTALLPRIVLIB INSTALL_BASE/lib/perl5 INSTALLBIN INSTALL_BASE/bin INSTALLSCRIPT INSTALL_BASE/bin INSTALLMAN1DIR INSTALL_BASE/man/man1 INSTALLMAN3DIR INSTALL_BASE/man/man3INSTALL_BASE in MakeMaker and C<--install_base> in Module::Build (asof 0.28) install to the same location. If you want MakeMaker andModule::Build to install to the same location simply set INSTALL_BASEand C<--install_base> to the same location.INSTALL_BASE was added in 6.31.=head2 PREFIX and LIB attributePREFIX and LIB can be used to set several INSTALL* attributes in onego. Here's an example for installing into your home directory. # Unix users, PREFIX=~ works fine perl Makefile.PL PREFIX=/path/to/your/home/dirThis will install all files in the module under your home directory,with man pages and libraries going into an appropriate place (usually~/man and ~/lib). How the exact location is determined is complicatedand depends on how your Perl was configured. INSTALL_BASE works morelike what other build systems call "prefix" than PREFIX and werecommend you use that instead.Another way to specify many INSTALL directories with a singleparameter is LIB. perl Makefile.PL LIB=~/libThis will install the module's architecture-independent files into~/lib, the architecture-dependent files into ~/lib/$archname.Note, that in both cases the tilde expansion is done by MakeMaker, notby perl by default, nor by make.Conflicts between parameters LIB, PREFIX and the various INSTALL*arguments are resolved so that:=over 4=item *setting LIB overrides any setting of INSTALLPRIVLIB, INSTALLARCHLIB,INSTALLSITELIB, INSTALLSITEARCH (and they are not affected by PREFIX);=item *without LIB, setting PREFIX replaces the initial C<$Config{prefix}>part of those INSTALL* arguments, even if the latter are explicitlyset (but are set to still start with C<$Config{prefix}>).=backIf the user has superuser privileges, and is not working on AFS orrelatives, then the defaults for INSTALLPRIVLIB, INSTALLARCHLIB,INSTALLSCRIPT, etc. will be appropriate, and this incantation will bethe best: perl Makefile.PL; make; make test make installmake install per default writes some documentation of what has beendone into the file C<$(INSTALLARCHLIB)/perllocal.pod>. This featurecan be bypassed by calling make pure_install.=head2 AFS userswill have to specify the installation directories as these mostprobably have changed since perl itself has been installed. They willhave to do this by calling perl Makefile.PL INSTALLSITELIB=/afs/here/today \ INSTALLSCRIPT=/afs/there/now INSTALLMAN3DIR=/afs/for/manpages makeBe careful to repeat this procedure every time you recompile anextension, unless you are sure the AFS installation directories arestill valid.=head2 Static Linking of a new Perl BinaryAn extension that is built with the above steps is ready to use onsystems supporting dynamic loading. On systems that do not supportdynamic loading, any newly created extension has to be linked togetherwith the available resources. MakeMaker supports the linking processby creating appropriate targets in the Makefile whenever an extensionis built. You can invoke the corresponding section of the makefile with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -