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