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