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