1 package ExtUtils::MakeMaker::FAQ;
4 $VERSION = eval $VERSION;
11 ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker
15 FAQs, tricks and tips for C<ExtUtils::MakeMaker>.
18 =head2 Module Installation
22 =item How do I install a module into my home directory?
24 If you're not the Perl administrator you probably don't have
25 permission to install a module to its default location. Ways of handling
26 this with a B<lot> less manual effort on your part are L<perlbrew>
29 Otherwise, you can install it for your own use into your home directory
32 # Non-unix folks, replace ~ with /path/to/your/home/dir
33 perl Makefile.PL INSTALL_BASE=~
35 This will put modules into F<~/lib/perl5>, man pages into F<~/man> and
36 programs into F<~/bin>.
38 To ensure your Perl programs can see these newly installed modules,
39 set your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell
40 each of your programs to look in that directory with the following:
42 use lib "$ENV{HOME}/lib/perl5";
44 or if $ENV{HOME} isn't set and you don't want to set it for some
45 reason, do it the long way.
47 use lib "/path/to/your/home/dir/lib/perl5";
49 =item How do I get MakeMaker and Module::Build to install to the same place?
51 Module::Build, as of 0.28, supports two ways to install to the same
52 location as MakeMaker.
54 We highly recommend the install_base method, its the simplest and most
55 closely approximates the expected behavior of an installation prefix.
57 1) Use INSTALL_BASE / C<--install_base>
59 MakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install
60 to the same locations using the "install_base" concept. See
61 L<ExtUtils::MakeMaker/INSTALL_BASE> for details. To get MM and MB to
62 install to the same location simply set INSTALL_BASE in MM and
63 C<--install_base> in MB to the same location.
65 perl Makefile.PL INSTALL_BASE=/whatever
66 perl Build.PL --install_base /whatever
68 This works most like other language's behavior when you specify a
69 prefix. We recommend this method.
71 2) Use PREFIX / C<--prefix>
73 Module::Build 0.28 added support for C<--prefix> which works like
76 perl Makefile.PL PREFIX=/whatever
77 perl Build.PL --prefix /whatever
79 We highly discourage this method. It should only be used if you know
80 what you're doing and specifically need the PREFIX behavior. The
81 PREFIX algorithm is complicated and focused on matching the system
84 =item How do I keep from installing man pages?
86 Recent versions of MakeMaker will only install man pages on Unix-like
89 For an individual module:
91 perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none
93 If you want to suppress man page installation for all modules you have
94 to reconfigure Perl and tell it 'none' when it asks where to install
98 =item How do I use a module without installing it?
100 Two ways. One is to build the module normally...
106 ...and then use L<blib> to point Perl at the built but uninstalled module:
108 perl -Mblib script.pl
111 The other is to install the module in a temporary location.
113 perl Makefile.PL INSTALL_BASE=~/tmp
118 And then set PERL5LIB to F<~/tmp/lib/perl5>. This works well when you
119 have multiple modules to work with. It also ensures that the module
120 goes through its full installation process which may modify it.
121 Again, L<local::lib> may assist you here.
123 =item How can I organize tests into subdirectories and have them run?
125 Let's take the following test directory structure:
129 t/bar/baz/anothertest.t
131 Now, inside of the C<WriteMakeFile()> function in your F<Makefile.PL>, specify
132 where your tests are located with the C<test> directive:
134 test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'}
136 The first entry in the string will run all tests in the top-level F<t/>
137 directory. The second will run all test files located in any subdirectory under
138 F<t/>. The third, runs all test files within any subdirectory within any other
139 subdirectory located under F<t/>.
141 Note that you do not have to use wildcards. You can specify explicitly which
142 subdirectories to run tests in:
144 test => {TESTS => 't/*.t t/foo/*.t t/bar/baz/*.t'}
146 =item PREFIX vs INSTALL_BASE from Module::Build::Cookbook
148 The behavior of PREFIX is complicated and depends closely on how your
149 Perl is configured. The resulting installation locations will vary
150 from machine to machine and even different installations of Perl on the
151 same machine. Because of this, its difficult to document where prefix
152 will place your modules.
154 In contrast, INSTALL_BASE has predictable, easy to explain installation
155 locations. Now that Module::Build and MakeMaker both have INSTALL_BASE
156 there is little reason to use PREFIX other than to preserve your existing
157 installation locations. If you are starting a fresh Perl installation we
158 encourage you to use INSTALL_BASE. If you have an existing installation
159 installed via PREFIX, consider moving it to an installation structure
160 matching INSTALL_BASE and using that instead.
162 =item Generating *.pm files with substitutions eg of $VERSION
164 If you want to configure your module files for local conditions, or to
165 automatically insert a version number, you can use EUMM's C<PL_FILES>
166 capability, where it will automatically run each F<*.PL> it finds to
167 generate its basename. For instance:
171 my $version = get_version();
172 my @pms = qw(Foo.pm);
176 PM => { map { ($_ => "\$(INST_LIB)/$_") } @pms },
177 clean => { FILES => join ' ', @pms },
181 sub get_version { '0.04' }
182 sub process { my $v = get_version(); s/__VERSION__/$v/g; }
187 $_ = join '', <DATA>;
190 open my $fh, '>', $file or die "$file: $!";
194 our $VERSION = '__VERSION__';
197 You may notice that C<PL_FILES> is not specified above, since the default
198 of mapping each .PL file to its basename works well.
200 If the generated module were architecture-specific, you could replace
201 C<$(INST_LIB)> above with C<$(INST_ARCHLIB)>, although if you locate
202 modules under F<lib>, that would involve ensuring any C<lib/> in front
203 of the module location were removed.
207 =head2 Common errors and problems
211 =item "No rule to make target `/usr/lib/perl5/CORE/config.h', needed by `Makefile'"
213 Just what it says, you're missing that file. MakeMaker uses it to
214 determine if perl has been rebuilt since the Makefile was made. It's
215 a bit of a bug that it halts installation.
217 Some operating systems don't ship the CORE directory with their base
218 perl install. To solve the problem, you likely need to install a perl
219 development package such as perl-devel (CentOS, Fedora and other
220 Redhat systems) or perl (Ubuntu and other Debian systems).
224 =head2 Philosophy and History
228 =item Why not just use <insert other build config tool here>?
230 Why did MakeMaker reinvent the build configuration wheel? Why not
231 just use autoconf or automake or ppm or Ant or ...
233 There are many reasons, but the major one is cross-platform
236 Perl is one of the most ported pieces of software ever. It works on
237 operating systems I've never even heard of (see perlport for details).
238 It needs a build tool that can work on all those platforms and with
239 any wacky C compilers and linkers they might have.
241 No such build tool exists. Even make itself has wildly different
242 dialects. So we have to build our own.
245 =item What is Module::Build and how does it relate to MakeMaker?
247 Module::Build is a project by Ken Williams to supplant MakeMaker.
248 Its primary advantages are:
252 =item * pure perl. no make, no shell commands
254 =item * easier to customize
256 =item * cleaner internals
262 Module::Build was long the official heir apparent to MakeMaker. The
263 rate of both its development and adoption has slowed in recent years,
264 though, and it is unclear what the future holds for it. That said,
265 Module::Build set the stage for I<something> to become the heir to
266 MakeMaker. MakeMaker's maintainers have long said that it is a dead
267 end and should be kept functioning, while being cautious about extending
272 =head2 Module Writing
276 =item How do I keep my $VERSION up to date without resetting it manually?
278 Often you want to manually set the $VERSION in the main module
279 distribution because this is the version that everybody sees on CPAN
280 and maybe you want to customize it a bit. But for all the other
281 modules in your dist, $VERSION is really just bookkeeping and all that's
282 important is it goes up every time the module is changed. Doing this
283 by hand is a pain and you often forget.
285 Probably the easiest way to do this is using F<perl-reversion> in
290 If your version control system supports revision numbers (git doesn't
291 easily), the simplest way to do it automatically is to use its revision
292 number (you are using version control, right?).
294 In CVS, RCS and SVN you use $Revision$ (see the documentation of your
295 version control system for details). Every time the file is checked
296 in the $Revision$ will be updated, updating your $VERSION.
298 SVN uses a simple integer for $Revision$ so you can adapt it for your
301 ($VERSION) = q$Revision$ =~ /(\d+)/;
303 In CVS and RCS version 1.9 is followed by 1.10. Since CPAN compares
304 version numbers numerically we use a sprintf() to convert 1.9 to 1.009
305 and 1.10 to 1.010 which compare properly.
307 $VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g;
309 If branches are involved (ie. $Revision: 1.5.3.4$) it's a little more
312 # must be all on one line or MakeMaker will get confused.
313 $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
315 In SVN, $Revision$ should be the same for every file in the project so
316 they would all have the same $VERSION. CVS and RCS have a different
317 $Revision$ per file so each file will have a different $VERSION.
318 Distributed version control systems, such as SVK, may have a different
319 $Revision$ based on who checks out the file, leading to a different $VERSION
320 on each machine! Finally, some distributed version control systems, such
321 as darcs, have no concept of revision number at all.
324 =item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?!
326 F<META.yml> is a module meta-data file pioneered by Module::Build and
327 automatically generated as part of the 'distdir' target (and thus
328 'dist'). See L<ExtUtils::MakeMaker/"Module Meta-Data">.
330 To shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>.
333 =item How do I delete everything not in my F<MANIFEST>?
335 Some folks are surprised that C<make distclean> does not delete
336 everything not listed in their MANIFEST (thus making a clean
337 distribution) but only tells them what they need to delete. This is
338 done because it is considered too dangerous. While developing your
339 module you might write a new file, not add it to the MANIFEST, then
340 run a C<distclean> and be sad because your new work was deleted.
342 If you really want to do this, you can use
343 C<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find
344 to delete the files. But you have to be careful. Here's a script to
345 do that. Use at your own risk. Have fun blowing holes in your foot.
353 use ExtUtils::Manifest qw(maniread);
355 my %manifest = map {( $_ => 1 )}
356 grep { File::Spec->canonpath($_) }
357 keys %{ maniread() };
359 if( !keys %manifest ) {
360 print "No files found in MANIFEST. Stopping.\n";
366 my $path = File::Spec->canonpath($_);
368 return unless -f $path;
369 return if exists $manifest{ $path };
371 print "unlink $path\n";
380 =item Which tar should I use on Windows?
382 We recommend ptar from Archive::Tar not older than 1.66 with '-C' option.
384 =item Which zip should I use on Windows for '[ndg]make zipdist'?
386 We recommend InfoZIP: L<http://www.info-zip.org/Zip.html>
395 =item How do I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors?
397 XS code is very sensitive to the module version number and will
398 complain if the version number in your Perl module doesn't match. If
399 you change your module's version # without rerunning Makefile.PL the old
400 version number will remain in the Makefile, causing the XS code to be built
401 with the wrong number.
403 To avoid this, you can force the Makefile to be rebuilt whenever you
404 change the module containing the version number by adding this to your
405 WriteMakefile() arguments.
407 depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
410 =item How do I make two or more XS files coexist in the same directory?
412 Sometimes you need to have two and more XS files in the same package.
413 There are three ways: C<XSMULTI>, separate directories, and bootstrapping
420 Structure your modules so they are all located under F<lib>, such that
421 C<Foo::Bar> is in F<lib/Foo/Bar.pm> and F<lib/Foo/Bar.xs>, etc. Have your
422 top-level C<WriteMakefile> set the variable C<XSMULTI> to a true value.
426 =item Separate directories
428 Put each XS files into separate directories, each with their own
429 F<Makefile.PL>. Make sure each of those F<Makefile.PL>s has the correct
430 C<CFLAGS>, C<INC>, C<LIBS> etc. You will need to make sure the top-level
431 F<Makefile.PL> refers to each of these using C<DIR>.
435 Let's assume that we have a package C<Cool::Foo>, which includes
436 C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
437 file. First we use the following I<Makefile.PL>:
439 use ExtUtils::MakeMaker;
443 VERSION_FROM => 'Foo.pm',
444 OBJECT => q/$(O_FILES)/,
445 # ... other attrs ...
448 Notice the C<OBJECT> attribute. MakeMaker generates the following
449 variables in I<Makefile>:
451 # Handy lists of source code files:
459 Therefore we can use the C<O_FILES> variable to tell MakeMaker to use
460 these objects into the shared library.
462 That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
463 and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
464 I<Bar.pm> simply loading I<Foo.pm>.
466 The only issue left is to how to bootstrap I<Bar.xs>. This is done
469 MODULE = Cool::Foo PACKAGE = Cool::Foo
472 # boot the second XS file
473 boot_Cool__Bar(aTHX_ cv);
475 If you have more than two files, this is the place where you should
476 boot extra XS files from.
478 The following four files sum up all the details discussed so far.
486 our @ISA = qw(DynaLoader);
487 our $VERSION = '0.01';
488 bootstrap Cool::Foo $VERSION;
496 use Cool::Foo; # bootstraps Bar.xs
506 MODULE = Cool::Foo PACKAGE = Cool::Foo
509 # boot the second XS file
510 boot_Cool__Bar(aTHX_ cv);
512 MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_
515 cool_foo_perl_rules()
518 fprintf(stderr, "Cool::Foo says: Perl Rules\n");
526 MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_
529 cool_bar_perl_rules()
532 fprintf(stderr, "Cool::Bar says: Perl Rules\n");
534 And of course a very basic test:
539 BEGIN { plan tests => 1 };
542 Cool::Foo::perl_rules();
543 Cool::Bar::perl_rules();
546 This tip has been brought to you by Nick Ing-Simmons and Stas Bekman.
548 An alternative way to achieve this can be seen in L<Gtk2::CodeGen>
549 and L<Glib::CodeGen>.
557 =head2 MakeMaker object hierarchy (simplified)
559 What most people need to know (superclasses on top.)
565 ExtUtils::MM_{Current OS}
571 The object actually used is of the class MY which allows you to
572 override bits of MakeMaker inside your Makefile.PL by declaring
575 =head2 MakeMaker object hierarchy (real)
577 Here's how it really works:
583 ExtUtils::Liblist::Kid ExtUtils::MM_{Current OS} (if necessary)
585 ExtUtils::Liblist ExtUtils::MakeMaker |
587 | | |-----------------------
590 ExtUtils::MY MM (created by ExtUtils::MM)
592 MY (created by ExtUtils::MY) |
596 PACK### (created each call to ExtUtils::MakeMaker->new)
598 NOTE: Yes, this is a mess. See
599 L<http://archive.develooper.com/makemaker@perl.org/msg00134.html>
602 NOTE: When ExtUtils::MM is loaded it chooses a superclass for MM from
603 amongst the ExtUtils::MM_* modules based on the current operating
606 NOTE: ExtUtils::MM_{Current OS} represents one of the ExtUtils::MM_*
607 modules except ExtUtils::MM_Any chosen based on your operating system.
609 NOTE: The main object used by MakeMaker is a PACK### object, *not*
610 ExtUtils::MakeMaker. It is, effectively, a subclass of MY,
611 ExtUtils::Makemaker, ExtUtils::Liblist and ExtUtils::MM_{Current OS}
613 NOTE: The methods in MY are simply copied into PACK### rather than
614 MY being a superclass of PACK###. I don't remember the rationale.
616 NOTE: ExtUtils::Liblist should be removed from the inheritance hiearchy
617 and simply be called as functions.
619 NOTE: Modules like File::Spec and Exporter have been omitted for clarity.
622 =head2 The MM_* hierarchy
626 MM_BeOS MM_Cygwin MM_OS2 MM_VMS MM_Win32 MM_DOS MM_UWIN
628 ------------------------------------------------
634 NOTE: Each direct MM_Unix subclass is also an MM_Any subclass. This
635 is a temporary hack because MM_Unix overrides some MM_Any methods with
636 Unix specific code. It allows the non-Unix modules to see the
637 original MM_Any implementations.
639 NOTE: Modules like File::Spec and Exporter have been omitted for clarity.
643 If you have a question you'd like to see added to the FAQ (whether or
644 not you have the answer) please either:
648 =item * make a pull request on the MakeMaker github repository
650 =item * raise a issue on the MakeMaker github repository
652 =item * file an RT ticket
654 =item * email makemaker@perl.org
660 The denizens of makemaker@perl.org.
664 L<ExtUtils::MakeMaker>