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