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