Move ExtUtils::MakeMaker from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / ExtUtils-MakeMaker / lib / ExtUtils / MakeMaker / FAQ.pod
CommitLineData
479d2113 1package ExtUtils::MakeMaker::FAQ;
2
a592ba15 3our $VERSION = '1.12';
479d2113 4
51;
6__END__
7
8=head1 NAME
9
10ExtUtils::MakeMaker::FAQ - Frequently Asked Questions About MakeMaker
11
12=head1 DESCRIPTION
13
14FAQs, tricks and tips for C<ExtUtils::MakeMaker>.
15
03c94fc2 16
17=head2 Module Installation
18
19=over 4
20
58d32538 21=item How do I install a module into my home directory?
22
23If you're not the Perl administrator you probably don't have
24permission to install a module to its default location. Then you
25should install it for your own use into your home directory like so:
26
1e65eb70 27 # Non-unix folks, replace ~ with /path/to/your/home/dir
58d32538 28 perl Makefile.PL INSTALL_BASE=~
29
30This will put modules into F<~/lib/perl5>, man pages into F<~/man> and
31programs into F<~/bin>.
32
33To ensure your Perl programs can see these newly installed modules,
34set your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell
35each of your programs to look in that directory with the following:
36
37 use lib "$ENV{HOME}/lib/perl5";
38
1e65eb70 39or if $ENV{HOME} isn't set and you don't want to set it for some
40reason, do it the long way.
41
42 use lib "/path/to/your/home/dir/lib/perl5";
43
58d32538 44
45=item How do I get MakeMaker and Module::Build to install to the same place?
46
47Module::Build, as of 0.28, supports two ways to install to the same
48location as MakeMaker.
49
501) Use INSTALL_BASE / C<--install_base>
51
52MakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install
53to the same locations using the "install_base" concept. See
54L<ExtUtils::MakeMaker/INSTALL_BASE> for details. To get MM and MB to
55install to the same location simply set INSTALL_BASE in MM and
56C<--install_base> in MB to the same location.
57
58 perl Makefile.PL INSTALL_BASE=/whatever
59 perl Build.PL --install_base /whatever
60
612) Use PREFIX / C<--prefix>
62
63Module::Build 0.28 added support for C<--prefix> which works like
64MakeMaker's PREFIX.
65
66 perl Makefile.PL PREFIX=/whatever
67 perl Build.PL --prefix /whatever
68
69
03c94fc2 70=item How do I keep from installing man pages?
71
72Recent versions of MakeMaker will only install man pages on Unix like
73operating systems.
74
75For an individual module:
76
77 perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none
78
79If you want to suppress man page installation for all modules you have
80to reconfigure Perl and tell it 'none' when it asks where to install
81man pages.
82
83
84=item How do I use a module without installing it?
85
86Two ways. One is to build the module normally...
87
88 perl Makefile.PL
89 make
58d32538 90 make test
03c94fc2 91
92...and then set the PERL5LIB environment variable to point at the
93blib/lib and blib/arch directories.
94
95The other is to install the module in a temporary location.
96
58d32538 97 perl Makefile.PL INSTALL_BASE=~/tmp
98 make
99 make test
100 make install
03c94fc2 101
58d32538 102And then set PERL5LIB to F<~/tmp/lib/perl5>. This works well when you
103have multiple modules to work with. It also ensures that the module
104goes through its full installation process which may modify it.
03c94fc2 105
277189c8 106=item PREFIX vs INSTALL_BASE from Module::Build::Cookbook
107
108The behavior of PREFIX is complicated and depends closely on how your
109Perl is configured. The resulting installation locations will vary from
110machine to machine and even different installations of Perl on the same machine.
111Because of this, its difficult to document where prefix will place your modules.
112
113In contrast, INSTALL_BASE has predictable, easy to explain installation locations.
114Now that Module::Build and MakeMaker both have INSTALL_BASE there is little reason
115to use PREFIX other than to preserve your existing installation locations. If you
116are starting a fresh Perl installation we encourage you to use INSTALL_BASE. If
117you have an existing installation installed via PREFIX, consider moving it to an
118installation structure matching INSTALL_BASE and using that instead.
119
03c94fc2 120=back
121
122
479d2113 123=head2 Philosophy and History
124
125=over 4
126
127=item Why not just use <insert other build config tool here>?
128
129Why did MakeMaker reinvent the build configuration wheel? Why not
130just use autoconf or automake or ppm or Ant or ...
131
132There are many reasons, but the major one is cross-platform
133compatibility.
134
135Perl is one of the most ported pieces of software ever. It works on
136operating systems I've never even heard of (see perlport for details).
137It needs a build tool that can work on all those platforms and with
03c94fc2 138any wacky C compilers and linkers they might have.
479d2113 139
03c94fc2 140No such build tool exists. Even make itself has wildly different
141dialects. So we have to build our own.
479d2113 142
143
03c94fc2 144=item What is Module::Build and how does it relate to MakeMaker?
479d2113 145
146Module::Build is a project by Ken Williams to supplant MakeMaker.
147Its primary advantages are:
148
149=over 8
150
151=item * pure perl. no make, no shell commands
152
153=item * easier to customize
154
155=item * cleaner internals
156
157=item * less cruft
158
159=back
160
161Module::Build is the official heir apparent to MakeMaker and we
03c94fc2 162encourage people to work on M::B rather than spending time adding features
163to MakeMaker.
479d2113 164
165=back
166
03c94fc2 167
2530b651 168=head2 Module Writing
169
170=over 4
171
e3aa3ecb 172=item How do I keep my $VERSION up to date without resetting it manually?
2530b651 173
174Often you want to manually set the $VERSION in the main module
175distribution because this is the version that everybody sees on CPAN
176and maybe you want to customize it a bit. But for all the other
177modules in your dist, $VERSION is really just bookkeeping and all that's
178important is it goes up every time the module is changed. Doing this
179by hand is a pain and you often forget.
180
181Simplest way to do it automatically is to use your version control
182system's revision number (you are using version control, right?).
183
7292dc67 184In CVS, RCS and SVN you use $Revision$ (see the documentation of your
2977d345 185version control system for details). Every time the file is checked
186in the $Revision$ will be updated, updating your $VERSION.
2530b651 187
2977d345 188SVN uses a simple integer for $Revision$ so you can adapt it for your
189$VERSION like so:
2530b651 190
277189c8 191 ($VERSION) = q$Revision$ =~ /(\d+)/;
2530b651 192
2977d345 193In CVS and RCS version 1.9 is followed by 1.10. Since CPAN compares
194version numbers numerically we use a sprintf() to convert 1.9 to 1.009
195and 1.10 to 1.010 which compare properly.
196
197 $VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g;
2530b651 198
7292dc67 199If branches are involved (ie. $Revision: 1.5.3.4$) its a little more
2530b651 200complicated.
201
202 # must be all on one line or MakeMaker will get confused.
7292dc67 203 $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r };
2530b651 204
2977d345 205In SVN, $Revision$ should be the same for every file in the project so
206they would all have the same $VERSION. CVS and RCS have a different
207$Revision$ per file so each file will have a differnt $VERSION.
208Distributed version control systems, such as SVK, may have a different
209$Revision$ based on who checks out the file leading to a different $VERSION
210on each machine! Finally, some distributed version control systems, such
211as darcs, have no concept of revision number at all.
212
213
e3aa3ecb 214=item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?!
c2990482 215
216F<META.yml> is a module meta-data file pioneered by Module::Build and
217automatically generated as part of the 'distdir' target (and thus
218'dist'). See L<ExtUtils::MakeMaker/"Module Meta-Data">.
219
220To shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>.
2530b651 221
58d32538 222
223=item How do I delete everything not in my F<MANIFEST>?
224
225Some folks are surpried that C<make distclean> does not delete
226everything not listed in their MANIFEST (thus making a clean
227distribution) but only tells them what they need to delete. This is
228done because it is considered too dangerous. While developing your
229module you might write a new file, not add it to the MANIFEST, then
230run a C<distclean> and be sad because your new work was deleted.
231
232If you really want to do this, you can use
233C<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find
234to delete the files. But you have to be careful. Here's a script to
235do that. Use at your own risk. Have fun blowing holes in your foot.
236
237 #!/usr/bin/perl -w
238
239 use strict;
240
241 use File::Spec;
242 use File::Find;
243 use ExtUtils::Manifest qw(maniread);
244
245 my %manifest = map {( $_ => 1 )}
246 grep { File::Spec->canonpath($_) }
247 keys %{ maniread() };
248
249 if( !keys %manifest ) {
250 print "No files found in MANIFEST. Stopping.\n";
251 exit;
252 }
253
254 find({
255 wanted => sub {
256 my $path = File::Spec->canonpath($_);
257
258 return unless -f $path;
259 return if exists $manifest{ $path };
260
261 print "unlink $path\n";
262 unlink $path;
263 },
264 no_chdir => 1
265 },
266 "."
267 );
268
269
5bdf71cc 270=item Which zip should I use on Windows for '[nd]make zipdist'?
271
272We recommend InfoZIP: L<http://www.info-zip.org/Zip.html>
273
274
2530b651 275=back
276
479d2113 277=head2 XS
278
279=over 4
280
e3aa3ecb 281=item How to I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors?
dedf98bc 282
283XS code is very sensitive to the module version number and will
284complain if the version number in your Perl module doesn't match. If
c2878c71 285you change your module's version # without rerunning Makefile.PL the old
dedf98bc 286version number will remain in the Makefile causing the XS code to be built
287with the wrong number.
288
289To avoid this, you can force the Makefile to be rebuilt whenever you
290change the module containing the version number by adding this to your
291WriteMakefile() arguments.
292
293 depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' }
294
295
e3aa3ecb 296=item How do I make two or more XS files coexist in the same directory?
479d2113 297
298Sometimes you need to have two and more XS files in the same package.
299One way to go is to put them into separate directories, but sometimes
300this is not the most suitable solution. The following technique allows
301you to put two (and more) XS files in the same directory.
302
303Let's assume that we have a package C<Cool::Foo>, which includes
304C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS
305file. First we use the following I<Makefile.PL>:
306
307 use ExtUtils::MakeMaker;
308
309 WriteMakefile(
310 NAME => 'Cool::Foo',
311 VERSION_FROM => 'Foo.pm',
312 OBJECT => q/$(O_FILES)/,
313 # ... other attrs ...
314 );
315
316Notice the C<OBJECT> attribute. MakeMaker generates the following
317variables in I<Makefile>:
318
319 # Handy lists of source code files:
320 XS_FILES= Bar.xs \
321 Foo.xs
322 C_FILES = Bar.c \
323 Foo.c
324 O_FILES = Bar.o \
325 Foo.o
326
327Therefore we can use the C<O_FILES> variable to tell MakeMaker to use
328these objects into the shared library.
329
330That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm>
331and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and
332I<Bar.pm> simply loading I<Foo.pm>.
333
334The only issue left is to how to bootstrap I<Bar.xs>. This is done
335from I<Foo.xs>:
336
337 MODULE = Cool::Foo PACKAGE = Cool::Foo
338
339 BOOT:
340 # boot the second XS file
341 boot_Cool__Bar(aTHX_ cv);
342
343If you have more than two files, this is the place where you should
344boot extra XS files from.
345
346The following four files sum up all the details discussed so far.
347
348 Foo.pm:
349 -------
350 package Cool::Foo;
351
352 require DynaLoader;
353
354 our @ISA = qw(DynaLoader);
355 our $VERSION = '0.01';
356 bootstrap Cool::Foo $VERSION;
357
358 1;
359
360 Bar.pm:
361 -------
362 package Cool::Bar;
363
364 use Cool::Foo; # bootstraps Bar.xs
365
366 1;
367
368 Foo.xs:
369 -------
370 #include "EXTERN.h"
371 #include "perl.h"
372 #include "XSUB.h"
373
374 MODULE = Cool::Foo PACKAGE = Cool::Foo
375
376 BOOT:
377 # boot the second XS file
378 boot_Cool__Bar(aTHX_ cv);
379
380 MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_
381
382 void
383 cool_foo_perl_rules()
384
385 CODE:
386 fprintf(stderr, "Cool::Foo says: Perl Rules\n");
387
388 Bar.xs:
389 -------
390 #include "EXTERN.h"
391 #include "perl.h"
392 #include "XSUB.h"
393
394 MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_
395
396 void
397 cool_bar_perl_rules()
398
399 CODE:
400 fprintf(stderr, "Cool::Bar says: Perl Rules\n");
401
402And of course a very basic test:
403
58d32538 404 t/cool.t:
479d2113 405 --------
406 use Test;
407 BEGIN { plan tests => 1 };
408 use Cool::Foo;
409 use Cool::Bar;
410 Cool::Foo::perl_rules();
411 Cool::Bar::perl_rules();
412 ok 1;
413
414This tip has been brought to you by Nick Ing-Simmons and Stas Bekman.
415
416=back
417
418=head1 PATCHING
419
420If you have a question you'd like to see added to the FAQ (whether or
421not you have the answer) please send it to makemaker@perl.org.
422
423=head1 AUTHOR
424
425The denizens of makemaker@perl.org.
426
427=head1 SEE ALSO
428
429L<ExtUtils::MakeMaker>
430
431=cut