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