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