perl5.000 patch.0j: fix minor portability and build problems remaining even after...
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MakeMaker.pm
1 package ExtUtils::MakeMaker;
2
3 $Version = 4.03; # Last edited 30th Jan 1995 by Andreas Koenig
4
5 use Config;
6 check_hints();
7 use Carp;
8 use Cwd;
9
10 require Exporter;
11 @ISA = qw(Exporter);
12 @EXPORT = qw(&WriteMakefile &mkbootstrap &mksymlists $Verbose);
13 @EXPORT_OK = qw($Version %att %skip %Recognized_Att_Keys
14         @MM_Sections %MM_Sections
15         &help &lsdir &neatvalue);
16
17 $Is_VMS = $Config{'osname'} eq 'VMS';
18 require ExtUtils::MM_VMS if $Is_VMS;
19
20 use strict qw(refs);
21
22 $Version = $Version;# avoid typo warning
23 $Verbose = 0;
24 $^W=1;
25
26
27 =head1 NAME
28
29 ExtUtils::MakeMaker - create an extension Makefile
30
31 =head1 SYNOPSIS
32
33 C<use ExtUtils::MakeMaker;>
34
35 C<WriteMakefile( ATTRIBUTE => VALUE [, ...] );>
36
37 =head1 DESCRIPTION
38
39 This utility is designed to write a Makefile for an extension module
40 from a Makefile.PL. It is based on the Makefile.SH model provided by
41 Andy Dougherty and the perl5-porters.
42
43 It splits the task of generating the Makefile into several subroutines
44 that can be individually overridden.  Each subroutine returns the text
45 it wishes to have written to the Makefile.
46
47 MakeMaker.pm uses the architecture specific information from
48 Config.pm. In addition the extension may contribute to the C<%Config>
49 hash table of Config.pm by supplying hints files in a C<hints/>
50 directory. The hints files are expected to be named like their
51 counterparts in PERL_SRC/hints (eg. next_3_2.sh). They are both
52 executed by the shell and parsed by MakeMaker to include the variables
53 in C<%Config>. If there is no hintsfile for the actual system, but for
54 some previous releases of the same operating system, the latest one of
55 those is used.
56
57 =head2 Default Makefile Behaviour
58
59 The automatically generated Makefile enables the user of the extension
60 to invoke
61
62   perl Makefile.PL
63   make
64   make test
65   make install # May need to invoke as root to write into INST_LIB
66
67 The Makefile to be produced may be altered by adding arguments of the
68 form C<KEY=VALUE>. If the user wants to have the extension installed
69 into a directory different from C<$Config{"installprivlib"}> it can be
70 done by specifying
71
72   perl Makefile.PL INST_LIB=~/myperllib
73
74 Note, that in this example MakeMaker does the tilde expansion for you
75 and INST_ARCHLIB is set to either C<INST_LIB/$Config{"osname"}> if
76 that directory exists and otherwise to INST_LIB.
77
78 Other interesting targets in the generated Makefile are
79
80   make config     # to check if the Makefile is up-to-date
81   make clean      # delete local temporary files (Makefile gets renamed)
82   make realclean  # delete all derived files (including installed files)
83   make distclean  # produce a gzipped file ready for shipping
84
85 The macros in the produced Makefile may be overridden on the command
86 line to the make call as in the following example:
87
88   make INST_LIB=/some/where INST_ARCHLIB=/some/where
89
90 Note, that this is a solution provided by C<make> in general, so tilde
91 expansion will probably not be available and INST_ARCHLIB will not be
92 set automatically when INST_LIB is given as argument.
93
94 The generated Makefile does not set any permissions. The installer has
95 to decide, which umask should be in effect.
96
97 =head2 Determination of Perl Library and Installation Locations
98
99 MakeMaker needs to know, or to guess, where certain things are
100 located.  Especially INST_LIB and INST_ARCHLIB (where to install files
101 into), PERL_LIB and PERL_ARCHLIB (where to read existing modules
102 from), and PERL_INC (header files and C<libperl*.*>).
103
104 Extensions may be built either using the contents of the perl source
105 directory tree or from an installed copy of the perl library.
106
107 If an extension is being built below the C<ext/> directory of the perl
108 source then MakeMaker will set PERL_SRC automatically (e.g., C<../..>).
109 If PERL_SRC is defined then other variables default to the following:
110
111   PERL_INC     = PERL_SRC
112   PERL_LIB     = PERL_SRC/lib
113   PERL_ARCHLIB = PERL_SRC/lib
114   INST_LIB     = PERL_LIB
115   INST_ARCHLIB = PERL_ARCHLIB
116
117 If an extension is being built away from the perl source then MakeMaker
118 will leave PERL_SRC undefined and default to using the installed copy
119 of the perl library. The other variables default to the following:
120
121   PERL_INC     = $archlib/CORE
122   PERL_LIB     = $privlib
123   PERL_ARCHLIB = $archlib
124   INST_LIB     = ./blib
125   INST_ARCHLIB = ./blib
126
127 If perl has not yet been installed then PERL_SRC can be defined on the
128 command line as shown in the previous section.
129
130 =head2 Useful Default Makefile Macros
131
132 FULLEXT = Pathname for extension directory (eg DBD/Oracle).
133
134 BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
135
136 ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
137
138 PERL_LIB = Directory where we read the perl library files
139
140 PERL_ARCHLIB = Same as above for architecture dependent files
141
142 INST_LIB = Directory where we put library files of this extension
143 while building it. If we are building below PERL_SRC/ext
144 we default to PERL_SRC/lib, else we default to ./blib.
145
146 INST_ARCHLIB = Same as above for architecture dependent files
147
148 INST_LIBDIR = $(INST_LIB)$(ROOTEXT)
149
150 INST_AUTODIR = $(INST_LIB)/auto/$(FULLEXT)
151
152 INST_ARCHAUTODIR = $(INST_ARCHLIB)/auto/$(FULLEXT)
153
154 =head2 Customizing The Generated Makefile
155
156 If the Makefile generated does not fit your purpose you can change it
157 using the mechanisms described below.
158
159 =head2 Using Attributes (and Parameters)
160
161 The following attributes can be specified as arguments to WriteMakefile()
162 or as NAME=VALUE pairs on the command line:
163
164 This description is not yet documented; you can get at the description
165 with the command
166     C<perl Makefile.PL help>    (if you already have a basic Makefile.PL)
167 or
168     C<perl -e 'use ExtUtils::MakeMaker qw(&help); &help;'>
169
170 =head2 Overriding MakeMaker Methods
171
172 If you cannot achieve the desired Makefile behaviour by specifying
173 attributes you may define private subroutines in the Makefile.PL.
174 Each subroutines returns the text it wishes to have written to
175 the Makefile. To override a section of the Makefile you can
176 either say:
177
178         sub MY::c_o { "new literal text" }
179
180 or you can edit the default by saying something like:
181
182         sub MY::c_o { $_=MM->c_o; s/old text/new text/; $_ }
183
184 If you still need a different solution, try to develop another 
185 subroutine, that fits your needs and submit the diffs to 
186 perl5-porters@nicoh.com or comp.lang.perl as appropriate.
187
188
189 =head1 AUTHORS
190
191 Andy Dougherty <doughera@lafcol.lafayette.edu>, Andreas Koenig
192 <k@franz.ww.TU-Berlin.DE>, Tim Bunce <Tim.Bunce@ig.co.uk>
193
194 =head1 MODIFICATION HISTORY
195
196 v1, August 1994; by Andreas Koenig. Based on Andy Dougherty's Makefile.SH.
197 v2, September 1994 by Tim Bunce.
198 v3.0 October  1994 by Tim Bunce.
199 v3.1 November 11th 1994 by Tim Bunce.
200 v3.2 November 18th 1994 by Tim Bunce.
201 v3.3 November 27th 1994 by Andreas Koenig.
202 v3.4 December  7th 1994 by Andreas Koenig and Tim Bunce.
203 v3.5 December 15th 1994 by Tim Bunce.
204 v3.6 December 15th 1994 by Tim Bunce.
205 v3.7 December 30th 1994 By Tim Bunce
206 v3.8 January  17th 1995 By Andreas Koenig and Tim Bunce
207
208 v3.9 January 19th 1995 By Tim Bunce
209
210 Added ~ processing to parse_args to allow perl Makefile.PL X=~/path.
211 Added warning about LDTARGET to LDFROM attribute name change.
212 Fallback INST_ARCHLIB is INST_LIB, or INST_LIB/$archname if it exists.
213 Tightened up dependency checking of Makefile against config.sh etc.
214 INST_STATIC is now INST_ARCHLIBDIR/BASEEXT.a for later make-a-perl.
215 AUTOSPLITFILE tidied up (AutoSplit patch included in this version).
216 MKPATH now skips inner loop if directory already exists.
217 The dynamic_lib section was revised with explicit dec_osf support added.
218 Make clean now renames Makefile to Makefile.old (make_ext also patched).
219 The large initialize function has been split into smaller pieces.
220 Added I_PERL_LIBS to simplify -I paths for PERL_*LIB.
221
222 v3.10 January 23rd 1995 By Tim Bunce
223
224 miniperl now given preference when defining PERL. This improves the
225 reliability of ext/*/Makefile's recreating themselves if needed.
226 $(XS), $(C) and $(H) renamed to XS_FILES C_FILES and H_FILES.
227 INST_STATIC now INST_ARCHLIBDIR/BASEEXT.a (alongside INST_DYNAMIC).
228 Static lib no longer copied back to local directory.
229
230 v3.11 January 24th 1995 By Andreas Koenig
231
232 DynaLoader.c was not deleted by clean target, now fixed.
233 Added PMDIR attribute that allows directories to be named that contain
234 only *.p[pl] files to be installed into INST_LIB. Added some documentation.
235
236 v4.00 January 24th 1995 By Tim Bunce
237
238 Revised some of the documentation. Changed version number to 4.00 to
239 avoid problems caused by my earlier poor choice of 3.10!  Renamed PMDIR
240 to PMLIBDIRS and restructured find code to use inherited MY->libscan.
241 Added ability to say: "perl Makefile.PL help"  to get help.
242 Added ability to say: "perl Makefile.PL verbose"  to get debugging.
243 Added MakeMaker version number to generated Makefiles.
244
245 v4.01 January 25th 1995 By Tim Bunce
246
247 Changes in the section that deals with PMLIBDIRS: some pm files were
248 put into INST_LIB instead of INST_LIBDIR.
249
250 v4.02 January 29th 1995 By Andreas Koenig
251
252 Enabled the use of the XXX_cflags variable from Config.pm for nested
253 extensions: to change e.g. the $Config{"ccflags"} variable on the NeXT
254 for the nTk::pTk extension, say
255     nTk__pTk_cflags='ccflags="-posix $ccflags"'
256 in the hints-file. 
257
258 Hints may now be put in a hints/*.sh file within the the module's
259 directory tree. Any *.sh file in that directory acts as if it had been
260 parsed during the perl build process.
261
262 Added O_FILES, which is an array like C_FILES. Done so to add a
263 dependency O_FILES from H_FILES. This has the effect, that the
264 extension gets rebuilt after some headerfiles have changed.
265
266 Made life easier in some "I've just edited config.sh" situations and
267 reduce the risk of "MakeMaker is being pedantic" complaints by letting
268 the Makefile proceed with a warning if Config.pm is out of date (Tim's
269 suggestion).
270
271 $Verbose now passed to the findperl routine, to get debugging output
272 from there, too.
273
274 Make clean now also deletes the ./blib directory.
275
276 Added lots of ideas of Charles Bailey that enable VMS support.
277
278 v4.03 January 30th 1995 By Andreas Koenig
279
280 check_hints() now also called within runsubdirpl(). More VMS code
281 included. Trivial cosmetics.
282
283 =head1 NOTES
284
285 MakeMaker development work still to be done:
286
287 Needs more complete documentation.
288
289 Add a html: target when there has been found a general solution to
290 installing html files.
291
292 =cut
293
294 sub check_hints {
295     # We allow extension-specific hints files. If we find one we act as if Config.pm
296     # had read the contents
297
298     # First we look for the best hintsfile we have
299     my(@goodhints);
300     my($hint)="$Config{'osname'}_$Config{'osvers'}";
301     $hint =~ s/\./_/g;
302     $hint =~ s/_$//;
303     opendir DIR, "hints";
304     while (defined ($_ = readdir DIR)) {
305         next if /^\./;
306         next unless s/\.sh$//;
307         next unless /^$Config{'osname'}/;
308         # Don't trust a hintfile for a later OS version:
309         next if $_ gt $hint;
310         push @goodhints, $_;
311         if ($_ eq $hint){
312             @goodhints=$_;
313             last;
314         }
315     }
316     closedir DIR;
317     return unless @goodhints; # There was no hintsfile
318     # the last one in lexical ordering is our choice:
319     $hint=(reverse sort @goodhints)[0]; 
320
321     # execute the hintsfile:
322     system "/bin/sh hints/$hint.sh" unless $Is_VMS;
323     # Read the hintsfile and process it similarly as in configpm
324     open HINT, "hints/$hint.sh";
325     my(@v_others);
326     while (<HINT>) {
327         next if /^\s*$/; # empty lines
328         next if /^\s*#/; # comments
329         s/^(\w+)=(true|\d+)\s*$/$1='$2'\n/;
330         next unless (m/^(\w+)='(.*)'\s*$/);
331         push @v_others, $_;
332     }
333     close HINT;
334
335     # The lines we found take precedence over those in Config.pm:
336     $Config::config_sh = "@v_others" . $Config::config_sh;
337 }
338
339 # Setup dummy package:
340 # MY exists for overriding methods to be defined within
341 unshift(@MY::ISA, qw(MM));
342
343 # Dummy package MM inherits actual methods from OS-specific
344 # default packages.  We use this intermediate package so
345 # MY->func() can call MM->func() and get the proper
346 # default routine without having to know under what OS
347 # it's running.
348 unshift(@MM::ISA, $Is_VMS ? qw(ExtUtils::MM_VMS MM_Unix) : qw(MM_Unix));
349
350 $Attrib_Help = <<'END';
351  NAME:          Perl module name for this extension (DBD::Oracle)
352                 This will default to the directory name but should
353                 be explicitly defined in the Makefile.PL.
354
355  DISTNAME:      Your name for distributing the package (by tar file)
356                 This defaults to NAME above.
357
358  VERSION:       Your version number for distributing the package.
359                 This defaults to 0.1.
360
361  INST_LIB:      Perl library directory to install the module into.
362  INST_ARCHLIB:  Perl architecture-dependent library to install into
363                 (defaults to INST_LIB)
364
365  PERL_LIB:      Directory containing the Perl library to use.
366  PERL_SRC:      Directory containing the Perl source code
367                 (use of this should be avoided, it may be undefined)
368
369  INC:           Include file dirs eg: '-I/usr/5include -I/path/to/inc'
370  DEFINE:        something like "-DHAVE_UNISTD_H"
371  OBJECT:        List of object files, defaults to '$(BASEEXT).o',
372                 but can be a long string containing all object files,
373                     e.g. "tkpBind.o tkpButton.o tkpCanvas.o"
374  MYEXTLIB:      If the extension links to a library that it builds
375                 set this to the name of the library (see SDBM_File)
376
377  LIBS:          An anonymous array of alternative library specifications
378                 to be searched for (in order) until at least one library
379                 is found.
380                   'LIBS' => [ "-lgdbm", "-ldbm -lfoo", "-L/path -ldbm.nfs" ]
381                 Mind, that any element of the array contains a complete
382                 set of arguments for the ld command. So do not specify
383                   'LIBS' => ["-ltcl", "-ltk", "-lX11" ], #wrong
384                 See ODBM_File/Makefile.PL for an example, where an
385                 array is needed. If you specify a scalar as in
386                   'LIBS' => "-ltcl -ltk -lX11"
387                 MakeMaker will turn it into an array with one element.
388
389  LDFROM:        defaults to "$(OBJECT)" and is used in the ld command
390                 to specify what files to link/load from
391                 (also see dynamic_lib below for how to specify ld flags)
392
393  DIR:           Ref to array of subdirectories containing Makefile.PLs
394                 e.g. [ 'sdbm' ] in ext/SDBM_File
395
396  PMLIBDIRS:     Ref to array of subdirectories containing library files.
397                 Defaults to [ 'lib', $(BASEEXT) ]. The directories will
398                 be scanned and any *.pm and *.pl files they contain will
399                 be installed in the corresponding location in the library.
400                 A MY::libscan() function can be used to alter the behaviour.
401                 Defining PM in the Makefile.PL will override PMLIBDIRS.
402
403  PM:            Hashref of .pm files and *.pl files to be installed.
404                 e.g. { 'name_of_file.pm' => '$(INST_LIBDIR)/install_as.pm' }
405                 By default this will include *.pm and *.pl. If a lib directory
406                 exists and is not listed in DIR (above) then any *.pm and
407                 *.pl files it contains will also be included by default.
408                 Defining PM in the Makefile.PL will override PMLIBDIRS.
409
410  XS:            Hashref of .xs files. MakeMaker will default this.
411                 e.g. { 'name_of_file.xs' => 'name_of_file.c' }
412                 The .c files will automatically be included in the list
413                 of files deleted by a make clean.
414
415  C:             Ref to array of *.c file names. Initialised from a directory scan
416                 and the values portion of the XS attribute hash. This is not
417                 currently used by MakeMaker but may be handy in Makefile.PLs.
418
419  H:             Ref to array of *.h file names. Similar to C: above.
420
421  LINKTYPE:      =>'static' or 'dynamic' (default unless usedl=undef in config.sh)
422                 Should only be used to force static linking (also see linkext below).
423
424  DL_FUNCS:      Hashref of symbol names for routines to be made available as
425                 universal symbols.  Each key/value pair consists of the package
426                 name and an array of routine names in that package.  Used only
427                 under AIX (export lists) and VMS (linker options) at present.
428                 The routine names supplied will be expanded in the same way
429                 as XSUB names are expanded by the XS() macro.
430                 Defaults to { "$(NAME)" => [ "boot_$(NAME)" ] }.
431                 (e.g. { "RPC" => [qw( boot_rpcb rpcb_gettime getnetconfigent )],
432                         "NetconfigPtr" => [ 'DESTROY'] } )
433
434  DL_VARS:       Array of symbol names for variables to be made available as
435                 universal symbols.  Used only under AIX (export lists) and VMS
436                 (linker options) at present.  Defaults to [].
437                 (e.g. [ qw( Foo_version Foo_numstreams Foo_tree ) ])
438  
439  CONFIG:        =>[qw(archname manext)] defines ARCHNAME & MANEXT from config.sh
440  SKIP:          =>[qw(name1 name2)] skip (do not write) sections of the Makefile
441
442  PERL:
443  FULLPERL:
444
445 Additional lowercase attributes can be used to pass parameters to the
446 methods which implement that part of the Makefile. These are not
447 normally required:
448
449  installpm:     {SPLITLIB => '$(INST_LIB)' (default) or '$(INST_ARCHLIB)'}
450  linkext:       {LINKTYPE => 'static', 'dynamic' or ''}
451  dynamic_lib:   {ARMAYBE => 'ar', OTHERLDFLAGS => '...'}
452  clean:         {FILES => "*.xyz foo"}
453  realclean:     {FILES => '$(INST_ARCHAUTODIR)/*.xyz'}
454  distclean:     {TARNAME=>'MyTarFile', TARFLAGS=>'cvfF', COMPRESS=>'gzip'}
455  tool_autosplit:        {MAXLEN => 8}
456 END
457
458 sub help {print $Attrib_Help;}
459
460 @MM_Sections_spec = (
461     'post_initialize'   => {},
462     'const_config'      => {},
463     'constants'         => {},
464     'const_loadlibs'    => {},
465     'const_cccmd'       => {},
466     'tool_autosplit'    => {},
467     'tool_xsubpp'       => {},
468     'tools_other'       => {},
469     'post_constants'    => {},
470     'c_o'               => {},
471     'xs_c'              => {},
472     'xs_o'              => {},
473     'top_targets'       => {},
474     'linkext'           => {},
475     'dlsyms'            => {},
476     'dynamic'           => {},
477     'dynamic_bs'        => {},
478     'dynamic_lib'       => {},
479     'static'            => {},
480     'static_lib'        => {},
481     'installpm'         => {},
482     'subdirs'           => {},
483     'clean'             => {},
484     'realclean'         => {},
485     'distclean'         => {},
486     'test'              => {},
487     'install'           => {},
488     'force'             => {},
489     'perldepend'        => {},
490     'makefile'          => {},
491     'postamble'         => {},
492 );
493 %MM_Sections = @MM_Sections_spec; # looses section ordering
494 @MM_Sections = grep(!ref, @MM_Sections_spec); # keeps order
495
496 %Recognized_Att_Keys = %MM_Sections; # All sections are valid keys.
497 foreach(split(/\n/,$Attrib_Help)){
498     chomp;
499     next unless m/^\s*(\w+):\s*(.*)/;
500     $Recognized_Att_Keys{$1} = $2;
501     print "Attribute '$1' => '$2'\n" if ($Verbose >= 2);
502 }
503
504 %att  = ();
505 %skip = ();
506
507 sub skipcheck{
508     my($section) = @_;
509     if ($section eq 'dynamic') {
510         warn "Warning (non-fatal): Target 'dynamic' depends on targets "
511           . "in skipped section 'dynamic_bs'\n"
512             if $skip{'dynamic_bs'} && $Verbose;
513         warn "Warning (non-fatal): Target 'dynamic' depends on targets "
514           . "in skipped section 'dynamic_lib'\n"
515             if $skip{'dynamic_lib'} && $Verbose;
516     }
517     if ($section eq 'dynamic_lib') {
518         warn "Warning (non-fatal): Target '\$(INST_DYNAMIC)' depends on "
519           . "targets in skipped section 'dynamic_bs'\n"
520             if $skip{'dynamic_bs'} && $Verbose;
521     }
522     if ($section eq 'static') {
523         warn "Warning (non-fatal): Target 'static' depends on targets "
524           . "in skipped section 'static_lib'\n"
525             if $skip{'static_lib'} && $Verbose;
526     }
527     return 'skipped' if $skip{$section};
528     return '';
529 }
530
531
532 sub WriteMakefile {
533     %att = @_;
534     local($\)="\n";
535
536     print STDOUT "MakeMaker" if $Verbose;
537
538     parse_args(\%att, @ARGV);
539     my(%initial_att) = %att; # record initial attributes
540
541     MY->init_main();
542
543     print STDOUT "Writing Makefile for $att{NAME}";
544
545     MY->init_dirscan();
546     MY->init_others();
547
548     unlink("Makefile", "MakeMaker.tmp", $Is_VMS ? 'Descrip.MMS' : '');
549     open MAKE, ">MakeMaker.tmp" or die "Unable to open MakeMaker.tmp: $!";
550     select MAKE; $|=1; select STDOUT;
551
552     print MAKE "# This Makefile is for the $att{NAME} extension to perl.\n#";
553     print MAKE "# It was generated automatically by MakeMaker version $Version from the contents";
554     print MAKE "# of Makefile.PL. Don't edit this file, edit Makefile.PL instead.";
555     print MAKE "#\n#    ANY CHANGES MADE HERE WILL BE LOST! \n#";
556     print MAKE "#   MakeMaker Parameters: ";
557     foreach $key (sort keys %initial_att){
558         my($v) = neatvalue($initial_att{$key});
559         $v =~ tr/\n/ /s;
560         print MAKE "#   $key => $v";
561     }
562
563     # build hash for SKIP to make testing easy
564     %skip = map( ($_,1), @{$att{'SKIP'} || []});
565
566     foreach $section ( @MM_Sections ){
567         print "Processing Makefile '$section' section" if ($Verbose >= 2);
568         my($skipit) = skipcheck($section);
569         if ($skipit){
570             print MAKE "\n# --- MakeMaker $section section $skipit.";
571         } else {
572             my(%a) = %{$att{$section} || {}};
573             print MAKE "\n# --- MakeMaker $section section:";
574             print MAKE "# ",%a if $Verbose;
575             print(MAKE MY->nicetext(MY->$section( %a )));
576         }
577     }
578
579     if ($Verbose){
580         print MAKE "\n# Full list of MakeMaker attribute values:";
581         foreach $key (sort keys %att){
582             my($v) = neatvalue($att{$key});
583             $v =~ tr/\n/ /s;
584             print MAKE "#       $key => $v";
585         }
586     }
587
588     print MAKE "\n# End.";
589     close MAKE;
590     my($finalname) = $Is_VMS ? "Descrip.MMS" : "Makefile";
591     rename("MakeMaker.tmp", $finalname);
592
593     chmod 0644, $finalname;
594     system("$Config{'eunicefix'} $finalname") unless $Config{'eunicefix'} eq ":";
595
596     1;
597 }
598
599
600 sub mkbootstrap{
601     parse_args(\%att, @ARGV);
602     MY->mkbootstrap(@_);
603 }
604
605 sub mksymlists{
606     %att = @_;
607     parse_args(\%att, @ARGV);
608     MY->mksymlists(@_);
609 }
610
611 sub parse_args{
612     my($attr, @args) = @_;
613     foreach (@args){
614         unless (m/(.*?)=(.*)/){
615             help(),exit 1 if m/^help$/;
616             ++$Verbose if m/^verb/;
617             next;
618         }
619         my($name, $value) = ($1, $2);
620         if ($value =~ m/^~(\w+)?/){ # tilde with optional username
621             my($home) = ($1) ? (getpwnam($1))[7] : (getpwuid($>))[7];
622             $value =~ s/^~(\w+)?/$home/;
623         }
624         $$attr{$name} = $value;
625     }
626     # catch old-style 'potential_libs' and inform user how to 'upgrade'
627     if (defined $$attr{'potential_libs'}){
628         my($msg)="'potential_libs' => '$$attr{potential_libs}' should be";
629         if ($$attr{'potential_libs'}){
630             print STDERR "$msg changed to:\n\t'LIBS' => ['$$attr{potential_libs}']\n";
631         } else {
632             print STDERR "$msg deleted.\n";
633         }
634         $$attr{LIBS} = [$$attr{'potential_libs'}];
635         delete $$attr{'potential_libs'};
636     }
637     # catch old-style 'ARMAYBE' and inform user how to 'upgrade'
638     if (defined $$attr{'ARMAYBE'}){
639         my($armaybe) = $$attr{'ARMAYBE'};
640         print STDERR "ARMAYBE => '$armaybe' should be changed to:\n",
641                         "\t'dynamic_lib' => {ARMAYBE => '$armaybe'}\n";
642         my(%dl) = %{$$attr{'dynamic_lib'} || {}};
643         $$attr{'dynamic_lib'} = { %dl, ARMAYBE => $armaybe};
644         delete $$attr{'ARMAYBE'};
645     }
646     if (defined $$attr{'LDTARGET'}){
647         print STDERR "LDTARGET should be changed to LDFROM\n";
648         $$attr{'LDFROM'} = $$attr{'LDTARGET'};
649         delete $$attr{'LDTARGET'};
650     }
651     foreach(sort keys %{$attr}){
652         print STDOUT "  $_ => ".neatvalue($$attr{$_}) if ($Verbose);
653         warn "'$_' is not a known MakeMaker parameter name.\n"
654             unless exists $Recognized_Att_Keys{$_};
655     }
656 }
657
658
659 sub neatvalue{
660     my($v) = @_;
661     my($t) = ref $v;
662     return "'$v'" unless $t;
663     return "[ ".join(', ',map("'$_'",@$v))." ]" if ($t eq 'ARRAY');
664     return "$v" unless $t eq 'HASH';
665     my(@m, $key, $val);
666     push(@m,"$key=>".neatvalue($val)) while (($key,$val) = each %$v);
667     return "{ ".join(', ',@m)." }";
668 }
669
670
671 # ------ Define the MakeMaker default methods in package MM_Unix ------
672
673 package MM_Unix;
674
675 use Config;
676 use Cwd;
677 use File::Basename;
678 require Exporter;
679
680 Exporter::import('ExtUtils::MakeMaker',
681         qw(%att %skip %Recognized_Att_Keys $Verbose));
682
683 # These attributes cannot be overridden externally
684 @Other_Att_Keys{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)} = (1) x 3;
685
686 if ($Is_VMS = $Config{'osname'} eq 'VMS') {
687     require File::VMSspec;
688     import File::VMSspec 'vmsify';
689 }
690
691
692 sub init_main {
693     # Find out directory name.  This may contain the extension name.
694     my($pwd) = fastcwd(); # from Cwd.pm
695
696     # --- Initialize PERL_LIB, INST_LIB, PERL_SRC
697
698     # *Real* information: where did we get these two from? ...
699     $inc_config_dir = dirname($INC{'Config.pm'});
700     $inc_carp_dir   = dirname($INC{'Carp.pm'});
701
702     # Typically PERL_* and INST_* will be identical but that need
703     # not be the case (e.g., installing into project libraries etc).
704
705     # Perl Macro:    With source    No source
706     # PERL_LIB       ../../lib      /usr/local/lib/perl5
707     # PERL_ARCHLIB   ../../lib      /usr/local/lib/perl5/sun4-sunos
708     # PERL_SRC       ../..          (undefined)
709
710     # INST Macro:    Locally        Publically
711     # INST_LIB       ../../lib      ./blib
712     # INST_ARCHLIB   ../../lib      ./blib
713
714     unless ($att{PERL_SRC}){
715         foreach(qw(../.. ../../.. ../../../..)){
716             ($att{PERL_SRC}=$_, last) if -f "$_/config.sh";
717         }
718     }
719     unless ($att{PERL_SRC}){
720         warn "Unable to locate perl source.\n";
721         # we should also consider $ENV{PERL5LIB} here
722         $att{PERL_LIB}     = $Config{'privlib'} unless $att{PERL_LIB};
723         $att{PERL_ARCHLIB} = $Config{'archlib'} unless $att{PERL_ARCHLIB};
724         $att{PERL_INC}     = "$att{PERL_ARCHLIB}/CORE"; # wild guess for now
725         die "Try setting PERL_SRC in Makefile.PL or on command line.\n"
726                 unless (-f "$att{PERL_INC}/perl.h");
727     } else {
728         $att{PERL_LIB}     = "$att{PERL_SRC}/lib" unless $att{PERL_LIB};
729         $att{PERL_ARCHLIB} = $att{PERL_LIB};
730         $att{PERL_INC}     = $att{PERL_SRC};
731     }
732
733     # INST_LIB typically pre-set if building an extension after
734     # perl has been built and installed. Setting INST_LIB allows
735     # you to build directly into privlib and avoid installperl.
736     unless ($att{INST_LIB}){
737         if (defined $att{PERL_SRC}) {
738             $att{INST_LIB} = $att{PERL_LIB};
739         } else {
740             $att{INST_LIB} = "$pwd/blib";
741         }
742     }
743     # Try to work out what INST_ARCHLIB should be if not set:
744     unless ($att{INST_ARCHLIB}){
745         my(%archmap) = (
746             "$pwd/blib"         => "$pwd/blib", # our private build lib
747             $att{PERL_LIB}      => $att{PERL_ARCHLIB},
748             $Config{'privlib'}  => $Config{'archlib'},
749             $Config{'installprivlib'}   => $Config{'installarchlib'},
750             $inc_carp_dir       => $inc_config_dir,
751         );
752         $att{INST_ARCHLIB} = $archmap{$att{INST_LIB}};
753         unless($att{INST_ARCHLIB}){
754             # Oh dear, we'll have to default it and warn the user
755             my($archname) = $Config{'archname'};
756             if (-d "$att{INST_LIB}/$archname"){
757                 $att{INST_ARCHLIB} = "$att{INST_LIB}/$archname";
758                 warn "Defaulting INST_ARCHLIB to INST_LIB/$archname\n";
759             } else {
760                 $att{INST_ARCHLIB} = $att{INST_LIB};
761                 warn "Warning: Defaulting INST_ARCHLIB to INST_LIB ",
762                         "(not architecture independent).\n";
763             }
764         }
765     }
766
767     # make a few simple checks
768     die "PERL_LIB ($att{PERL_LIB}) is not a perl library directory"
769         unless (-f "$att{PERL_LIB}/Exporter.pm");
770
771     # --- Initialize Module Name and Paths
772
773     # NAME    = The perl module name for this extension (eg DBD::Oracle).
774     # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
775     # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
776     # ROOTEXT = Directory part of FULLEXT with leading /.
777     unless($att{NAME}){ # we have to guess our name
778         my($name) = $pwd;
779         if ($Is_VMS) {
780           $name =~ s:.*?([^.\]]+)\]:$1: unless ($name =~ s:.*[.\[]ext\.(.*)\]:$1:i);
781           ($att{NAME}=$name) =~ s#[.\]]#::#g;
782         } else {
783           $name =~ s:.*/:: unless ($name =~ s:^.*/ext/::);
784           ($att{NAME} =$name) =~ s#/#::#g;
785         }
786     }
787     ($att{FULLEXT} =$att{NAME}) =~ s#::#/#g ;           #eg. BSD/Foo/Socket
788     ($att{BASEEXT} =$att{NAME}) =~ s#.*::##;            #eg. Socket
789     ($att{ROOTEXT} =$att{FULLEXT}) =~ s#/?\Q$att{BASEEXT}\E$## ; # eg. /BSD/Foo
790     $att{ROOTEXT} = ($Is_VMS ? '' : '/') . $att{ROOTEXT} if $att{ROOTEXT};
791
792     ($att{DISTNAME}=$att{NAME}) =~ s#(::)#-#g;
793     $att{VERSION} = "0.1" unless $att{VERSION};
794
795
796     # --- Initialize Perl Binary Locations
797
798     # Find Perl 5. The only contract here is that both 'PERL' and 'FULLPERL'
799     # will be working versions of perl 5. miniperl has priority over perl
800     # for PERL to ensure that $(PERL) is usable while building ./ext/*
801     $att{'PERL'} = MY->find_perl(5.0, [ qw(miniperl perl) ],
802             [ $att{PERL_SRC}, split(":", $ENV{PATH}), $Config{'bin'} ], $Verbose )
803         unless ($att{'PERL'} && -x $att{'PERL'});
804
805     # Define 'FULLPERL' to be a non-miniperl (used in test: target)
806     ($att{'FULLPERL'} = $att{'PERL'}) =~ s/miniperl/perl/
807         unless ($att{'FULLPERL'} && -x $att{'FULLPERL'});
808
809     if ($Is_VMS) {
810         $att{'PERL'} = 'MCR ' . vmsify($att{'PERL'});
811         $att{'FULLPERL'} = 'MCR ' . vmsify($att{'FULLPERL'});
812     }
813 }
814
815
816 sub init_dirscan {      # --- File and Directory Lists (.xs .pm etc)
817
818     my($name, %dir, %xs, %c, %h, %ignore);
819     local(%pm); #the sub in find() has to see this hash
820     $ignore{'test.pl'} = 1;
821     $ignore{'makefile.pl'} = 1 if $Is_VMS;
822     foreach $name (lsdir(".")){
823         next if ($name =~ /^\./ or $ignore{$name});
824         if (-d $name){
825             $dir{$name} = $name if (-f "$name/Makefile.PL");
826         } elsif ($name =~ /\.xs$/){
827             my($c); ($c = $name) =~ s/\.xs$/.c/;
828             $xs{$name} = $c;
829             $c{$c} = 1;
830         } elsif ($name =~ /\.c$/){
831             $c{$name} = 1;
832         } elsif ($name =~ /\.h$/){
833             $h{$name} = 1;
834         } elsif ($name =~ /\.p[ml]$/){
835             $pm{$name} = "\$(INST_LIBDIR)/$name";
836         }
837     }
838
839     # Some larger extensions often wish to install a number of *.pm/pl
840     # files into the library in various locations.
841
842     # The attribute PMLIBDIRS holds an array reference which lists
843     # subdirectories which we should search for library files to
844     # install. PMLIBDIRS defaults to [ 'lib', $att{BASEEXT} ].
845     # We recursively search through the named directories (skipping
846     # any which don't exist or contain Makefile.PL files).
847
848     # For each *.pm or *.pl file found MY->libscan() is called with
849     # the default installation path in $_. The return value of libscan
850     # defines the actual installation location.
851     # The default libscan function simply returns $_.
852     # The file is skipped if libscan returns false.
853
854     # The default installation location passed to libscan in $_ is:
855     #
856     #  ./*.pm           => $(INST_LIBDIR)/*.pm
857     #  ./xyz/...        => $(INST_LIBDIR)/xyz/...
858     #  ./lib/...        => $(INST_LIB)/...
859     #
860     # In this way the 'lib' directory is seen as the root of the actual
861     # perl library whereas the others are relative to INST_LIBDIR
862     # (which includes ROOTEXT). This is a subtle distinction but one
863     # that's important for nested modules.
864
865     $att{PMLIBDIRS} = [ 'lib', $att{BASEEXT} ] unless $att{PMLIBDIRS};
866
867     #only existing directories that aren't in $dir are allowed
868     @{$att{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$att{PMLIBDIRS}};
869
870     if (@{$att{PMLIBDIRS}}){
871         print "Searching PMLIBDIRS: @{$att{PMLIBDIRS}}"
872             if ($Verbose >= 2);
873         use File::Find;         # try changing to require !
874         File::Find::find(sub {
875                 return unless m/\.p[ml]$/;
876                 my($path, $prefix) = ($File::Find::name, '$(INST_LIBDIR)');
877                 $prefix =  '$(INST_LIB)' if ($path =~ s:^lib/::);
878                 local($_) = "$prefix/$path";
879                 my($inst) = MY->libscan();
880                 print "libscan($path) => '$inst'" if ($Verbose >= 2);
881                 return unless $inst;
882                 $pm{$path} = $inst;
883              }, @{$att{PMLIBDIRS}});
884     }
885
886     $att{DIR} = [sort keys %dir] unless $att{DIRS};
887     $att{XS}  = \%xs             unless $att{XS};
888     $att{PM}  = \%pm             unless $att{PM};
889     $att{C}   = [sort keys %c]   unless $att{C};
890     my(@o_files) = @{$att{C}};
891     my($sufx) = $Is_VMS ? '.obj' : '.o';
892     $att{O_FILES} = [grep s/\.c$/$sufx/, @o_files] ;
893     $att{H}   = [sort keys %h]   unless $att{H};
894 }
895
896
897 sub libscan {
898     $_;
899 }
900
901 sub init_others {       # --- Initialize Other Attributes
902
903     for $key (keys(%Recognized_Att_Keys), keys(%Other_Att_Keys)){
904         # avoid warnings for uninitialized vars
905         next if exists $att{$key};
906         $att{$key} = "";
907     }
908
909     # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $att{'LIBS'}
910     # Lets look at $att{LIBS} carefully: It may be an anon array, a string or
911     # undefined. In any case we turn it into an anon array:
912     $att{LIBS}=[] unless $att{LIBS};
913     $att{LIBS}=[$att{LIBS}] if ref \$att{LIBS} eq SCALAR;
914     foreach ( @{$att{'LIBS'}} ){
915         s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
916         my(@libs) = MY->extliblist($_);
917         if ($libs[0] or $libs[1] or $libs[2]){
918             @att{EXTRALIBS, BSLOADLIBS, LDLOADLIBS} = @libs;
919             last;
920         }
921     }
922
923     warn "CONFIG must be an array ref\n"
924         if ($att{CONFIG} and ref $att{CONFIG} ne 'ARRAY');
925     $att{CONFIG} = [] unless (ref $att{CONFIG});
926     push(@{$att{CONFIG}},
927         qw( cc libc ldflags lddlflags ccdlflags cccdlflags
928             ranlib so dlext dlsrc installprivlib installarchlib
929         ));
930     push(@{$att{CONFIG}}, 'shellflags') if $Config{'shellflags'};
931
932     if ($Is_VMS) {
933       $att{OBJECT} = '$(BASEEXT).obj' unless $att{OBJECT};
934       $att{OBJECT} =~ s/[^,\s]\s+/, /g;
935       $att{OBJECT} =~ s/\n+/, /g;
936       $att{OBJECT} =~ s#\.o,#\.obj,#;
937     } else {
938       $att{OBJECT} = '$(BASEEXT).o' unless $att{OBJECT};
939       $att{OBJECT} =~ s/\n+/ \\\n\t/g;
940     }
941     $att{BOOTDEP}  = (-f "$att{BASEEXT}_BS") ? "$att{BASEEXT}_BS" : "";
942     $att{LD}       = ($Config{'ld'} || 'ld') unless $att{LD};
943     $att{LDFROM} = '$(OBJECT)' unless $att{LDFROM};
944     # Sanity check: don't define LINKTYPE = dynamic if we're skipping
945     # the 'dynamic' section of MM.  We don't have this problem with
946     # 'static', since we either must use it (%Config says we can't
947     # use dynamic loading) or the caller asked for it explicitly.
948     if (!$att{LINKTYPE}) {
949        $att{LINKTYPE} = grep(/dynamic/,@{$att{SKIP} || []})
950                         ? 'static'
951                         : ($Config{'usedl'} ? 'dynamic' : 'static');
952     };
953
954     # These get overridden for VMS and maybe some other systems
955     $att{NOOP}  = "";
956     $att{MAKEFILE} = "Makefile";
957     $att{RM_F}  = "rm -f";
958     $att{RM_RF} = "rm -rf";
959     $att{TOUCH} = "touch";
960     $att{CP} = "cp";
961     $att{MV} = "mv";
962 }
963
964
965 sub lsdir{
966     my($dir, $regex) = @_;
967     local(*DIR, @ls);
968     opendir(DIR, $_[0] || ".") or die "opendir: $!";
969     @ls = readdir(DIR);
970     closedir(DIR);
971     @ls = grep(/$regex/, @ls) if $regex;
972     @ls;
973 }
974
975
976 sub find_perl{
977     my($self, $ver, $names, $dirs, $trace) = @_;
978     my($name, $dir);
979     print "Looking for perl $ver by these names: @$names, in these dirs: @$dirs\n"
980         if ($trace);
981     foreach $dir (@$dirs){
982         next unless defined $dir; # $att{PERL_SRC} may be undefined
983         foreach $name (@$names){
984             print "checking $dir/$name\n" if ($trace >= 2);
985             if ($Is_VMS) {
986               $name .= ".exe" unless -x "$dir/$name";
987             }
988             next unless -x "$dir/$name";
989             print "executing $dir/$name\n" if ($trace);
990             my($out);
991             if ($Is_VMS) {
992               my($vmscmd) = 'MCR ' . vmsify("$dir/$name");
993               $out = `$vmscmd -e "require $ver; print ""VER_OK\n"""`;
994             } else {
995               $out = `$dir/$name -e 'require $ver; print "VER_OK\n" ' 2>&1`;
996             }
997             return "$dir/$name" if $out =~ /VER_OK/;
998         }
999     }
1000     warn "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1001     0; # false and not empty
1002 }
1003
1004
1005 sub post_initialize{
1006     "";
1007 }
1008  
1009
1010 sub constants {
1011     my(@m);
1012
1013     push @m, "
1014 NAME = $att{NAME}
1015 DISTNAME = $att{DISTNAME}
1016 VERSION = $att{VERSION}
1017
1018 # In which library should we install this extension?
1019 # This is typically the same as PERL_LIB.
1020 # (also see INST_LIBDIR and relationship to ROOTEXT)
1021 INST_LIB = $att{INST_LIB}
1022 INST_ARCHLIB = $att{INST_ARCHLIB}
1023
1024 # Perl library to use when building the extension
1025 PERL_LIB = $att{PERL_LIB}
1026 PERL_ARCHLIB = $att{PERL_ARCHLIB}
1027 ";
1028
1029     # Define I_PERL_LIBS to include the required -Ipaths
1030     # To be cute we only include PERL_ARCHLIB if different
1031     # To be portable we add quotes for VMS
1032     my(@i_perl_libs) = qw{-I$(PERL_ARCHLIB) -I$(PERL_LIB)};
1033     shift(@i_perl_libs) if ($att{PERL_ARCHLIB} eq $att{PERL_LIB});
1034     if ($Is_VMS){
1035         push @m, "I_PERL_LIBS = \"".join('" "',@i_perl_libs)."\"\n";
1036     } else {
1037         push @m, "I_PERL_LIBS = ".join(' ',@i_perl_libs)."\n";
1038     }
1039
1040     push @m, "
1041 # Where is the perl source code located? (Eventually we should
1042 # be able to build extensions without requiring the perl source
1043 # but that's a way off yet).
1044 PERL_SRC = $att{PERL_SRC}
1045 # Perl header files (will eventually be under PERL_LIB)
1046 PERL_INC = $att{PERL_INC}
1047 # Perl binaries
1048 PERL = $att{'PERL'}
1049 FULLPERL = $att{'FULLPERL'}
1050 ";
1051     push @m, "
1052 # FULLEXT = Pathname for extension directory (eg DBD/Oracle).
1053 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT.
1054 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)
1055 FULLEXT = $att{FULLEXT}
1056 BASEEXT = $att{BASEEXT}
1057 ROOTEXT = $att{ROOTEXT}
1058 ";
1059     push @m, "
1060 INC = $att{INC}
1061 DEFINE = $att{DEFINE}
1062 OBJECT = $att{OBJECT}
1063 LDFROM = $att{LDFROM}
1064 LINKTYPE = $att{LINKTYPE}
1065
1066 # Handy lists of source code files:
1067 XS_FILES= ".join(" \\\n\t", sort keys %{$att{XS}})."
1068 C_FILES = ".join(" \\\n\t", @{$att{C}})."
1069 O_FILES = ".join(" \\\n\t", @{$att{O_FILES}})."
1070 H_FILES = ".join(" \\\n\t", @{$att{H}})."
1071
1072 .SUFFIXES: .xs
1073
1074 .PRECIOUS: Makefile
1075
1076 .PHONY: all config static dynamic test linkext
1077
1078 # This extension may link to it's own library (see SDBM_File)
1079 MYEXTLIB = $att{MYEXTLIB}
1080
1081 # Where is the Config information that we are using/depend on
1082 CONFIGDEP = \$(PERL_ARCHLIB)/Config.pm \$(PERL_INC)/config.h
1083 ";
1084
1085     push @m, '
1086 # Where to put things:
1087 INST_LIBDIR     = $(INST_LIB)$(ROOTEXT)
1088 INST_ARCHLIBDIR = $(INST_ARCHLIB)$(ROOTEXT)
1089
1090 INST_AUTODIR      = $(INST_LIB)/auto/$(FULLEXT)
1091 INST_ARCHAUTODIR  = $(INST_ARCHLIB)/auto/$(FULLEXT)
1092 ';
1093
1094     push @m, '
1095 INST_STATIC  = $(INST_ARCHAUTODIR)/$(BASEEXT).a
1096 INST_DYNAMIC = $(INST_ARCHAUTODIR)/$(BASEEXT).$(DLEXT)
1097 INST_BOOT    = $(INST_ARCHAUTODIR)/$(BASEEXT).bs
1098 INST_PM = '.join(" \\\n\t", sort values %{$att{PM}}).'
1099 ';
1100
1101     join('',@m);
1102 }
1103
1104
1105 sub const_cccmd{
1106     # This is implemented in the same manner as extliblist,
1107     # e.g., do both and compare results during the transition period.
1108     my($cc,$ccflags,$optimize,$large,$split, $shflags)
1109         = @Config{qw(cc ccflags optimize large split shellflags)};
1110     $shflags = '' unless $shflags;
1111     my($prog, $old);
1112
1113     chop($old = `cd $att{PERL_SRC}; sh $shflags ./cflags $att{BASEEXT}.c 2>/dev/null`)
1114         if $att{PERL_SRC};
1115
1116     my($name);
1117     ( $name = $att{NAME} . "_cflags" ) =~ s/:/_/g ;
1118     if ($prog = $Config{$name}) {
1119         # Expand hints for this extension via the shell
1120         print STDERR "Processing $name hint:\n" if $Verbose;
1121         my(@o)=`cc=\"$cc\"
1122           ccflags=\"$ccflags\"
1123           optimize=\"$optimize\"
1124           large=\"$large\"
1125           split=\"$split\"
1126           eval '$prog'
1127           echo cc=\$cc
1128           echo ccflags=\$ccflags
1129           echo optimize=\$optimize
1130           echo large=\$large
1131           echo split=\$split
1132           `;
1133         my(%cflags);
1134         foreach $line (@o){
1135             chomp $line;
1136             if ($line =~ /(.*?)=\s*(.*)\s*$/){
1137                 $cflags{$1} = $2;
1138                 print STDERR "  $1 = $2" if $Verbose;
1139             } else {
1140                 print STDERR "Unrecognised result from hint: '$line'\n";
1141             }
1142         }
1143         ($cc,$ccflags,$optimize,$large,$split)=@cflags{qw(cc ccflags optimize large split)};
1144     }
1145
1146     my($new) = "$cc -c $ccflags $optimize  $large $split";
1147     if (defined($old) and $new ne $old) {
1148         warn "Warning (non-fatal): cflags evaluation in MakeMaker differs from shell output\n"
1149         ."   package: $att{NAME}\n"
1150         ."   old: $old\n"
1151         ."   new: $new\n"
1152         ."   Using 'old' set.\n"
1153         ."Please notify perl5-porters\@nicoh.com\n";
1154     }
1155     my($cccmd)=($old) ? $old : $new;
1156     "CCCMD = $cccmd\n";
1157 }
1158
1159
1160 # --- Constants Sections ---
1161
1162 sub const_config{
1163     my(@m,$m);
1164     push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
1165     my(%once_only);
1166     foreach $m (@{$att{'CONFIG'}}){
1167         next if $once_only{$m};
1168         warn "CONFIG key '$m' does not exist in Config.pm\n"
1169                 unless exists $Config{$m};
1170         push @m, "\U$m\E = $Config{$m}\n";
1171         $once_only{$m} = 1;
1172     }
1173     join('', @m);
1174 }
1175
1176
1177 sub const_loadlibs{
1178     "
1179 # $att{NAME} might depend on some other libraries:
1180 # (These comments may need revising:)
1181 #
1182 # Dependent libraries can be linked in one of three ways:
1183 #
1184 #  1.  (For static extensions) by the ld command when the perl binary
1185 #      is linked with the extension library. See EXTRALIBS below.
1186 #
1187 #  2.  (For dynamic extensions) by the ld command when the shared
1188 #      object is built/linked. See LDLOADLIBS below.
1189 #
1190 #  3.  (For dynamic extensions) by the DynaLoader when the shared
1191 #      object is loaded. See BSLOADLIBS below.
1192 #
1193 # EXTRALIBS =   List of libraries that need to be linked with when
1194 #               linking a perl binary which includes this extension
1195 #               Only those libraries that actually exist are included.
1196 #               These are written to a file and used when linking perl.
1197 #
1198 # LDLOADLIBS =  List of those libraries which can or must be linked into
1199 #               the shared library when created using ld. These may be
1200 #               static or dynamic libraries.
1201 #
1202 # BSLOADLIBS =  List of those libraries that are needed but can be
1203 #               linked in dynamically at run time on this platform.
1204 #               SunOS/Solaris does not need this because ld records
1205 #               the information (from LDLOADLIBS) into the object file.
1206 #               This list is used to create a .bs (bootstrap) file.
1207 #
1208 EXTRALIBS  = $att{'EXTRALIBS'}
1209 LDLOADLIBS = $att{'LDLOADLIBS'}
1210 BSLOADLIBS = $att{'BSLOADLIBS'}
1211 ";
1212 }
1213
1214
1215 # --- Tool Sections ---
1216
1217 sub tool_autosplit{
1218     my($self, %attribs) = @_;
1219     my($asl) = "";
1220     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
1221     q{
1222 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
1223 # Remark: the "" around the -I switches are helpful for the VMS support
1224 AUTOSPLITFILE = $(PERL) $(I_PERL_LIBS) -e 'use AutoSplit;}.$asl.q{ \
1225         AutoSplit::autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1) ;'
1226 };
1227 }
1228
1229
1230 sub tool_xsubpp{
1231     my($xsdir)  = '$(PERL_LIB)/ExtUtils';
1232     # drop back to old location if xsubpp is not in new location yet
1233     $xsdir = '$(PERL_SRC)/ext' unless (-f "$att{PERL_LIB}/ExtUtils/xsubpp");
1234     my(@tmdeps) = ('$(XSUBPPDIR)/typemap');
1235     push(@tmdeps, "typemap") if -f "typemap";
1236     my(@tmargs) = map("-typemap $_", @tmdeps);
1237     "
1238 XSUBPPDIR = $xsdir
1239 XSUBPP = \$(XSUBPPDIR)/xsubpp
1240 XSUBPPDEPS = @tmdeps
1241 XSUBPPARGS = @tmargs
1242 ";
1243 };
1244
1245
1246 sub tools_other{
1247     "
1248 SHELL = /bin/sh
1249 LD = $att{LD}
1250 TOUCH = $att{TOUCH}
1251 CP = $att{CP}
1252 MV = $att{MV}
1253 RM_F  = $att{RM_F}
1254 RM_RF = $att{RM_RF}
1255 ".q{
1256 # The following is a portable way to say mkdir -p
1257 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;'
1258 };
1259 }
1260
1261
1262 sub post_constants{
1263     "";
1264 }
1265
1266
1267 # --- Translation Sections ---
1268
1269 sub c_o {
1270     '
1271 $(O_FILES): $(H_FILES)
1272
1273 .c.o:
1274         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1275 ';
1276 }
1277
1278 sub xs_c {
1279     '
1280 .xs.c:
1281         $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $@
1282 ';
1283 }
1284
1285 sub xs_o {      # many makes are too dumb to use xs_c then c_o
1286     '
1287 .xs.o:
1288         $(PERL) $(XSUBPP) $(XSUBPPARGS) $*.xs >xstmp.c && mv xstmp.c $*.c
1289         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $(INC) $*.c
1290 ';
1291 }
1292
1293
1294 # --- Target Sections ---
1295
1296 sub top_targets{
1297     '
1298 all ::  config linkext $(INST_PM)
1299 '.$att{NOOP}.'
1300
1301 config :: '.$att{MAKEFILE}.'
1302         @$(MKPATH) $(INST_LIBDIR) $(INST_ARCHAUTODIR)
1303 ';
1304 }
1305
1306 sub linkext {
1307     my($self, %attribs) = @_;
1308     # LINKTYPE => static or dynamic
1309     my($linktype) = $attribs{LINKTYPE} || '$(LINKTYPE)';
1310     "
1311 linkext :: $linktype
1312 $att{NOOP}
1313 ";
1314 }
1315
1316 sub dlsyms {
1317     my($self,%attribs) = @_;
1318
1319     return '' if ($Config{'osname'} ne 'AIX');
1320
1321     my($funcs) = $attribs{DL_FUNCS} || $att{DL_FUNCS} || {};
1322     my($vars)  = $attribs{DL_VARS} || $att{DL_VARS} || [];
1323     my(@m);
1324
1325     push(@m,"
1326 dynamic :: $att{BASEEXT}.exp
1327
1328 ") unless $skip{'dynamic'};
1329
1330     push(@m,"
1331 static :: $att{BASEEXT}.exp
1332
1333 ") unless $skip{'static'};
1334
1335     push(@m,"
1336 $att{BASEEXT}.exp: Makefile.PL
1337 ",'     $(PERL) $(I_PERL_LIBS) -e \'use ExtUtils::MakeMaker; \\
1338         mksymlists(DL_FUNCS => ',neatvalue($att{DL_FUNCS}),', DL_VARS => ',neatvalue($att{DL_VARS}),')\'
1339 ');
1340
1341     join('',@m);
1342 }
1343
1344 # --- Dynamic Loading Sections ---
1345
1346 sub dynamic {
1347     '
1348 # $(INST_PM) has been moved to the all: target.
1349 # It remains here for awhile to allow for old usage: "make dynamic"
1350 dynamic :: '.$att{MAKEFILE}.' $(INST_DYNAMIC) $(INST_BOOT) $(INST_PM)
1351 '.$att{NOOP}.'
1352 ';
1353 }
1354
1355 sub dynamic_bs {
1356     my($self, %attribs) = @_;
1357     '
1358 BOOTSTRAP = '."$att{BASEEXT}.bs".'
1359
1360 # As MakeMaker mkbootstrap might not write a file (if none is required)
1361 # we use touch to prevent make continually trying to remake it.
1362 # The DynaLoader only reads a non-empty file.
1363 $(BOOTSTRAP): '."$att{MAKEFILE} $att{BOOTDEP}".'
1364         $(PERL) $(I_PERL_LIBS) \
1365                 -e \'use ExtUtils::MakeMaker; &mkbootstrap("$(BSLOADLIBS)");\' \
1366                 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) PERL_SRC=$(PERL_SRC) NAME=$(NAME)
1367         @$(TOUCH) $(BOOTSTRAP)
1368
1369 $(INST_BOOT): $(BOOTSTRAP)
1370         @'.$att{RM_RF}.' $(INST_BOOT)
1371         '.$att{CP}.' $(BOOTSTRAP) $(INST_BOOT)
1372 ';
1373 }
1374
1375
1376 sub dynamic_lib {
1377     my($self, %attribs) = @_;
1378     my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
1379     my($armaybe) = $attribs{ARMAYBE} || $att{ARMAYBE} || ":";
1380     my($ldfrom) = '$(LDFROM)';
1381     my($osname) = $Config{'osname'};
1382     $armaybe = 'ar' if ($osname eq 'dec_osf' and $armaybe eq ':');
1383     my(@m);
1384     push(@m,'
1385 # This section creates the dynamically loadable $(INST_DYNAMIC)
1386 # from $(OBJECT) and possibly $(MYEXTLIB).
1387 ARMAYBE = '.$armaybe.'
1388 OTHERLDFLAGS = '.$otherldflags.'
1389
1390 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP)
1391         @$(MKPATH) $(INST_ARCHAUTODIR)
1392 ');
1393     if ($armaybe ne ':'){
1394         $ldfrom = "tmp.a";
1395         push(@m,'       $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
1396         push(@m,'       $(RANLIB) '."$ldfrom\n");
1397     }
1398     $ldfrom = "-all $ldfrom -none" if ($osname eq 'dec_osf');
1399     push(@m,'   $(LD) -o $@ $(LDDLFLAGS) '.$ldfrom.
1400                         ' $(OTHERLDFLAGS) $(MYEXTLIB) $(LDLOADLIBS)'."\n");
1401     join('',@m);
1402 }
1403
1404
1405 # --- Static Loading Sections ---
1406
1407 sub static {
1408     '
1409 # $(INST_PM) has been moved to the all: target.
1410 # It remains here for awhile to allow for old usage: "make static"
1411 static :: '.$att{MAKEFILE}.' $(INST_STATIC) $(INST_PM) 
1412 '.$att{NOOP}.'
1413 ';
1414 }
1415
1416 sub static_lib{
1417     my(@m);
1418     push(@m, <<'END');
1419 $(INST_STATIC): $(OBJECT) $(MYEXTLIB)
1420 END
1421     # If this extension has it's own library (eg SDBM_File)
1422     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
1423     push(@m, "  $att{CP} \$(MYEXTLIB) \$\@\n") if $att{MYEXTLIB};
1424
1425     push(@m, <<'END');
1426         ar cr $@ $(OBJECT) && $(RANLIB) $@
1427         @echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)/extralibs.ld
1428 END
1429     push(@m, <<'END') if $att{PERL_SRC};
1430         @: Old mechanism - still needed:
1431         @echo "$(EXTRALIBS)" >> $(PERL_SRC)/ext.libs
1432 END
1433     join('', "\n",@m);
1434 }
1435
1436
1437 sub installpm {
1438     my($self, %attribs) = @_;
1439     # By default .pm files are split into the architecture independent
1440     # library. This is a good thing. If a specific module requires that
1441     # it's .pm files are split into the architecture specific library
1442     # then it should use: installpm => {SPLITLIB=>'$(INST_ARCHLIB)'}
1443     # Note that installperl currently interferes with this (Config.pm)
1444     # User can disable split by saying: installpm => {SPLITLIB=>''}
1445     my($splitlib) = '$(INST_LIB)'; # NOT arch specific by default
1446     $splitlib = $attribs{SPLITLIB} if exists $attribs{SPLITLIB};
1447     my(@m, $dist);
1448     foreach $dist (sort keys %{$att{PM}}){
1449         my($inst) = $att{PM}->{$dist};
1450         push(@m, "\n# installpm: $dist => $inst, splitlib=$splitlib\n");
1451         push(@m, MY->installpm_x($dist, $inst, $splitlib));
1452         push(@m, "\n");
1453     }
1454     join('', @m);
1455 }
1456
1457 sub installpm_x { # called by installpm per file
1458     my($self, $dist, $inst, $splitlib) = @_;
1459     my($instdir) = $inst =~ m|(.*)/|;
1460     my(@m);
1461     push(@m,"
1462 $inst: $dist
1463 ".'     @'.$att{RM_F}.' $@
1464         @$(MKPATH) '.$instdir.'
1465         '.$att{CP}.' $? $@
1466 ');
1467     push(@m, "\t\$(AUTOSPLITFILE) \$@ $splitlib/auto\n")
1468         if ($splitlib and $inst =~ m/\.pm$/);
1469     join('', @m);
1470 }
1471
1472
1473 # --- Sub-directory Sections ---
1474
1475 sub subdirs {
1476     my(@m);
1477     # This method provides a mechanism to automatically deal with
1478     # subdirectories containing further Makefile.PL scripts.
1479     # It calls the subdir_x() method for each subdirectory.
1480     foreach(<*/Makefile.PL>){
1481         s:/Makefile\.PL$:: ;
1482         print "Including $_ subdirectory" if ($Verbose);
1483         push(@m, MY->subdir_x($_));
1484     }
1485     if (@m){
1486         unshift(@m, "
1487 # The default clean, realclean and test targets in this Makefile
1488 # have automatically been given entries for each subdir.
1489
1490 all :: subdirs
1491 ");
1492     } else {
1493         push(@m, "\n# none")
1494     }
1495     join('',@m);
1496 }
1497
1498 sub runsubdirpl{        # Experimental! See subdir_x section
1499     my($self,$subdir) = @_;
1500     chdir($subdir) or die "chdir($subdir): $!";
1501     ExtUtils::MakeMaker::check_hints();
1502     require "Makefile.PL";
1503 }
1504
1505 sub subdir_x {
1506     my($self, $subdir) = @_;
1507     my(@m);
1508     # The intention is that the calling Makefile.PL should define the
1509     # $(SUBDIR_MAKEFILE_PL_ARGS) make macro to contain whatever
1510     # information needs to be passed down to the other Makefile.PL scripts.
1511     # If this does not suit your needs you'll need to write your own
1512     # MY::subdir_x() method to override this one.
1513     qq{
1514 config :: $subdir/$att{MAKEFILE}
1515         cd $subdir ; \$(MAKE) config INST_LIB=\$(INST_LIB) INST_ARCHLIB=\$(INST_ARCHLIB)  LINKTYPE=\$(LINKTYPE)
1516
1517 $subdir/$att{MAKEFILE}: $subdir/Makefile.PL \$(CONFIGDEP)
1518 }.'     @echo "Rebuilding $@ ..."
1519         $(PERL) $(I_PERL_LIBS) \\
1520                 -e "use ExtUtils::MakeMaker; MM->runsubdirpl(qw('.$subdir.'))" \\
1521                 INST_LIB=$(INST_LIB) INST_ARCHLIB=$(INST_ARCHLIB) $(SUBDIR_MAKEFILE_PL_ARGS)
1522         @echo "Rebuild of $@ complete."
1523 '.qq{
1524
1525 subdirs ::
1526         cd $subdir ; \$(MAKE) all LINKTYPE=\$(LINKTYPE)
1527
1528 };
1529 }
1530
1531
1532 # --- Cleanup and Distribution Sections ---
1533
1534 sub clean {
1535     my($self, %attribs) = @_;
1536     my(@m);
1537     push(@m, '
1538 # Delete temporary files but do not touch installed files. We don\'t delete
1539 # the Makefile here so a later make realclean still has a makefile to use.
1540
1541 clean ::
1542 ');
1543     # clean subdirectories first
1544     push(@m, map("\t-cd $_ && test -f $att{MAKEFILE} && \$(MAKE) clean\n",@{$att{DIR}}));
1545     my(@otherfiles) = values %{$att{XS}}; # .c files from *.xs files
1546     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1547     push(@otherfiles, "./blib");
1548     push(@m, "  -$att{RM_RF} *~ t/*~ *.o *.a mon.out core so_locations "
1549                         ."\$(BOOTSTRAP) \$(BASEEXT).bso @otherfiles\n");
1550     # See realclean and ext/utils/make_ext for usage of Makefile.old
1551     push(@m, "  -$att{MV} $att{MAKEFILE} $att{MAKEFILE}.old 2>/dev/null\n");
1552     push(@m, "  $attribs{POSTOP}\n")   if $attribs{POSTOP};
1553     join("", @m);
1554 }
1555
1556 sub realclean {
1557     my($self, %attribs) = @_;
1558     my(@m);
1559     push(@m,'
1560 # Delete temporary files (via clean) and also delete installed files
1561 realclean purge ::  clean
1562 ');
1563     # realclean subdirectories first (already cleaned)
1564     $sub = "\t-cd %s && test -f %s && \$(MAKE) %s realclean\n";
1565     foreach(@{$att{DIR}}){
1566         push(@m, sprintf($sub,$_,"$att{MAKEFILE}.old","-f $att{MAKEFILE}.old"));
1567         push(@m, sprintf($sub,$_,"$att{MAKEFILE}",''));
1568     }
1569     push(@m, "  $att{RM_RF} \$(INST_AUTODIR) \$(INST_ARCHAUTODIR)\n");
1570     push(@m, "  $att{RM_F} \$(INST_DYNAMIC) \$(INST_BOOT)\n");
1571     push(@m, "  $att{RM_F} \$(INST_STATIC) \$(INST_PM)\n");
1572     my(@otherfiles) = ($att{MAKEFILE}, "$att{MAKEFILE}.old"); # Makefiles last
1573     push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
1574     push(@m, "  $att{RM_RF} @otherfiles\n") if @otherfiles;
1575     push(@m, "  $attribs{POSTOP}\n")       if $attribs{POSTOP};
1576     join("", @m);
1577 }
1578
1579
1580 sub distclean {
1581     my($self, %attribs) = @_;
1582     # VERSION should be sanitised before use as a file name
1583     my($tarname)  = $attribs{TARNAME}  || '$(DISTNAME)-$(VERSION)';
1584     my($tarflags) = $attribs{TARFLAGS} || 'cvf';
1585     my($compress) = $attribs{COMPRESS} || 'compress'; # eg gzip
1586     my($preop)    = $attribs{PREOP}  || '@:'; # e.g., update MANIFEST
1587     my($postop)   = $attribs{POSTOP} || '@:';
1588     my($mkfiles)  = join(' ', map("$_/$att{MAKEFILE}", ".", @{$att{DIR}}));
1589     "
1590 distclean:     clean
1591         $preop
1592         $att{RM_F} $mkfiles
1593         cd ..; tar $tarflags $tarname.tar \$(BASEEXT)
1594         cd ..; $compress $tarname.tar
1595         $postop
1596 ";
1597 }
1598
1599
1600 # --- Test and Installation Sections ---
1601
1602 sub test {
1603     my($self, %attribs) = @_;
1604     my($tests) = $attribs{TESTS} || (-d "t" ? "t/*.t" : "");
1605     my(@m);
1606     push(@m,"
1607 test :: all
1608 ");
1609     push(@m, <<"END") if $tests;
1610         \$(FULLPERL) -I\$(INST_ARCHLIB) -I\$(INST_LIB) -I\$(PERL_ARCHLIB) -I\$(PERL_LIB) -e 'use Test::Harness; runtests \@ARGV;' $tests
1611 END
1612     push(@m, <<'END') if -f "test.pl";
1613         $(FULLPERL) -I$(INST_ARCHLIB) -I$(INST_LIB) $(I_PERL_LIBS) test.pl
1614 END
1615     push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) test LINKTYPE=\$(LINKTYPE)\n",@{$att{DIR}}));
1616     push(@m, "\t\@echo 'No tests defined for \$(NAME) extension.'\n") unless @m > 1;
1617     join("", @m);
1618 }
1619
1620
1621 sub install {
1622     my($self, %attribs) = @_;
1623     my(@m);
1624     push(@m, "
1625 install :: all
1626 ");
1627     # install subdirectories first
1628     push(@m, map("\tcd $_ && test -f $att{MAKEFILE} && \$(MAKE) install\n",@{$att{DIR}}));
1629
1630     push(@m, "\t: perl5.000 and MM pre 3.8 autosplit into INST_ARCHLIB, we delete these old files here
1631         $att{RM_F} \$(INST_ARCHLIB)/auto/\$(FULLEXT)/*.al \$(INST_ARCHLIB)/auto/\$(FULLEXT)/*.ix
1632         \$(MAKE) INST_LIB=\$(INST_PRIVLIB) INST_ARCHLIB=\$(INST_ARCHLIB)
1633 ");
1634
1635     join("",@m);
1636 }
1637
1638 sub force {
1639     '# Phony target to force checking subdirectories.
1640 FORCE:
1641 ';
1642 }
1643
1644
1645 sub perldepend {
1646         my(@m);
1647     push(@m,'
1648 PERL_HDRS = $(PERL_INC)/EXTERN.h $(PERL_INC)/INTERN.h \
1649     $(PERL_INC)/XSUB.h  $(PERL_INC)/av.h        $(PERL_INC)/cop.h \
1650     $(PERL_INC)/cv.h    $(PERL_INC)/dosish.h    $(PERL_INC)/embed.h \
1651     $(PERL_INC)/form.h  $(PERL_INC)/gv.h        $(PERL_INC)/handy.h \
1652     $(PERL_INC)/hv.h    $(PERL_INC)/keywords.h  $(PERL_INC)/mg.h \
1653     $(PERL_INC)/op.h    $(PERL_INC)/opcode.h    $(PERL_INC)/patchlevel.h \
1654     $(PERL_INC)/perl.h  $(PERL_INC)/perly.h     $(PERL_INC)/pp.h \
1655     $(PERL_INC)/proto.h $(PERL_INC)/regcomp.h   $(PERL_INC)/regexp.h \
1656     $(PERL_INC)/scope.h $(PERL_INC)/sv.h        $(PERL_INC)/unixish.h \
1657     $(PERL_INC)/util.h  $(PERL_INC)/config.h
1658
1659 $(OBJECT) : $(PERL_HDRS)
1660 ');
1661
1662     push(@m,'
1663 # Check for unpropogated config.sh changes. Should never happen.
1664 # We do NOT just update config.h because that is not sufficient.
1665 # An out of date config.h is not fatal but complains loudly!
1666 $(PERL_INC)/config.h: $(PERL_SRC)/config.sh
1667         -@echo "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
1668
1669 $(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
1670         @echo "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
1671         cd $(PERL_SRC); $(MAKE) lib/Config.pm
1672 ') if $att{PERL_SRC};
1673
1674     push(@m, join(" ", values %{$att{XS}})." : \$(XSUBPPDEPS)\n")
1675         if %{$att{XS}};
1676     join("\n",@m);
1677 }
1678
1679
1680 sub makefile {
1681     # We do not know what target was originally specified so we
1682     # must force a manual rerun to be sure. But as it should only
1683     # happen very rarely it is not a significant problem.
1684     '
1685 $(OBJECT) : '.$att{MAKEFILE}.'
1686
1687 # We take a very conservative approach here, but it\'s worth it.
1688 # We move Makefile to Makefile.old here to avoid gnu make looping.
1689 '.$att{MAKEFILE}.':     Makefile.PL $(CONFIGDEP) 
1690         @echo "Makefile out-of-date with respect to $?"
1691         @echo "Cleaning current config before rebuilding Makefile..."
1692         -@mv '."$att{MAKEFILE} $att{MAKEFILE}.old".'
1693         -$(MAKE) -f '.$att{MAKEFILE}.'.old clean >/dev/null 2>&1 || true
1694         $(PERL) $(I_PERL_LIBS) Makefile.PL
1695         @echo "Now you must rerun make."; false
1696 ';
1697 }
1698
1699
1700 sub postamble{
1701     "";
1702 }
1703
1704
1705 # --- Determine libraries to use and how to use them ---
1706
1707 sub extliblist{
1708     my($self, $libs) = @_;
1709     return ("", "", "") unless $libs;
1710     print STDERR "Potential libraries are '$libs':" if $Verbose;
1711     my(@new) = MY->new_extliblist($libs);
1712
1713     if ($att{PERL_SRC}){
1714         my(@old) = MY->old_extliblist($libs);
1715         my($oldlibs) = join(" : ",@old);
1716         my($newlibs) = join(" : ",@new);
1717         warn "Warning (non-fatal): $att{NAME} extliblist consistency check failed:\n".
1718             "  old: $oldlibs\n".
1719             "  new: $newlibs\n".
1720             "Using 'new' set. Please notify perl5-porters\@nicoh.com.\n"
1721                 if ("$newlibs" ne "$oldlibs");
1722     }
1723     @new;
1724 }
1725
1726
1727 sub old_extliblist {
1728     my($self, $potential_libs)=@_;
1729     return ("", "", "") unless $potential_libs;
1730     die "old_extliblist requires PERL_SRC" unless $att{PERL_SRC};
1731
1732     my(%attrib, @w);
1733     # Now run ext/util/extliblist to discover what *libs definitions
1734     # are required for the needs of $potential_libs
1735     $ENV{'potential_libs'} = $potential_libs;
1736     my(@o)=`. $att{PERL_SRC}/config.sh
1737             . $att{PERL_SRC}/ext/util/extliblist;
1738             echo EXTRALIBS=\$extralibs
1739             echo BSLOADLIBS=\$dynaloadlibs
1740             echo LDLOADLIBS=\$statloadlibs
1741             `;
1742     foreach $line (@o){
1743         chomp $line;
1744         if ($line =~ /(.*)\s*=\s*(.*)\s*$/){
1745             $attrib{$1} = $2;
1746             print STDERR "      $1 = $2" if $Verbose;
1747         }else{
1748             push(@w, $line);
1749         }
1750     }
1751     print STDERR "Messages from extliblist:\n", join("\n",@w,'')
1752        if @w ;
1753     @attrib{qw(EXTRALIBS BSLOADLIBS LDLOADLIBS)};
1754 }
1755
1756
1757 sub new_extliblist {
1758     my($self, $potential_libs)=@_;
1759     return ("", "", "") unless $potential_libs;
1760
1761     my($so)   = $Config{'so'};
1762     my($libs) = $Config{'libs'};
1763
1764     # compute $extralibs, $bsloadlibs and $ldloadlibs from
1765     # $potential_libs
1766     # this is a rewrite of Andy Dougherty's extliblist in perl
1767     # its home is in <distribution>/ext/util
1768
1769     my(@searchpath); # from "-L/path" entries in $potential_libs
1770     my(@libpath) = split " ", $Config{'libpth'};
1771     my(@ldloadlibs);
1772     my(@bsloadlibs);
1773     my(@extralibs);
1774     my($fullname);
1775     my($pwd) = fastcwd(); # from Cwd.pm
1776
1777     foreach $thislib (split ' ', $potential_libs){
1778
1779         # Handle possible linker path arguments.
1780         if ($thislib =~ s/^(-[LR])//){  # save path flag type
1781             my($ptype) = $1;
1782             unless (-d $thislib){
1783                 warn "$ptype$thislib ignored, directory does not exist\n"
1784                         if $Verbose;
1785                 next;
1786             }
1787             if ($thislib !~ m|^/|) {
1788               warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
1789               $thislib = "$pwd/$thislib";
1790             }
1791             push(@searchpath, $thislib);
1792             push(@extralibs,  "$ptype$thislib");
1793             push(@ldloadlibs, "$ptype$thislib");
1794             next;
1795         }
1796
1797         # Handle possible library arguments.
1798         unless ($thislib =~ s/^-l//){
1799           warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
1800           next;
1801         }
1802
1803         my($found_lib)=0;
1804         foreach $thispth (@searchpath, @libpath){
1805
1806             if (@fullname=<${thispth}/lib${thislib}.${so}.[0-9]*>){
1807                 $fullname=$fullname[-1]; #ATTN: 10 looses against 9!
1808             } elsif (-f ($fullname="$thispth/lib$thislib.$so")){
1809             } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")
1810                      && ($thislib .= "_s") ){ # we must explicitly ask for _s version
1811             } elsif (-f ($fullname="$thispth/lib$thislib.a")){
1812             } elsif (-f ($fullname="$thispth/Slib$thislib.a")){
1813             } else { 
1814                 warn "$thislib not found in $thispth\n" if $Verbose;
1815                 next;
1816             }
1817             warn "'-l$thislib' found at $fullname\n" if $Verbose;
1818             $found_lib++;
1819
1820             # Now update library lists
1821
1822             # what do we know about this library...
1823             my $is_dyna = ($fullname !~ /\.a$/);
1824             my $in_perl = ($libs =~ /\B-l${thislib}\b/s);
1825
1826             # Do not add it into the list if it is already linked in
1827             # with the main perl executable.
1828             # We have to special-case the NeXT, because all the math is also in libsys_s
1829             unless ( $in_perl || ($Config{'osname'} eq 'next' && $thislib eq 'm') ){
1830                 push(@extralibs, "-l$thislib");
1831             }
1832                         
1833
1834             # We might be able to load this archive file dynamically
1835             if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){
1836                 # We push -l$thislib instead of $fullname because
1837                 # it avoids hardwiring a fixed path into the .bs file.
1838                 # mkbootstrap will automatically add dl_findfile() to
1839                 # the .bs file if it sees a name in the -l format.
1840                 # USE THIS LATER: push(@bsloadlibs, "-l$thislib"); # " $fullname";
1841                 # USE THIS while checking results against old_extliblist
1842                 push(@bsloadlibs, "$fullname");
1843             } else {
1844                 if ($is_dyna){
1845                     # For SunOS4, do not add in this shared library if
1846                     # it is already linked in the main perl executable
1847                     push(@ldloadlibs, "-l$thislib")
1848                         unless ($in_perl and $Config{'osname'} eq 'sunos');
1849                 } else {
1850                     push(@ldloadlibs, "-l$thislib");
1851                 }
1852             }
1853             last;       # found one here so don't bother looking further
1854         }
1855         warn "Warning (non-fatal): No library found for -l$thislib\n" unless $found_lib>0;
1856     }
1857     ("@extralibs", "@bsloadlibs", "@ldloadlibs");
1858 }
1859
1860
1861 # --- Write a DynaLoader bootstrap file if required
1862
1863 sub mkbootstrap {
1864
1865 =head1 NAME
1866
1867 mkbootstrap
1868
1869 =head1 DESCRIPTION
1870
1871 Make a bootstrap file for use by this system's DynaLoader.
1872 It typically gets called from an extension Makefile.
1873
1874 There is no .bs file supplied with the extension. Instead a _BS file
1875 which has code for the special cases, like posix for berkeley db on the
1876 NeXT.
1877
1878 This file will get parsed, and produce a maybe empty
1879 @DynaLoader::dl_resolve_using array for the current architecture.
1880 That will be extended by $BSLOADLIBS, which was computed by Andy's
1881 extliblist script. If this array still is empty, we do nothing, else
1882 we write a .bs file with an @DynaLoader::dl_resolve_using array, but
1883 without any C<if>s, because there is no longer a need to deal with
1884 special cases.
1885
1886 The _BS file can put some code into the generated .bs file by placing
1887 it in $bscode. This is a handy 'escape' mechanism that may prove
1888 useful in complex situations.
1889
1890 If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then
1891 mkbootstrap will automatically add a dl_findfile() call to the
1892 generated .bs file.
1893
1894 =head1 AUTHORS
1895
1896 Andreas Koenig <k@otto.ww.TU-Berlin.DE>, Tim Bunce
1897 <Tim.Bunce@ig.co.uk>, Andy Dougherty <doughera@lafcol.lafayette.edu>.
1898 VMS support by Charles Bailey <bailey@HMIVAX.HUMGEN.UPENN.EDU>.
1899
1900 =cut
1901
1902     my($self, @bsloadlibs)=@_;
1903
1904     @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
1905
1906     print STDERR "      bsloadlibs=@bsloadlibs\n" if $Verbose;
1907
1908     # We need DynaLoader here because we and/or the *_BS file may
1909     # call dl_findfile(). We don't say `use' here because when
1910     # first building perl extensions the DynaLoader will not have
1911     # been built when MakeMaker gets first used.
1912     require DynaLoader;
1913     import DynaLoader;
1914
1915     init_main() unless defined $att{'BASEEXT'};
1916
1917     rename "$att{BASEEXT}.bs", "$att{BASEEXT}.bso";
1918
1919     if (-f "$att{BASEEXT}_BS"){
1920         $_ = "$att{BASEEXT}_BS";
1921         package DynaLoader; # execute code as if in DynaLoader
1922         local($osname, $dlsrc) = (); # avoid warnings
1923         ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)};
1924         $bscode = "";
1925         unshift @INC, ".";
1926         require $_;
1927         shift @INC;
1928     }
1929
1930     if ($Config{'dlsrc'} =~ /^dl_dld/){
1931         package DynaLoader;
1932         push(@dl_resolve_using, dl_findfile('-lc'));
1933     }
1934
1935     my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
1936     my($method) = '';
1937     if (@all){
1938         open BS, ">$att{BASEEXT}.bs"
1939                 or die "Unable to open $att{BASEEXT}.bs: $!";
1940         print STDOUT "Writing $att{BASEEXT}.bs\n";
1941         print STDOUT "  containing: @all" if $Verbose;
1942         print BS "# $att{BASEEXT} DynaLoader bootstrap file for $Config{'osname'} architecture.\n";
1943         print BS "# Do not edit this file, changes will be lost.\n";
1944         print BS "# This file was automatically generated by the\n";
1945         print BS "# mkbootstrap routine in ExtUtils/MakeMaker.pm.\n";
1946         print BS "\@DynaLoader::dl_resolve_using = ";
1947         # If @all contains names in the form -lxxx or -Lxxx then it's asking for
1948         # runtime library location so we automatically add a call to dl_findfile()
1949         if (" @all" =~ m/ -[lLR]/){
1950             print BS "  dl_findfile(qw(\n  @all\n  ));\n";
1951         }else{
1952             print BS "  qw(@all);\n";
1953         }
1954         # write extra code if *_BS says so
1955         print BS $DynaLoader::bscode if $DynaLoader::bscode;
1956         print BS "\n1;\n";
1957         close BS;
1958     }
1959
1960     # special handling for systems which needs a list of all global
1961     # symbols exported by a modules to be dynamically linked.
1962     if ($Config{'dlsrc'} =~ /^dl_aix/){
1963        my($bootfunc);
1964        ($bootfunc = $att{NAME}) =~ s/\W/_/g;
1965        open EXP, ">$att{BASEEXT}.exp";
1966        print EXP "#!\nboot_$bootfunc\n";
1967        close EXP;
1968     }
1969 }
1970
1971 sub mksymlists {
1972     my($self) = shift;
1973
1974     # only AIX requires a symbol list at this point
1975     # (so does VMS, but that's handled by the MM_VMS package)
1976     return '' unless $Config{'osname'} eq 'AIX';
1977
1978     init_main(@ARGV) unless defined $att{'BASEEXT'};
1979     if (!$att{DL_FUNCS}) {
1980        (my($bootfunc) = $att{NAME}) =~ s/\W/_/g;
1981        $att{DL_FUNCS} = {$att{BASEEXT} => ["boot_$bootfunc"]};
1982     }
1983     rename "$att{BASEEXT}.exp", "$att{BASEEXT}.exp_old";
1984
1985     open(EXP,">$att{BASEEXT}.exp") or die $!;
1986     print EXP join("\n",@{$att{DL_VARS}}) if @{$att{DL_VARS}};
1987     foreach $pkg (keys %{$att{DL_FUNC}}) {
1988         (my($prefix) = $pkg) =~ s/\W/_/g;
1989         foreach $func (@{$att{DL_FUNC}->{$pkg}}) {
1990             $func = "XS_${prefix}_$func" unless $func =~ /^boot_/;
1991             print EXP "$func\n";
1992         }
1993     }
1994     close EXP;
1995 }
1996
1997 # --- Output postprocessing section ---
1998 #nicetext is included to make VMS support easier
1999 sub nicetext { # Just return the input - no action needed
2000     my($self,$text) = @_;
2001     $text;
2002 }
2003  
2004 # the following keeps AutoSplit happy
2005 package ExtUtils::MakeMaker;
2006 1;
2007
2008 __END__