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