xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MakeMaker/FAQ.pod (revision e068048151d29f2562a32185e21a8ba885482260)
1b39c5158Smillertpackage ExtUtils::MakeMaker::FAQ;
2b39c5158Smillert
3*e0680481Safresh1our $VERSION = '7.70';
456d68f1eSafresh1$VERSION =~ tr/_//d;
5b39c5158Smillert
6b39c5158Smillert1;
7b39c5158Smillert__END__
8b39c5158Smillert
9b39c5158Smillert=head1 NAME
10b39c5158Smillert
11b39c5158SmillertExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker
12b39c5158Smillert
13b39c5158Smillert=head1 DESCRIPTION
14b39c5158Smillert
1556d68f1eSafresh1FAQs, tricks and tips for L<ExtUtils::MakeMaker>.
16b39c5158Smillert
17b39c5158Smillert
18b39c5158Smillert=head2 Module Installation
19b39c5158Smillert
20b39c5158Smillert=over 4
21b39c5158Smillert
22b39c5158Smillert=item How do I install a module into my home directory?
23b39c5158Smillert
24b39c5158SmillertIf you're not the Perl administrator you probably don't have
259f11ffb7Safresh1permission to install a module to its default location. Ways of handling
269f11ffb7Safresh1this with a B<lot> less manual effort on your part are L<perlbrew>
279f11ffb7Safresh1and L<local::lib>.
289f11ffb7Safresh1
299f11ffb7Safresh1Otherwise, you can install it for your own use into your home directory
309f11ffb7Safresh1like so:
31b39c5158Smillert
32b39c5158Smillert    # Non-unix folks, replace ~ with /path/to/your/home/dir
33b39c5158Smillert    perl Makefile.PL INSTALL_BASE=~
34b39c5158Smillert
35b39c5158SmillertThis will put modules into F<~/lib/perl5>, man pages into F<~/man> and
36b39c5158Smillertprograms into F<~/bin>.
37b39c5158Smillert
38b39c5158SmillertTo ensure your Perl programs can see these newly installed modules,
39b39c5158Smillertset your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell
40b39c5158Smillerteach of your programs to look in that directory with the following:
41b39c5158Smillert
42b39c5158Smillert    use lib "$ENV{HOME}/lib/perl5";
43b39c5158Smillert
44b39c5158Smillertor if $ENV{HOME} isn't set and you don't want to set it for some
45b39c5158Smillertreason, do it the long way.
46b39c5158Smillert
47b39c5158Smillert    use lib "/path/to/your/home/dir/lib/perl5";
48b39c5158Smillert
49b39c5158Smillert=item How do I get MakeMaker and Module::Build to install to the same place?
50b39c5158Smillert
51b39c5158SmillertModule::Build, as of 0.28, supports two ways to install to the same
52b39c5158Smillertlocation as MakeMaker.
53b39c5158Smillert
54e9ce3842Safresh1We highly recommend the install_base method, its the simplest and most
55e9ce3842Safresh1closely approximates the expected behavior of an installation prefix.
56e9ce3842Safresh1
57b39c5158Smillert1) Use INSTALL_BASE / C<--install_base>
58b39c5158Smillert
59b39c5158SmillertMakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install
60b39c5158Smillertto the same locations using the "install_base" concept.  See
61b39c5158SmillertL<ExtUtils::MakeMaker/INSTALL_BASE> for details.  To get MM and MB to
62b39c5158Smillertinstall to the same location simply set INSTALL_BASE in MM and
63b39c5158SmillertC<--install_base> in MB to the same location.
64b39c5158Smillert
65b39c5158Smillert    perl Makefile.PL INSTALL_BASE=/whatever
66b39c5158Smillert    perl Build.PL    --install_base /whatever
67b39c5158Smillert
68e9ce3842Safresh1This works most like other language's behavior when you specify a
69e9ce3842Safresh1prefix.  We recommend this method.
70e9ce3842Safresh1
71b39c5158Smillert2) Use PREFIX / C<--prefix>
72b39c5158Smillert
73b39c5158SmillertModule::Build 0.28 added support for C<--prefix> which works like
74b39c5158SmillertMakeMaker's PREFIX.
75b39c5158Smillert
76b39c5158Smillert    perl Makefile.PL PREFIX=/whatever
77b39c5158Smillert    perl Build.PL    --prefix /whatever
78b39c5158Smillert
79e9ce3842Safresh1We highly discourage this method.  It should only be used if you know
80e9ce3842Safresh1what you're doing and specifically need the PREFIX behavior.  The
81e9ce3842Safresh1PREFIX algorithm is complicated and focused on matching the system
82e9ce3842Safresh1installation.
83b39c5158Smillert
84b39c5158Smillert=item How do I keep from installing man pages?
85b39c5158Smillert
86e9ce3842Safresh1Recent versions of MakeMaker will only install man pages on Unix-like
8756d68f1eSafresh1operating systems by default. To generate manpages on non-Unix operating
8856d68f1eSafresh1systems, make the "manifypods" target.
89b39c5158Smillert
90b39c5158SmillertFor an individual module:
91b39c5158Smillert
92b39c5158Smillert        perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none
93b39c5158Smillert
94b39c5158SmillertIf you want to suppress man page installation for all modules you have
95b39c5158Smillertto reconfigure Perl and tell it 'none' when it asks where to install
96b39c5158Smillertman pages.
97b39c5158Smillert
98b39c5158Smillert
99b39c5158Smillert=item How do I use a module without installing it?
100b39c5158Smillert
101b39c5158SmillertTwo ways.  One is to build the module normally...
102b39c5158Smillert
103b39c5158Smillert        perl Makefile.PL
104b39c5158Smillert        make
105b39c5158Smillert        make test
106b39c5158Smillert
1079f11ffb7Safresh1...and then use L<blib> to point Perl at the built but uninstalled module:
1089f11ffb7Safresh1
1099f11ffb7Safresh1	perl -Mblib script.pl
1109f11ffb7Safresh1	perl -Mblib -e '...'
111b39c5158Smillert
112b39c5158SmillertThe other is to install the module in a temporary location.
113b39c5158Smillert
114b39c5158Smillert        perl Makefile.PL INSTALL_BASE=~/tmp
115b39c5158Smillert        make
116b39c5158Smillert        make test
117b39c5158Smillert        make install
118b39c5158Smillert
119b39c5158SmillertAnd then set PERL5LIB to F<~/tmp/lib/perl5>.  This works well when you
120b39c5158Smillerthave multiple modules to work with.  It also ensures that the module
121b39c5158Smillertgoes through its full installation process which may modify it.
1229f11ffb7Safresh1Again, L<local::lib> may assist you here.
1239f11ffb7Safresh1
1249f11ffb7Safresh1=item How can I organize tests into subdirectories and have them run?
1259f11ffb7Safresh1
1269f11ffb7Safresh1Let's take the following test directory structure:
1279f11ffb7Safresh1
1289f11ffb7Safresh1    t/foo/sometest.t
1299f11ffb7Safresh1    t/bar/othertest.t
1309f11ffb7Safresh1    t/bar/baz/anothertest.t
1319f11ffb7Safresh1
132*e0680481Safresh1Now, inside of the C<WriteMakefile()> function in your F<Makefile.PL>, specify
1339f11ffb7Safresh1where your tests are located with the C<test> directive:
1349f11ffb7Safresh1
1359f11ffb7Safresh1    test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'}
1369f11ffb7Safresh1
1379f11ffb7Safresh1The first entry in the string will run all tests in the top-level F<t/>
1389f11ffb7Safresh1directory. The second will run all test files located in any subdirectory under
1399f11ffb7Safresh1F<t/>. The third, runs all test files within any subdirectory within any other
1409f11ffb7Safresh1subdirectory located under F<t/>.
1419f11ffb7Safresh1
1429f11ffb7Safresh1Note that you do not have to use wildcards. You can specify explicitly which
1439f11ffb7Safresh1subdirectories to run tests in:
1449f11ffb7Safresh1
1459f11ffb7Safresh1    test => {TESTS => 't/*.t t/foo/*.t t/bar/baz/*.t'}
146b39c5158Smillert
147b39c5158Smillert=item PREFIX vs INSTALL_BASE from Module::Build::Cookbook
148b39c5158Smillert
149b39c5158SmillertThe behavior of PREFIX is complicated and depends closely on how your
1509f11ffb7Safresh1Perl is configured. The resulting installation locations will vary
1519f11ffb7Safresh1from machine to machine and even different installations of Perl on the
1529f11ffb7Safresh1same machine.  Because of this, its difficult to document where prefix
1539f11ffb7Safresh1will place your modules.
154b39c5158Smillert
1559f11ffb7Safresh1In contrast, INSTALL_BASE has predictable, easy to explain installation
1569f11ffb7Safresh1locations.  Now that Module::Build and MakeMaker both have INSTALL_BASE
1579f11ffb7Safresh1there is little reason to use PREFIX other than to preserve your existing
1589f11ffb7Safresh1installation locations. If you are starting a fresh Perl installation we
1599f11ffb7Safresh1encourage you to use INSTALL_BASE. If you have an existing installation
1609f11ffb7Safresh1installed via PREFIX, consider moving it to an installation structure
1619f11ffb7Safresh1matching INSTALL_BASE and using that instead.
1629f11ffb7Safresh1
1639f11ffb7Safresh1=item Generating *.pm files with substitutions eg of $VERSION
1649f11ffb7Safresh1
1659f11ffb7Safresh1If you want to configure your module files for local conditions, or to
1669f11ffb7Safresh1automatically insert a version number, you can use EUMM's C<PL_FILES>
1679f11ffb7Safresh1capability, where it will automatically run each F<*.PL> it finds to
1689f11ffb7Safresh1generate its basename. For instance:
1699f11ffb7Safresh1
1709f11ffb7Safresh1    # Makefile.PL:
1719f11ffb7Safresh1    require 'common.pl';
1729f11ffb7Safresh1    my $version = get_version();
1739f11ffb7Safresh1    my @pms = qw(Foo.pm);
1749f11ffb7Safresh1    WriteMakefile(
1759f11ffb7Safresh1      NAME => 'Foo',
1769f11ffb7Safresh1      VERSION => $version,
1779f11ffb7Safresh1      PM => { map { ($_ => "\$(INST_LIB)/$_") } @pms },
1789f11ffb7Safresh1      clean => { FILES => join ' ', @pms },
1799f11ffb7Safresh1    );
1809f11ffb7Safresh1
1819f11ffb7Safresh1    # common.pl:
1829f11ffb7Safresh1    sub get_version { '0.04' }
1839f11ffb7Safresh1    sub process { my $v = get_version(); s/__VERSION__/$v/g; }
1849f11ffb7Safresh1    1;
1859f11ffb7Safresh1
1869f11ffb7Safresh1    # Foo.pm.PL:
1879f11ffb7Safresh1    require 'common.pl';
1889f11ffb7Safresh1    $_ = join '', <DATA>;
1899f11ffb7Safresh1    process();
1909f11ffb7Safresh1    my $file = shift;
1919f11ffb7Safresh1    open my $fh, '>', $file or die "$file: $!";
1929f11ffb7Safresh1    print $fh $_;
1939f11ffb7Safresh1    __DATA__
1949f11ffb7Safresh1    package Foo;
1959f11ffb7Safresh1    our $VERSION = '__VERSION__';
1969f11ffb7Safresh1    1;
1979f11ffb7Safresh1
1989f11ffb7Safresh1You may notice that C<PL_FILES> is not specified above, since the default
1999f11ffb7Safresh1of mapping each .PL file to its basename works well.
2009f11ffb7Safresh1
2019f11ffb7Safresh1If the generated module were architecture-specific, you could replace
2029f11ffb7Safresh1C<$(INST_LIB)> above with C<$(INST_ARCHLIB)>, although if you locate
2039f11ffb7Safresh1modules under F<lib>, that would involve ensuring any C<lib/> in front
2049f11ffb7Safresh1of the module location were removed.
205b39c5158Smillert
206b39c5158Smillert=back
207b39c5158Smillert
208e9ce3842Safresh1=head2 Common errors and problems
209e9ce3842Safresh1
210e9ce3842Safresh1=over 4
211e9ce3842Safresh1
212e9ce3842Safresh1=item "No rule to make target `/usr/lib/perl5/CORE/config.h', needed by `Makefile'"
213e9ce3842Safresh1
214e9ce3842Safresh1Just what it says, you're missing that file.  MakeMaker uses it to
215e9ce3842Safresh1determine if perl has been rebuilt since the Makefile was made.  It's
216e9ce3842Safresh1a bit of a bug that it halts installation.
217e9ce3842Safresh1
218e9ce3842Safresh1Some operating systems don't ship the CORE directory with their base
219e9ce3842Safresh1perl install.  To solve the problem, you likely need to install a perl
220e9ce3842Safresh1development package such as perl-devel (CentOS, Fedora and other
221e9ce3842Safresh1Redhat systems) or perl (Ubuntu and other Debian systems).
222e9ce3842Safresh1
223e9ce3842Safresh1=back
224b39c5158Smillert
225b39c5158Smillert=head2 Philosophy and History
226b39c5158Smillert
227b39c5158Smillert=over 4
228b39c5158Smillert
229b39c5158Smillert=item Why not just use <insert other build config tool here>?
230b39c5158Smillert
231b39c5158SmillertWhy did MakeMaker reinvent the build configuration wheel?  Why not
232b39c5158Smillertjust use autoconf or automake or ppm or Ant or ...
233b39c5158Smillert
234b39c5158SmillertThere are many reasons, but the major one is cross-platform
235b39c5158Smillertcompatibility.
236b39c5158Smillert
237b39c5158SmillertPerl is one of the most ported pieces of software ever.  It works on
238b39c5158Smillertoperating systems I've never even heard of (see perlport for details).
239b39c5158SmillertIt needs a build tool that can work on all those platforms and with
240b39c5158Smillertany wacky C compilers and linkers they might have.
241b39c5158Smillert
242b39c5158SmillertNo such build tool exists.  Even make itself has wildly different
243b39c5158Smillertdialects.  So we have to build our own.
244b39c5158Smillert
245b39c5158Smillert
246b39c5158Smillert=item What is Module::Build and how does it relate to MakeMaker?
247b39c5158Smillert
248b39c5158SmillertModule::Build is a project by Ken Williams to supplant MakeMaker.
249b39c5158SmillertIts primary advantages are:
250b39c5158Smillert
251b39c5158Smillert=over 8
252b39c5158Smillert
253b39c5158Smillert=item * pure perl.  no make, no shell commands
254b39c5158Smillert
255b39c5158Smillert=item * easier to customize
256b39c5158Smillert
257b39c5158Smillert=item * cleaner internals
258b39c5158Smillert
259b39c5158Smillert=item * less cruft
260b39c5158Smillert
261b39c5158Smillert=back
262b39c5158Smillert
2639f11ffb7Safresh1Module::Build was long the official heir apparent to MakeMaker.  The
2649f11ffb7Safresh1rate of both its development and adoption has slowed in recent years,
2659f11ffb7Safresh1though, and it is unclear what the future holds for it.  That said,
2669f11ffb7Safresh1Module::Build set the stage for I<something> to become the heir to
2679f11ffb7Safresh1MakeMaker.  MakeMaker's maintainers have long said that it is a dead
2689f11ffb7Safresh1end and should be kept functioning, while being cautious about extending
2699f11ffb7Safresh1with new features.
270b39c5158Smillert
271b39c5158Smillert=back
272b39c5158Smillert
273b39c5158Smillert=head2 Module Writing
274b39c5158Smillert
275b39c5158Smillert=over 4
276b39c5158Smillert
277b39c5158Smillert=item How do I keep my $VERSION up to date without resetting it manually?
278b39c5158Smillert
279b39c5158SmillertOften you want to manually set the $VERSION in the main module
280b39c5158Smillertdistribution because this is the version that everybody sees on CPAN
281b39c5158Smillertand maybe you want to customize it a bit.  But for all the other
282b39c5158Smillertmodules in your dist, $VERSION is really just bookkeeping and all that's
283b39c5158Smillertimportant is it goes up every time the module is changed.  Doing this
284b39c5158Smillertby hand is a pain and you often forget.
285b39c5158Smillert
2869f11ffb7Safresh1Probably the easiest way to do this is using F<perl-reversion> in
2879f11ffb7Safresh1L<Perl::Version>:
2889f11ffb7Safresh1
2899f11ffb7Safresh1  perl-reversion -bump
2909f11ffb7Safresh1
2919f11ffb7Safresh1If your version control system supports revision numbers (git doesn't
2929f11ffb7Safresh1easily), the simplest way to do it automatically is to use its revision
2939f11ffb7Safresh1number (you are using version control, right?).
294b39c5158Smillert
295b39c5158SmillertIn CVS, RCS and SVN you use $Revision$ (see the documentation of your
296b39c5158Smillertversion control system for details).  Every time the file is checked
297b39c5158Smillertin the $Revision$ will be updated, updating your $VERSION.
298b39c5158Smillert
299b39c5158SmillertSVN uses a simple integer for $Revision$ so you can adapt it for your
300b39c5158Smillert$VERSION like so:
301b39c5158Smillert
302b39c5158Smillert    ($VERSION) = q$Revision$ =~ /(\d+)/;
303b39c5158Smillert
304b39c5158SmillertIn CVS and RCS version 1.9 is followed by 1.10.  Since CPAN compares
305b39c5158Smillertversion numbers numerically we use a sprintf() to convert 1.9 to 1.009
306b39c5158Smillertand 1.10 to 1.010 which compare properly.
307b39c5158Smillert
308b39c5158Smillert    $VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g;
309b39c5158Smillert
310e9ce3842Safresh1If branches are involved (ie. $Revision: 1.5.3.4$) it's a little more
311b39c5158Smillertcomplicated.
312b39c5158Smillert
313b39c5158Smillert    # must be all on one line or MakeMaker will get confused.
314b39c5158Smillert    $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
315b39c5158Smillert
316b39c5158SmillertIn SVN, $Revision$ should be the same for every file in the project so
317b39c5158Smillertthey would all have the same $VERSION.  CVS and RCS have a different
318e9ce3842Safresh1$Revision$ per file so each file will have a different $VERSION.
319b39c5158SmillertDistributed version control systems, such as SVK, may have a different
320e9ce3842Safresh1$Revision$ based on who checks out the file, leading to a different $VERSION
321b39c5158Smillerton each machine!  Finally, some distributed version control systems, such
322b39c5158Smillertas darcs, have no concept of revision number at all.
323b39c5158Smillert
324b39c5158Smillert
325b39c5158Smillert=item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?!
326b39c5158Smillert
327b39c5158SmillertF<META.yml> is a module meta-data file pioneered by Module::Build and
328b39c5158Smillertautomatically generated as part of the 'distdir' target (and thus
329b39c5158Smillert'dist').  See L<ExtUtils::MakeMaker/"Module Meta-Data">.
330b39c5158Smillert
331b39c5158SmillertTo shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>.
332b39c5158Smillert
333b39c5158Smillert
334b39c5158Smillert=item How do I delete everything not in my F<MANIFEST>?
335b39c5158Smillert
336e9ce3842Safresh1Some folks are surprised that C<make distclean> does not delete
337b39c5158Smillerteverything not listed in their MANIFEST (thus making a clean
338b39c5158Smillertdistribution) but only tells them what they need to delete.  This is
339b39c5158Smillertdone because it is considered too dangerous.  While developing your
340b39c5158Smillertmodule you might write a new file, not add it to the MANIFEST, then
341b39c5158Smillertrun a C<distclean> and be sad because your new work was deleted.
342b39c5158Smillert
343b39c5158SmillertIf you really want to do this, you can use
344b39c5158SmillertC<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find
345b39c5158Smillertto delete the files.  But you have to be careful.  Here's a script to
346b39c5158Smillertdo that.  Use at your own risk.  Have fun blowing holes in your foot.
347b39c5158Smillert
348b39c5158Smillert    #!/usr/bin/perl -w
349b39c5158Smillert
350b39c5158Smillert    use strict;
351b39c5158Smillert
352b39c5158Smillert    use File::Spec;
353b39c5158Smillert    use File::Find;
354b39c5158Smillert    use ExtUtils::Manifest qw(maniread);
355b39c5158Smillert
356b39c5158Smillert    my %manifest = map  {( $_ => 1 )}
357b39c5158Smillert                   grep { File::Spec->canonpath($_) }
358b39c5158Smillert                        keys %{ maniread() };
359b39c5158Smillert
360b39c5158Smillert    if( !keys %manifest ) {
361b39c5158Smillert        print "No files found in MANIFEST.  Stopping.\n";
362b39c5158Smillert        exit;
363b39c5158Smillert    }
364b39c5158Smillert
365b39c5158Smillert    find({
366b39c5158Smillert          wanted   => sub {
367b39c5158Smillert              my $path = File::Spec->canonpath($_);
368b39c5158Smillert
369b39c5158Smillert              return unless -f $path;
370b39c5158Smillert              return if exists $manifest{ $path };
371b39c5158Smillert
372b39c5158Smillert              print "unlink $path\n";
373b39c5158Smillert              unlink $path;
374b39c5158Smillert          },
375b39c5158Smillert          no_chdir => 1
376b39c5158Smillert         },
377b39c5158Smillert         "."
378b39c5158Smillert    );
379b39c5158Smillert
380b39c5158Smillert
38148950c12Ssthen=item Which tar should I use on Windows?
38248950c12Ssthen
383e9ce3842Safresh1We recommend ptar from Archive::Tar not older than 1.66 with '-C' option.
38448950c12Ssthen
3859f11ffb7Safresh1=item Which zip should I use on Windows for '[ndg]make zipdist'?
386b39c5158Smillert
387b39c5158SmillertWe recommend InfoZIP: L<http://www.info-zip.org/Zip.html>
388b39c5158Smillert
389b39c5158Smillert
390b39c5158Smillert=back
391b39c5158Smillert
392b39c5158Smillert=head2 XS
393b39c5158Smillert
394b39c5158Smillert=over 4
395b39c5158Smillert
396e9ce3842Safresh1=item How do I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors?
397b39c5158Smillert
398b39c5158SmillertXS code is very sensitive to the module version number and will
399b39c5158Smillertcomplain if the version number in your Perl module doesn't match.  If
400b39c5158Smillertyou change your module's version # without rerunning Makefile.PL the old
401e9ce3842Safresh1version number will remain in the Makefile, causing the XS code to be built
402b39c5158Smillertwith the wrong number.
403b39c5158Smillert
404b39c5158SmillertTo avoid this, you can force the Makefile to be rebuilt whenever you
405b39c5158Smillertchange the module containing the version number by adding this to your
406b39c5158SmillertWriteMakefile() arguments.
407b39c5158Smillert
408b39c5158Smillert    depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
409b39c5158Smillert
410b39c5158Smillert
411b39c5158Smillert=item How do I make two or more XS files coexist in the same directory?
412b39c5158Smillert
413b39c5158SmillertSometimes you need to have two and more XS files in the same package.
4149f11ffb7Safresh1There are three ways: C<XSMULTI>, separate directories, and bootstrapping
4159f11ffb7Safresh1one XS from another.
4169f11ffb7Safresh1
4179f11ffb7Safresh1=over 8
4189f11ffb7Safresh1
4199f11ffb7Safresh1=item XSMULTI
4209f11ffb7Safresh1
4219f11ffb7Safresh1Structure your modules so they are all located under F<lib>, such that
4229f11ffb7Safresh1C<Foo::Bar> is in F<lib/Foo/Bar.pm> and F<lib/Foo/Bar.xs>, etc. Have your
4239f11ffb7Safresh1top-level C<WriteMakefile> set the variable C<XSMULTI> to a true value.
4249f11ffb7Safresh1
4259f11ffb7Safresh1Er, that's it.
4269f11ffb7Safresh1
4279f11ffb7Safresh1=item Separate directories
4289f11ffb7Safresh1
4299f11ffb7Safresh1Put each XS files into separate directories, each with their own
4309f11ffb7Safresh1F<Makefile.PL>. Make sure each of those F<Makefile.PL>s has the correct
4319f11ffb7Safresh1C<CFLAGS>, C<INC>, C<LIBS> etc. You will need to make sure the top-level
4329f11ffb7Safresh1F<Makefile.PL> refers to each of these using C<DIR>.
4339f11ffb7Safresh1
4349f11ffb7Safresh1=item Bootstrapping
435b39c5158Smillert
436b39c5158SmillertLet's assume that we have a package C<Cool::Foo>, which includes
437b39c5158SmillertC<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
438b39c5158Smillertfile. First we use the following I<Makefile.PL>:
439b39c5158Smillert
440b39c5158Smillert  use ExtUtils::MakeMaker;
441b39c5158Smillert
442b39c5158Smillert  WriteMakefile(
443b39c5158Smillert      NAME		=> 'Cool::Foo',
444b39c5158Smillert      VERSION_FROM	=> 'Foo.pm',
445b39c5158Smillert      OBJECT              => q/$(O_FILES)/,
446b39c5158Smillert      # ... other attrs ...
447b39c5158Smillert  );
448b39c5158Smillert
449b39c5158SmillertNotice the C<OBJECT> attribute. MakeMaker generates the following
450b39c5158Smillertvariables in I<Makefile>:
451b39c5158Smillert
452b39c5158Smillert  # Handy lists of source code files:
453b39c5158Smillert  XS_FILES= Bar.xs \
454b39c5158Smillert  	Foo.xs
455b39c5158Smillert  C_FILES = Bar.c \
456b39c5158Smillert  	Foo.c
457b39c5158Smillert  O_FILES = Bar.o \
458b39c5158Smillert  	Foo.o
459b39c5158Smillert
460b39c5158SmillertTherefore we can use the C<O_FILES> variable to tell MakeMaker to use
461b39c5158Smillertthese objects into the shared library.
462b39c5158Smillert
463b39c5158SmillertThat's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
464b39c5158Smillertand I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
465b39c5158SmillertI<Bar.pm> simply loading I<Foo.pm>.
466b39c5158Smillert
467b39c5158SmillertThe only issue left is to how to bootstrap I<Bar.xs>. This is done
468b39c5158Smillertfrom I<Foo.xs>:
469b39c5158Smillert
470b39c5158Smillert  MODULE = Cool::Foo PACKAGE = Cool::Foo
471b39c5158Smillert
472b39c5158Smillert  BOOT:
473b39c5158Smillert  # boot the second XS file
474b39c5158Smillert  boot_Cool__Bar(aTHX_ cv);
475b39c5158Smillert
476b39c5158SmillertIf you have more than two files, this is the place where you should
477b39c5158Smillertboot extra XS files from.
478b39c5158Smillert
479b39c5158SmillertThe following four files sum up all the details discussed so far.
480b39c5158Smillert
481b39c5158Smillert  Foo.pm:
482b39c5158Smillert  -------
483b39c5158Smillert  package Cool::Foo;
484b39c5158Smillert
485b39c5158Smillert  require DynaLoader;
486b39c5158Smillert
487b39c5158Smillert  our @ISA = qw(DynaLoader);
488b39c5158Smillert  our $VERSION = '0.01';
489b39c5158Smillert  bootstrap Cool::Foo $VERSION;
490b39c5158Smillert
491b39c5158Smillert  1;
492b39c5158Smillert
493b39c5158Smillert  Bar.pm:
494b39c5158Smillert  -------
495b39c5158Smillert  package Cool::Bar;
496b39c5158Smillert
497b39c5158Smillert  use Cool::Foo; # bootstraps Bar.xs
498b39c5158Smillert
499b39c5158Smillert  1;
500b39c5158Smillert
501b39c5158Smillert  Foo.xs:
502b39c5158Smillert  -------
503b39c5158Smillert  #include "EXTERN.h"
504b39c5158Smillert  #include "perl.h"
505b39c5158Smillert  #include "XSUB.h"
506b39c5158Smillert
507b39c5158Smillert  MODULE = Cool::Foo  PACKAGE = Cool::Foo
508b39c5158Smillert
509b39c5158Smillert  BOOT:
510b39c5158Smillert  # boot the second XS file
511b39c5158Smillert  boot_Cool__Bar(aTHX_ cv);
512b39c5158Smillert
513b39c5158Smillert  MODULE = Cool::Foo  PACKAGE = Cool::Foo  PREFIX = cool_foo_
514b39c5158Smillert
515b39c5158Smillert  void
516b39c5158Smillert  cool_foo_perl_rules()
517b39c5158Smillert
518b39c5158Smillert      CODE:
519b39c5158Smillert      fprintf(stderr, "Cool::Foo says: Perl Rules\n");
520b39c5158Smillert
521b39c5158Smillert  Bar.xs:
522b39c5158Smillert  -------
523b39c5158Smillert  #include "EXTERN.h"
524b39c5158Smillert  #include "perl.h"
525b39c5158Smillert  #include "XSUB.h"
526b39c5158Smillert
527b39c5158Smillert  MODULE = Cool::Bar  PACKAGE = Cool::Bar PREFIX = cool_bar_
528b39c5158Smillert
529b39c5158Smillert  void
530b39c5158Smillert  cool_bar_perl_rules()
531b39c5158Smillert
532b39c5158Smillert      CODE:
533b39c5158Smillert      fprintf(stderr, "Cool::Bar says: Perl Rules\n");
534b39c5158Smillert
535b39c5158SmillertAnd of course a very basic test:
536b39c5158Smillert
537b39c5158Smillert  t/cool.t:
538b39c5158Smillert  --------
539*e0680481Safresh1  use Test::More tests => 1;
540b39c5158Smillert  use Cool::Foo;
541b39c5158Smillert  use Cool::Bar;
542b39c5158Smillert  Cool::Foo::perl_rules();
543b39c5158Smillert  Cool::Bar::perl_rules();
544b39c5158Smillert  ok 1;
545b39c5158Smillert
546b39c5158SmillertThis tip has been brought to you by Nick Ing-Simmons and Stas Bekman.
547b39c5158Smillert
5489f11ffb7Safresh1An alternative way to achieve this can be seen in L<Gtk2::CodeGen>
5499f11ffb7Safresh1and L<Glib::CodeGen>.
5509f11ffb7Safresh1
551b39c5158Smillert=back
552b39c5158Smillert
5539f11ffb7Safresh1=back
5549f11ffb7Safresh1
5559f11ffb7Safresh1=head1 DESIGN
5569f11ffb7Safresh1
5579f11ffb7Safresh1=head2 MakeMaker object hierarchy (simplified)
5589f11ffb7Safresh1
5599f11ffb7Safresh1What most people need to know (superclasses on top.)
5609f11ffb7Safresh1
5619f11ffb7Safresh1        ExtUtils::MM_Any
5629f11ffb7Safresh1                |
5639f11ffb7Safresh1        ExtUtils::MM_Unix
5649f11ffb7Safresh1                |
5659f11ffb7Safresh1        ExtUtils::MM_{Current OS}
5669f11ffb7Safresh1                |
5679f11ffb7Safresh1        ExtUtils::MakeMaker
5689f11ffb7Safresh1                |
5699f11ffb7Safresh1               MY
5709f11ffb7Safresh1
57156d68f1eSafresh1The object actually used is of the class L<MY|ExtUtils::MY> which allows you to
5729f11ffb7Safresh1override bits of MakeMaker inside your Makefile.PL by declaring
5739f11ffb7Safresh1MY::foo() methods.
5749f11ffb7Safresh1
5759f11ffb7Safresh1=head2 MakeMaker object hierarchy (real)
5769f11ffb7Safresh1
5779f11ffb7Safresh1Here's how it really works:
5789f11ffb7Safresh1
5799f11ffb7Safresh1                                    ExtUtils::MM_Any
5809f11ffb7Safresh1                                            |
5819f11ffb7Safresh1                                    ExtUtils::MM_Unix
5829f11ffb7Safresh1                                            |
5839f11ffb7Safresh1    ExtUtils::Liblist::Kid          ExtUtils::MM_{Current OS} (if necessary)
5849f11ffb7Safresh1          |                                          |
5859f11ffb7Safresh1    ExtUtils::Liblist     ExtUtils::MakeMaker        |
5869f11ffb7Safresh1                    |     |                          |
5879f11ffb7Safresh1                    |     |   |-----------------------
5889f11ffb7Safresh1                   ExtUtils::MM
5899f11ffb7Safresh1                   |          |
5909f11ffb7Safresh1        ExtUtils::MY         MM (created by ExtUtils::MM)
5919f11ffb7Safresh1        |                                   |
5929f11ffb7Safresh1        MY (created by ExtUtils::MY)        |
5939f11ffb7Safresh1                    .                       |
5949f11ffb7Safresh1                 (mixin)                    |
5959f11ffb7Safresh1                    .                       |
5969f11ffb7Safresh1               PACK### (created each call to ExtUtils::MakeMaker->new)
5979f11ffb7Safresh1
5989f11ffb7Safresh1NOTE: Yes, this is a mess.  See
5999f11ffb7Safresh1L<http://archive.develooper.com/makemaker@perl.org/msg00134.html>
6009f11ffb7Safresh1for some history.
6019f11ffb7Safresh1
60256d68f1eSafresh1NOTE: When L<ExtUtils::MM> is loaded it chooses a superclass for MM from
6039f11ffb7Safresh1amongst the ExtUtils::MM_* modules based on the current operating
6049f11ffb7Safresh1system.
6059f11ffb7Safresh1
6069f11ffb7Safresh1NOTE: ExtUtils::MM_{Current OS} represents one of the ExtUtils::MM_*
60756d68f1eSafresh1modules except L<ExtUtils::MM_Any> chosen based on your operating system.
6089f11ffb7Safresh1
6099f11ffb7Safresh1NOTE: The main object used by MakeMaker is a PACK### object, *not*
61056d68f1eSafresh1L<ExtUtils::MakeMaker>.  It is, effectively, a subclass of L<MY|ExtUtils::MY>,
61156d68f1eSafresh1L<ExtUtils::MakeMaker>, L<ExtUtils::Liblist> and ExtUtils::MM_{Current OS}
6129f11ffb7Safresh1
61356d68f1eSafresh1NOTE: The methods in L<MY|ExtUtils::MY> are simply copied into PACK### rather
61456d68f1eSafresh1than MY being a superclass of PACK###.  I don't remember the rationale.
6159f11ffb7Safresh1
61656d68f1eSafresh1NOTE: L<ExtUtils::Liblist> should be removed from the inheritance hiearchy
6179f11ffb7Safresh1and simply be called as functions.
6189f11ffb7Safresh1
61956d68f1eSafresh1NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity.
6209f11ffb7Safresh1
6219f11ffb7Safresh1
6229f11ffb7Safresh1=head2 The MM_* hierarchy
6239f11ffb7Safresh1
6249f11ffb7Safresh1                                MM_Win95   MM_NW5
6259f11ffb7Safresh1                                     \      /
6269f11ffb7Safresh1 MM_BeOS  MM_Cygwin  MM_OS2  MM_VMS  MM_Win32  MM_DOS  MM_UWIN
6279f11ffb7Safresh1       \        |      |         |        /      /      /
6289f11ffb7Safresh1        ------------------------------------------------
6299f11ffb7Safresh1                           |       |
6309f11ffb7Safresh1                        MM_Unix    |
6319f11ffb7Safresh1                              |    |
6329f11ffb7Safresh1                              MM_Any
6339f11ffb7Safresh1
63456d68f1eSafresh1NOTE: Each direct L<MM_Unix|ExtUtils::MM_Unix> subclass is also an
63556d68f1eSafresh1L<MM_Any|ExtUtils::MM_Any> subclass.  This
6369f11ffb7Safresh1is a temporary hack because MM_Unix overrides some MM_Any methods with
6379f11ffb7Safresh1Unix specific code.  It allows the non-Unix modules to see the
6389f11ffb7Safresh1original MM_Any implementations.
6399f11ffb7Safresh1
64056d68f1eSafresh1NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity.
6419f11ffb7Safresh1
642b39c5158Smillert=head1 PATCHING
643b39c5158Smillert
644b39c5158SmillertIf you have a question you'd like to see added to the FAQ (whether or
6459f11ffb7Safresh1not you have the answer) please either:
6469f11ffb7Safresh1
6479f11ffb7Safresh1=over 2
6489f11ffb7Safresh1
6499f11ffb7Safresh1=item * make a pull request on the MakeMaker github repository
6509f11ffb7Safresh1
6519f11ffb7Safresh1=item * raise a issue on the MakeMaker github repository
6529f11ffb7Safresh1
6539f11ffb7Safresh1=item * file an RT ticket
6549f11ffb7Safresh1
6559f11ffb7Safresh1=item * email makemaker@perl.org
6569f11ffb7Safresh1
6579f11ffb7Safresh1=back
658b39c5158Smillert
659b39c5158Smillert=head1 AUTHOR
660b39c5158Smillert
661b39c5158SmillertThe denizens of makemaker@perl.org.
662b39c5158Smillert
663b39c5158Smillert=head1 SEE ALSO
664b39c5158Smillert
665b39c5158SmillertL<ExtUtils::MakeMaker>
666b39c5158Smillert
667b39c5158Smillert=cut
668