This is my patch patch.1j for perl5.001.
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MakeMaker.pm
1 package ExtUtils::MakeMaker;
2
3 $Version = 4.095; # Last edited 17 Apr 1995 by Andy Dougherty
4
5 use Config;
6 use Carp;
7 use Cwd;
8
9 require Exporter;
10 @ISA = qw(Exporter);
11 @EXPORT = qw(&WriteMakefile $Verbose);
12 @EXPORT_OK = qw($Version %att %skip %Recognized_Att_Keys
13         @MM_Sections %MM_Sections
14         &help &lsdir &neatvalue &mkbootstrap &mksymlists);
15
16 $Is_VMS = $Config{'osname'} eq 'VMS';
17 require ExtUtils::MM_VMS if $Is_VMS;
18
19 use strict qw(refs);
20
21 $Version = $Version;# avoid typo warning
22 $Verbose = 0;
23 $^W=1;
24
25 =head1 NAME
26
27 ExtUtils::MakeMaker - create an extension Makefile
28
29 =head1 SYNOPSIS
30
31 C<use ExtUtils::MakeMaker;>
32
33 C<WriteMakefile( ATTRIBUTE =E<gt> VALUE [, ...] );>
34
35 =head1 DESCRIPTION
36
37 This utility is designed to write a Makefile for an extension module
38 from a Makefile.PL. It is based on the Makefile.SH model provided by
39 Andy Dougherty and the perl5-porters.
40
41 It splits the task of generating the Makefile into several subroutines
42 that can be individually overridden.  Each subroutine returns the text
43 it wishes to have written to the Makefile.
44
45 MakeMaker.pm uses the architecture specific information from
46 Config.pm. In addition the extension may contribute to the C<%Config>
47 hash table of Config.pm by supplying hints files in a C<hints/>
48 directory. The hints files are expected to be named like their
49 counterparts in C<PERL_SRC/hints>, but with an C<.pl> file name
50 extension (eg. C<next_3_2.pl>). They are simply C<eval>ed by MakeMaker
51 within the WriteMakefile() subroutine, and can be used to execute
52 commands as well as to include special variables. If there is no
53 hintsfile for the actual system, but for some previous releases of the
54 same operating system, the latest one of those is used.
55
56 =head2 Default Makefile Behaviour
57
58 The automatically generated Makefile enables the user of the extension
59 to invoke
60
61   perl Makefile.PL
62   make
63   make test # optionally set TEST_VERBOSE=1
64   make install # See below
65
66 The Makefile to be produced may be altered by adding arguments of the
67 form C<KEY=VALUE>. If the user wants to have the extension installed
68 into a directory different from C<$Config{"installprivlib"}> it can be
69 done by specifying
70
71   perl Makefile.PL INST_LIB=~/myperllib INST_EXE=~/bin
72
73 Note, that in this example MakeMaker does the tilde expansion for you
74 and INST_ARCHLIB is set to either C<INST_LIB/$Config{"archname"}> if
75 that directory exists and otherwise to INST_LIB.
76
77 Other interesting targets in the generated Makefile are
78
79   make config     # to check if the Makefile is up-to-date
80   make clean      # delete local temporary files (Makefile gets renamed)
81   make realclean  # delete all derived files (including installed files)
82   make dist       # produce a gzipped file ready for shipping
83
84 The macros in the produced Makefile may be overridden on the command
85 line to the make call as in the following example:
86
87   make INST_LIB=/some/where INST_ARCHLIB=/some/where INST_EXE=/u/k/bin
88
89 Note, that this is a solution provided by C<make> in general, so tilde
90 expansion will probably not be available and INST_ARCHLIB will not be
91 set automatically when INST_LIB is given as argument.
92
93 The generated Makefile does not set any permissions. The installer has
94 to decide, which umask should be in effect.
95
96 =head2 Special case C<make install>
97
98 The I<install> target of the generated Makefile is for system
99 administrators only that have writing permissions on the
100 system-specific directories $Config{installprivlib},
101 $Config{installarchlib}, and $Config{installbin}. This works, because
102 C<make> alone in fact puts all relevant files into directories that
103 are named by the macros INST_LIB, INST_ARCHLIB, and INST_EXE. All
104 three default to ./blib if you are not building below the perl source
105 directory. C<make install> is just a recursive call to C<make> with
106 the three relevant parameters set accordingly to the system-wide
107 defaults.
108
109 C<make install> per default writes some documentation of what has been
110 done into the file C<$Config{'installarchlib'}/perllocal.pod>. This is
111 an experimental feature. It can be bypassed by calling C<make
112 pure_install>.
113
114 Users that do not have privileges on the system but want to install
115 the relevant files of the module into their private library or binary
116 directories do not call C<make install>. In priciple they have the
117 choice to either say
118
119     # case: trust the module
120     perl Makefile.PL INST_LIB=~/perllib INST_EXE=~/bin
121     make
122     make test
123
124 or
125
126     # case: want to run tests before installation
127     perl Makefile.PL
128     make
129     make test
130     make INST_LIB=/some/where INST_ARCHLIB=/foo/bar INST_EXE=/somebin
131
132 (C<make test> is not necessarily supported for all modules.)
133
134 =head2 Support to Link a new Perl Binary
135
136 An extension that is built with the above steps is ready to use on
137 systems supporting dynamic loading. On systems that do not support
138 dynamic loading, any newly created extension has to be linked together
139 with the available ressources. MakeMaker supports the linking process
140 by creating appropriate targets in the Makefile whenever an extension
141 is built. You can invoke the corresponding section of the makefile with
142
143     make perl
144
145 That produces a new perl binary in the current directory with all
146 extensions linked in that can be found in INST_ARCHLIB and
147 PERL_ARCHLIB.
148
149 The binary can be installed into the directory where perl normally
150 resides on your machine with
151
152     make inst_perl
153
154 To produce a perl binary with a different name than C<perl>, either say
155
156     perl Makefile.PL MAP_TARGET=myperl
157     make myperl
158     make inst_perl
159
160 or say
161
162     perl Makefile.PL
163     make myperl MAP_TARGET=myperl
164     make inst_perl MAP_TARGET=myperl
165
166 In any case you will be prompted with the correct invocation of the
167 C<inst_perl> target that installs the new binary into
168 $Config{'installbin'}.
169
170 Note, that there is a C<makeaperl> scipt in the perl distribution,
171 that supports the linking of a new perl binary in a similar fashion,
172 but with more options.
173
174 C<make inst_perl> per default writes some documentation of what has been
175 done into the file C<$Config{'installarchlib'}/perllocal.pod>. This
176 can be bypassed by calling C<make pure_inst_perl>.
177
178 Warning: the inst_perl: target is rather mighty and will probably
179 overwrite your existing perl binary. Use with care!
180
181 =head2 Determination of Perl Library and Installation Locations
182
183 MakeMaker needs to know, or to guess, where certain things are
184 located.  Especially INST_LIB and INST_ARCHLIB (where to install files
185 into), PERL_LIB and PERL_ARCHLIB (where to read existing modules
186 from), and PERL_INC (header files and C<libperl*.*>).
187
188 Extensions may be built either using the contents of the perl source
189 directory tree or from an installed copy of the perl library.
190
191 If an extension is being built below the C<ext/> directory of the perl
192 source then MakeMaker will set PERL_SRC automatically (e.g., C<../..>).
193 If PERL_SRC is defined then other variables default to the following:
194
195   PERL_INC     = PERL_SRC
196   PERL_LIB     = PERL_SRC/lib
197   PERL_ARCHLIB = PERL_SRC/lib
198   INST_LIB     = PERL_LIB
199   INST_ARCHLIB = PERL_ARCHLIB
200
201 If an extension is being built away from the perl source then MakeMaker
202 will leave PERL_SRC undefined and default to using the installed copy
203 of the perl library. The other variables default to the following:
204
205   PERL_INC     = $archlib/CORE
206   PERL_LIB     = $privlib
207   PERL_ARCHLIB = $archlib
208   INST_LIB     = ./blib
209   INST_ARCHLIB = ./blib
210
211 If perl has not yet been installed then PERL_SRC can be defined on the
212 command line as shown in the previous section.
213
214 =head2 Useful Default Makefile Macros
215
216 FULLEXT = Pathname for extension directory (eg DBD/Oracle).
217
218 BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
219
220 ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
221
222 PERL_LIB = Directory where we read the perl library files
223
224 PERL_ARCHLIB = Same as above for architecture dependent files
225
226 INST_LIB = Directory where we put library files of this extension
227 while building it. If we are building below PERL_SRC/ext
228 we default to PERL_SRC/lib, else we default to ./blib.
229
230 INST_ARCHLIB = Same as above for architecture dependent files
231
232 INST_LIBDIR = C<$(INST_LIB)$(ROOTEXT)>
233
234 INST_AUTODIR = C<$(INST_LIB)/auto/$(FULLEXT)>
235
236 INST_ARCHAUTODIR = C<$(INST_ARCHLIB)/auto/$(FULLEXT)>
237
238 =head2 Customizing The Generated Makefile
239
240 If the Makefile generated does not fit your purpose you can change it
241 using the mechanisms described below.
242
243 =head2 Using Attributes (and Parameters)
244
245 The following attributes can be specified as arguments to WriteMakefile()
246 or as NAME=VALUE pairs on the command line:
247
248 This description is not yet documented; you can get at the description
249 with the command
250
251 C<perl Makefile.PL help>    (if you already have a basic Makefile.PL)
252
253 or
254
255 C<perl -e 'use ExtUtils::MakeMaker qw(&help); &help;'>
256
257 =head2 Overriding MakeMaker Methods
258
259 If you cannot achieve the desired Makefile behaviour by specifying
260 attributes you may define private subroutines in the Makefile.PL.
261 Each subroutines returns the text it wishes to have written to
262 the Makefile. To override a section of the Makefile you can
263 either say:
264
265         sub MY::c_o { "new literal text" }
266
267 or you can edit the default by saying something like:
268
269         sub MY::c_o { $_=MM->c_o; s/old text/new text/; $_ }
270
271 If you still need a different solution, try to develop another
272 subroutine, that fits your needs and submit the diffs to
273 F<perl5-porters@nicoh.com> or F<comp.lang.perl> as appropriate.
274
275 =cut
276
277 sub check_hints {
278     # We allow extension-specific hints files.
279
280     # First we look for the best hintsfile we have
281     my(@goodhints);
282     my($hint)="$Config{'osname'}_$Config{'osvers'}";
283     $hint =~ s/\./_/g;
284     $hint =~ s/_$//;
285     opendir DIR, "hints";
286     while (defined ($_ = readdir DIR)) {
287         next if /^\./;
288         next unless s/\.pl$//;
289         next unless /^$Config{'osname'}/;
290         # Don't trust a hintfile for a later OS version:
291         next if $_ gt $hint;
292         push @goodhints, $_;
293         if ($_ eq $hint){
294             @goodhints=$_;
295             last;
296         }
297     }
298     closedir DIR;
299     return unless @goodhints; # There was no hintsfile
300     # the last one in lexical ordering is our choice:
301     $hint=(sort @goodhints)[-1];
302
303     # execute the hintsfile:
304     open HINTS, "hints/$hint.pl";
305     @goodhints = <HINTS>;
306     close HINTS;
307     print STDOUT "Processing hints file hints/$hint.pl";
308     eval join('',@goodhints);
309     print STDOUT $@ if $@;
310 }
311
312 # Setup dummy package:
313 # MY exists for overriding methods to be defined within
314 unshift(@MY::ISA, qw(MM));
315
316 # Dummy package MM inherits actual methods from OS-specific
317 # default packages.  We use this intermediate package so
318 # MY->func() can call MM->func() and get the proper
319 # default routine without having to know under what OS
320 # it's running.
321 unshift(@MM::ISA, $Is_VMS ? qw(ExtUtils::MM_VMS MM_Unix) : qw(MM_Unix));
322
323 $Attrib_Help = <<'END';
324  NAME:          Perl module name for this extension (DBD::Oracle)
325                 This will default to the directory name but should
326                 be explicitly defined in the Makefile.PL.
327
328  DISTNAME:      Your name for distributing the package (by tar file)
329                 This defaults to NAME above.
330
331  VERSION:       Your version number for distributing the package.
332                 This defaults to 0.1.
333
334  INST_LIB:      Perl library directory to install the module into.
335  INST_ARCHLIB:  Perl architecture-dependent library to install into
336                 (defaults to INST_LIB)
337
338  PERL_LIB:      Directory containing the Perl library to use.
339  PERL_SRC:      Directory containing the Perl source code
340                 (use of this should be avoided, it may be undefined)
341
342  INC:           Include file dirs eg: '-I/usr/5include -I/path/to/inc'
343  DEFINE:        something like "-DHAVE_UNISTD_H"
344  OBJECT:        List of object files, defaults to '$(BASEEXT).o',
345                 but can be a long string containing all object files,
346                     e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
347  MYEXTLIB:      If the extension links to a library that it builds
348                 set this to the name of the library (see SDBM_File)
349
350  LIBS:          An anonymous array of alternative library specifications
351                 to be searched for (in order) until at least one library
352                 is found.
353                   'LIBS' => [ "-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs" ]
354                 Mind, that any element of the array contains a complete
355                 set of arguments for the ld command. So do not specify
356                   'LIBS' => ["-ltcl", "-ltk", "-lX11" ], #wrong
357                 See ODBM_File/Makefile.PL for an example, where an
358                 array is needed. If you specify a scalar as in
359                   'LIBS' => "-ltcl -ltk -lX11"
360                 MakeMaker will turn it into an array with one element.
361
362  LDFROM:        defaults to "$(OBJECT)" and is used in the ld command
363                 to specify what files to link/load from
364                 (also see dynamic_lib below for how to specify ld flags)
365
366  DIR:           Ref to array of subdirectories containing Makefile.PLs
367                 e.g. [ 'sdbm' ] in ext/SDBM_File
368
369  PMLIBDIRS:     Ref to array of subdirectories containing library files.
370                 Defaults to [ 'lib', $(BASEEXT) ]. The directories will
371                 be scanned and any files they contain will
372                 be installed in the corresponding location in the library.
373                 A MY::libscan() function can be used to alter the behaviour.
374                 Defining PM in the Makefile.PL will override PMLIBDIRS.
375
376  PM:            Hashref of .pm files and *.pl files to be installed.
377                 e.g. { 'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm' }
378                 By default this will include *.pm and *.pl. If a lib directory
379                 exists and is not listed in DIR (above) then any *.pm and
380                 *.pl files it contains will also be included by default.
381                 Defining PM in the Makefile.PL will override PMLIBDIRS.
382
383  XS:            Hashref of .xs files. MakeMaker will default this.
384                 e.g. { 'name_of_file.xs' => 'name_of_file.c' }
385                 The .c files will automatically be included in the list
386                 of files deleted by a make clean.
387
388  C:             Ref to array of *.c file names. Initialised from a directory scan
389                 and the values portion of the XS attribute hash. This is not
390                 currently used by MakeMaker but may be handy in Makefile.PLs.
391
392  H:             Ref to array of *.h file names. Similar to C: above.
393
394  PL_FILES:      Ref to hash of files to be processed as perl programs. MakeMaker
395                 will default to any found C<*.PL> file (except C<Makefile.PL>) being
396                 keys and the basename of the file being the value. E.g.
397                 C<{ 'foobar.PL' => 'foobar' }>. The C<*.PL> files are expected to
398                 produce output to the target files themselves.
399
400  EXE_FILES:     Ref to array of executable files. The files will be copied to 
401                 the INST_EXE directory. The installed files will be deleted 
402                 by a make realclean.
403
404  INST_EXE:      Directory, where executable scripts should be installed. Defaults
405                 to "./blib", just to have a dummy location during testing.
406                 C<make install> will set INST_EXE to $Config{'installbin'}.
407
408  LINKTYPE:      =>'static' or 'dynamic' (default unless usedl=undef in config.sh)
409                 Should only be used to force static linking (also see linkext below).
410
411  DL_FUNCS:      Hashref of symbol names for routines to be made available as
412                 universal symbols.  Each key/value pair consists of the package
413                 name and an array of routine names in that package.  Used only
414                 under AIX (export lists) and VMS (linker options) at present.
415                 The routine names supplied will be expanded in the same way
416                 as XSUB names are expanded by the XS() macro.
417                 Defaults to { "$(NAME)" => [ "boot_$(NAME)" ] }.
418                 (e.g. { "RPC" => [qw( boot_rpcb rpcb_gettime getnetconfigent )],
419                         "NetconfigPtr" => [ 'DESTROY'] } )
420
421  DL_VARS:       Array of symbol names for variables to be made available as
422                 universal symbols.  Used only under AIX (export lists) and VMS
423                 (linker options) at present.  Defaults to [].
424                 (e.g. [ qw( Foo_version Foo_numstreams Foo_tree ) ])
425
426  CONFIG:        =>[qw(archname manext)] defines ARCHNAME & MANEXT from config.sh
427  SKIP:          =>[qw(name1 name2)] skip (do not write) sections of the Makefile
428
429  MAP_TARGET:    If it is intended, that a new perl binary be produced, this variable
430                 may hold a name for that binary. Defaults to C<perl>
431
432  LIBPERL_A:     The filename of the perllibrary that will be used together
433                 with this extension. Defaults to C<libperl.a>.
434
435  PERL:
436  FULLPERL:
437
438 Additional lowercase attributes can be used to pass parameters to the
439 methods which implement that part of the Makefile. These are not
440 normally required:
441
442  installpm:     {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'}
443  linkext:       {LINKTYPE => 'static', 'dynamic' or ''}
444  dynamic_lib:   {ARMAYBE => 'ar', OTHERLDFLAGS => '...'}
445  clean:         {FILES => "*.xyz foo"}
446  realclean:     {FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
447  dist:          {TARNAME=>'MyTarFile', TARFLAGS=>'cvfF', COMPRESS=>'gzip'}
448  tool_autosplit:        {MAXLEN => 8}
449 END
450
451 sub help {print $Attrib_Help;}
452
453 @MM_Sections_spec = (
454     'post_initialize'   => {},
455     'const_config'      => {},
456     'constants'         => {},
457     'const_loadlibs'    => {},
458     'const_cccmd'       => {},
459     'tool_autosplit'    => {},
460     'tool_xsubpp'       => {},
461     'tools_other'       => {},
462     'post_constants'    => {},
463     'pasthru'           => {},
464     'c_o'               => {},
465     'xs_c'              => {},
466     'xs_o'              => {},
467     'top_targets'       => {},
468     'linkext'           => {},
469     'dlsyms'            => {},
470     'dynamic'           => {},
471     'dynamic_bs'        => {},
472     'dynamic_lib'       => {},
473     'static'            => {},
474     'static_lib'        => {},
475     'installpm'         => {},
476     'processPL'         => {},
477     'installbin'        => {},
478     'subdirs'           => {},
479     'clean'             => {},
480     'realclean'         => {},
481     'dist'              => {},
482     'test'              => {},
483     'install'           => {},
484     'force'             => {},
485     'perldepend'        => {},
486     'makefile'          => {},
487     'postamble'         => {},
488     'staticmake'        => {},
489 );
490 %MM_Sections = @MM_Sections_spec; # looses section ordering
491 @MM_Sections = grep(!ref, @MM_Sections_spec); # keeps order
492
493 %Recognized_Att_Keys = %MM_Sections; # All sections are valid keys.
494 foreach(split(/\n/,$Attrib_Help)){
495     chomp;
496     next unless m/^\s*(\w+):\s*(.*)/;
497     $Recognized_Att_Keys{$1} = $2;
498     print "Attribute '$1' => '$2'\n" if ($Verbose >= 2);
499 }
500
501 %att  = ();
502 %skip = ();
503
504 sub skipcheck{
505     my($section) = @_;
506     if ($section eq 'dynamic') {
507         print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets "
508           . "in skipped section 'dynamic_bs'\n"
509             if $skip{'dynamic_bs'} && $Verbose;
510         print STDOUT "Warning (non-fatal): Target 'dynamic' depends on targets "
511           . "in skipped section 'dynamic_lib'\n"
512             if $skip{'dynamic_lib'} && $Verbose;
513     }
514     if ($section eq 'dynamic_lib') {
515         print STDOUT "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on "
516           . "targets in skipped section 'dynamic_bs'\n"
517             if $skip{'dynamic_bs'} && $Verbose;
518     }
519     if ($section eq 'static') {
520         print STDOUT "Warning (non-fatal): Target 'static' depends on targets "
521           . "in skipped section 'static_lib'\n"
522             if $skip{'static_lib'} && $Verbose;
523     }
524     return 'skipped' if $skip{$section};
525     return '';
526 }
527
528
529 sub WriteMakefile {
530     %att = @_;
531     local($\)="\n";
532
533     print STDOUT "MakeMaker" if $Verbose;
534
535     parse_args(\%att, @ARGV);
536     my(%initial_att) = %att; # record initial attributes
537
538     check_hints();
539
540     my($key);
541
542     MY->init_main();
543
544     print STDOUT "Writing Makefile for $att{NAME}";
545
546     MY->init_dirscan();
547     MY->init_others();
548
549     unlink("Makefile", "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : '');
550     open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!";
551     select MAKE; $|=1; select STDOUT;
552
553     print MAKE "# This Makefile is for the $att{NAME} extension to perl.\n#";
554     print MAKE "# It was generated automatically by MakeMaker version $Version from the contents";
555     print MAKE "# of Makefile.PL. Don't edit this file, edit Makefile.PL instead.";
556     print MAKE "#\n#    ANY CHANGES MADE HERE WILL BE LOST! \n#";
557     print MAKE "#   MakeMaker Parameters: ";
558     foreach $key (sort keys %initial_att){
559         my($v) = neatvalue($initial_att{$key});
560         $v =~ tr/\n/ /s;
561         print MAKE "#   $key => $v";
562     }
563
564     # build hash for SKIP to make testing easy
565     %skip = map( ($_,1), @{$att{'SKIP'} || []});
566
567     my $section;
568     foreach $section ( @MM_Sections ){
569         print "Processing Makefile '$section' section" if ($Verbose >= 2);
570         my($skipit) = skipcheck($section);
571         if ($skipit){
572             print MAKE "\n# --- MakeMaker $section section $skipit.";
573         } else {
574             my(%a) = %{$att{$section} || {}};
575             print MAKE "\n# --- MakeMaker $section section:";
576             print MAKE "# ", join ", ", %a if $Verbose;
577             print(MAKE MY->nicetext(MY->$section( %a )));
578         }
579     }
580
581     if ($Verbose){
582         print MAKE "\n# Full list of MakeMaker attribute values:";
583         foreach $key (sort keys %att){
584             my($v) = neatvalue($att{$key});
585             $v =~ tr/\n/ /s;
586             print MAKE "#       $key => $v";
587         }
588     }
589
590     print MAKE "\n# End.";
591     close MAKE;
592     my($finalname) = $Is_VMS ? "Descrip.MMS" : "Makefile";
593     rename("MakeMaker.tmp", $finalname);
594
595     chmod 0644, $finalname;
596     system("$Config{'eunicefix'} $finalname") unless $Config{'eunicefix'} eq ":";
597
598     1;
599 }
600
601
602 sub mkbootstrap{
603     parse_args(\%att, @ARGV);
604     MY->mkbootstrap(@_);
605 }
606
607 sub mksymlists{
608     %att = @_;
609     parse_args(\%att, @ARGV);
610     MY->mksymlists(@_);
611 }
612
613 sub parse_args{
614     my($attr, @args) = @_;
615     foreach (@args){
616         unless (m/(.*?)=(.*)/){
617             help(),exit 1 if m/^help$/;
618             ++$Verbose if m/^verb/;
619             next;
620         }
621         my($name, $value) = ($1, $2);
622         if ($value =~ m/^~(\w+)?/){ # tilde with optional username
623             my($home) = ($1) ? (getpwnam($1))[7] : (getpwuid($>))[7];
624             $value =~ s/^~(\w+)?/$home/;
625         }
626         $$attr{$name} = $value;
627     }
628     # catch old-style 'potential_libs' and inform user how to 'upgrade'
629     if (defined $$attr{'potential_libs'}){
630         my($msg)="'potential_libs' => '$$attr{potential_libs}' should be";
631         if ($$attr{'potential_libs'}){
632             print STDOUT "$msg changed to:\n\t'LIBS' => ['$$attr{potential_libs}']\n";
633         } else {
634             print STDOUT "$msg deleted.\n";
635         }
636         $$attr{LIBS} = [$$attr{'potential_libs'}];
637         delete $$attr{'potential_libs'};
638     }
639     # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
640     if (defined $$attr{'ARMAYBE'}){
641         my($armaybe) = $$attr{'ARMAYBE'};
642         print STDOUT "ARMAYBE => '$armaybe' should be changed to:\n",
643                         "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
644         my(%dl) = %{$$attr{'dynamic_lib'} || {}};
645         $$attr{'dynamic_lib'} = { %dl, ARMAYBE => $armaybe};
646         delete $$attr{'ARMAYBE'};
647     }
648     if (defined $$attr{'LDTARGET'}){
649         print STDOUT "LDTARGET should be changed to LDFROM\n";
650         $$attr{'LDFROM'} = $$attr{'LDTARGET'};
651         delete $$attr{'LDTARGET'};
652     }
653     foreach(sort keys %{$attr}){
654         print STDOUT "  $_ => ".neatvalue($$attr{$_}) if ($Verbose);
655         print STDOUT "'$_' is not a known MakeMaker parameter name.\n"
656             unless exists $Recognized_Att_Keys{$_};
657     }
658 }
659
660
661 sub neatvalue{
662     my($v) = @_;
663     return "undef" unless defined $v;
664     my($t) = ref $v;
665     return "'$v'" unless $t;
666     return "[ ".join(', ',map("'$_'",@$v))." ]" if ($t eq 'ARRAY');
667     return "$v" unless $t eq 'HASH';
668     my(@m, $key, $val);
669     push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v);
670     return "{ ".join(', ',@m)." }";
671 }
672
673 # ------ Define the MakeMaker default methods in package MM_Unix ------
674
675 package MM_Unix;
676
677 use Config;
678 use Cwd;
679 use File::Basename;
680 require Exporter;
681
682 Exporter::import('ExtUtils::MakeMaker',
683         qw(%att %skip %Recognized_Att_Keys $Verbose));
684
685 # These attributes cannot be overridden externally
686 @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3;
687
688 if ($Is_VMS = $Config{'osname'} eq 'VMS') {
689     require VMS::Filespec;
690     import VMS::Filespec 'vmsify';
691 }
692
693
694 sub init_main {
695     # Find out directory name.  This may contain the extension name.
696     my($pwd) = fastcwd(); # from Cwd.pm
697
698     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
699
700     # *Real* information: where did we get these two from? ...
701     my $inc_config_dir = dirname($INC{'Config.pm'});
702     my $inc_carp_dir   = dirname($INC{'Carp.pm'});
703
704     # Typically PERL_* and INST_* will be identical but that need
705     # not be the case (e.g., installing into project libraries etc).
706
707     # Perl Macro:    With source    No source
708     # PERL_LIB       ../../lib      /usr/local/lib/perl5
709     # PERL_ARCHLIB   ../../lib      /usr/local/lib/perl5/sun4-sunos
710     # PERL_SRC       ../..          (undefined)
711
712     # INST Macro:    Locally        Publically
713     # INST_LIB       ../../lib      ./blib
714     # INST_ARCHLIB   ../../lib      ./blib
715
716     unless ($att{PERL_SRC}){
717         foreach(qw(../.. ../../.. ../../../..)){
718             if ( -f "$_/config.sh" && -f "$_/perl.h" && -f "$_/lib/Exporter.pm") {
719                 $att{PERL_SRC}=$_ ;
720                 last;
721             }
722         }
723     }
724     unless ($att{PERL_SRC}){
725         # we should also consider $ENV{PERL5LIB} here
726         $att{PERL_LIB}     = $Config{'privlib'} unless $att{PERL_LIB};
727         $att{PERL_ARCHLIB} = $Config{'archlib'} unless $att{PERL_ARCHLIB};
728         $att{PERL_INC}     = "$att{PERL_ARCHLIB}/CORE"; # wild guess for now
729         die "Unable to locate Perl source. Try setting PERL_SRC in Makefile.PL or on command line.\n"
730                 unless (-f "$att{PERL_INC}/perl.h");
731         print STDOUT "Using header files found in $att{PERL_INC}" if $Verbose;
732     } else {
733         $att{PERL_LIB}     = "$att{PERL_SRC}/lib" unless $att{PERL_LIB};
734         $att{PERL_ARCHLIB} = $att{PERL_LIB};
735         $att{PERL_INC}     = $att{PERL_SRC};
736         # catch an situation that has occurred a few times in the past:
737         warn <<EOM unless -s "$att{PERL_SRC}/cflags";
738 You cannot build extensions below the perl source tree after executing
739 a 'make clean' in the perl source tree.
740
741 To rebuild extensions distributed with the perl source you should
742 simply Configure (to include those extensions) and then build perl as
743 normal. After installing perl the source tree can be deleted. It is not
744 needed for building extensions.
745
746 It is recommended that you unpack and build additional extensions away
747 from the perl source tree.
748 EOM
749     }
750
751     # INST_LIB typically pre-set if building an extension after
752     # perl has been built and installed. Setting INST_LIB allows
753     # you to build directly into privlib and avoid installperl.
754     unless ($att{INST_LIB}){
755         if (defined $att{PERL_SRC}) {
756             $att{INST_LIB} = $att{PERL_LIB};
757         } else {
758             $att{INST_LIB} = "./blib";
759         }
760     }
761     # Try to work out what INST_ARCHLIB should be if not set:
762     unless ($att{INST_ARCHLIB}){
763         my(%archmap) = (
764             "./blib"            => "./blib", # our private build lib
765             $att{PERL_LIB}      => $att{PERL_ARCHLIB},
766             $Config{'privlib'}  => $Config{'archlib'},
767             $Config{'installprivlib'}   => $Config{'installarchlib'},
768             $inc_carp_dir       => $inc_config_dir,
769         );
770         $att{INST_ARCHLIB} = $archmap{$att{INST_LIB}};
771         unless($att{INST_ARCHLIB}){
772             # Oh dear, we'll have to default it and warn the user
773             my($archname) = $Config{'archname'};
774             if (-d "$att{INST_LIB}/$archname"){
775                 $att{INST_ARCHLIB} = "$att{INST_LIB}/$archname";
776                 print STDOUT "Defaulting INST_ARCHLIB to INST_LIB/$archname\n";
777             } else {
778                 $att{INST_ARCHLIB} = $att{INST_LIB};
779                 print STDOUT "Warning: Defaulting INST_ARCHLIB to INST_LIB ",
780                         "(not architecture independent).\n";
781             }
782         }
783         $att{INST_EXE} = "./blib" unless $att{INST_EXE};
784         $att{MAP_TARGET} = "perl" unless $att{MAP_TARGET};
785         $att{LIBPERL_A} = $Is_VMS ? 'libperl.olb' : 'libperl.a'
786             unless $att{LIBPERL_A};
787     }
788
789     # make a few simple checks
790     die "PERL_LIB ($att{PERL_LIB}) is not a perl library directory"
791         unless (-f "$att{PERL_LIB}/Exporter.pm");
792
793     # --- Initialize Module Name and Paths
794
795     # NAME    = The perl module name for this extension (eg DBD::Oracle).
796     # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
797     # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
798     # ROOTEXT = Directory part of FULLEXT with leading /.
799     unless($att{NAME}){ # we have to guess our name
800         my($name) = $pwd;
801         if ($Is_VMS) {
802           $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.(.*)\]:$1:i);
803           ($att{NAME}=$name) =~ s#[.\]]#::#g;
804         } else {
805           $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::);
806           ($att{NAME} =$name) =~ s#/#::#g;
807         }
808     }
809     ($att{FULLEXT} =$att{NAME}) =~ s#::#/#g ;           #eg. BSD/Foo/Socket
810     ($att{BASEEXT} =$att{NAME}) =~ s#.*::##;            #eg. Socket
811     ($att{ROOTEXT} =$att{FULLEXT}) =~ s#/?\Q$att{BASEEXT}\E$## ; # eg. /BSD/Foo
812     $att{ROOTEXT} = ($Is_VMS ? '' : '/') . $att{ROOTEXT} if $att{ROOTEXT};
813
814     ($att{DISTNAME}=$att{NAME}) =~ s#(::)#-#g unless $att{DISTNAME};
815     $att{VERSION} = "0.1" unless $att{VERSION};
816
817
818     # --- Initialize Perl Binary Locations
819
820     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
821     # will be working versions of perl 5. miniperl has priority over perl
822     # for PERL to ensure that $(PERL) is usable while building ./ext/*
823     $att{'PERL'} = MY->find_perl(5.0, [ qw(miniperl perl) ],
824             [ grep defined $_, $att{PERL_SRC}, split(":", $ENV{PATH}), $Config{'bin'} ], $Verbose )
825         unless ($att{'PERL'} && -x $att{'PERL'});
826
827     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
828     ($att{'FULLPERL'} = $att{'PERL'}) =~ s/miniperl/perl/
829         unless ($att{'FULLPERL'} && -x $att{'FULLPERL'});
830
831     if ($Is_VMS) {
832         $att{'PERL'} = 'MCR ' . vmsify($att{'PERL'});
833         $att{'FULLPERL'} = 'MCR ' . vmsify($att{'FULLPERL'});
834     }
835 }
836
837
838 sub init_dirscan {      # --- File and Directory Lists (.xs .pm .pod etc)
839
840     my($name, %dir, %xs, %c, %h, %ignore, %pl_files);
841     local(%pm); #the sub in find() has to see this hash
842     $ignore{'test.pl'} = 1;
843     $ignore{'makefile.pl'} = 1 if $Is_VMS;
844     foreach $name (lsdir(".")){
845         next if ($name =~ /^\./ or $ignore{$name});
846         if (-d $name){
847             $dir{$name} = $name if (-f "$name/Makefile.PL");
848         } elsif ($name =~ /\.xs$/){
849             my($c); ($c = $name) =~ s/\.xs$/.c/;
850             $xs{$name} = $c;
851             $c{$c} = 1;
852         } elsif ($name =~ /\.c$/){
853             $c{$name} = 1;
854         } elsif ($name =~ /\.h$/){
855             $h{$name} = 1;
856         } elsif ($name =~ /\.(p[ml]|pod)$/){
857             $pm{$name} = "\$(INST_LIBDIR)/$name";
858         } elsif ($name =~ /\.PL$/ && $name ne "Makefile.PL") {
859             ($pl_files{$name} = $name) =~ s/\.PL$// ;
860         }
861     }
862
863     # Some larger extensions often wish to install a number of *.pm/pl
864     # files into the library in various locations.
865
866     # The attribute PMLIBDIRS holds an array reference which lists
867     # subdirectories which we should search for library files to
868     # install. PMLIBDIRS defaults to [ 'lib', $att{BASEEXT} ].
869     # We recursively search through the named directories (skipping
870     # any which don't exist or contain Makefile.PL files).
871
872     # For each *.pm or *.pl file found MY->libscan() is called with
873     # the default installation path in $_. The return value of libscan
874     # defines the actual installation location.
875     # The default libscan function simply returns $_.
876     # The file is skipped if libscan returns false.
877
878     # The default installation location passed to libscan in $_ is:
879     #
880     #  ./*.pm           => $(INST_LIBDIR)/*.pm
881     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
882     #  ./lib/...        => $(INST_LIB)/...
883     #
884     # In this way the 'lib' directory is seen as the root of the actual
885     # perl library whereas the others are relative to INST_LIBDIR
886     # (which includes ROOTEXT). This is a subtle distinction but one
887     # that's important for nested modules.
888
889     $att{PMLIBDIRS} = [ 'lib', $att{BASEEXT} ] unless $att{PMLIBDIRS};
890
891     #only existing directories that aren't in $dir are allowed
892     @{$att{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$att{PMLIBDIRS}};
893
894     if (@{$att{PMLIBDIRS}}){
895         print "Searching PMLIBDIRS: @{$att{PMLIBDIRS}}"
896             if ($Verbose >= 2);
897         use File::Find;         # try changing to require !
898         File::Find::find(sub {
899 # We now allow any file in PMLIBDIRS to be installed. nTk needs that, and
900 # we should allow it.
901 #               return unless m/\.p[ml]$/;
902                 return if -d $_; # anything else that Can't be copied?
903                 my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
904                 my $striplibpath;
905                 $prefix =  '$(INST_LIB)' if (($striplibpath = $path) =~ s:^lib/::);
906                 local($_) = "$prefix/$striplibpath";
907                 my($inst) = MY->libscan();
908                 print "libscan($path) => '$inst'" if ($Verbose >= 2);
909                 return unless $inst;
910                 $pm{$path} = $inst;
911              }, @{$att{PMLIBDIRS}});
912     }
913
914     $att{DIR} = [sort keys %dir] unless $att{DIRS};
915     $att{XS}  = \%xs             unless $att{XS};
916     $att{PM}  = \%pm             unless $att{PM};
917     $att{C}   = [sort keys %c]   unless $att{C};
918     my(@o_files) = @{$att{C}};
919     my($sufx) = $Is_VMS ? '.obj' : '.o';
920     $att{O_FILES} = [grep s/\.c$/$sufx/, @o_files] ;
921     $att{H}   = [sort keys %h]   unless $att{H};
922     $att{PL_FILES} = \%pl_files unless $att{PL_FILES};
923 }
924
925
926 sub libscan {
927     return undef if m:/RCS/: ;
928     $_;
929 }
930
931 sub init_others {       # --- Initialize Other Attributes
932     my($key);
933     for $key (keys(%Recognized_Att_Keys), keys(%Other_Att_Keys)){
934         # avoid warnings for uninitialized vars
935         next if exists $att{$key};
936         $att{$key} = "";
937     }
938
939     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $att{'LIBS'}
940     # Lets look at $att{LIBS} carefully: It may be an anon array, a string or
941     # undefined. In any case we turn it into an anon array:
942     $att{LIBS}=[] unless $att{LIBS};
943     $att{LIBS}=[$att{LIBS}] if ref \$att{LIBS} eq SCALAR;
944     foreach ( @{$att{'LIBS'}} ){
945         s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
946         my(@libs) = MY->extliblist($_);
947         if ($libs[0] or $libs[1] or $libs[2]){
948             @att{EXTRALIBS, BSLOADLIBS, LDLOADLIBS} = @libs;
949             last;
950         }
951     }
952
953     print STDOUT "CONFIG must be an array ref\n"
954         if ($att{CONFIG} and ref $att{CONFIG} ne 'ARRAY');
955     $att{CONFIG} = [] unless (ref $att{CONFIG});
956     push(@{$att{CONFIG}},
957         qw( cc libc ldflags lddlflags ccdlflags cccdlflags
958             ranlib so dlext dlsrc installprivlib installarchlib
959         ));
960     push(@{$att{CONFIG}}, 'shellflags') if $Config{'shellflags'};
961
962     if ($Is_VMS) {
963       $att{OBJECT} = '$(BASEEXT).obj' unless $att{OBJECT};
964       $att{OBJECT} =~ s/[^,\s]\s+/, /g;
965       $att{OBJECT} =~ s/\n+/, /g;
966       $att{OBJECT} =~ s#\.o,#\.obj,#;
967     } else {
968       $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT};
969       $att{OBJECT} =~ s/\n+/ \\\n\t/g;
970     }
971     $att{BOOTDEP}  = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
972     $att{LD}       = ($Config{'ld'} || 'ld') unless $att{LD};
973     $att{LDFROM} = '$(OBJECT)' unless $att{LDFROM};
974     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
975     # the 'dynamic' section of MM.  We don't have this problem with
976     # 'static', since we either must use it (%Config says we can't
977     # use dynamic loading) or the caller asked for it explicitly.
978     if (!$att{LINKTYPE}) {
979        $att{LINKTYPE} = grep(/dynamic/,@{$att{SKIP} || []})
980                         ? 'static'
981                         : ($Config{'usedl'} ? 'dynamic' : 'static');
982     };
983
984     # These get overridden for VMS and maybe some other systems
985     $att{NOOP}  = "";
986     $att{MAKEFILE} = "Makefile";
987     $att{RM_F}  = "rm -f";
988     $att{RM_RF} = "rm -rf";
989     $att{TOUCH} = "touch";
990     $att{CP} = "cp";
991     $att{MV} = "mv";
992 }
993
994
995 sub lsdir{
996     my($dir, $regex) = @_;
997     local(*DIR, @ls);
998     opendir(DIR, $_[0] || ".") or die "opendir: $!";
999     @ls = readdir(DIR);
1000     closedir(DIR);
1001     @ls = grep(/$regex/, @ls) if $regex;
1002     @ls;
1003 }
1004
1005
1006 sub find_perl{
1007     my($self, $ver, $names, $dirs, $trace) = @_;
1008     my($name, $dir);
1009     if ($trace >= 2){
1010         print "Looking for perl $ver by these names: ";
1011         print "@$names, ";
1012         print "in these dirs:";
1013         print "@$dirs";
1014     }
1015     foreach $dir (@$dirs){
1016         next unless defined $dir; # $att{PERL_SRC} may be undefined
1017         foreach $name (@$names){
1018             print "Checking $dir/$name " if ($trace >= 2);
1019             if ($Is_VMS) {
1020               $name .= ".exe" unless -x "$dir/$name";
1021             }
1022             next unless -x "$dir/$name";
1023             print "Executing $dir/$name" if ($trace >= 2);
1024             my($out);
1025             if ($Is_VMS) {
1026               my($vmscmd) = 'MCR ' . vmsify("$dir/$name");
1027               $out = `$vmscmd -e "require $ver; print ""VER_OK\n"""`;
1028             } else {
1029               $out = `$dir/$name -e 'require $ver; print "VER_OK\n" ' 2>&1`;
1030             }
1031             if ($out =~ /VER_OK/) {
1032                 print "Using $dir/$name" if $trace;
1033                 return "$dir/$name";
1034             }
1035         }
1036     }
1037     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1038     0; # false and not empty
1039 }
1040
1041
1042 sub post_initialize{
1043     "";
1044 }
1045
1046
1047 sub constants {
1048     my(@m);
1049
1050     push @m, "
1051 NAME = $att{NAME}
1052 DISTNAME = $att{DISTNAME}
1053 VERSION = $att{VERSION}
1054
1055 # In which library should we install this extension?
1056 # This is typically the same as PERL_LIB.
1057 # (also see INST_LIBDIR and relationship to ROOTEXT)
1058 INST_LIB = $att{INST_LIB}
1059 INST_ARCHLIB = $att{INST_ARCHLIB}
1060 INST_EXE = $att{INST_EXE}
1061
1062 # Perl library to use when building the extension
1063 PERL_LIB = $att{PERL_LIB}
1064 PERL_ARCHLIB = $att{PERL_ARCHLIB}
1065 LIBPERL_A = $att{LIBPERL_A}
1066 ";
1067
1068     # Define I_PERL_LIBS to include the required -Ipaths
1069     # To be cute we only include PERL_ARCHLIB if different
1070     # To be portable we add quotes for VMS
1071     my(@i_perl_libs) = qw{-I$(PERL_ARCHLIB) -I$(PERL_LIB)};
1072     shift(@i_perl_libs) if ($att{PERL_ARCHLIB} eq $att{PERL_LIB});
1073     if ($Is_VMS){
1074         push @m, "I_PERL_LIBS = \"".join('" "',@i_perl_libs)."\"\n";
1075     } else {
1076         push @m, "I_PERL_LIBS = ".join(' ',@i_perl_libs)."\n";
1077     }
1078
1079     push @m, "
1080 # Where is the perl source code located?
1081 PERL_SRC = $att{PERL_SRC}\n" if $att{PERL_SRC};
1082
1083     push @m, "
1084 # Perl header files (will eventually be under PERL_LIB)
1085 PERL_INC = $att{PERL_INC}
1086 # Perl binaries
1087 PERL = $att{'PERL'}
1088 FULLPERL = $att{'FULLPERL'}
1089 ";
1090     push @m, "
1091 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
1092 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
1093 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
1094 FULLEXT = $att{FULLEXT}
1095 BASEEXT = $att{BASEEXT}
1096 ROOTEXT = $att{ROOTEXT}
1097 ";
1098     push @m, "
1099 INC = $att{INC}
1100 DEFINE = $att{DEFINE}
1101 OBJECT = $att{OBJECT}
1102 LDFROM = $att{LDFROM}
1103 LINKTYPE = $att{LINKTYPE}
1104
1105 # Handy lists of source code files:
1106 XS_FILES= ".join(" \\\n\t", sort keys %{$att{XS}})."
1107 C_FILES = ".join(" \\\n\t", @{$att{C}})."
1108 O_FILES = ".join(" \\\n\t", @{$att{O_FILES}})."
1109 H_FILES = ".join(" \\\n\t", @{$att{H}})."
1110
1111 .SUFFIXES: .xs
1112
1113 .PRECIOUS: Makefile
1114
1115 .PHONY: all config static dynamic test linkext
1116
1117 # This extension may link to it's own library (see SDBM_File)
1118 MYEXTLIB = $att{MYEXTLIB}
1119
1120 # Where is the Config information that we are using/depend on
1121 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
1122 ";
1123
1124     push @m, '
1125 # Where to put things:
1126 INST_LIBDIR     = $(INST_LIB)$(ROOTEXT)
1127 INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT)
1128
1129 INST_AUTODIR      = $(INST_LIB)/auto/$(FULLEXT)
1130 INST_ARCHAUTODIR  = $(INST_ARCHLIB)/auto/$(FULLEXT)
1131 ';
1132
1133     push @m, '
1134 INST_STATIC  = $(INST_ARCHAUTODIR)/$(BASEEXT).a
1135 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(BASEEXT).$(DLEXT)
1136 INST_BOOT    = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
1137 INST_PM = '.join(" \\\n\t", sort values %{$att{PM}}).'
1138 ';
1139
1140     join('',@m);
1141 }
1142
1143 $Const_cccmd=0; # package global
1144
1145 sub const_cccmd{
1146     my($self,$libperl)=@_;
1147     $libperl or $libperl = $att{LIBPERL_A} || "libperl.a" ;
1148     # This is implemented in the same manner as extliblist,
1149     # e.g., do both and compare results during the transition period.
1150     my($cc,$ccflags,$optimize,$large,$split, $shflags)
1151         = @Config{qw(cc ccflags optimize large split shellflags)};
1152     my($optdebug)="";
1153
1154     $shflags = '' unless $shflags;
1155     my($prog, $old, $uc, $perltype);
1156
1157     unless ($Const_cccmd++){
1158         chop($old = `cd $att{PERL_SRC}; sh $shflags ./cflags $libperl $att{BASEEXT}.c`)
1159           if $att{PERL_SRC};
1160         $Const_cccmd++; # shut up typo warning
1161     }
1162
1163     my(%map) =  (
1164                 D =>   '-DDEBUGGING',
1165                 E =>   '-DEMBED',
1166                 DE =>  '-DDEBUGGING -DEMBED',
1167                 M =>   '-DEMBED -DMULTIPLICITY',
1168                 DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
1169                 );
1170
1171     if ($libperl =~ /libperl(\w*)\.a/){
1172         $uc = uc($1);
1173     } else {
1174         $uc = ""; # avoid warning
1175     }
1176     $perltype = $map{$uc} ? $map{$uc} : "";
1177
1178     if ($uc =~ /^D/) {
1179         $optdebug = "-g";
1180     }
1181
1182
1183     my($name);
1184     ( $name = $att{NAME} . "_cflags" ) =~ s/:/_/g ;
1185     if ($prog = $Config{$name}) {
1186         # Expand hints for this extension via the shell
1187         print STDOUT "Processing $name hint:\n" if $Verbose;
1188         my(@o)=`cc=\"$cc\"
1189           ccflags=\"$ccflags\"
1190           optimize=\"$optimize\"
1191           perltype=\"$perltype\"
1192           optdebug=\"$optdebug\"
1193           large=\"$large\"
1194           split=\"$split\"
1195           eval '$prog'
1196           echo cc=\$cc
1197           echo ccflags=\$ccflags
1198           echo optimize=\$optimize
1199           echo perltype=\$perltype
1200           echo optdebug=\$optdebug
1201           echo large=\$large
1202           echo split=\$split
1203           `;
1204         my(%cflags,$line);
1205         foreach $line (@o){
1206             chomp $line;
1207             if ($line =~ /(.*?)=\s*(.*)\s*$/){
1208                 $cflags{$1} = $2;
1209                 print STDOUT "  $1 = $2" if $Verbose;
1210             } else {
1211                 print STDOUT "Unrecognised result from hint: '$line'\n";
1212             }
1213         }
1214         (    $cc,$ccflags,$perltype,$optdebug,$optimize,$large,$split )=@cflags{
1215           qw( cc  ccflags  perltype  optdebug  optimize  large  split)};
1216     }
1217
1218     if ($optdebug) {
1219         $optimize = $optdebug;
1220     }
1221
1222     my($new) = "$cc -c $ccflags $optimize $perltype $large $split";
1223     if (defined($old) and $new ne $old) {
1224         print STDOUT "Warning (non-fatal): cflags evaluation in MakeMaker differs from shell output\n"
1225         ."   package: $att{NAME}\n"
1226         ."   old: $old\n"
1227         ."   new: $new\n"
1228         ."   Using 'old' set.\n"
1229         ."Please notify perl5-porters\@nicoh.com\n";
1230     }
1231     my($cccmd)=($old) ? $old : $new;
1232     $cccmd =~ s/^\s*\Q$Config{'cc'}\E\s/\$(CC) /;
1233     "CCCMD = $cccmd\n";
1234 }
1235
1236
1237 # --- Constants Sections ---
1238
1239 sub const_config{
1240     my(@m,$m);
1241     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
1242     my(%once_only);
1243     foreach $m (@{$att{'CONFIG'}}){
1244         next if $once_only{$m};
1245         print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
1246                 unless exists $Config{$m};
1247         push @m, "\U$m\E = $Config{$m}\n";
1248         $once_only{$m} = 1;
1249     }
1250     join('', @m);
1251 }
1252
1253
1254 sub const_loadlibs{
1255     "
1256 # $att{NAME} might depend on some other libraries:
1257 # (These comments may need revising:)
1258 #
1259 # Dependent libraries can be linked in one of three ways:
1260 #
1261 #  1.  (For static extensions) by the ld command when the perl binary
1262 #      is linked with the extension library. See EXTRALIBS below.
1263 #
1264 #  2.  (For dynamic extensions) by the ld command when the shared
1265 #      object is built/linked. See LDLOADLIBS below.
1266 #
1267 #  3.  (For dynamic extensions) by the DynaLoader when the shared
1268 #      object is loaded. See BSLOADLIBS below.
1269 #
1270 # EXTRALIBS =   List of libraries that need to be linked with when
1271 #               linking a perl binary which includes this extension
1272 #               Only those libraries that actually exist are included.
1273 #               These are written to a file and used when linking perl.
1274 #
1275 # LDLOADLIBS =  List of those libraries which can or must be linked into
1276 #               the shared library when created using ld. These may be
1277 #               static or dynamic libraries.
1278 #
1279 # BSLOADLIBS =  List of those libraries that are needed but can be
1280 #               linked in dynamically at run time on this platform.
1281 #               SunOS/Solaris does not need this because ld records
1282 #               the information (from LDLOADLIBS) into the object file.
1283 #               This list is used to create a .bs (bootstrap) file.
1284 #
1285 EXTRALIBS  = $att{'EXTRALIBS'}
1286 LDLOADLIBS = $att{'LDLOADLIBS'}
1287 BSLOADLIBS = $att{'BSLOADLIBS'}
1288 ";
1289 }
1290
1291
1292 # --- Tool Sections ---
1293
1294 sub tool_autosplit{
1295     my($self, %attribs) = @_;
1296     my($asl) = "";
1297     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
1298     q{
1299 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1300 AUTOSPLITFILE = $(PERL) $(I_PERL_LIBS) -e 'use AutoSplit;}.$asl.q{autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
1301 };
1302 }
1303
1304
1305 sub tool_xsubpp{
1306     my($xsdir)  = '$(PERL_LIB)/ExtUtils';
1307     # drop back to old location if xsubpp is not in new location yet
1308     $xsdir = '$(PERL_SRC)/ext' unless (-f "$att{PERL_LIB}/ExtUtils/xsubpp");
1309     my(@tmdeps) = ('$(XSUBPPDIR)/typemap');
1310     push(@tmdeps, "typemap") if -f "typemap";
1311     my(@tmargs) = map("-typemap $_", @tmdeps);
1312     "
1313 XSUBPPDIR = $xsdir
1314 XSUBPP = \$(XSUBPPDIR)/xsubpp
1315 XSUBPPDEPS = @tmdeps
1316 XSUBPPARGS = @tmargs
1317 ";
1318 };
1319
1320
1321 sub tools_other{
1322     "
1323 SHELL = /bin/sh
1324 LD = $att{LD}
1325 TOUCH = $att{TOUCH}
1326 CP = $att{CP}
1327 MV = $att{MV}
1328 RM_F  = $att{RM_F}
1329 RM_RF = $att{RM_RF}
1330 ".q{
1331 # The following is a portable way to say mkdir -p
1332 MKPATH = $(PERL) -wle '$$"="/"; foreach $$p (@ARGV){ next if -d $$p; my(@p); foreach(split(/\//,$$p)){ push(@p,$$_); next if -d "@p/"; print "mkdir @p"; mkdir("@p",0777)||die $$! }} exit 0;'
1333 };
1334 }
1335
1336
1337 sub post_constants{
1338     "";
1339 }
1340
1341 sub pasthru {
1342     my(@m,@pasthru,$key);
1343     # It has to be considered carefully, which variables are apt to be passed through, e.g. PERL_SRC
1344     # is not suited for subdirectories, as it might be relativ to the parent directory.
1345     # Probably we need a PASTHRU2 variable. PASTHRU1 is a conservative approach, that hardly changes
1346     # MakeMaker between version 4.086 and 4.09.
1347     push @m, "\nPASTHRU1 = ";
1348     foreach $key (qw(INST_ARCHLIB INST_EXE INST_LIB LIBPERL_A LINKTYPE)){
1349         push @pasthru, "$key=\"\$($key)\"";
1350     }
1351     push @m, join "\\\n\t", @pasthru;
1352     join "", @m;
1353 }
1354
1355 # --- Translation Sections ---
1356
1357 sub c_o {
1358     my(@m);
1359     push @m, '
1360 .c.o:
1361         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1362 ';
1363     join "", @m;
1364 }
1365
1366 sub xs_c {
1367     '
1368 .xs.c:
1369         $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >$*.tc && mv $*.tc $@
1370 ';
1371 }
1372
1373 sub xs_o {      # many makes are too dumb to use xs_c then c_o
1374     '
1375 .xs.o:
1376         $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
1377         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1378 ';
1379 }
1380
1381
1382 # --- Target Sections ---
1383
1384 sub top_targets{
1385     my(@m);
1386     push @m, '
1387 all ::  config linkext $(INST_PM)
1388 '.$att{NOOP}.'
1389
1390 config :: '.$att{MAKEFILE}.' $(INST_LIBDIR)/.exists $(INST_ARCHAUTODIR)/.exists
1391 ';
1392
1393     push @m, MM->dir_target('$(INST_LIBDIR)', '$(INST_ARCHAUTODIR)');
1394
1395     push @m, '
1396 $(O_FILES): $(H_FILES)
1397 ' if @{$att{O_FILES} || []} && @{$att{H} || []};
1398     join('',@m);
1399 }
1400
1401 sub linkext {
1402     my($self, %attribs) = @_;
1403     # LINKTYPE => static or dynamic
1404     my($linktype) = $attribs{LINKTYPE} || '$(LINKTYPE)';
1405     "
1406 linkext :: $linktype
1407 $att{NOOP}
1408 ";
1409 }
1410
1411 sub dlsyms {
1412     my($self,%attribs) = @_;
1413
1414     return '' if ($Config{'osname'} ne 'aix');
1415
1416     my($funcs) = $attribs{DL_FUNCS} || $att{DL_FUNCS} || {};
1417     my($vars)  = $attribs{DL_VARS} || $att{DL_VARS} || [];
1418     my(@m);
1419
1420     push(@m,"
1421 dynamic :: $att{BASEEXT}.exp
1422
1423 ") unless $skip{'dynamic'};
1424
1425     push(@m,"
1426 static :: $att{BASEEXT}.exp
1427
1428 ") unless $skip{'static'};
1429
1430     push(@m,"
1431 $att{BASEEXT}.exp: Makefile.PL
1432 ",'     $(PERL) $(I_PERL_LIBS) -e \'use ExtUtils::MakeMaker qw(&mksymlists); \\
1433         &mksymlists(DL_FUNCS => ',
1434         %$funcs ? neatvalue($funcs) : '""',', DL_VARS => ',
1435         @$vars  ? neatvalue($vars)  : '""', ", NAME => \"$att{NAME}\")'
1436 ");
1437
1438     join('',@m);
1439 }
1440
1441 # --- Dynamic Loading Sections ---
1442
1443 sub dynamic {
1444     '
1445 # $(INST_PM) has been moved to the all: target.
1446 # It remains here for awhile to allow for old usage: "make dynamic"
1447 dynamic :: '.$att{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
1448 '.$att{NOOP}.'
1449 ';
1450 }
1451
1452 sub dynamic_bs {
1453     my($self, %attribs) = @_;
1454     '
1455 BOOTSTRAP = '."$att{BASEEXT}.bs".'
1456
1457 # As MakeMaker mkbootstrap might not write a file (if none is required)
1458 # we use touch to prevent make continually trying to remake it.
1459 # The DynaLoader only reads a non-empty file.
1460 $(BOOTSTRAP): '."$att{MAKEFILE} $att{BOOTDEP}".'
1461         @ echo "Running mkbootstrap for $(NAME) ($(BSLOADLIBS))"
1462         @ $(PERL) $(I_PERL_LIBS) \
1463                 -e \'use ExtUtils::MakeMaker qw(&mkbootstrap); &mkbootstrap("$(BSLOADLIBS)");\' \
1464                 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) PERL_SRC=$(PERL_SRC) NAME=$(NAME)
1465         @ $(TOUCH) $(BOOTSTRAP)
1466
1467 $(INST_BOOT): $(BOOTSTRAP)
1468         @ '.$att{RM_RF}.' $(INST_BOOT)
1469         -'.$att{CP}.' $(BOOTSTRAP) $(INST_BOOT)
1470 ';
1471 }
1472
1473
1474 sub dynamic_lib {
1475     my($self, %attribs) = @_;
1476     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
1477     my($armaybe) = $attribs{ARMAYBE} || $att{ARMAYBE} || ":";
1478     my($ldfrom) = '$(LDFROM)';
1479     my($osname) = $Config{'osname'};
1480     $armaybe = 'ar' if ($osname eq 'dec_osf' and $armaybe eq ':');
1481     my(@m);
1482     push(@m,'
1483 # This section creates the dynamically loadable $(INST_DYNAMIC)
1484 # from $(OBJECT) and possibly $(MYEXTLIB).
1485 ARMAYBE = '.$armaybe.'
1486 OTHERLDFLAGS = '.$otherldflags.'
1487
1488 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)/.exists
1489 ');
1490     if ($armaybe ne ':'){
1491         $ldfrom = "tmp.a";
1492         push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
1493         push(@m,'       $(RANLIB) '."$ldfrom\n");
1494     }
1495     $ldfrom = "-all $ldfrom -none" if ($osname eq 'dec_osf');
1496     push(@m,'   $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
1497                         ' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS)'."\n");
1498
1499     push @m, MM->dir_target('$(INST_ARCHAUTODIR)');
1500     join('',@m);
1501 }
1502
1503
1504 # --- Static Loading Sections ---
1505
1506 sub static {
1507     '
1508 # $(INST_PM) has been moved to the all: target.
1509 # It remains here for awhile to allow for old usage: "make static"
1510 static :: '.$att{MAKEFILE}.' $(INST_STATIC) $(INST_PM)
1511 '.$att{NOOP}.'
1512 ';
1513 }
1514
1515 sub static_lib{
1516     my(@m);
1517     push(@m, <<'END');
1518 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)/.exists
1519 END
1520     # If this extension has it's own library (eg SDBM_File)
1521     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
1522     push(@m, "  $att{CP} \$(MYEXTLIB) \$\@\n") if $att{MYEXTLIB};
1523
1524     push(@m, <<'END');
1525         ar cr $@ $(OBJECT) && $(RANLIB) $@
1526         @echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
1527 END
1528
1529 # Old mechanism - still available:
1530
1531     push(@m, <<'END') if $att{PERL_SRC};
1532         @ echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
1533 END
1534     push @m, MM->dir_target('$(INST_ARCHAUTODIR)');
1535     join('', "\n",@m);
1536 }
1537
1538
1539 sub installpm {
1540     my($self, %attribs) = @_;
1541     # By default .pm files are split into the architecture independent
1542     # library. This is a good thing. If a specific module requires that
1543     # it's .pm files are split into the architecture specific library
1544     # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'}
1545     # Note that installperl currently interferes with this (Config.pm)
1546     # User can disable split by saying: installpm => {SPLITLIB=>''}
1547     my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default
1548     $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB};
1549     my(@m, $dist);
1550     foreach $dist (sort keys %{$att{PM}}){
1551         my($inst) = $att{PM}->{$dist};
1552         push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n");
1553         push(@m, MY->installpm_x($dist, $inst, $splitlib));
1554         push(@m, "\n");
1555     }
1556     join('', @m);
1557 }
1558
1559 sub installpm_x { # called by installpm per file
1560     my($self, $dist, $inst, $splitlib) = @_;
1561     my($instdir) = $inst =~ m|(.*)/|;
1562     my(@m);
1563     push(@m,"
1564 $inst: $dist Makefile $instdir/.exists
1565 ".'     @ '.$att{RM_F}.' $@
1566         '."$att{CP} $dist".' $@
1567 ');
1568     push(@m, "\t\@\$(AUTOSPLITFILE) \$@ $splitlib/auto\n")
1569         if ($splitlib and $inst =~ m/\.pm$/);
1570
1571     push @m, MM->dir_target($instdir);
1572     join('', @m);
1573 }
1574
1575 sub processPL {
1576     return "" unless $att{PL_FILES};
1577     my(@m, $plfile);
1578     foreach $plfile (sort keys %{$att{PL_FILES}}) {
1579         push @m, "
1580 all :: $att{PL_FILES}->{$plfile}
1581
1582 $att{PL_FILES}->{$plfile} :: $plfile
1583         \$(PERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) $plfile
1584 ";
1585     }
1586     join "", @m;
1587 }
1588
1589 sub installbin {
1590     return "" unless $att{EXE_FILES} && ref $att{EXE_FILES} eq "ARRAY";
1591     my(@m, $from, $to, %fromto, @to);
1592     for $from (@{$att{EXE_FILES}}) {
1593         local($_)= '$(INST_EXE)/' . basename($from);
1594         $to = MY->exescan();
1595         print "exescan($from) => '$to'" if ($Verbose >=2);
1596         $fromto{$from}=$to;
1597     }
1598     @to   = values %fromto;
1599     push(@m, "
1600 EXE_FILES = @{$att{EXE_FILES}}
1601
1602 all :: @to
1603
1604 realclean ::
1605         $att{RM_F} @to
1606 ");
1607
1608     while (($from,$to) = each %fromto) {
1609         push @m, "
1610 $to: $from $att{MAKEFILE}
1611         $att{CP} $from $to
1612 ";
1613     }
1614     join "", @m;
1615 }
1616
1617 sub exescan {
1618     $_;
1619 }
1620 # --- Sub-directory Sections ---
1621
1622 sub subdirs {
1623     my(@m);
1624     # This method provides a mechanism to automatically deal with
1625     # subdirectories containing further Makefile.PL scripts.
1626     # It calls the subdir_x() method for each subdirectory.
1627     foreach(grep -d, &lsdir()){
1628         next if /^\./;
1629         next unless -f "$_/Makefile\.PL" ;
1630         print "Including $_ subdirectory" if ($Verbose);
1631         push(@m, MY->subdir_x($_));
1632     }
1633     if (@m){
1634         unshift(@m, "
1635 # The default clean, realclean and test targets in this Makefile
1636 # have automatically been given entries for each subdir.
1637
1638 all :: subdirs
1639 ");
1640     } else {
1641         push(@m, "\n# none")
1642     }
1643     join('',@m);
1644 }
1645
1646 sub runsubdirpl{        # Experimental! See subdir_x section
1647     my($self,$subdir) = @_;
1648     chdir($subdir) or die "chdir($subdir): $!";
1649     ExtUtils::MakeMaker::check_hints();
1650     require "Makefile.PL";
1651 }
1652
1653 sub subdir_x {
1654     my($self, $subdir) = @_;
1655     my(@m);
1656     # The intention is that the calling Makefile.PL should define the
1657     # $(SUBDIR_MAKEFILE_PL_ARGS) make macro to contain whatever
1658     # information needs to be passed down to the other Makefile.PL scripts.
1659     # If this does not suit your needs you'll need to write your own
1660     # MY::subdir_x() method to override this one.
1661     qq{
1662 config :: $subdir/$att{MAKEFILE}
1663         cd $subdir && \$(MAKE) config \$(PASTHRU1) \$(SUBDIR_MAKEFILE_PL_ARGS)
1664
1665 $subdir/$att{MAKEFILE}: $subdir/Makefile.PL \$(CONFIGDEP)
1666 }.'     @echo "Rebuilding $@ ..."
1667         $(PERL) $(I_PERL_LIBS) \\
1668                 -e "use ExtUtils::MakeMaker; MM->runsubdirpl(qw('.$subdir.'))" \\
1669                 $(PASTHRU1) $(SUBDIR_MAKEFILE_PL_ARGS)
1670         @echo "Rebuild of $@ complete."
1671 '.qq{
1672
1673 subdirs ::
1674         cd $subdir && \$(MAKE) all \$(PASTHRU1)
1675
1676 };
1677 }
1678
1679
1680 # --- Cleanup and Distribution Sections ---
1681
1682 sub clean {
1683     my($self, %attribs) = @_;
1684     my(@m);
1685     push(@m, '
1686 # Delete temporary files but do not touch installed files. We don\'t delete
1687 # the Makefile here so a later make realclean still has a makefile to use.
1688
1689 clean ::
1690 ');
1691     # clean subdirectories first
1692     push(@m, map("\t-cd $_ && test -f $att{MAKEFILE} && \$(MAKE) clean\n",@{$att{DIR}}));
1693     my(@otherfiles) = values %{$att{XS}}; # .c files from *.xs files
1694     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1695     push(@otherfiles, "./blib");
1696     push(@m, "  -$att{RM_RF} *~ t/*~ *.o *.a mon.out core so_locations "
1697                         ."\$(BOOTSTRAP) \$(BASEEXT).bso \$(BASEEXT).exp @otherfiles\n");
1698     # See realclean and ext/utils/make_ext for usage of Makefile.old
1699     push(@m, "  -$att{MV} $att{MAKEFILE} $att{MAKEFILE}.old 2>/dev/null\n");
1700     push(@m, "  $attribs{POSTOP}\n")   if $attribs{POSTOP};
1701     join("", @m);
1702 }
1703
1704 sub realclean {
1705     my($self, %attribs) = @_;
1706     my(@m);
1707     push(@m,'
1708 # Delete temporary files (via clean) and also delete installed files
1709 realclean purge ::  clean
1710 ');
1711     # realclean subdirectories first (already cleaned)
1712     my $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
1713     foreach(@{$att{DIR}}){
1714         push(@m, sprintf($sub,$_,"$att{MAKEFILE}.old","-f $att{MAKEFILE}.old"));
1715         push(@m, sprintf($sub,$_,"$att{MAKEFILE}",''));
1716     }
1717     push(@m, "  $att{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
1718     push(@m, "  $att{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
1719     push(@m, "  $att{RM_F} \$(INST_STATIC) \$(INST_PM)\n");
1720     my(@otherfiles) = ($att{MAKEFILE}, 
1721                        "$att{MAKEFILE}.old"); # Makefiles last
1722     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1723     push(@m, "  $att{RM_RF} @otherfiles\n") if @otherfiles;
1724     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
1725     join("", @m);
1726 }
1727
1728
1729 sub dist {
1730     my($self, %attribs) = @_;
1731     # VERSION should be sanitised before use as a file name
1732     my($tarname)  = $attribs{TARNAME}  || '$(DISTNAME)-$(VERSION)';
1733     my($tarflags) = $attribs{TARFLAGS} || 'cvf';
1734     my($compress) = $attribs{COMPRESS} || 'compress'; # eg gzip
1735     my($preop)    = $attribs{PREOP}  || '@:'; # e.g., update MANIFEST
1736     my($postop)   = $attribs{POSTOP} || '@:';
1737     my($mkfiles)  = join(' ', map("$_/$att{MAKEFILE} $_/$att{MAKEFILE}.old", ".", @{$att{DIR}}));
1738     "
1739 dist:     clean
1740         $preop
1741         $att{RM_F} $mkfiles
1742         cd .. && tar $tarflags $tarname.tar \$(BASEEXT)
1743         cd .. && $compress $tarname.tar
1744         $postop
1745 ";
1746 }
1747
1748
1749 # --- Test and Installation Sections ---
1750
1751 sub test {
1752     my($self, %attribs) = @_;
1753     my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
1754     my(@m);
1755     push(@m,"
1756 TEST_VERBOSE=0
1757
1758 test :: all
1759 ");
1760     push(@m, <<"END") if $tests;
1761         \$(FULLPERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) -e 'use Test::Harness qw(&runtests \$\$verbose); \$\$verbose=\$(TEST_VERBOSE); runtests \@ARGV;' $tests
1762 END
1763     push(@m, <<'END') if -f "test.pl";
1764         $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB) test.pl
1765 END
1766     push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) test \$(PASTHRU)\n",
1767                  @{$att{DIR}}));
1768     push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n") unless @m > 1;
1769     join("", @m);
1770 }
1771
1772
1773 sub install {
1774     my($self, %attribs) = @_;
1775     my(@m);
1776     push @m, q{
1777 doc_install ::
1778         @ $(PERL) -I$(INST_ARCHLIB) -I$(INST_LIB) -I$(PERL_ARCHLIB) -I$(PERL_LIB)  \\
1779                 -e "use ExtUtils::MakeMaker; MM->writedoc('Module', '$(NAME)', \\
1780                 'LINKTYPE=$(LINKTYPE)', 'VERSION=$(VERSION)', 'EXE_FILES=$(EXE_FILES)')"
1781 };
1782
1783     push(@m, "
1784 install :: pure_install doc_install
1785
1786 pure_install :: all
1787 ");
1788     # install subdirectories first
1789     push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) install\n",@{$att{DIR}}));
1790
1791     push(@m, "\t: perl5.000 and MM pre 3.8 autosplit into INST_ARCHLIB, we delete these old files here
1792         $att{RM_F} $Config{'installarchlib'}/auto/\$(FULLEXT)/*.al
1793         $att{RM_F} $Config{'installarchlib'}/auto/\$(FULLEXT)/*.ix
1794         \$(MAKE) INST_LIB=$Config{'installprivlib'} INST_ARCHLIB=$Config{'installarchlib'} INST_EXE=$Config{'installbin'}
1795 ");
1796
1797     join("",@m);
1798 }
1799
1800 sub force {
1801     '# Phony target to force checking subdirectories.
1802 FORCE:
1803 ';
1804 }
1805
1806
1807 sub perldepend {
1808         my(@m);
1809     push(@m,'
1810 PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \
1811     $(PERL_INC)/XSUB.h  $(PERL_INC)/av.h        $(PERL_INC)/cop.h \
1812     $(PERL_INC)/cv.h    $(PERL_INC)/dosish.h    $(PERL_INC)/embed.h \
1813     $(PERL_INC)/form.h  $(PERL_INC)/gv.h        $(PERL_INC)/handy.h \
1814     $(PERL_INC)/hv.h    $(PERL_INC)/keywords.h  $(PERL_INC)/mg.h \
1815     $(PERL_INC)/op.h    $(PERL_INC)/opcode.h    $(PERL_INC)/patchlevel.h \
1816     $(PERL_INC)/perl.h  $(PERL_INC)/perly.h     $(PERL_INC)/pp.h \
1817     $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h   $(PERL_INC)/regexp.h \
1818     $(PERL_INC)/scope.h $(PERL_INC)/sv.h        $(PERL_INC)/unixish.h \
1819     $(PERL_INC)/util.h  $(PERL_INC)/config.h
1820
1821 $(OBJECT) : $(PERL_HDRS)
1822 ');
1823
1824     push(@m,'
1825 # Check for unpropogated config.sh changes. Should never happen.
1826 # We do NOT just update config.h because that is not sufficient.
1827 # An out of date config.h is not fatal but complains loudly!
1828 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
1829         -@echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
1830
1831 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
1832         @echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
1833         cd $(PERL_SRC) && $(MAKE) lib/Config.pm
1834 ') if $att{PERL_SRC};
1835
1836     push(@m, join(" ", values %{$att{XS}})." : \$(XSUBPPDEPS)\n")
1837         if %{$att{XS}};
1838     join("\n",@m);
1839 }
1840
1841
1842 sub makefile {
1843     # We do not know what target was originally specified so we
1844     # must force a manual rerun to be sure. But as it should only
1845     # happen very rarely it is not a significant problem.
1846     '
1847 $(OBJECT) : '.$att{MAKEFILE}.'
1848
1849 # We take a very conservative approach here, but it\'s worth it.
1850 # We move Makefile to Makefile.old here to avoid gnu make looping.
1851 '.$att{MAKEFILE}.':     Makefile.PL $(CONFIGDEP)
1852         @echo "Makefile out-of-date with respect to $?"
1853         @echo "Cleaning current config before rebuilding Makefile..."
1854         -@mv '."$att{MAKEFILE} $att{MAKEFILE}.old".'
1855         -$(MAKE) -f '.$att{MAKEFILE}.'.old clean >/dev/null 2>&1 || true
1856         $(PERL) $(I_PERL_LIBS) Makefile.PL '."@ARGV".'
1857         @echo "Now you must rerun make."; false
1858 ';
1859 }
1860
1861 sub postamble{
1862     "";
1863 }
1864
1865 # --- Make-Directories section (internal method) ---
1866 # dir_target(@array) returns a Makefile entry for the file .exists in each
1867 # named directory. Returns nothing, if the entry has already been processed.
1868 # We're helpless though, if the same directory comes as $(FOO) _and_ as "bar".
1869 # Both of them get an entry, that's why we use "::". I chose '$(PERL)' as the 
1870 # prerequisite, because there has to be one, something that doesn't change 
1871 # too often :)
1872 %Dir_Target = (); # package global
1873
1874 sub dir_target {
1875     my($self,@dirs)=@_;
1876     my(@m,$dir);
1877     foreach $dir (@dirs) {
1878         next if $Dir_Target{$dir};
1879         push @m, "
1880 $dir/.exists :: \$(PERL)
1881         \@ \$(MKPATH) $dir
1882         \@ \$(TOUCH) $dir/.exists
1883 ";
1884         $Dir_Target{$dir}++;
1885     }
1886     join "", @m;
1887 }
1888
1889 # --- Make-A-Perl section ---
1890
1891 sub staticmake {
1892     my($self, %attribs) = @_;
1893
1894     my(%searchdirs)=($att{PERL_ARCHLIB} => 1,  $att{INST_ARCHLIB} => 1);
1895     my(@searchdirs)=keys %searchdirs;
1896     # And as it's not yet built, we add the current extension
1897     my(@static)="$att{INST_ARCHLIB}/auto/$att{FULLEXT}/$att{BASEEXT}.a";
1898     my(@perlinc) = ($att{INST_ARCHLIB}, $att{INST_LIB}, $att{PERL_ARCHLIB}, $att{PERL_LIB});
1899     MY->makeaperl('MAKE' => $att{MAKEFILE}, 
1900                              'DIRS' => \@searchdirs, 
1901                              'STAT' => \@static, 
1902                              'INCL' => \@perlinc,
1903                              'TARGET' => $att{MAP_TARGET},
1904                              'TMP' => "",
1905                              'LIBPERL' => $att{LIBPERL_A}
1906                              );
1907 }
1908
1909 sub makeaperl {
1910     my($self, %attribs) = @_;
1911     my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) = 
1912       @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
1913     my(@m);
1914     my($cccmd, $linkcmd);
1915
1916     # This emulates cflags to get the compiler invocation...
1917     $cccmd = MY->const_cccmd($libperl);
1918     $cccmd =~ s/^CCCMD\s*=\s*//;
1919     chomp $cccmd;
1920     $cccmd =~ s/\s/ -I$att{PERL_INC} /;
1921     $cccmd .= " $Config{'cccdlflags'}" if ($Config{'d_shrplib'});
1922
1923     # The front matter of the linkcommand...
1924     $linkcmd = join ' ', "\$(CC)",
1925             grep($_, @Config{qw(large split ldflags ccdlflags)});
1926     $linkcmd =~ s/\s+/ /g;
1927
1928     # Which *.a files could we make use of...
1929     local(%static);
1930     File::Find::find(sub {
1931         return unless m/\.a$/;
1932         return if m/^libperl/;
1933         # don't include the installed version of this extension
1934         return if $File::Find::name =~ m:auto/$att{FULLEXT}/$att{BASEEXT}.a$:;
1935         $static{fastcwd() . "/" . $_}++;
1936     }, grep( -d $_, @{$searchdirs || []}) );
1937
1938     # We trust that what has been handed in as argument, will be buildable
1939     $static = [] unless $static;
1940     @static{@{$static}} = (1) x @{$static};
1941
1942     $extra = [] unless $extra && ref $extra eq 'ARRAY';
1943     for (sort keys %static) {
1944         next unless /\.a$/;
1945         $_ = dirname($_) . "/extralibs.ld";
1946         push @$extra, $_;
1947     }
1948
1949     grep(s/^/-I/, @$perlinc);
1950
1951     $target = "perl" unless $target;
1952     $tmp = "." unless $tmp;
1953
1954     push @m, "
1955 # --- MakeMaker makeaperl section ---
1956 MAP_TARGET    = $target
1957 FULLPERL      = $att{'FULLPERL'}
1958 MAP_LINKCMD   = $linkcmd
1959 MAP_PERLINC   = @{$perlinc}
1960 MAP_STATIC    = ",
1961 join(" ", sort keys %static), "
1962 MAP_PRELIBS   = $Config{'libs'} $Config{'cryptlib'}
1963 ";
1964
1965     unless ($libperl && -f $libperl) {
1966         my $dir = (defined $att{PERL_SRC}) ? $att{PERL_SRC}
1967                                            : "$Config{'installarchlib'}/CORE";
1968         $libperl = "libperl.a" unless $libperl;
1969         $libperl = "$dir/$libperl";
1970         print STDOUT "Warning: $libperl not found"
1971                 unless (-f $libperl || defined($att{PERL_SRC}));
1972     }
1973
1974     push @m, "
1975 MAP_LIBPERL = $libperl
1976 ";
1977
1978     push @m, "
1979 extralibs.ld: @$extra
1980         \@ $att{RM_F} \$\@
1981         \@ \$(TOUCH) \$\@
1982 ";
1983
1984     foreach (@$extra){
1985         push @m, "\tcat $_ >> \$\@\n";
1986     }
1987
1988     push @m, "
1989 \$(MAP_TARGET): $tmp/perlmain.o \$(MAP_LIBPERL) \$(MAP_STATIC) extralibs.ld
1990         \$(MAP_LINKCMD) -o \$\@ $tmp/perlmain.o \$(MAP_LIBPERL) \$(MAP_STATIC) `cat extralibs.ld` \$(MAP_PRELIBS)
1991         @ echo 'To install the new \"\$(MAP_TARGET)\" binary, call'
1992         @ echo '    make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
1993         @ echo 'To remove the intermediate files say'
1994         @ echo '    make -f $makefilename map_clean'
1995
1996 $tmp/perlmain.o: $tmp/perlmain.c
1997 ";
1998     push @m, "\tcd $tmp && $cccmd perlmain.c\n";
1999
2000     push @m, qq{
2001 $tmp/perlmain.c: $makefilename}, q{
2002         @ echo Writing $@
2003         @ $(FULLPERL) $(MAP_PERLINC) -e 'use ExtUtils::Miniperl; \\
2004                 writemain(grep s#.*/auto/##, qw|$(MAP_STATIC)|)' > $@.tmp && mv $@.tmp $@
2005
2006 };
2007
2008 # We write EXTRA outside the perl program to have it eval'd by the shell
2009     push @m, q{
2010 doc_inst_perl:
2011         @ $(FULLPERL) -e 'use ExtUtils::MakeMaker; MM->writedoc("Perl binary",' \\
2012                 -e '"$(MAP_TARGET)", "MAP_STATIC=$(MAP_STATIC)",' \\
2013                 -e '"MAP_EXTRA=@ARGV", "MAP_LIBPERL=$(MAP_LIBPERL)")' -- `cat extralibs.ld`
2014 };
2015
2016     push @m, qq{
2017 inst_perl: pure_inst_perl doc_inst_perl
2018
2019 pure_inst_perl: \$(MAP_TARGET)
2020         $att{CP} \$(MAP_TARGET) $Config{'installbin'}/\$(MAP_TARGET)
2021
2022 realclean :: map_clean
2023
2024 distclean :: realclean
2025
2026 map_clean :
2027         $att{RM_F} $tmp/perlmain.o $tmp/perlmain.c $makefilename
2028 };
2029
2030     join '', @m;
2031 }
2032
2033 # --- Determine libraries to use and how to use them ---
2034
2035 sub extliblist{
2036     my($self, $potential_libs)=@_;
2037     return ("", "", "") unless $potential_libs;
2038     print STDOUT "Potential libraries are '$potential_libs':" if $Verbose;
2039
2040     my($so)   = $Config{'so'};
2041     my($libs) = $Config{'libs'};
2042
2043     # compute $extralibs, $bsloadlibs and $ldloadlibs from
2044     # $potential_libs
2045     # this is a rewrite of Andy Dougherty's extliblist in perl
2046     # its home is in <distribution>/ext/util
2047
2048     my(@searchpath); # from "-L/path" entries in $potential_libs
2049     my(@libpath) = split " ", $Config{'libpth'};
2050     my(@ldloadlibs, @bsloadlibs, @extralibs);
2051     my($fullname, $thislib, $thispth, @fullname);
2052     my($pwd) = fastcwd(); # from Cwd.pm
2053     my($found) = 0;
2054
2055     foreach $thislib (split ' ', $potential_libs){
2056
2057         # Handle possible linker path arguments.
2058         if ($thislib =~ s/^(-[LR])//){  # save path flag type
2059             my($ptype) = $1;
2060             unless (-d $thislib){
2061                 print STDOUT "$ptype$thislib ignored, directory does not exist\n"
2062                         if $Verbose;
2063                 next;
2064             }
2065             if ($thislib !~ m|^/|) {
2066               print STDOUT "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
2067               $thislib = "$pwd/$thislib";
2068             }
2069             push(@searchpath, $thislib);
2070             push(@extralibs,  "$ptype$thislib");
2071             push(@ldloadlibs, "$ptype$thislib");
2072             next;
2073         }
2074
2075         # Handle possible library arguments.
2076         unless ($thislib =~ s/^-l//){
2077           print STDOUT "Unrecognized argument in LIBS ignored: '$thislib'\n";
2078           next;
2079         }
2080
2081         my($found_lib)=0;
2082         foreach $thispth (@searchpath, @libpath){
2083
2084                 # Try to find the full name of the library.  We need this to
2085                 # determine whether it's a dynamically-loadable library or not.
2086                 # This tends to be subject to various os-specific quirks.
2087                 # For gcc-2.6.2 on linux (March 1995), DLD can not load
2088                 # .sa libraries, with the exception of libm.sa, so we
2089                 # deliberately skip them.
2090             if (@fullname = lsdir($thispth,"^lib$thislib\.$so\.[0-9]+")){
2091                 # Take care that libfoo.so.10 wins against libfoo.so.9.
2092                 # Compare two libraries to find the most recent version
2093                 # number.  E.g.  if you have libfoo.so.9.0.7 and
2094                 # libfoo.so.10.1, first convert all digits into two
2095                 # decimal places.  Then we'll add ".00" to the shorter
2096                 # strings so that we're comparing strings of equal length
2097                 # Thus we'll compare libfoo.so.09.07.00 with
2098                 # libfoo.so.10.01.00.  Some libraries might have letters
2099                 # in the version.  We don't know what they mean, but will
2100                 # try to skip them gracefully -- we'll set any letter to
2101                 # '0'.  Finally, sort in reverse so we can take the
2102                 # first element.
2103                 $fullname = "$thispth/" .
2104                 (sort { my($ma) = $a;
2105                         my($mb) = $b;
2106                         $ma =~ tr/A-Za-z/0/s;
2107                         $ma =~ s/\b(\d)\b/0$1/g;
2108                         $mb =~ tr/A-Za-z/0/s;
2109                         $mb =~ s/\b(\d)\b/0$1/g;
2110                         while (length($ma) < length($mb)) { $ma .= ".00"; }
2111                         while (length($mb) < length($ma)) { $mb .= ".00"; }
2112                         # Comparison deliberately backwards
2113                         $mb cmp $ma;} @fullname)[0];
2114             } elsif (-f ($fullname="$thispth/lib$thislib.$so")
2115                  && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
2116             } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")
2117                  && ($thislib .= "_s") ){ # we must explicitly use _s version
2118             } elsif (-f ($fullname="$thispth/lib$thislib.a")){
2119             } elsif (-f ($fullname="$thispth/Slib$thislib.a")){
2120             } else {
2121                 print STDOUT "$thislib not found in $thispth" if $Verbose;
2122                 next;
2123             }
2124             print STDOUT "'-l$thislib' found at $fullname" if $Verbose;
2125             $found++;
2126             $found_lib++;
2127
2128             # Now update library lists
2129
2130             # what do we know about this library...
2131             my $is_dyna = ($fullname !~ /\.a$/);
2132             my $in_perl = ($libs =~ /\B-l${thislib}\b/s);
2133
2134             # Do not add it into the list if it is already linked in
2135             # with the main perl executable.
2136             # We have to special-case the NeXT, because all the math 
2137             # is also in libsys_s
2138             unless ($in_perl || 
2139                     ($Config{'osname'} eq 'next' && $thislib eq 'm') ){
2140                 push(@extralibs, "-l$thislib");
2141             }
2142
2143             # We might be able to load this archive file dynamically
2144             if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){
2145                 # We push -l$thislib instead of $fullname because
2146                 # it avoids hardwiring a fixed path into the .bs file.
2147                 # mkbootstrap will automatically add dl_findfile() to
2148                 # the .bs file if it sees a name in the -l format.
2149                 # USE THIS, when dl_findfile() is fixed: 
2150                 # push(@bsloadlibs, "-l$thislib");
2151                 # OLD USE WAS while checking results against old_extliblist
2152                 push(@bsloadlibs, "$fullname");
2153             } else {
2154                 if ($is_dyna){
2155                     # For SunOS4, do not add in this shared library if
2156                     # it is already linked in the main perl executable
2157                     push(@ldloadlibs, "-l$thislib")
2158                         unless ($in_perl and $Config{'osname'} eq 'sunos');
2159                 } else {
2160                     push(@ldloadlibs, "-l$thislib");
2161                 }
2162             }
2163             last;       # found one here so don't bother looking further
2164         }
2165         print STDOUT "Warning (non-fatal): No library found for -l$thislib" 
2166             unless $found_lib>0;
2167     }
2168     return ('','','') unless $found;
2169     ("@extralibs", "@bsloadlibs", "@ldloadlibs");
2170 }
2171
2172
2173 # --- Write a DynaLoader bootstrap file if required
2174
2175 sub mkbootstrap {
2176
2177 =head1 USEFUL SUBROUTINES
2178
2179 =head2 mkbootstrap()
2180
2181 Make a bootstrap file for use by this system's DynaLoader.  It
2182 typically gets called from an extension Makefile.
2183
2184 There is no C<*.bs> file supplied with the extension. Instead a
2185 C<*_BS> file which has code for the special cases, like posix for
2186 berkeley db on the NeXT.
2187
2188 This file will get parsed, and produce a maybe empty
2189 C<@DynaLoader::dl_resolve_using> array for the current architecture.
2190 That will be extended by $BSLOADLIBS, which was computed by Andy's
2191 extliblist script. If this array still is empty, we do nothing, else
2192 we write a .bs file with an C<@DynaLoader::dl_resolve_using> array, but
2193 without any C<if>s, because there is no longer a need to deal with
2194 special cases.
2195
2196 The C<*_BS> file can put some code into the generated C<*.bs> file by placing
2197 it in C<$bscode>. This is a handy 'escape' mechanism that may prove
2198 useful in complex situations.
2199
2200 If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
2201 mkbootstrap will automatically add a dl_findfile() call to the
2202 generated C<*.bs> file.
2203
2204 =cut
2205
2206     my($self, @bsloadlibs)=@_;
2207
2208     @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
2209
2210     print STDOUT "      bsloadlibs=@bsloadlibs\n" if $Verbose;
2211
2212     # We need DynaLoader here because we and/or the *_BS file may
2213     # call dl_findfile(). We don't say `use' here because when
2214     # first building perl extensions the DynaLoader will not have
2215     # been built when MakeMaker gets first used.
2216     require DynaLoader;
2217     import DynaLoader;
2218
2219     init_main() unless defined $att{'BASEEXT'};
2220
2221     rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
2222
2223     if (-f "$att{BASEEXT}_BS"){
2224         $_ = "$att{BASEEXT}_BS";
2225         package DynaLoader; # execute code as if in DynaLoader
2226         local($osname, $dlsrc) = (); # avoid warnings
2227         ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
2228         $bscode = "";
2229         unshift @INC, ".";
2230         require $_;
2231         shift @INC;
2232     }
2233
2234     if ($Config{'dlsrc'} =~ /^dl_dld/){
2235         package DynaLoader;
2236         push(@dl_resolve_using, dl_findfile('-lc'));
2237     }
2238
2239     my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
2240     my($method) = '';
2241     if (@all){
2242         open BS, ">$att{BASEEXT}.bs"
2243                 or die "Unable to open $att{BASEEXT}.bs: $!";
2244         print STDOUT "Writing $att{BASEEXT}.bs\n";
2245         print STDOUT "  containing: @all" if $Verbose;
2246         print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
2247         print BS "# Do not edit this file, changes will be lost.\n";
2248         print BS "# This file was automatically generated by the\n";
2249         print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
2250         print BS "\@DynaLoader::dl_resolve_using = ";
2251         # If @all contains names in the form -lxxx or -Lxxx then it's asking for
2252         # runtime library location so we automatically add a call to dl_findfile()
2253         if (" @all" =~ m/ -[lLR]/){
2254             print BS "  dl_findfile(qw(\n  @all\n  ));\n";
2255         }else{
2256             print BS "  qw(@all);\n";
2257         }
2258         # write extra code if *_BS says so
2259         print BS $DynaLoader::bscode if $DynaLoader::bscode;
2260         print BS "\n1;\n";
2261         close BS;
2262     }
2263 }
2264
2265 sub mksymlists {
2266     my($self) = shift;
2267     my($pkg);
2268
2269     # only AIX requires a symbol list at this point
2270     # (so does VMS, but that's handled by the MM_VMS package)
2271     return '' unless $Config{'osname'} eq 'aix';
2272
2273     init_main(@ARGV) unless defined $att{'BASEEXT'};
2274     if (! $att{DL_FUNCS}) {
2275         my($bootfunc);
2276         ($bootfunc = $att{NAME}) =~ s/\W/_/g;
2277         $att{DL_FUNCS} = {$att{BASEEXT} => ["boot_$bootfunc"]};
2278     }
2279     rename "$att{BASEEXT}.exp", "$att{BASEEXT}.exp_old";
2280
2281     open(EXP,">$att{BASEEXT}.exp") or die $!;
2282     print EXP join("\n",@{$att{DL_VARS}}) if $att{DL_VARS};
2283     foreach $pkg (keys %{$att{DL_FUNCS}}) {
2284         (my($prefix) = $pkg) =~ s/\W/_/g;
2285         my $func;
2286         foreach $func (@{$att{DL_FUNCS}->{$pkg}}) {
2287             $func = "XS_${prefix}_$func" unless $func =~ /^boot_/;
2288             print EXP "$func\n";
2289         }
2290     }
2291     close EXP;
2292 }
2293
2294 # --- Output postprocessing section ---
2295 #nicetext is included to make VMS support easier
2296 sub nicetext { # Just return the input - no action needed
2297     my($self,$text) = @_;
2298     $text;
2299 }
2300
2301 # --- perllocal.pod section ---
2302 sub writedoc {
2303     my($self,$what,$name,@attribs)=@_;
2304     -w $Config{'installarchlib'} or die "No write permission to $Config{'installarchlib'}";
2305     my($localpod) = "$Config{'installarchlib'}/perllocal.pod";
2306     my($time);
2307     if (-f $localpod) {
2308         print "Appending installation info to $localpod\n";
2309         open POD, ">>$localpod" or die "Couldn't open $localpod";
2310     } else {
2311         print "Writing new file $localpod\n";
2312         open POD, ">$localpod" or die "Couldn't open $localpod";
2313         print POD "=head1 NAME
2314
2315 perllocal - locally installed modules and perl binaries
2316 \n=head1 HISTORY OF LOCAL INSTALLATIONS
2317
2318 ";
2319     }
2320     require "ctime.pl";
2321     chop($time = ctime(time));
2322     print POD "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
2323     print POD join "\n\n=item *\n\n", map("C<$_>",@attribs);
2324     print POD "\n\n=back\n\n";
2325     close POD;
2326 }
2327
2328
2329 =head1 AUTHORS
2330
2331 Andy Dougherty F<E<lt>doughera@lafcol.lafayette.eduE<gt>>, Andreas
2332 Koenig F<E<lt>k@franz.ww.TU-Berlin.DEE<gt>>, Tim Bunce
2333 F<E<lt>Tim.Bunce@ig.co.ukE<gt>>.  VMS support by Charles Bailey
2334 F<E<lt>bailey@HMIVAX.HUMGEN.UPENN.EDUE<gt>>.
2335
2336 =head1 MODIFICATION HISTORY
2337
2338 v1, August 1994; by Andreas Koenig. Based on Andy Dougherty's Makefile.SH.
2339
2340 v2, September 1994 by Tim Bunce.
2341
2342 v3.0 October  1994 by Tim Bunce.
2343
2344 v3.1 November 11th 1994 by Tim Bunce.
2345
2346 v3.2 November 18th 1994 by Tim Bunce.
2347
2348 v3.3 November 27th 1994 by Andreas Koenig.
2349
2350 v3.4 December  7th 1994 by Andreas Koenig and Tim Bunce.
2351
2352 v3.5 December 15th 1994 by Tim Bunce.
2353
2354 v3.6 December 15th 1994 by Tim Bunce.
2355
2356 v3.7 December 30th 1994 By Tim Bunce
2357
2358 v3.8 January  17th 1995 By Andreas Koenig and Tim Bunce
2359
2360 v3.9 January 19th 1995 By Tim Bunce
2361
2362 v3.10 January 23rd 1995 By Tim Bunce
2363
2364 v3.11 January 24th 1995 By Andreas Koenig
2365
2366 v4.00 January 24th 1995 By Tim Bunce
2367
2368 v4.01 January 25th 1995 By Tim Bunce
2369
2370 v4.02 January 29th 1995 By Andreas Koenig
2371
2372 v4.03 January 30th 1995 By Andreas Koenig
2373
2374 v4.04 Februeary 5th 1995 By Andreas Koenig
2375
2376 v4.05 February 8th 1995 By Andreas Koenig
2377
2378 v4.06 February 10th 1995 By Andreas Koenig
2379
2380 v4.061 February 12th 1995 By Andreas Koenig
2381
2382 v4.08 - 4.085  February 14th-21st 1995 by Andreas Koenig
2383
2384 Introduces EXE_FILES and INST_EXE for installing executable scripts 
2385 and fixes documentation to reflect the new variable.
2386
2387 Introduces the automated documentation of the installation history. Every
2388   make install
2389 and
2390   make inst_perl
2391 add some documentation to the file C<$installarchlib/perllocal.pod>.
2392 This is done by the writedoc() routine in the MM_Unix class. The
2393 documentation is rudimentary until we find an agreement, what 
2394 information is supposed to go into the pod.
2395
2396 Added ability to specify the another name than C<perl> for a new binary.
2397
2398 Both C<make perl> and C<makeaperl> now prompt the user, how to install
2399 the new binary after the build.
2400
2401 Reduced noise during the make.
2402
2403 Variable LIBPERL_A enables indirect setting of the switches -DEMBED,
2404 -DDEBUGGING and -DMULTIPLICITY in the same way as done by cflags.
2405
2406 old_extliblist() code deleted, new_extliblist() renamed to extliblist().
2407
2408 Improved algorithm in extliblist, that returns ('','','') if no
2409 library has been found, even if a C<-L> directory has been found.
2410
2411 Fixed a bug that didn't allow lib/ directory work as documented.
2412
2413 Allowed C<make test TEST_VERBOSE=1>
2414
2415 v4.086 March 9 1995 by Andy Dougherty
2416
2417 Fixed some AIX buglets.  Fixed DLD support for Linux with gcc 2.6.2.
2418
2419 v4.09 March 31 1995 by Andreas Koenig
2420
2421 Patches from Tim (/usr/local/lib/perl5/hpux/CORE/libperl.a not found
2422 message eliminated, and a small makeaperl patch).
2423
2424 blib now is a relative directory (./blib).
2425
2426 Documentation bug fixed.
2427
2428 Chdir in the Makefile always followed by "&&", not by ";".
2429
2430 The output of cflags is no longer directed to /dev/null, but the shell
2431 version of cflags is now only called once.
2432
2433 The result of MakeMaker's cflags takes precedence over
2434 shell-cflags.
2435
2436 Introduced a $(PASTHRU) variable, that doesn't have much effect yet,
2437 but now it's easier to add variables that have to be passed to
2438 recursive makes.
2439
2440 'make config' will now always reapply the original arguments to the
2441 'perl Makefile.PL'.
2442
2443 MKPATH will be called only once for any directory (should speed up Tk
2444 building and installation considerably).
2445
2446 "Subroutine mkbootstrap redefined" message eliminated. It was
2447 necessary to move &mkbootstrap and &mksymlists from @EXPORT to
2448 @EXPORT_OK.
2449
2450 C<*.PL> files will be processed by C<$(PERL)>.
2451
2452 Turned some globals into my() variables, where it was obvious to be an
2453 oversight.
2454
2455 Changed some continuation lines so that they work on Solaris and Unicos.
2456
2457 v4.091 April 3 1995 by Andy Dougherty
2458
2459 Another attempt to fix writedoc() from Dean Roehrich.
2460
2461 v4.092 April 11 1995 by Andreas Koenig
2462
2463 Fixed a docu bug in hint file description. Added printing of a warning
2464 from eval in the hintfile section if the eval has errors.  Moved
2465 check_hints() into the WriteMakefile() subroutine to avoid evaling
2466 hintsfiles for other uses of the module (mkbootstrap, mksymlists).
2467
2468 Eliminated csh globbing to work around buggy Linux csh.
2469
2470 In extliblist() libfoo.so.10 now wins against libfoo.so.9.
2471
2472 Use $(CC) instead of $Config{'cc'} everywhere to allow overriding
2473 according to a patch by Dean Roehrich.
2474
2475 Introduce a ./extralibs.ld file that contains the contents of all
2476 relevant extralibs.ld files for a static build to shorten the command
2477 line for the linking of a new static perl.
2478
2479 Minor cosmetics.
2480
2481 v4.093 April 12 1995 by Andy Dougherty
2482
2483 Rename distclean target to plain dist.  Insert a dummy distclean
2484 target that's the same as realclean.  This is more consistent with the
2485 main perl makefile.
2486
2487 Fix up extliblist() so even bizarre names like libfoo.so.10.0.1
2488 are handled.
2489
2490 Include Tim's suggestions about $verbose and more careful substitution
2491 of $(CC) for $Config{'cc'}.
2492
2493 v4.094 April 12 1995 by Andy Dougherty
2494
2495 Include Andreas' improvement of $(CC) detection.
2496
2497 v4.095 May 30 1995 by Andy Dougherty
2498
2499 Include installation of .pod and .pm files.
2500
2501 Space out documentation for better printing with pod2man.
2502
2503 =head1 NOTES
2504
2505 MakeMaker development work still to be done:
2506
2507 Needs more complete documentation.
2508
2509 Add a html: target when there has been found a general solution to
2510 installing html files.
2511
2512 Add an uninstall target.
2513
2514 Add a FLAVOR variable that makes it easier to build debugging,
2515 embedded or multiplicity perls.
2516
2517 =cut
2518
2519 # the following keeps AutoSplit happy
2520 package ExtUtils::MakeMaker;
2521 1;
2522
2523 __END__