Upgrade to Module-Build-0.30
[p5sagit/p5-mst-13.2.git] / lib / Module / Build.pm
1 package Module::Build;
2
3 # This module doesn't do much of anything itself, it inherits from the
4 # modules that do the real work.  The only real thing it has to do is
5 # figure out which OS-specific module to pull in.  Many of the
6 # OS-specific modules don't do anything either - most of the work is
7 # done in Module::Build::Base.
8
9 use strict;
10 use File::Spec ();
11 use File::Path ();
12 use File::Basename ();
13
14 use Module::Build::Base;
15
16 use vars qw($VERSION @ISA);
17 @ISA = qw(Module::Build::Base);
18 $VERSION = '0.30';
19 $VERSION = eval $VERSION;
20
21 # Okay, this is the brute-force method of finding out what kind of
22 # platform we're on.  I don't know of a systematic way.  These values
23 # came from the latest (bleadperl) perlport.pod.
24
25 my %OSTYPES = qw(
26                  aix       Unix
27                  bsdos     Unix
28                  dgux      Unix
29                  dragonfly Unix
30                  dynixptx  Unix
31                  freebsd   Unix
32                  linux     Unix
33                  hpux      Unix
34                  irix      Unix
35                  darwin    Unix
36                  machten   Unix
37                  midnightbsd Unix
38                  next      Unix
39                  openbsd   Unix
40                  netbsd    Unix
41                  dec_osf   Unix
42                  nto       Unix
43                  svr4      Unix
44                  svr5      Unix
45                  sco_sv    Unix
46                  unicos    Unix
47                  unicosmk  Unix
48                  solaris   Unix
49                  sunos     Unix
50                  cygwin    Unix
51                  os2       Unix
52                  interix   Unix
53                  gnu       Unix
54                  gnukfreebsd Unix
55
56                  dos       Windows
57                  MSWin32   Windows
58
59                  os390     EBCDIC
60                  os400     EBCDIC
61                  posix-bc  EBCDIC
62                  vmesa     EBCDIC
63
64                  MacOS     MacOS
65                  VMS       VMS
66                  VOS       VOS
67                  riscos    RiscOS
68                  amigaos   Amiga
69                  mpeix     MPEiX
70                 );
71
72 # Inserts the given module into the @ISA hierarchy between
73 # Module::Build and its immediate parent
74 sub _interpose_module {
75   my ($self, $mod) = @_;
76   eval "use $mod";
77   die $@ if $@;
78
79   no strict 'refs';
80   my $top_class = $mod;
81   while (@{"${top_class}::ISA"}) {
82     last if ${"${top_class}::ISA"}[0] eq $ISA[0];
83     $top_class = ${"${top_class}::ISA"}[0];
84   }
85
86   @{"${top_class}::ISA"} = @ISA;
87   @ISA = ($mod);
88 }
89
90 if (grep {-e File::Spec->catfile($_, qw(Module Build Platform), $^O) . '.pm'} @INC) {
91   __PACKAGE__->_interpose_module("Module::Build::Platform::$^O");
92
93 } elsif (exists $OSTYPES{$^O}) {
94   __PACKAGE__->_interpose_module("Module::Build::Platform::$OSTYPES{$^O}");
95
96 } else {
97   warn "Unknown OS type '$^O' - using default settings\n";
98 }
99
100 sub os_type { $OSTYPES{$^O} }
101
102 sub is_vmsish { return ((os_type() || '') eq 'VMS') }
103 sub is_windowsish { return ((os_type() || '') eq 'Windows') }
104 sub is_unixish { return ((os_type() || '') eq 'Unix') }
105
106 1;
107
108 __END__
109
110
111 =head1 NAME
112
113 Module::Build - Build and install Perl modules
114
115
116 =head1 SYNOPSIS
117
118 Standard process for building & installing modules:
119
120   perl Build.PL
121   ./Build
122   ./Build test
123   ./Build install
124
125 Or, if you're on a platform (like DOS or Windows) that doesn't require
126 the "./" notation, you can do this:
127
128   perl Build.PL
129   Build
130   Build test
131   Build install
132
133
134 =head1 DESCRIPTION
135
136 C<Module::Build> is a system for building, testing, and installing
137 Perl modules.  It is meant to be an alternative to
138 C<ExtUtils::MakeMaker>.  Developers may alter the behavior of the
139 module through subclassing in a much more straightforward way than
140 with C<MakeMaker>.  It also does not require a C<make> on your system
141 - most of the C<Module::Build> code is pure-perl and written in a very
142 cross-platform way.  In fact, you don't even need a shell, so even
143 platforms like MacOS (traditional) can use it fairly easily.  Its only
144 prerequisites are modules that are included with perl 5.6.0, and it
145 works fine on perl 5.005 if you can install a few additional modules.
146
147 See L<"MOTIVATIONS"> for more comparisons between C<ExtUtils::MakeMaker>
148 and C<Module::Build>.
149
150 To install C<Module::Build>, and any other module that uses
151 C<Module::Build> for its installation process, do the following:
152
153   perl Build.PL       # 'Build.PL' script creates the 'Build' script
154   ./Build             # Need ./ to ensure we're using this "Build" script
155   ./Build test        # and not another one that happens to be in the PATH
156   ./Build install
157
158 This illustrates initial configuration and the running of three
159 'actions'.  In this case the actions run are 'build' (the default
160 action), 'test', and 'install'.  Other actions defined so far include:
161
162   build                          manifest    
163   clean                          manpages    
164   code                           pardist     
165   config_data                    ppd         
166   diff                           ppmdist     
167   dist                           prereq_report
168   distcheck                      pure_install
169   distclean                      realclean   
170   distdir                        retest      
171   distmeta                       skipcheck   
172   distsign                       test        
173   disttest                       testall     
174   docs                           testcover   
175   fakeinstall                    testdb      
176   help                           testpod     
177   html                           testpodcoverage
178   install                        versioninstall
179
180
181 You can run the 'help' action for a complete list of actions.
182
183
184 =head1 GUIDE TO DOCUMENTATION
185
186 The documentation for C<Module::Build> is broken up into three sections:
187
188 =over
189
190 =item General Usage (L<Module::Build>)
191
192 This is the document you are currently reading. It describes basic
193 usage and background information.  Its main purpose is to assist the
194 user who wants to learn how to invoke and control C<Module::Build>
195 scripts at the command line.
196
197 =item Authoring Reference (L<Module::Build::Authoring>)
198
199 This document describes the structure and organization of
200 C<Module::Build>, and the relevant concepts needed by authors who are
201 writing F<Build.PL> scripts for a distribution or controlling
202 C<Module::Build> processes programmatically.
203
204 =item API Reference (L<Module::Build::API>)
205
206 This is a reference to the C<Module::Build> API.
207
208 =item Cookbook (L<Module::Build::Cookbook>)
209
210 This document demonstrates how to accomplish many common tasks.  It
211 covers general command line usage and authoring of F<Build.PL>
212 scripts.  Includes working examples.
213
214 =back
215
216
217 =head1 ACTIONS
218
219 There are some general principles at work here.  First, each task when
220 building a module is called an "action".  These actions are listed
221 above; they correspond to the building, testing, installing,
222 packaging, etc., tasks.
223
224 Second, arguments are processed in a very systematic way.  Arguments
225 are always key=value pairs.  They may be specified at C<perl Build.PL>
226 time (i.e. C<perl Build.PL destdir=/my/secret/place>), in which case
227 their values last for the lifetime of the C<Build> script.  They may
228 also be specified when executing a particular action (i.e.
229 C<Build test verbose=1>), in which case their values last only for the
230 lifetime of that command.  Per-action command line parameters take
231 precedence over parameters specified at C<perl Build.PL> time.
232
233 The build process also relies heavily on the C<Config.pm> module.
234 If the user wishes to override any of the
235 values in C<Config.pm>, she may specify them like so:
236
237   perl Build.PL --config cc=gcc --config ld=gcc
238
239 The following build actions are provided by default.
240
241 =over 4
242
243 =item build
244
245 [version 0.01]
246
247 If you run the C<Build> script without any arguments, it runs the
248 C<build> action, which in turn runs the C<code> and C<docs> actions.
249
250 This is analogous to the MakeMaker 'make all' target.
251
252 =item clean
253
254 [version 0.01]
255
256 This action will clean up any files that the build process may have
257 created, including the C<blib/> directory (but not including the
258 C<_build/> directory and the C<Build> script itself).
259
260 =item code
261
262 [version 0.20]
263
264 This action builds your codebase.
265
266 By default it just creates a C<blib/> directory and copies any C<.pm>
267 and C<.pod> files from your C<lib/> directory into the C<blib/>
268 directory.  It also compiles any C<.xs> files from C<lib/> and places
269 them in C<blib/>.  Of course, you need a working C compiler (probably
270 the same one that built perl itself) for the compilation to work
271 properly.
272
273 The C<code> action also runs any C<.PL> files in your F<lib/>
274 directory.  Typically these create other files, named the same but
275 without the C<.PL> ending.  For example, a file F<lib/Foo/Bar.pm.PL>
276 could create the file F<lib/Foo/Bar.pm>.  The C<.PL> files are
277 processed first, so any C<.pm> files (or other kinds that we deal
278 with) will get copied correctly.
279
280 =item config_data
281
282 [version 0.26]
283
284 ...
285
286 =item diff
287
288 [version 0.14]
289
290 This action will compare the files about to be installed with their
291 installed counterparts.  For .pm and .pod files, a diff will be shown
292 (this currently requires a 'diff' program to be in your PATH).  For
293 other files like compiled binary files, we simply report whether they
294 differ.
295
296 A C<flags> parameter may be passed to the action, which will be passed
297 to the 'diff' program.  Consult your 'diff' documentation for the
298 parameters it will accept - a good one is C<-u>:
299
300   ./Build diff flags=-u
301
302 =item dist
303
304 [version 0.02]
305
306 This action is helpful for module authors who want to package up their
307 module for source distribution through a medium like CPAN.  It will create a
308 tarball of the files listed in F<MANIFEST> and compress the tarball using
309 GZIP compression.
310
311 By default, this action will use the external C<tar> and C<gzip>
312 executables on Unix-like platforms, and the C<Archive::Tar> module
313 elsewhere.  However, you can force it to use whatever executable you
314 want by supplying an explicit C<tar> (and optional C<gzip>) parameter:
315
316   ./Build dist --tar C:\path\to\tar.exe --gzip C:\path\to\zip.exe
317
318 =item distcheck
319
320 [version 0.05]
321
322 Reports which files are in the build directory but not in the
323 F<MANIFEST> file, and vice versa.  (See L<manifest> for details.)
324
325 =item distclean
326
327 [version 0.05]
328
329 Performs the 'realclean' action and then the 'distcheck' action.
330
331 =item distdir
332
333 [version 0.05]
334
335 Creates a "distribution directory" named C<$dist_name-$dist_version>
336 (if that directory already exists, it will be removed first), then
337 copies all the files listed in the F<MANIFEST> file to that directory.
338 This directory is what the distribution tarball is created from.
339
340 =item distmeta
341
342 [version 0.21]
343
344 Creates the F<META.yml> file that describes the distribution.
345
346 F<META.yml> is a file containing various bits of "metadata" about the
347 distribution.  The metadata includes the distribution name, version,
348 abstract, prerequisites, license, and various other data about the
349 distribution.  This file is created as F<META.yml> in YAML format.
350 It is recommended that the C<YAML> module be installed to create it.
351 If the C<YAML> module is not installed, an internal module supplied
352 with Module::Build will be used to write the META.yml file, and this
353 will most likely be fine.
354
355 F<META.yml> file must also be listed in F<MANIFEST> - if it's not, a
356 warning will be issued.
357
358 The current version of the F<META.yml> specification can be found at
359 L<http://module-build.sourceforge.net/META-spec-current.html>
360
361 =item distsign
362
363 [version 0.16]
364
365 Uses C<Module::Signature> to create a SIGNATURE file for your
366 distribution, and adds the SIGNATURE file to the distribution's
367 MANIFEST.
368
369 =item disttest
370
371 [version 0.05]
372
373 Performs the 'distdir' action, then switches into that directory and
374 runs a C<perl Build.PL>, followed by the 'build' and 'test' actions in
375 that directory.
376
377 =item docs
378
379 [version 0.20]
380
381 This will generate documentation (e.g. Unix man pages and html
382 documents) for any installable items under B<blib/> that
383 contain POD.  If there are no C<bindoc> or C<libdoc> installation
384 targets defined (as will be the case on systems that don't support
385 Unix manpages) no action is taken for manpages.  If there are no
386 C<binhtml> or C<libhtml> installation targets defined no action is
387 taken for html documents.
388
389 =item fakeinstall
390
391 [version 0.02]
392
393 This is just like the C<install> action, but it won't actually do
394 anything, it will just report what it I<would> have done if you had
395 actually run the C<install> action.
396
397 =item help
398
399 [version 0.03]
400
401 This action will simply print out a message that is meant to help you
402 use the build process.  It will show you a list of available build
403 actions too.
404
405 With an optional argument specifying an action name (e.g. C<Build help
406 test>), the 'help' action will show you any POD documentation it can
407 find for that action.
408
409 =item html
410
411 [version 0.26]
412
413 This will generate HTML documentation for any binary or library files
414 under B<blib/> that contain POD.  The HTML documentation will only be
415 installed if the install paths can be determined from values in
416 C<Config.pm>.  You can also supply or override install paths on the
417 command line by specifying C<install_path> values for the C<binhtml>
418 and/or C<libhtml> installation targets.
419
420 =item install
421
422 [version 0.01]
423
424 This action will use C<ExtUtils::Install> to install the files from
425 C<blib/> into the system.  See L<"INSTALL PATHS">
426 for details about how Module::Build determines where to install
427 things, and how to influence this process.
428
429 If you want the installation process to look around in C<@INC> for
430 other versions of the stuff you're installing and try to delete it,
431 you can use the C<uninst> parameter, which tells C<ExtUtils::Install> to
432 do so:
433
434   ./Build install uninst=1
435
436 This can be a good idea, as it helps prevent multiple versions of a
437 module from being present on your system, which can be a confusing
438 situation indeed.
439
440 =item manifest
441
442 [version 0.05]
443
444 This is an action intended for use by module authors, not people
445 installing modules.  It will bring the F<MANIFEST> up to date with the
446 files currently present in the distribution.  You may use a
447 F<MANIFEST.SKIP> file to exclude certain files or directories from
448 inclusion in the F<MANIFEST>.  F<MANIFEST.SKIP> should contain a bunch
449 of regular expressions, one per line.  If a file in the distribution
450 directory matches any of the regular expressions, it won't be included
451 in the F<MANIFEST>.
452
453 The following is a reasonable F<MANIFEST.SKIP> starting point, you can
454 add your own stuff to it:
455
456   ^_build
457   ^Build$
458   ^blib
459   ~$
460   \.bak$
461   ^MANIFEST\.SKIP$
462   CVS
463
464 See the L<distcheck> and L<skipcheck> actions if you want to find out
465 what the C<manifest> action would do, without actually doing anything.
466
467 =item manpages
468
469 [version 0.28]
470
471 This will generate man pages for any binary or library files under
472 B<blib/> that contain POD.  The man pages will only be installed if the
473 install paths can be determined from values in C<Config.pm>.  You can
474 also supply or override install paths by specifying there values on
475 the command line with the C<bindoc> and C<libdoc> installation
476 targets.
477
478 =item pardist
479
480 [version 0.2806]
481
482 Generates a PAR binary distribution for use with L<PAR> or L<PAR::Dist>.
483
484 It requires that the PAR::Dist module (version 0.17 and up) is
485 installed on your system.
486
487 =item ppd
488
489 [version 0.20]
490
491 Build a PPD file for your distribution.
492
493 This action takes an optional argument C<codebase> which is used in
494 the generated ppd file to specify the (usually relative) URL of the
495 distribution.  By default, this value is the distribution name without
496 any path information.
497
498 Example:
499
500   ./Build ppd --codebase "MSWin32-x86-multi-thread/Module-Build-0.21.tar.gz"
501
502 =item ppmdist
503
504 [version 0.23]
505
506 Generates a PPM binary distribution and a PPD description file.  This
507 action also invokes the 'ppd' action, so it can accept the same
508 C<codebase> argument described under that action.
509
510 This uses the same mechanism as the C<dist> action to tar & zip its
511 output, so you can supply C<tar> and/or C<gzip> parameters to affect
512 the result.
513
514 =item prereq_report
515
516 [version 0.28]
517
518 This action prints out a list of all prerequisites, the versions required, and
519 the versions actually installed.  This can be useful for reviewing the
520 configuration of your system prior to a build, or when compiling data to send
521 for a bug report.
522
523 =item pure_install
524
525 [version 0.28]
526
527 This action is identical to the C<install> action.  In the future,
528 though, when C<install> starts writing to the file 
529 F<$(INSTALLARCHLIB)/perllocal.pod>, C<pure_install> won't, and that
530 will be the only difference between them.
531
532 =item realclean
533
534 [version 0.01]
535
536 This action is just like the C<clean> action, but also removes the
537 C<_build> directory and the C<Build> script.  If you run the
538 C<realclean> action, you are essentially starting over, so you will
539 have to re-create the C<Build> script again.
540
541 =item retest
542
543 [version 0.2806]
544
545 This is just like the C<test> action, but doesn't actually build the
546 distribution first, and doesn't add F<blib/> to the load path, and
547 therefore will test against a I<previously> installed version of the
548 distribution.  This can be used to verify that a certain installed
549 distribution still works, or to see whether newer versions of a
550 distribution still pass the old regression tests, and so on.
551
552 =item skipcheck
553
554 [version 0.05]
555
556 Reports which files are skipped due to the entries in the
557 F<MANIFEST.SKIP> file (See L<manifest> for details)
558
559 =item test
560
561 [version 0.01]
562
563 This will use C<Test::Harness> or C<TAP::Harness> to run any regression
564 tests and report their results. Tests can be defined in the standard
565 places: a file called C<test.pl> in the top-level directory, or several
566 files ending with C<.t> in a C<t/> directory.
567
568 If you want tests to be 'verbose', i.e. show details of test execution
569 rather than just summary information, pass the argument C<verbose=1>.
570
571 If you want to run tests under the perl debugger, pass the argument
572 C<debugger=1>.
573
574 If you want to have Module::Build find test files with different file
575 name extensions, pass the C<test_file_exts> argument with an array
576 of extensions, such as C<[qw( .t .s .z )]>.
577
578 If you want test to be run by C<TAP::Harness>, rather than C<Test::Harness>,
579 pass the argument C<tap_harness_args> as an array reference of arguments to
580 pass to the TAP::Harness constructor.
581
582 In addition, if a file called C<visual.pl> exists in the top-level
583 directory, this file will be executed as a Perl script and its output
584 will be shown to the user.  This is a good place to put speed tests or
585 other tests that don't use the C<Test::Harness> format for output.
586
587 To override the choice of tests to run, you may pass a C<test_files>
588 argument whose value is a whitespace-separated list of test scripts to
589 run.  This is especially useful in development, when you only want to
590 run a single test to see whether you've squashed a certain bug yet:
591
592   ./Build test --test_files t/something_failing.t
593
594 You may also pass several C<test_files> arguments separately:
595
596   ./Build test --test_files t/one.t --test_files t/two.t
597
598 or use a C<glob()>-style pattern:
599
600   ./Build test --test_files 't/01-*.t'
601
602 =item testall
603
604 [verion 0.2807]
605
606 [Note: the 'testall' action and the code snippets below are currently
607 in alpha stage, see
608 L<"http://www.nntp.perl.org/group/perl.module.build/2007/03/msg584.html"> ]
609
610 Runs the C<test> action plus each of the C<test$type> actions defined by
611 the keys of the C<test_types> parameter.
612
613 Currently, you need to define the ACTION_test$type method yourself and
614 enumerate them in the test_types parameter.
615
616   my $mb = Module::Build->subclass(
617     code => q(
618       sub ACTION_testspecial { shift->generic_test(type => 'special'); }
619       sub ACTION_testauthor  { shift->generic_test(type => 'author'); }
620     )
621   )->new(
622     ...
623     test_types  => {
624       special => '.st',
625       author  => ['.at', '.pt' ],
626     },
627     ...
628
629 =item testcover
630
631 [version 0.26]
632
633 Runs the C<test> action using C<Devel::Cover>, generating a
634 code-coverage report showing which parts of the code were actually
635 exercised during the tests.
636
637 To pass options to C<Devel::Cover>, set the C<$DEVEL_COVER_OPTIONS>
638 environment variable:
639
640   DEVEL_COVER_OPTIONS=-ignore,Build ./Build testcover
641
642 =item testdb
643
644 [version 0.05]
645
646 This is a synonym for the 'test' action with the C<debugger=1>
647 argument.
648
649 =item testpod
650
651 [version 0.25]
652
653 This checks all the files described in the C<docs> action and 
654 produces C<Test::Harness>-style output.  If you are a module author,
655 this is useful to run before creating a new release.
656
657 =item testpodcoverage
658
659 [version 0.28]
660
661 This checks the pod coverage of the distribution and 
662 produces C<Test::Harness>-style output. If you are a module author,
663 this is useful to run before creating a new release.
664
665 =item versioninstall
666
667 [version 0.16]
668
669 ** Note: since C<only.pm> is so new, and since we just recently added
670 support for it here too, this feature is to be considered
671 experimental. **
672
673 If you have the C<only.pm> module installed on your system, you can
674 use this action to install a module into the version-specific library
675 trees.  This means that you can have several versions of the same
676 module installed and C<use> a specific one like this:
677
678   use only MyModule => 0.55;
679
680 To override the default installation libraries in C<only::config>,
681 specify the C<versionlib> parameter when you run the C<Build.PL> script:
682
683   perl Build.PL --versionlib /my/version/place/
684
685 To override which version the module is installed as, specify the
686 C<versionlib> parameter when you run the C<Build.PL> script:
687
688   perl Build.PL --version 0.50
689
690 See the C<only.pm> documentation for more information on
691 version-specific installs.
692
693 =back
694
695
696 =head1 OPTIONS
697
698 =head2 Command Line Options
699
700 The following options can be used during any invocation of C<Build.PL>
701 or the Build script, during any action.  For information on other
702 options specific to an action, see the documentation for the
703 respective action.
704
705 NOTE: There is some preliminary support for options to use the more
706 familiar long option style.  Most options can be preceded with the
707 C<--> long option prefix, and the underscores changed to dashes
708 (e.g. --use-rcfile).  Additionally, the argument to boolean options is
709 optional, and boolean options can be negated by prefixing them with
710 'no' or 'no-' (e.g. --noverbose or --no-verbose).
711
712 =over 4
713
714 =item quiet
715
716 Suppress informative messages on output.
717
718 =item use_rcfile
719
720 Load the F<~/.modulebuildrc> option file.  This option can be set to
721 false to prevent the custom resource file from being loaded.
722
723 =item verbose
724
725 Display extra information about the Build on output.
726
727 =item allow_mb_mismatch
728
729 Suppresses the check upon startup that the version of Module::Build
730 we're now running under is the same version that was initially invoked
731 when building the distribution (i.e. when the C<Build.PL> script was
732 first run).  Use with caution.
733
734 =back
735
736
737 =head2 Default Options File (F<.modulebuildrc>)
738
739 [version 0.28]
740
741 When Module::Build starts up, it will look first for a file,
742 F<$ENV{HOME}/.modulebuildrc>.  If it's not found there, it will look
743 in the the F<.modulebuildrc> file in the directories referred to by
744 the environment variables C<HOMEDRIVE> + C<HOMEDIR>, C<USERPROFILE>,
745 C<APPDATA>, C<WINDIR>, C<SYS$LOGIN>.  If the file exists, the options
746 specified there will be used as defaults, as if they were typed on the
747 command line.  The defaults can be overridden by specifying new values
748 on the command line.
749
750 The action name must come at the beginning of the line, followed by any
751 amount of whitespace and then the options.  Options are given the same
752 as they would be on the command line.  They can be separated by any
753 amount of whitespace, including newlines, as long there is whitespace at
754 the beginning of each continued line.  Anything following a hash mark (C<#>)
755 is considered a comment, and is stripped before parsing.  If more than
756 one line begins with the same action name, those lines are merged into
757 one set of options.
758
759 Besides the regular actions, there are two special pseudo-actions: the
760 key C<*> (asterisk) denotes any global options that should be applied
761 to all actions, and the key 'Build_PL' specifies options to be applied
762 when you invoke C<perl Build.PL>.
763
764   *        verbose=1   # global options
765   diff     flags=-u
766   install  --install_base /home/ken
767            --install_path html=/home/ken/docs/html
768
769 If you wish to locate your resource file in a different location, you
770 can set the environment variable 'MODULEBUILDRC' to the complete
771 absolute path of the file containing your options.
772
773
774 =head1 INSTALL PATHS
775
776 [version 0.19]
777
778 When you invoke Module::Build's C<build> action, it needs to figure
779 out where to install things.  The nutshell version of how this works
780 is that default installation locations are determined from
781 F<Config.pm>, and they may be overridden by using the C<install_path>
782 parameter.  An C<install_base> parameter lets you specify an
783 alternative installation root like F</home/foo>, and a C<destdir> lets
784 you specify a temporary installation directory like F</tmp/install> in
785 case you want to create bundled-up installable packages.
786
787 Natively, Module::Build provides default installation locations for
788 the following types of installable items:
789
790 =over 4
791
792 =item lib
793
794 Usually pure-Perl module files ending in F<.pm>.
795
796 =item arch
797
798 "Architecture-dependent" module files, usually produced by compiling
799 XS, Inline, or similar code.
800
801 =item script
802
803 Programs written in pure Perl.  In order to improve reuse, try to make
804 these as small as possible - put the code into modules whenever
805 possible.
806
807 =item bin
808
809 "Architecture-dependent" executable programs, i.e. compiled C code or
810 something.  Pretty rare to see this in a perl distribution, but it
811 happens.
812
813 =item bindoc
814
815 Documentation for the stuff in C<script> and C<bin>.  Usually
816 generated from the POD in those files.  Under Unix, these are manual
817 pages belonging to the 'man1' category.
818
819 =item libdoc
820
821 Documentation for the stuff in C<lib> and C<arch>.  This is usually
822 generated from the POD in F<.pm> files.  Under Unix, these are manual
823 pages belonging to the 'man3' category.
824
825 =item binhtml
826
827 This is the same as C<bindoc> above, but applies to html documents.
828
829 =item libhtml
830
831 This is the same as C<bindoc> above, but applies to html documents.
832
833 =back
834
835 Four other parameters let you control various aspects of how
836 installation paths are determined:
837
838 =over 4
839
840 =item installdirs
841
842 The default destinations for these installable things come from
843 entries in your system's C<Config.pm>.  You can select from three
844 different sets of default locations by setting the C<installdirs>
845 parameter as follows:
846
847                           'installdirs' set to:
848                    core          site                vendor
849
850               uses the following defaults from Config.pm:
851
852   lib     => installprivlib  installsitelib      installvendorlib
853   arch    => installarchlib  installsitearch     installvendorarch
854   script  => installscript   installsitebin      installvendorbin
855   bin     => installbin      installsitebin      installvendorbin
856   bindoc  => installman1dir  installsiteman1dir  installvendorman1dir
857   libdoc  => installman3dir  installsiteman3dir  installvendorman3dir
858   binhtml => installhtml1dir installsitehtml1dir installvendorhtml1dir [*]
859   libhtml => installhtml3dir installsitehtml3dir installvendorhtml3dir [*]
860
861   * Under some OS (eg. MSWin32) the destination for html documents is
862     determined by the C<Config.pm> entry C<installhtmldir>.
863
864 The default value of C<installdirs> is "site".  If you're creating
865 vendor distributions of module packages, you may want to do something
866 like this:
867
868   perl Build.PL --installdirs vendor
869
870 or
871
872   ./Build install --installdirs vendor
873
874 If you're installing an updated version of a module that was included
875 with perl itself (i.e. a "core module"), then you may set
876 C<installdirs> to "core" to overwrite the module in its present
877 location.
878
879 (Note that the 'script' line is different from MakeMaker -
880 unfortunately there's no such thing as "installsitescript" or
881 "installvendorscript" entry in C<Config.pm>, so we use the
882 "installsitebin" and "installvendorbin" entries to at least get the
883 general location right.  In the future, if C<Config.pm> adds some more
884 appropriate entries, we'll start using those.)
885
886 =item install_path
887
888 Once the defaults have been set, you can override them.
889
890 On the command line, that would look like this:
891
892   perl Build.PL --install_path lib=/foo/lib --install_path arch=/foo/lib/arch
893
894 or this:
895
896   ./Build install --install_path lib=/foo/lib --install_path arch=/foo/lib/arch
897
898 =item install_base
899
900 You can also set the whole bunch of installation paths by supplying the
901 C<install_base> parameter to point to a directory on your system.  For
902 instance, if you set C<install_base> to "/home/ken" on a Linux
903 system, you'll install as follows:
904
905   lib     => /home/ken/lib/perl5
906   arch    => /home/ken/lib/perl5/i386-linux
907   script  => /home/ken/bin
908   bin     => /home/ken/bin
909   bindoc  => /home/ken/man/man1
910   libdoc  => /home/ken/man/man3
911   binhtml => /home/ken/html
912   libhtml => /home/ken/html
913
914 Note that this is I<different> from how MakeMaker's C<PREFIX>
915 parameter works.  C<install_base> just gives you a default layout under the
916 directory you specify, which may have little to do with the
917 C<installdirs=site> layout.
918
919 The exact layout under the directory you specify may vary by system -
920 we try to do the "sensible" thing on each platform.
921
922 =item destdir
923
924 If you want to install everything into a temporary directory first
925 (for instance, if you want to create a directory tree that a package
926 manager like C<rpm> or C<dpkg> could create a package from), you can
927 use the C<destdir> parameter:
928
929   perl Build.PL --destdir /tmp/foo
930
931 or
932
933   ./Build install --destdir /tmp/foo
934
935 This will effectively install to "/tmp/foo/$sitelib",
936 "/tmp/foo/$sitearch", and the like, except that it will use
937 C<File::Spec> to make the pathnames work correctly on whatever
938 platform you're installing on.
939
940 =item prefix
941
942 Provided for compatibility with ExtUtils::MakeMaker's PREFIX argument.
943 C<prefix> should be used when you wish Module::Build to install your
944 modules, documentation and scripts in the same place
945 ExtUtils::MakeMaker does.
946
947 The following are equivalent.
948
949     perl Build.PL --prefix /tmp/foo
950     perl Makefile.PL PREFIX=/tmp/foo
951
952 Because of the very complex nature of the prefixification logic, the
953 behavior of PREFIX in MakeMaker has changed subtly over time.
954 Module::Build's --prefix logic is equivalent to the PREFIX logic found
955 in ExtUtils::MakeMaker 6.30.
956
957 If you do not need to retain compatibility with ExtUtils::MakeMaker or
958 are starting a fresh Perl installation we recommand you use
959 C<install_base> instead (and C<INSTALL_BASE> in ExtUtils::MakeMaker).
960 See L<Module::Build::Cookbook/Instaling in the same location as
961 ExtUtils::MakeMaker> for further information.
962
963
964 =back
965
966
967 =head1 MOTIVATIONS
968
969 There are several reasons I wanted to start over, and not just fix
970 what I didn't like about MakeMaker:
971
972 =over 4
973
974 =item *
975
976 I don't like the core idea of MakeMaker, namely that C<make> should be
977 involved in the build process.  Here are my reasons:
978
979 =over 4
980
981 =item +
982
983 When a person is installing a Perl module, what can you assume about
984 their environment?  Can you assume they have C<make>?  No, but you can
985 assume they have some version of Perl.
986
987 =item +
988
989 When a person is writing a Perl module for intended distribution, can
990 you assume that they know how to build a Makefile, so they can
991 customize their build process?  No, but you can assume they know Perl,
992 and could customize that way.
993
994 =back
995
996 For years, these things have been a barrier to people getting the
997 build/install process to do what they want.
998
999 =item *
1000
1001 There are several architectural decisions in MakeMaker that make it
1002 very difficult to customize its behavior.  For instance, when using
1003 MakeMaker you do C<use ExtUtils::MakeMaker>, but the object created in
1004 C<WriteMakefile()> is actually blessed into a package name that's
1005 created on the fly, so you can't simply subclass
1006 C<ExtUtils::MakeMaker>.  There is a workaround C<MY> package that lets
1007 you override certain MakeMaker methods, but only certain explicitly
1008 preselected (by MakeMaker) methods can be overridden.  Also, the method
1009 of customization is very crude: you have to modify a string containing
1010 the Makefile text for the particular target.  Since these strings
1011 aren't documented, and I<can't> be documented (they take on different
1012 values depending on the platform, version of perl, version of
1013 MakeMaker, etc.), you have no guarantee that your modifications will
1014 work on someone else's machine or after an upgrade of MakeMaker or
1015 perl.
1016
1017 =item *
1018
1019 It is risky to make major changes to MakeMaker, since it does so many
1020 things, is so important, and generally works.  C<Module::Build> is an
1021 entirely separate package so that I can work on it all I want, without
1022 worrying about backward compatibility.
1023
1024 =item *
1025
1026 Finally, Perl is said to be a language for system administration.
1027 Could it really be the case that Perl isn't up to the task of building
1028 and installing software?  Even if that software is a bunch of stupid
1029 little C<.pm> files that just need to be copied from one place to
1030 another?  My sense was that we could design a system to accomplish
1031 this in a flexible, extensible, and friendly manner.  Or die trying.
1032
1033 =back
1034
1035
1036 =head1 TO DO
1037
1038 The current method of relying on time stamps to determine whether a
1039 derived file is out of date isn't likely to scale well, since it
1040 requires tracing all dependencies backward, it runs into problems on
1041 NFS, and it's just generally flimsy.  It would be better to use an MD5
1042 signature or the like, if available.  See C<cons> for an example.
1043
1044  - append to perllocal.pod
1045  - add a 'plugin' functionality
1046
1047
1048 =head1 AUTHOR
1049
1050 Ken Williams <kwilliams@cpan.org>
1051
1052 Development questions, bug reports, and patches should be sent to the
1053 Module-Build mailing list at <module-build@perl.org>.
1054
1055 Bug reports are also welcome at
1056 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build>.
1057
1058 The latest development version is available from the Subversion
1059 repository at <https://svn.perl.org/modules/Module-Build/trunk/>
1060
1061
1062 =head1 COPYRIGHT
1063
1064 Copyright (c) 2001-2006 Ken Williams.  All rights reserved.
1065
1066 This library is free software; you can redistribute it and/or
1067 modify it under the same terms as Perl itself.
1068
1069
1070 =head1 SEE ALSO
1071
1072 perl(1), L<Module::Build::Cookbook>, L<Module::Build::Authoring>,
1073 L<Module::Build::API>, L<ExtUtils::MakeMaker>, L<YAML>
1074
1075 F<META.yml> Specification:
1076 L<http://module-build.sourceforge.net/META-spec-current.html>
1077
1078 L<http://www.dsmit.com/cons/>
1079
1080 L<http://search.cpan.org/dist/PerlBuildSystem/>
1081
1082 =cut