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