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