📄 makemaker.pm
字号:
=head1 NAMEExtUtils::MakeMaker - create an extension Makefile=head1 SYNOPSISC<use ExtUtils::MakeMaker;>C<WriteMakefile( ATTRIBUTE =E<gt> VALUE [, ...] );>which is reallyC<MM-E<gt>new(\%att)-E<gt>flush;>=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.PLThe short answer is: Don't. Always begin with h2xs. Always begin with h2xs! ALWAYS BEGIN WITH H2XS!even if you're not building around a header file, and even if youdon't have an XS component.Run h2xs(1) before you start thinking about writing a module. For socalled pm-only modules that consist of C<*.pm> files only, h2xs hasthe C<-X> switch. This will generate dummy files of all kinds that areuseful for the module developer.The medium answer is: use ExtUtils::MakeMaker; WriteMakefile( NAME => "Foo::Bar" );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 PREFIX=/tmp/myperl5Other 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 adds commands to the test targetof the generated Makefile that will execute the script with the properset of perl C<-I> options.MakeMaker also checks for any files matching glob("t/*.t"). It willadd commands to the test target of the generated Makefile that executeall matching files via the L<Test::Harness> module with the C<-I>switches set correctly.=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 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 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_HTMLLIBDIR,INST_HTMLSCRIPTDIR, INST_MAN1DIR, and INST_MAN3DIR. All these defaultto something below ./blib if you are I<not> building below the perlsource directory. If you I<are> building below the perl source,INST_LIB and INST_ARCHLIB default to ../../lib, and INST_SCRIPT is notdefined.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 INST_ARCHLIB INSTALLARCHLIB INSTALLSITEARCH INST_LIB INSTALLPRIVLIB INSTALLSITELIB INST_HTMLLIBDIR INSTALLHTMLPRIVLIBDIR INSTALLHTMLSITELIBDIR INST_HTMLSCRIPTDIR INSTALLHTMLSCRIPTDIR INST_BIN INSTALLBIN INST_SCRIPT INSTALLSCRIPT INST_MAN1DIR INSTALLMAN1DIR INST_MAN3DIR INSTALLMAN3DIRThe 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'=head2 PREFIX and LIB attributePREFIX and LIB can be used to set several INSTALL* attributes in onego. The quickest way to install a module in a non-standard place mightbe perl Makefile.PL LIB=~/libThis will install the module's architecture-independent files into~/lib, the architecture-dependent files into ~/lib/$archname.Another way to specify many INSTALL directories with a singleparameter is PREFIX. perl Makefile.PL PREFIX=~This will replace the string specified by C<$Config{prefix}> in allC<$Config{install*}> values.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 AFSor relatives, then the defaults forINSTALLPRIVLIB, INSTALLARCHLIB, INSTALLSCRIPT, etc. will be appropriate,and this incantation will be the 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 make perlThat produces a new perl binary in the current directory with allextensions linked in that can be found in INST_ARCHLIB , SITELIBEXP,and PERL_ARCHLIB. To do that, MakeMaker writes a new Makefile, onUNIX, this is called Makefile.aperl (may be system dependent). If youwant to force the creation of a new perl, it is recommended, that youdelete this Makefile.aperl, so the directories are searched-throughfor linkable libraries again.The binary can be installed into the directory where perl normallyresides on your machine with make inst_perlTo produce a perl binary with a different name than C<perl>, either say perl Makefile.PL MAP_TARGET=myperl make myperl make inst_perlor say perl Makefile.PL make myperl MAP_TARGET=myperl make inst_perl MAP_TARGET=myperlIn any case you will be prompted with the correct invocation of theC<inst_perl> target that installs the new binary into INSTALLBIN.make inst_perl per default writes some documentation of what has beendone into the file C<$(INSTALLARCHLIB)/perllocal.pod>. Thiscan be bypassed by calling make pure_inst_perl.Warning: the inst_perl: target will most probably overwrite yourexisting perl binary. Use with care!Sometimes you might want to build a statically linked perl althoughyour system supports dynamic loading. In this case you may explicitlyset the linktype with the invocation of the Makefile.PL or make: perl Makefile.PL LINKTYPE=static # recommendedor make LINKTYPE=static # works on most systems=head2 Determination of Perl Library and Installation LocationsMakeMaker needs to know, or to guess, where certain things arelocated. Especially INST_LIB and INST_ARCHLIB (where to put the filesduring the make(1) run), PERL_LIB and PERL_ARCHLIB (where to readexisting modules from), and PERL_INC (header files and C<libperl*.*>).Extensions may be built either using the contents of the perl sourcedirectory tree or from the installed perl library. The recommended wayis to build extensions after you have run 'make install' on perlitself. You can do that in any directory on your hard disk that is notbelow the perl source tree. The support for extensions below the extdirectory of the perl distribution is only good for the standardextensions that come with perl.If an extension is being built below the C<ext/> directory of the perlsource then MakeMaker will set PERL_SRC automatically (e.g.,C<../..>). If PERL_SRC is defined and the extension is recognized asa standard extension, then other variables default to the following: PERL_INC = PERL_SRC PERL_LIB = PERL_SRC/lib PERL_ARCHLIB = PERL_SRC/lib INST_LIB = PERL_LIB INST_ARCHLIB = PERL_ARCHLIBIf an extension is being built away from the perl source then MakeMakerwill leave PERL_SRC undefined and default to using the installed copyof the perl library. The other variables default to the following: PERL_INC = $archlibexp/CORE PERL_LIB = $privlibexp PERL_ARCHLIB = $archlibexp INST_LIB = ./blib/lib INST_ARCHLIB = ./blib/archIf perl has not yet been installed then PERL_SRC can be defined on thecommand line as shown in the previous section.=head2 Which architecture dependent directory?If you don't want to keep the defaults for the INSTALL* macros,MakeMaker helps you to minimize the typing needed: the usualrelationship between INSTALLPRIVLIB and INSTALLARCHLIB is determinedby Configure at perl compilation time. MakeMaker supports the user whosets INSTALLPRIVLIB. If INSTALLPRIVLIB is set, but INSTALLARCHLIB not,then MakeMaker defaults the latter to be the same subdirectory ofINSTALLPRIVLIB as Configure decided for the counterparts in %Config ,otherwise it defaults to INSTALLPRIVLIB. The same relationship holdsfor INSTALLSITELIB and INSTALLSITEARCH.MakeMaker gives you much more freedom than needed to configureinternal variables and get different results. It is worth to mention,that make(1) also lets you configure most of the variables that areused in the Makefile. But in the majority of situations this will notbe necessary, and should only be done if the author of a packagerecommends it (or you know what you're doing).=head2 Using Attributes and ParametersThe following attributes can be specified as arguments to WriteMakefile()or as NAME=VALUE pairs on the command line:=over 2=item ABSTRACTOne line description of the module. Will be included in PPD file.=item ABSTRACT_FROMName of the file that contains the package description. MakeMaker looksfor a line in the POD matching /^($package\s-\s)(.*)/. This is typicallythe first line in the "=head1 NAME" section. $2 becomes the abstract.=item AUTHORString containing name (and email address) of package author(s). Is usedin PPD (Perl Package Description) files for PPM (Perl Package Manager).=item BINARY_LOCATIONUsed when creating PPD files for binary packages. It can be set to afull or relative path or URL to the binary archive for a particulararchitecture. For example: perl Makefile.PL BINARY_LOCATION=x86/Agent.tar.gzbuilds a PPD package that references a binary of the C<Agent> package,located in the C<x86> directory relative to the PPD itself.=item CRef to array of *.c file names. Initialised from a directory scanand the values portion of the XS attribute hash. This is notcurrently used by MakeMaker but may be handy in Makefile.PLs.=item CAPI[This attribute is obsolete in Perl 5.6. PERL_OBJECT builds are C-compatibleby default.]Switch to force usage of the Perl C API even when compiling for PERL_OBJECT.Note that this attribute is passed through to any recursive build,but if and only if the submodule's Makefile.PL itself makes no mentionof the 'CAPI' attribute.=item CCFLAGSString that will be included in the compiler call command line betweenthe arguments INC and OPTIMIZE.=item CONFIGArrayref. E.g. [qw(archname manext)] defines ARCHNAME & MANEXT fromconfig.sh. MakeMaker will add to CONFIG the following values anyway:arcccccdlflagsccdlflagsdlextdlsrcldlddlflagsldflagslibclib_extobj_extranlibsitelibexpsitearchexpso=item CONFIGURECODE reference. The subroutine should return a hash reference. Thehash may contain further attributes, e.g. {LIBS =E<gt> ...}, that have tobe determined by some evaluation method.=item DEFINESomething like C<"-DHAVE_UNISTD_H">=item DIRRef to array of subdirectories containing Makefile.PLs e.g. [ 'sdbm'] in ext/SDBM_File=item DISTNAMEYour name for distributing the package (by tar file). This defaults toNAME above.=item DL_FUNCS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -