1package ExtUtils::MakeMaker::FAQ; 2 3our $VERSION = '7.64'; 4$VERSION =~ tr/_//d; 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 L<ExtUtils::MakeMaker>. 16 17 18=head2 Module Installation 19 20=over 4 21 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. Ways of handling 26this with a B<lot> less manual effort on your part are L<perlbrew> 27and L<local::lib>. 28 29Otherwise, you can install it for your own use into your home directory 30like so: 31 32 # Non-unix folks, replace ~ with /path/to/your/home/dir 33 perl Makefile.PL INSTALL_BASE=~ 34 35This will put modules into F<~/lib/perl5>, man pages into F<~/man> and 36programs into F<~/bin>. 37 38To ensure your Perl programs can see these newly installed modules, 39set your C<PERL5LIB> environment variable to F<~/lib/perl5> or tell 40each of your programs to look in that directory with the following: 41 42 use lib "$ENV{HOME}/lib/perl5"; 43 44or if $ENV{HOME} isn't set and you don't want to set it for some 45reason, do it the long way. 46 47 use lib "/path/to/your/home/dir/lib/perl5"; 48 49=item How do I get MakeMaker and Module::Build to install to the same place? 50 51Module::Build, as of 0.28, supports two ways to install to the same 52location as MakeMaker. 53 54We highly recommend the install_base method, its the simplest and most 55closely approximates the expected behavior of an installation prefix. 56 571) Use INSTALL_BASE / C<--install_base> 58 59MakeMaker (as of 6.31) and Module::Build (as of 0.28) both can install 60to the same locations using the "install_base" concept. See 61L<ExtUtils::MakeMaker/INSTALL_BASE> for details. To get MM and MB to 62install to the same location simply set INSTALL_BASE in MM and 63C<--install_base> in MB to the same location. 64 65 perl Makefile.PL INSTALL_BASE=/whatever 66 perl Build.PL --install_base /whatever 67 68This works most like other language's behavior when you specify a 69prefix. We recommend this method. 70 712) Use PREFIX / C<--prefix> 72 73Module::Build 0.28 added support for C<--prefix> which works like 74MakeMaker's PREFIX. 75 76 perl Makefile.PL PREFIX=/whatever 77 perl Build.PL --prefix /whatever 78 79We highly discourage this method. It should only be used if you know 80what you're doing and specifically need the PREFIX behavior. The 81PREFIX algorithm is complicated and focused on matching the system 82installation. 83 84=item How do I keep from installing man pages? 85 86Recent versions of MakeMaker will only install man pages on Unix-like 87operating systems by default. To generate manpages on non-Unix operating 88systems, make the "manifypods" target. 89 90For an individual module: 91 92 perl Makefile.PL INSTALLMAN1DIR=none INSTALLMAN3DIR=none 93 94If you want to suppress man page installation for all modules you have 95to reconfigure Perl and tell it 'none' when it asks where to install 96man pages. 97 98 99=item How do I use a module without installing it? 100 101Two ways. One is to build the module normally... 102 103 perl Makefile.PL 104 make 105 make test 106 107...and then use L<blib> to point Perl at the built but uninstalled module: 108 109 perl -Mblib script.pl 110 perl -Mblib -e '...' 111 112The other is to install the module in a temporary location. 113 114 perl Makefile.PL INSTALL_BASE=~/tmp 115 make 116 make test 117 make install 118 119And then set PERL5LIB to F<~/tmp/lib/perl5>. This works well when you 120have multiple modules to work with. It also ensures that the module 121goes through its full installation process which may modify it. 122Again, L<local::lib> may assist you here. 123 124=item How can I organize tests into subdirectories and have them run? 125 126Let's take the following test directory structure: 127 128 t/foo/sometest.t 129 t/bar/othertest.t 130 t/bar/baz/anothertest.t 131 132Now, inside of the C<WriteMakeFile()> function in your F<Makefile.PL>, specify 133where your tests are located with the C<test> directive: 134 135 test => {TESTS => 't/*.t t/*/*.t t/*/*/*.t'} 136 137The first entry in the string will run all tests in the top-level F<t/> 138directory. The second will run all test files located in any subdirectory under 139F<t/>. The third, runs all test files within any subdirectory within any other 140subdirectory located under F<t/>. 141 142Note that you do not have to use wildcards. You can specify explicitly which 143subdirectories to run tests in: 144 145 test => {TESTS => 't/*.t t/foo/*.t t/bar/baz/*.t'} 146 147=item PREFIX vs INSTALL_BASE from Module::Build::Cookbook 148 149The behavior of PREFIX is complicated and depends closely on how your 150Perl is configured. The resulting installation locations will vary 151from machine to machine and even different installations of Perl on the 152same machine. Because of this, its difficult to document where prefix 153will place your modules. 154 155In contrast, INSTALL_BASE has predictable, easy to explain installation 156locations. Now that Module::Build and MakeMaker both have INSTALL_BASE 157there is little reason to use PREFIX other than to preserve your existing 158installation locations. If you are starting a fresh Perl installation we 159encourage you to use INSTALL_BASE. If you have an existing installation 160installed via PREFIX, consider moving it to an installation structure 161matching INSTALL_BASE and using that instead. 162 163=item Generating *.pm files with substitutions eg of $VERSION 164 165If you want to configure your module files for local conditions, or to 166automatically insert a version number, you can use EUMM's C<PL_FILES> 167capability, where it will automatically run each F<*.PL> it finds to 168generate its basename. For instance: 169 170 # Makefile.PL: 171 require 'common.pl'; 172 my $version = get_version(); 173 my @pms = qw(Foo.pm); 174 WriteMakefile( 175 NAME => 'Foo', 176 VERSION => $version, 177 PM => { map { ($_ => "\$(INST_LIB)/$_") } @pms }, 178 clean => { FILES => join ' ', @pms }, 179 ); 180 181 # common.pl: 182 sub get_version { '0.04' } 183 sub process { my $v = get_version(); s/__VERSION__/$v/g; } 184 1; 185 186 # Foo.pm.PL: 187 require 'common.pl'; 188 $_ = join '', <DATA>; 189 process(); 190 my $file = shift; 191 open my $fh, '>', $file or die "$file: $!"; 192 print $fh $_; 193 __DATA__ 194 package Foo; 195 our $VERSION = '__VERSION__'; 196 1; 197 198You may notice that C<PL_FILES> is not specified above, since the default 199of mapping each .PL file to its basename works well. 200 201If the generated module were architecture-specific, you could replace 202C<$(INST_LIB)> above with C<$(INST_ARCHLIB)>, although if you locate 203modules under F<lib>, that would involve ensuring any C<lib/> in front 204of the module location were removed. 205 206=back 207 208=head2 Common errors and problems 209 210=over 4 211 212=item "No rule to make target `/usr/lib/perl5/CORE/config.h', needed by `Makefile'" 213 214Just what it says, you're missing that file. MakeMaker uses it to 215determine if perl has been rebuilt since the Makefile was made. It's 216a bit of a bug that it halts installation. 217 218Some operating systems don't ship the CORE directory with their base 219perl install. To solve the problem, you likely need to install a perl 220development package such as perl-devel (CentOS, Fedora and other 221Redhat systems) or perl (Ubuntu and other Debian systems). 222 223=back 224 225=head2 Philosophy and History 226 227=over 4 228 229=item Why not just use <insert other build config tool here>? 230 231Why did MakeMaker reinvent the build configuration wheel? Why not 232just use autoconf or automake or ppm or Ant or ... 233 234There are many reasons, but the major one is cross-platform 235compatibility. 236 237Perl is one of the most ported pieces of software ever. It works on 238operating systems I've never even heard of (see perlport for details). 239It needs a build tool that can work on all those platforms and with 240any wacky C compilers and linkers they might have. 241 242No such build tool exists. Even make itself has wildly different 243dialects. So we have to build our own. 244 245 246=item What is Module::Build and how does it relate to MakeMaker? 247 248Module::Build is a project by Ken Williams to supplant MakeMaker. 249Its primary advantages are: 250 251=over 8 252 253=item * pure perl. no make, no shell commands 254 255=item * easier to customize 256 257=item * cleaner internals 258 259=item * less cruft 260 261=back 262 263Module::Build was long the official heir apparent to MakeMaker. The 264rate of both its development and adoption has slowed in recent years, 265though, and it is unclear what the future holds for it. That said, 266Module::Build set the stage for I<something> to become the heir to 267MakeMaker. MakeMaker's maintainers have long said that it is a dead 268end and should be kept functioning, while being cautious about extending 269with new features. 270 271=back 272 273=head2 Module Writing 274 275=over 4 276 277=item How do I keep my $VERSION up to date without resetting it manually? 278 279Often you want to manually set the $VERSION in the main module 280distribution because this is the version that everybody sees on CPAN 281and maybe you want to customize it a bit. But for all the other 282modules in your dist, $VERSION is really just bookkeeping and all that's 283important is it goes up every time the module is changed. Doing this 284by hand is a pain and you often forget. 285 286Probably the easiest way to do this is using F<perl-reversion> in 287L<Perl::Version>: 288 289 perl-reversion -bump 290 291If your version control system supports revision numbers (git doesn't 292easily), the simplest way to do it automatically is to use its revision 293number (you are using version control, right?). 294 295In CVS, RCS and SVN you use $Revision$ (see the documentation of your 296version control system for details). Every time the file is checked 297in the $Revision$ will be updated, updating your $VERSION. 298 299SVN uses a simple integer for $Revision$ so you can adapt it for your 300$VERSION like so: 301 302 ($VERSION) = q$Revision$ =~ /(\d+)/; 303 304In CVS and RCS version 1.9 is followed by 1.10. Since CPAN compares 305version numbers numerically we use a sprintf() to convert 1.9 to 1.009 306and 1.10 to 1.010 which compare properly. 307 308 $VERSION = sprintf "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/g; 309 310If branches are involved (ie. $Revision: 1.5.3.4$) it's a little more 311complicated. 312 313 # must be all on one line or MakeMaker will get confused. 314 $VERSION = do { my @r = (q$Revision$ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; 315 316In SVN, $Revision$ should be the same for every file in the project so 317they would all have the same $VERSION. CVS and RCS have a different 318$Revision$ per file so each file will have a different $VERSION. 319Distributed version control systems, such as SVK, may have a different 320$Revision$ based on who checks out the file, leading to a different $VERSION 321on each machine! Finally, some distributed version control systems, such 322as darcs, have no concept of revision number at all. 323 324 325=item What's this F<META.yml> thing and how did it get in my F<MANIFEST>?! 326 327F<META.yml> is a module meta-data file pioneered by Module::Build and 328automatically generated as part of the 'distdir' target (and thus 329'dist'). See L<ExtUtils::MakeMaker/"Module Meta-Data">. 330 331To shut off its generation, pass the C<NO_META> flag to C<WriteMakefile()>. 332 333 334=item How do I delete everything not in my F<MANIFEST>? 335 336Some folks are surprised that C<make distclean> does not delete 337everything not listed in their MANIFEST (thus making a clean 338distribution) but only tells them what they need to delete. This is 339done because it is considered too dangerous. While developing your 340module you might write a new file, not add it to the MANIFEST, then 341run a C<distclean> and be sad because your new work was deleted. 342 343If you really want to do this, you can use 344C<ExtUtils::Manifest::manifind()> to read the MANIFEST and File::Find 345to delete the files. But you have to be careful. Here's a script to 346do that. Use at your own risk. Have fun blowing holes in your foot. 347 348 #!/usr/bin/perl -w 349 350 use strict; 351 352 use File::Spec; 353 use File::Find; 354 use ExtUtils::Manifest qw(maniread); 355 356 my %manifest = map {( $_ => 1 )} 357 grep { File::Spec->canonpath($_) } 358 keys %{ maniread() }; 359 360 if( !keys %manifest ) { 361 print "No files found in MANIFEST. Stopping.\n"; 362 exit; 363 } 364 365 find({ 366 wanted => sub { 367 my $path = File::Spec->canonpath($_); 368 369 return unless -f $path; 370 return if exists $manifest{ $path }; 371 372 print "unlink $path\n"; 373 unlink $path; 374 }, 375 no_chdir => 1 376 }, 377 "." 378 ); 379 380 381=item Which tar should I use on Windows? 382 383We recommend ptar from Archive::Tar not older than 1.66 with '-C' option. 384 385=item Which zip should I use on Windows for '[ndg]make zipdist'? 386 387We recommend InfoZIP: L<http://www.info-zip.org/Zip.html> 388 389 390=back 391 392=head2 XS 393 394=over 4 395 396=item How do I prevent "object version X.XX does not match bootstrap parameter Y.YY" errors? 397 398XS code is very sensitive to the module version number and will 399complain if the version number in your Perl module doesn't match. If 400you change your module's version # without rerunning Makefile.PL the old 401version number will remain in the Makefile, causing the XS code to be built 402with the wrong number. 403 404To avoid this, you can force the Makefile to be rebuilt whenever you 405change the module containing the version number by adding this to your 406WriteMakefile() arguments. 407 408 depend => { '$(FIRST_MAKEFILE)' => '$(VERSION_FROM)' } 409 410 411=item How do I make two or more XS files coexist in the same directory? 412 413Sometimes you need to have two and more XS files in the same package. 414There are three ways: C<XSMULTI>, separate directories, and bootstrapping 415one XS from another. 416 417=over 8 418 419=item XSMULTI 420 421Structure your modules so they are all located under F<lib>, such that 422C<Foo::Bar> is in F<lib/Foo/Bar.pm> and F<lib/Foo/Bar.xs>, etc. Have your 423top-level C<WriteMakefile> set the variable C<XSMULTI> to a true value. 424 425Er, that's it. 426 427=item Separate directories 428 429Put each XS files into separate directories, each with their own 430F<Makefile.PL>. Make sure each of those F<Makefile.PL>s has the correct 431C<CFLAGS>, C<INC>, C<LIBS> etc. You will need to make sure the top-level 432F<Makefile.PL> refers to each of these using C<DIR>. 433 434=item Bootstrapping 435 436Let's assume that we have a package C<Cool::Foo>, which includes 437C<Cool::Foo> and C<Cool::Bar> modules each having a separate XS 438file. First we use the following I<Makefile.PL>: 439 440 use ExtUtils::MakeMaker; 441 442 WriteMakefile( 443 NAME => 'Cool::Foo', 444 VERSION_FROM => 'Foo.pm', 445 OBJECT => q/$(O_FILES)/, 446 # ... other attrs ... 447 ); 448 449Notice the C<OBJECT> attribute. MakeMaker generates the following 450variables in I<Makefile>: 451 452 # Handy lists of source code files: 453 XS_FILES= Bar.xs \ 454 Foo.xs 455 C_FILES = Bar.c \ 456 Foo.c 457 O_FILES = Bar.o \ 458 Foo.o 459 460Therefore we can use the C<O_FILES> variable to tell MakeMaker to use 461these objects into the shared library. 462 463That's pretty much it. Now write I<Foo.pm> and I<Foo.xs>, I<Bar.pm> 464and I<Bar.xs>, where I<Foo.pm> bootstraps the shared library and 465I<Bar.pm> simply loading I<Foo.pm>. 466 467The only issue left is to how to bootstrap I<Bar.xs>. This is done 468from I<Foo.xs>: 469 470 MODULE = Cool::Foo PACKAGE = Cool::Foo 471 472 BOOT: 473 # boot the second XS file 474 boot_Cool__Bar(aTHX_ cv); 475 476If you have more than two files, this is the place where you should 477boot extra XS files from. 478 479The following four files sum up all the details discussed so far. 480 481 Foo.pm: 482 ------- 483 package Cool::Foo; 484 485 require DynaLoader; 486 487 our @ISA = qw(DynaLoader); 488 our $VERSION = '0.01'; 489 bootstrap Cool::Foo $VERSION; 490 491 1; 492 493 Bar.pm: 494 ------- 495 package Cool::Bar; 496 497 use Cool::Foo; # bootstraps Bar.xs 498 499 1; 500 501 Foo.xs: 502 ------- 503 #include "EXTERN.h" 504 #include "perl.h" 505 #include "XSUB.h" 506 507 MODULE = Cool::Foo PACKAGE = Cool::Foo 508 509 BOOT: 510 # boot the second XS file 511 boot_Cool__Bar(aTHX_ cv); 512 513 MODULE = Cool::Foo PACKAGE = Cool::Foo PREFIX = cool_foo_ 514 515 void 516 cool_foo_perl_rules() 517 518 CODE: 519 fprintf(stderr, "Cool::Foo says: Perl Rules\n"); 520 521 Bar.xs: 522 ------- 523 #include "EXTERN.h" 524 #include "perl.h" 525 #include "XSUB.h" 526 527 MODULE = Cool::Bar PACKAGE = Cool::Bar PREFIX = cool_bar_ 528 529 void 530 cool_bar_perl_rules() 531 532 CODE: 533 fprintf(stderr, "Cool::Bar says: Perl Rules\n"); 534 535And of course a very basic test: 536 537 t/cool.t: 538 -------- 539 use Test; 540 BEGIN { plan tests => 1 }; 541 use Cool::Foo; 542 use Cool::Bar; 543 Cool::Foo::perl_rules(); 544 Cool::Bar::perl_rules(); 545 ok 1; 546 547This tip has been brought to you by Nick Ing-Simmons and Stas Bekman. 548 549An alternative way to achieve this can be seen in L<Gtk2::CodeGen> 550and L<Glib::CodeGen>. 551 552=back 553 554=back 555 556=head1 DESIGN 557 558=head2 MakeMaker object hierarchy (simplified) 559 560What most people need to know (superclasses on top.) 561 562 ExtUtils::MM_Any 563 | 564 ExtUtils::MM_Unix 565 | 566 ExtUtils::MM_{Current OS} 567 | 568 ExtUtils::MakeMaker 569 | 570 MY 571 572The object actually used is of the class L<MY|ExtUtils::MY> which allows you to 573override bits of MakeMaker inside your Makefile.PL by declaring 574MY::foo() methods. 575 576=head2 MakeMaker object hierarchy (real) 577 578Here's how it really works: 579 580 ExtUtils::MM_Any 581 | 582 ExtUtils::MM_Unix 583 | 584 ExtUtils::Liblist::Kid ExtUtils::MM_{Current OS} (if necessary) 585 | | 586 ExtUtils::Liblist ExtUtils::MakeMaker | 587 | | | 588 | | |----------------------- 589 ExtUtils::MM 590 | | 591 ExtUtils::MY MM (created by ExtUtils::MM) 592 | | 593 MY (created by ExtUtils::MY) | 594 . | 595 (mixin) | 596 . | 597 PACK### (created each call to ExtUtils::MakeMaker->new) 598 599NOTE: Yes, this is a mess. See 600L<http://archive.develooper.com/makemaker@perl.org/msg00134.html> 601for some history. 602 603NOTE: When L<ExtUtils::MM> is loaded it chooses a superclass for MM from 604amongst the ExtUtils::MM_* modules based on the current operating 605system. 606 607NOTE: ExtUtils::MM_{Current OS} represents one of the ExtUtils::MM_* 608modules except L<ExtUtils::MM_Any> chosen based on your operating system. 609 610NOTE: The main object used by MakeMaker is a PACK### object, *not* 611L<ExtUtils::MakeMaker>. It is, effectively, a subclass of L<MY|ExtUtils::MY>, 612L<ExtUtils::MakeMaker>, L<ExtUtils::Liblist> and ExtUtils::MM_{Current OS} 613 614NOTE: The methods in L<MY|ExtUtils::MY> are simply copied into PACK### rather 615than MY being a superclass of PACK###. I don't remember the rationale. 616 617NOTE: L<ExtUtils::Liblist> should be removed from the inheritance hiearchy 618and simply be called as functions. 619 620NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity. 621 622 623=head2 The MM_* hierarchy 624 625 MM_Win95 MM_NW5 626 \ / 627 MM_BeOS MM_Cygwin MM_OS2 MM_VMS MM_Win32 MM_DOS MM_UWIN 628 \ | | | / / / 629 ------------------------------------------------ 630 | | 631 MM_Unix | 632 | | 633 MM_Any 634 635NOTE: Each direct L<MM_Unix|ExtUtils::MM_Unix> subclass is also an 636L<MM_Any|ExtUtils::MM_Any> subclass. This 637is a temporary hack because MM_Unix overrides some MM_Any methods with 638Unix specific code. It allows the non-Unix modules to see the 639original MM_Any implementations. 640 641NOTE: Modules like L<File::Spec> and L<Exporter> have been omitted for clarity. 642 643=head1 PATCHING 644 645If you have a question you'd like to see added to the FAQ (whether or 646not you have the answer) please either: 647 648=over 2 649 650=item * make a pull request on the MakeMaker github repository 651 652=item * raise a issue on the MakeMaker github repository 653 654=item * file an RT ticket 655 656=item * email makemaker@perl.org 657 658=back 659 660=head1 AUTHOR 661 662The denizens of makemaker@perl.org. 663 664=head1 SEE ALSO 665 666L<ExtUtils::MakeMaker> 667 668=cut 669