makemaker.html

来自「perl教程」· HTML 代码 · 共 1,694 行 · 第 1/5 页

HTML
1,694
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>ExtUtils::MakeMaker - Create a module Makefile</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>ExtUtils::MakeMaker - Create a module Makefile</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<ul>

		<li><a href="#how_to_write_a_makefile_pl">How To Write A Makefile.PL</a></li>
		<li><a href="#default_makefile_behaviour">Default Makefile Behaviour</a></li>
		<li><a href="#make_test">make test</a></li>
		<li><a href="#make_testdb">make testdb</a></li>
		<li><a href="#make_install">make install</a></li>
		<li><a href="#prefix_and_lib_attribute">PREFIX and LIB attribute</a></li>
		<li><a href="#afs_users">AFS users</a></li>
		<li><a href="#static_linking_of_a_new_perl_binary">Static Linking of a new Perl Binary</a></li>
		<li><a href="#determination_of_perl_library_and_installation_locations">Determination of Perl Library and Installation Locations</a></li>
		<li><a href="#which_architecture_dependent_directory">Which architecture dependent directory?</a></li>
		<li><a href="#using_attributes_and_parameters">Using Attributes and Parameters</a></li>
		<li><a href="#additional_lowercase_attributes">Additional lowercase attributes</a></li>
		<li><a href="#overriding_makemaker_methods">Overriding MakeMaker Methods</a></li>
		<li><a href="#the_end_of_cargo_cult_programming">The End Of Cargo Cult Programming</a></li>
		<li><a href="#hintsfile_support">Hintsfile support</a></li>
		<li><a href="#distribution_support">Distribution Support</a></li>
		<li><a href="#module_metadata">Module Meta-Data</a></li>
		<li><a href="#disabling_an_extension">Disabling an extension</a></li>
		<li><a href="#other_handy_functions">Other Handy Functions</a></li>
	</ul>

	<li><a href="#environment">ENVIRONMENT</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
	<li><a href="#authors">AUTHORS</a></li>
	<li><a href="#license">LICENSE</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>ExtUtils::MakeMaker - Create a module Makefile</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
  <span class="keyword">use</span> <span class="variable">ExtUtils::MakeMaker</span><span class="operator">;</span>
</pre>
<pre>
  <span class="variable">WriteMakefile</span><span class="operator">(</span> <span class="string">ATTRIBUTE</span> <span class="operator">=&gt;</span> <span class="variable">VALUE</span> <span class="operator">[</span><span class="operator">,</span> <span class="operator">...</span><span class="operator">]</span> <span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This utility is designed to write a Makefile for an extension module
from a Makefile.PL. It is based on the Makefile.SH model provided by
Andy Dougherty and the perl5-porters.</p>
<p>It splits the task of generating the Makefile into several subroutines
that can be individually overridden.  Each subroutine returns the text
it wishes to have written to the Makefile.</p>
<p>MakeMaker is object oriented. Each directory below the current
directory that contains a Makefile.PL is treated as a separate
object. This makes it possible to write an unlimited number of
Makefiles with a single invocation of WriteMakefile().</p>
<p>
</p>
<h2><a name="how_to_write_a_makefile_pl">How To Write A Makefile.PL</a></h2>
<p>See ExtUtils::MakeMaker::Tutorial.</p>
<p>The long answer is the rest of the manpage :-)</p>
<p>
</p>
<h2><a name="default_makefile_behaviour">Default Makefile Behaviour</a></h2>
<p>The generated Makefile enables the user of the extension to invoke</p>
<pre>
  perl Makefile.PL # optionally &quot;perl Makefile.PL verbose&quot;
  make
  make test        # optionally set TEST_VERBOSE=1
  make install     # See below</pre>
<p>The Makefile to be produced may be altered by adding arguments of the
form <code>KEY=VALUE</code>. E.g.</p>
<pre>
  perl Makefile.PL PREFIX=~</pre>
<p>Other interesting targets in the generated Makefile are</p>
<pre>
  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</pre>
<p>
</p>
<h2><a name="make_test">make test</a></h2>
<p>MakeMaker checks for the existence of a file named <em>test.pl</em> in the
current directory and if it exists it execute the script with the
proper set of perl <code>-I</code> options.</p>
<p>MakeMaker also checks for any files matching glob(&quot;t/*.t&quot;). It will
execute all matching files in alphabetical order via the
<a href="../../lib/Test/Harness.html">the Test::Harness manpage</a> module with the <code>-I</code> switches set correctly.</p>
<p>If you'd like to see the raw output of your tests, set the
<code>TEST_VERBOSE</code> variable to true.</p>
<pre>
  make test TEST_VERBOSE=1</pre>
<p>
</p>
<h2><a name="make_testdb">make testdb</a></h2>
<p>A useful variation of the above is the target <code>testdb</code>. It runs the
test under the Perl debugger (see <a href="../../lib/Pod/perldebug.html">the perldebug manpage</a>). If the file
<em>test.pl</em> exists in the current directory, it is used for the test.</p>
<p>If you want to debug some other testfile, set the <code>TEST_FILE</code> variable
thusly:</p>
<pre>
  make testdb TEST_FILE=t/mytest.t</pre>
<p>By default the debugger is called using <a href="../../lib/Pod/perlrun.html#item__2dd"><code>-d</code></a> option to perl. If you
want to specify some other option, set the <code>TESTDB_SW</code> variable:</p>
<pre>
  make testdb TESTDB_SW=-Dx</pre>
<p>
</p>
<h2><a name="make_install">make install</a></h2>
<p>make alone puts all relevant files into directories that are named by
the macros INST_LIB, INST_ARCHLIB, INST_SCRIPT, INST_MAN1DIR, INST_MAN3DIR
INST_HTMLDIR.  All these default to something below ./blib if you are
<em>not</em> building below the perl source directory. If you <em>are</em>
building below the perl source, INST_LIB and INST_ARCHLIB default to
../../lib, and INST_SCRIPT is not defined.</p>
<p>The <em>install</em> target of the generated Makefile copies the files found
below each of the INST_* directories to their INSTALL*
counterparts. Which counterparts are chosen depends on the setting of
INSTALLDIRS according to the following table:</p>
<pre>
                                 INSTALLDIRS set to
                           perl        site          vendor</pre>
<pre>
                 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  INSTALLVENDORMAN3DIR
  INST_HTMLDIR   INSTALLHTMLDIR  INSTALLSITEHTMLDIR  INSTALLVENDORHTMLDIR</pre>
<p>The INSTALL... macros in turn default to their %Config
($Config{installprivlib}, $Config{installarchlib}, etc.) counterparts.</p>
<p>You can check the values of these variables on your system with</p>
<pre>
    perl '-V:install.*'</pre>
<p>And to check the sequence in which the library directories are
searched by perl, run</p>
<pre>
    perl -le 'print join $/, @INC'</pre>
<p>Sometimes older versions of the module you're installing live in other
directories in @INC.  Because Perl loads the first version of a module it 
finds, not the newest, you might accidentally get one of these older
versions even after installing a brand new version.  To delete <em>all other
versions of the module you're installing</em> (not simply older ones) set the
<code>UNINST</code> variable.</p>
<pre>
    make install UNINST=1</pre>
<p>
</p>
<h2><a name="prefix_and_lib_attribute">PREFIX and LIB attribute</a></h2>
<p>PREFIX and LIB can be used to set several INSTALL* attributes in one
go. The quickest way to install a module in a non-standard place might
be</p>
<pre>
    perl Makefile.PL PREFIX=~</pre>
<p>This 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).</p>
<p>Another way to specify many INSTALL directories with a single
parameter is LIB.</p>
<pre>
    perl Makefile.PL LIB=~/lib</pre>
<p>This will install the module's architecture-independent files into
~/lib, the architecture-dependent files into ~/lib/$archname.</p>
<p>Note, that in both cases the tilde expansion is done by MakeMaker, not
by perl by default, nor by make.</p>
<p>Conflicts between parameters LIB, PREFIX and the various INSTALL*
arguments are resolved so that:</p>
<ul>
<li>
<p>setting LIB overrides any setting of INSTALLPRIVLIB, INSTALLARCHLIB,
INSTALLSITELIB, INSTALLSITEARCH (and they are not affected by PREFIX);</p>
</li>
<li>
<p>without LIB, setting PREFIX replaces the initial <code>$Config{prefix}</code>
part of those INSTALL* arguments, even if the latter are explicitly
set (but are set to still start with <code>$Config{prefix}</code>).</p>
</li>
</ul>
<p>If the user has superuser privileges, and is not working on AFS or
relatives, then the defaults for INSTALLPRIVLIB, INSTALLARCHLIB,
INSTALLSCRIPT, etc. will be appropriate, and this incantation will be
the best:</p>
<pre>
    <span class="variable">perl</span> <span class="variable">Makefile</span><span class="operator">.</span><span class="variable">PL</span><span class="operator">;</span> 
    <span class="variable">make</span><span class="operator">;</span> 
    <span class="variable">make</span> <span class="variable">test</span>
    <span class="variable">make</span> <span class="variable">install</span>
</pre>
<p>make install per default writes some documentation of what has been
done into the file <code>$(INSTALLARCHLIB)/perllocal.pod</code>. This feature
can be bypassed by calling make pure_install.</p>
<p>
</p>
<h2><a name="afs_users">AFS users</a></h2>
<p>will have to specify the installation directories as these most
probably have changed since perl itself has been installed. They will
have to do this by calling</p>
<pre>
    perl Makefile.PL INSTALLSITELIB=/afs/here/today \
        INSTALLSCRIPT=/afs/there/now INSTALLMAN3DIR=/afs/for/manpages
    make</pre>
<p>Be careful to repeat this procedure every time you recompile an
extension, unless you are sure the AFS installation directories are
still valid.</p>
<p>
</p>
<h2><a name="static_linking_of_a_new_perl_binary">Static Linking of a new Perl Binary</a></h2>
<p>An extension that is built with the above steps is ready to use on
systems supporting dynamic loading. On systems that do not support
dynamic loading, any newly created extension has to be linked together
with the available resources. MakeMaker supports the linking process
by creating appropriate targets in the Makefile whenever an extension
is built. You can invoke the corresponding section of the makefile with</p>
<pre>
    make perl</pre>
<p>That produces a new perl binary in the current directory with all
extensions linked in that can be found in INST_ARCHLIB, SITELIBEXP,
and PERL_ARCHLIB. To do that, MakeMaker writes a new Makefile, on
UNIX, this is called Makefile.aperl (may be system dependent). If you
want to force the creation of a new perl, it is recommended, that you
delete this Makefile.aperl, so the directories are searched-through
for linkable libraries again.</p>
<p>The binary can be installed into the directory where perl normally
resides on your machine with</p>
<pre>
    make inst_perl</pre>
<p>To produce a perl binary with a different name than <code>perl</code>, either say</p>
<pre>
    perl Makefile.PL MAP_TARGET=myperl
    make myperl
    make inst_perl</pre>
<p>or say</p>
<pre>
    perl Makefile.PL
    make myperl MAP_TARGET=myperl
    make inst_perl MAP_TARGET=myperl</pre>
<p>In any case you will be prompted with the correct invocation of the
<code>inst_perl</code> target that installs the new binary into INSTALLBIN.</p>
<p>make inst_perl per default writes some documentation of what has been
done into the file <code>$(INSTALLARCHLIB)/perllocal.pod</code>. This
can be bypassed by calling make pure_inst_perl.</p>
<p>Warning: the inst_perl: target will most probably overwrite your
existing perl binary. Use with care!</p>
<p>Sometimes you might want to build a statically linked perl although
your system supports dynamic loading. In this case you may explicitly
set the linktype with the invocation of the Makefile.PL or make:</p>
<pre>
    perl Makefile.PL LINKTYPE=static    # recommended</pre>
<p>or</p>
<pre>
    make LINKTYPE=static                # works on most systems</pre>
<p>
</p>
<h2><a name="determination_of_perl_library_and_installation_locations">Determination of Perl Library and Installation Locations</a></h2>
<p>MakeMaker needs to know, or to guess, where certain things are
located.  Especially INST_LIB and INST_ARCHLIB (where to put the files
during the <code>make(1)</code> run), PERL_LIB and PERL_ARCHLIB (where to read
existing modules from), and PERL_INC (header files and <code>libperl*.*</code>).</p>
<p>Extensions may be built either using the contents of the perl source
directory tree or from the installed perl library. The recommended way
is to build extensions after you have run 'make install' on perl
itself. You can do that in any directory on your hard disk that is not
below the perl source tree. The support for extensions below the ext
directory of the perl distribution is only good for the standard
extensions that come with perl.</p>
<p>If an extension is being built below the <code>ext/</code> directory of the perl
source then MakeMaker will set PERL_SRC automatically (e.g.,
<code>../..</code>).  If PERL_SRC is defined and the extension is recognized as
a standard extension, then other variables default to the following:</p>
<pre>
  PERL_INC     = PERL_SRC
  PERL_LIB     = PERL_SRC/lib
  PERL_ARCHLIB = PERL_SRC/lib
  INST_LIB     = PERL_LIB
  INST_ARCHLIB = PERL_ARCHLIB</pre>
<p>If an extension is being built away from the perl source then MakeMaker
will leave PERL_SRC undefined and default to using the installed copy
of the perl library. The other variables default to the following:</p>
<pre>
  PERL_INC     = $archlibexp/CORE
  PERL_LIB     = $privlibexp
  PERL_ARCHLIB = $archlibexp
  INST_LIB     = ./blib/lib
  INST_ARCHLIB = ./blib/arch</pre>
<p>If perl has not yet been installed then PERL_SRC can be defined on the
command line as shown in the previous section.</p>
<p>
</p>
<h2><a name="which_architecture_dependent_directory">Which architecture dependent directory?</a></h2>
<p>If you don't want to keep the defaults for the INSTALL* macros,
MakeMaker helps you to minimize the typing needed: the usual
relationship between INSTALLPRIVLIB and INSTALLARCHLIB is determined
by Configure at perl compilation time. MakeMaker supports the user who
sets INSTALLPRIVLIB. If INSTALLPRIVLIB is set, but INSTALLARCHLIB not,
then MakeMaker defaults the latter to be the same subdirectory of
INSTALLPRIVLIB as Configure decided for the counterparts in %Config ,
otherwise it defaults to INSTALLPRIVLIB. The same relationship holds
for INSTALLSITELIB and INSTALLSITEARCH.</p>
<p>MakeMaker gives you much more freedom than needed to configure
internal variables and get different results. It is worth to mention,
that <code>make(1)</code> also lets you configure most of the variables that are
used in the Makefile. But in the majority of situations this will not
be necessary, and should only be done if the author of a package
recommends it (or you know what you're doing).</p>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?