1 package ExtUtils::MakeMaker::FAQ;
10 ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker
14 FAQs, tricks and tips for C<ExtUtils::MakeMaker>.
17 =head2 Module Installation
21 =item How do I install a module into my home directory?
23 If you're not the Perl administrator you probably don't have
24 permission to install a module to its default location. Then you
25 should install it for your own use into your home directory like so:
27 # Non-unix folks, replace ~ with /path/to/your/home/dir
28 perl Makefile.PL INSTALL_BASE=~
30 This will put modules into F<~/lib/perl5>, man pages into F<~/man> and
31 programs into F<~/bin>.
33 To ensure your Perl programs can see these newly installed modules,
34 set your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell
35 each of your programs to look in that directory with the following:
37 use lib "$ENV{HOME}/lib/perl5";
39 or if $ENV{HOME} isn't set and you don't want to set it for some
40 reason, do it the long way.
42 use lib "/path/to/your/home/dir/lib/perl5";
45 =item How do I get MakeMaker and Module::Build to install to the same place?
47 Module::Build, as of 0.28, supports two ways to install to the same
48 location as MakeMaker.
50 We highly recommend the install_base method, its the simplest and most
51 closely approximates the expected behavior of an installation prefix.
53 1) Use INSTALL_BASE / C<--install_base>
55 MakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install
56 to the same locations using the "install_base" concept. See
57 L<ExtUtils::MakeMaker/INSTALL_BASE> for details. To get MM and MB to
58 install to the same location simply set INSTALL_BASE in MM and
59 C<--install_base> in MB to the same location.
61 perl Makefile.PL INSTALL_BASE=/whatever
62 perl Build.PL --install_base /whatever
64 This works most like other language's behavior when you specify a
65 prefix. We recommend this method.
67 2) Use PREFIX / C<--prefix>
69 Module::Build 0.28 added support for C<--prefix> which works like
72 perl Makefile.PL PREFIX=/whatever
73 perl Build.PL --prefix /whatever
75 We highly discourage this method. It should only be used if you know
76 what you're doing and specifically need the PREFIX behavior. The
77 PREFIX algorithm is complicated and focused on matching the system
80 =item How do I keep from installing man pages?
82 Recent versions of MakeMaker will only install man pages on Unix-like
85 For an individual module:
87 perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none
89 If you want to suppress man page installation for all modules you have
90 to reconfigure Perl and tell it 'none' when it asks where to install
94 =item How do I use a module without installing it?
96 Two ways. One is to build the module normally...
102 ...and then set the PERL5LIB environment variable to point at the
103 blib/lib and blib/arch directories.
105 The other is to install the module in a temporary location.
107 perl Makefile.PL INSTALL_BASE=~/tmp
112 And then set PERL5LIB to F<~/tmp/lib/perl5>. This works well when you
113 have multiple modules to work with. It also ensures that the module
114 goes through its full installation process which may modify it.
116 =item PREFIX vs INSTALL_BASE from Module::Build::Cookbook
118 The behavior of PREFIX is complicated and depends closely on how your
119 Perl is configured. The resulting installation locations will vary from
120 machine to machine and even different installations of Perl on the same machine.
121 Because of this, its difficult to document where prefix will place your modules.
123 In contrast, INSTALL_BASE has predictable, easy to explain installation locations.
124 Now that Module::Build and MakeMaker both have INSTALL_BASE there is little reason
125 to use PREFIX other than to preserve your existing installation locations. If you
126 are starting a fresh Perl installation we encourage you to use INSTALL_BASE. If
127 you have an existing installation installed via PREFIX, consider moving it to an
128 installation structure matching INSTALL_BASE and using that instead.
132 =head2 Common errors and problems
136 =item "No rule to make target `/usr/lib/perl5/CORE/config.h', needed by `Makefile'"
138 Just what it says, you're missing that file. MakeMaker uses it to
139 determine if perl has been rebuilt since the Makefile was made. It's
140 a bit of a bug that it halts installation.
142 Some operating systems don't ship the CORE directory with their base
143 perl install. To solve the problem, you likely need to install a perl
144 development package such as perl-devel (CentOS, Fedora and other
145 Redhat systems) or perl (Ubuntu and other Debian systems).
149 =head2 Philosophy and History
153 =item Why not just use <insert other build config tool here>?
155 Why did MakeMaker reinvent the build configuration wheel? Why not
156 just use autoconf or automake or ppm or Ant or ...
158 There are many reasons, but the major one is cross-platform
161 Perl is one of the most ported pieces of software ever. It works on
162 operating systems I've never even heard of (see perlport for details).
163 It needs a build tool that can work on all those platforms and with
164 any wacky C compilers and linkers they might have.
166 No such build tool exists. Even make itself has wildly different
167 dialects. So we have to build our own.
170 =item What is Module::Build and how does it relate to MakeMaker?
172 Module::Build is a project by Ken Williams to supplant MakeMaker.
173 Its primary advantages are:
177 =item * pure perl. no make, no shell commands
179 =item * easier to customize
181 =item * cleaner internals
187 Module::Build was long the official heir apparent to MakeMaker. The rate of
188 both its development and adoption has slowed in recent years, though, and it is
189 unclear what the future holds for it. That said, Module::Build set the stage
190 for I<something> to become the heir to MakeMaker. MakeMaker's maintainers have
191 long said that it is a dead end and should be kept functioning, but not
192 extended with new features. It's complicated enough as it is!
197 =head2 Module Writing
201 =item How do I keep my $VERSION up to date without resetting it manually?
203 Often you want to manually set the $VERSION in the main module
204 distribution because this is the version that everybody sees on CPAN
205 and maybe you want to customize it a bit. But for all the other
206 modules in your dist, $VERSION is really just bookkeeping and all that's
207 important is it goes up every time the module is changed. Doing this
208 by hand is a pain and you often forget.
210 Simplest way to do it automatically is to use your version control
211 system's revision number (you are using version control, right?).
213 In CVS, RCS and SVN you use $Revision$ (see the documentation of your
214 version control system for details). Every time the file is checked
215 in the $Revision$ will be updated, updating your $VERSION.
217 SVN uses a simple integer for $Revision$ so you can adapt it for your
220 ($VERSION) = q$Revision$ =~ /(\d+)/;
222 In CVS and RCS version 1.9 is followed by 1.10. Since CPAN compares
223 version numbers numerically we use a sprintf() to convert 1.9 to 1.009
224 and 1.10 to 1.010 which compare properly.
226 $VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g;
228 If branches are involved (ie. $Revision: 1.5.3.4$) it's a little more
231 # must be all on one line or MakeMaker will get confused.
232 $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
234 In SVN, $Revision$ should be the same for every file in the project so
235 they would all have the same $VERSION. CVS and RCS have a different
236 $Revision$ per file so each file will have a different $VERSION.
237 Distributed version control systems, such as SVK, may have a different
238 $Revision$ based on who checks out the file, leading to a different $VERSION
239 on each machine! Finally, some distributed version control systems, such
240 as darcs, have no concept of revision number at all.
243 =item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?!
245 F<META.yml> is a module meta-data file pioneered by Module::Build and
246 automatically generated as part of the 'distdir' target (and thus
247 'dist'). See L<ExtUtils::MakeMaker/"Module Meta-Data">.
249 To shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>.
252 =item How do I delete everything not in my F<MANIFEST>?
254 Some folks are surprised that C<make distclean> does not delete
255 everything not listed in their MANIFEST (thus making a clean
256 distribution) but only tells them what they need to delete. This is
257 done because it is considered too dangerous. While developing your
258 module you might write a new file, not add it to the MANIFEST, then
259 run a C<distclean> and be sad because your new work was deleted.
261 If you really want to do this, you can use
262 C<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find
263 to delete the files. But you have to be careful. Here's a script to
264 do that. Use at your own risk. Have fun blowing holes in your foot.
272 use ExtUtils::Manifest qw(maniread);
274 my %manifest = map {( $_ => 1 )}
275 grep { File::Spec->canonpath($_) }
276 keys %{ maniread() };
278 if( !keys %manifest ) {
279 print "No files found in MANIFEST. Stopping.\n";
285 my $path = File::Spec->canonpath($_);
287 return unless -f $path;
288 return if exists $manifest{ $path };
290 print "unlink $path\n";
299 =item Which tar should I use on Windows?
301 We recommend ptar from Archive::Tar not older than 1.66 with '-C' option.
303 =item Which zip should I use on Windows for '[nd]make zipdist'?
305 We recommend InfoZIP: L<http://www.info-zip.org/Zip.html>
314 =item How do I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors?
316 XS code is very sensitive to the module version number and will
317 complain if the version number in your Perl module doesn't match. If
318 you change your module's version # without rerunning Makefile.PL the old
319 version number will remain in the Makefile, causing the XS code to be built
320 with the wrong number.
322 To avoid this, you can force the Makefile to be rebuilt whenever you
323 change the module containing the version number by adding this to your
324 WriteMakefile() arguments.
326 depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
329 =item How do I make two or more XS files coexist in the same directory?
331 Sometimes you need to have two and more XS files in the same package.
332 One way to go is to put them into separate directories, but sometimes
333 this is not the most suitable solution. The following technique allows
334 you to put two (and more) XS files in the same directory.
336 Let's assume that we have a package C<Cool::Foo>, which includes
337 C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
338 file. First we use the following I<Makefile.PL>:
340 use ExtUtils::MakeMaker;
344 VERSION_FROM => 'Foo.pm',
345 OBJECT => q/$(O_FILES)/,
346 # ... other attrs ...
349 Notice the C<OBJECT> attribute. MakeMaker generates the following
350 variables in I<Makefile>:
352 # Handy lists of source code files:
360 Therefore we can use the C<O_FILES> variable to tell MakeMaker to use
361 these objects into the shared library.
363 That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
364 and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
365 I<Bar.pm> simply loading I<Foo.pm>.
367 The only issue left is to how to bootstrap I<Bar.xs>. This is done
370 MODULE = Cool::Foo PACKAGE = Cool::Foo
373 # boot the second XS file
374 boot_Cool__Bar(aTHX_ cv);
376 If you have more than two files, this is the place where you should
377 boot extra XS files from.
379 The following four files sum up all the details discussed so far.
387 our @ISA = qw(DynaLoader);
388 our $VERSION = '0.01';
389 bootstrap Cool::Foo $VERSION;
397 use Cool::Foo; # bootstraps Bar.xs
407 MODULE = Cool::Foo PACKAGE = Cool::Foo
410 # boot the second XS file
411 boot_Cool__Bar(aTHX_ cv);
413 MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_
416 cool_foo_perl_rules()
419 fprintf(stderr, "Cool::Foo says: Perl Rules\n");
427 MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_
430 cool_bar_perl_rules()
433 fprintf(stderr, "Cool::Bar says: Perl Rules\n");
435 And of course a very basic test:
440 BEGIN { plan tests => 1 };
443 Cool::Foo::perl_rules();
444 Cool::Bar::perl_rules();
447 This tip has been brought to you by Nick Ing-Simmons and Stas Bekman.
453 If you have a question you'd like to see added to the FAQ (whether or
454 not you have the answer) please send it to makemaker@perl.org.
458 The denizens of makemaker@perl.org.
462 L<ExtUtils::MakeMaker>