This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[PATCH 5.8.2 @21574] make install: line noise
[perl5.git] / lib / ExtUtils / MM_Unix.pm
CommitLineData
1e44e2bf
PP
1package ExtUtils::MM_Unix;
2
f6d6199c
MS
3require 5.005_03; # Maybe further back, dunno
4
b75c8c73
MS
5use strict;
6
dbc738d9 7use Exporter ();
45bc4d3a 8use Carp;
479d2113 9use Config qw(%Config);
a7d1454b 10use File::Basename qw(basename dirname);
f1387719 11use DirHandle;
479d2113 12
f6d6199c 13use vars qw($VERSION @ISA
479d2113 14 $Is_Mac $Is_OS2 $Is_VMS $Is_Win32 $Is_Win95 $Is_Dos $Is_VOS
2530b651 15 $Is_QNX $Is_AIX $Is_OSF $Is_IRIX $Is_NetBSD $Is_BSD
479d2113 16 $Is_SunOS4 $Is_Solaris $Is_SunOS
1b0fc073 17 $Verbose %pm %static
5c161494
MS
18 %Config_Override
19 );
f6d6199c
MS
20
21use ExtUtils::MakeMaker qw($Verbose neatvalue);
dbc738d9 22
a7d1454b 23$VERSION = '1.44';
1e44e2bf 24
f6d6199c
MS
25require ExtUtils::MM_Any;
26@ISA = qw(ExtUtils::MM_Any);
1e44e2bf 27
479d2113
MS
28$Is_OS2 = $^O eq 'os2';
29$Is_Mac = $^O eq 'MacOS';
30$Is_Win32 = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
31$Is_Win95 = $Is_Win32 && Win32::IsWin95();
32$Is_Dos = $^O eq 'dos';
33$Is_VOS = $^O eq 'vos';
34$Is_VMS = $^O eq 'VMS';
35$Is_QNX = $^O eq 'qnx';
36$Is_AIX = $^O eq 'aix';
37$Is_OSF = $^O eq 'dec_osf';
38$Is_IRIX = $^O eq 'irix';
39$Is_NetBSD = $^O eq 'netbsd';
40$Is_SunOS4 = $^O eq 'sunos';
41$Is_Solaris = $^O eq 'solaris';
42$Is_SunOS = $Is_SunOS4 || $Is_Solaris;
2530b651 43$Is_BSD = $^O =~ /^(?:free|net|open)bsd|bsdos$/;
479d2113 44
1e44e2bf
PP
45
46=head1 NAME
47
48ExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
49
50=head1 SYNOPSIS
51
52C<require ExtUtils::MM_Unix;>
53
54=head1 DESCRIPTION
55
56The methods provided by this package are designed to be used in
57conjunction with ExtUtils::MakeMaker. When MakeMaker writes a
58Makefile, it creates one or more objects that inherit their methods
59from a package C<MM>. MM itself doesn't provide any methods, but it
60ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
61specific packages take the responsibility for all the methods provided
62by MM_Unix. We are trying to reduce the number of the necessary
63overrides by defining rather primitive operations within
64ExtUtils::MM_Unix.
65
66If you are going to write a platform specific MM package, please try
1fef88e7
JM
67to limit the necessary overrides to primitive methods, and if it is not
68possible to do so, let's work out how to achieve that gain.
1e44e2bf 69
f4ae0f5e
PP
70If you are overriding any of these methods in your Makefile.PL (in the
71MY class), please report that to the makemaker mailing list. We are
72trying to minimize the necessary method overrides and switch to data
73driven Makefile.PLs wherever possible. In the long run less methods
74will be overridable via the MY class.
75
1e44e2bf
PP
76=head1 METHODS
77
78The following description of methods is still under
79development. Please refer to the code for not suitably documented
479d2113
MS
80sections and complain loudly to the makemaker@perl.org mailing list.
81Better yet, provide a patch.
1e44e2bf 82
f1387719 83Not all of the methods below are overridable in a
f4ae0f5e
PP
84Makefile.PL. Overridable methods are marked as (o). All methods are
85overridable by a platform specific MM_*.pm file (See
bab2b58e 86L<ExtUtils::MM_VMS>) and L<ExtUtils::MM_OS2>).
f4ae0f5e 87
1e44e2bf
PP
88=cut
89
f6d6199c 90# So we don't have to keep calling the methods over and over again,
479d2113
MS
91# we have these globals to cache the values. Faster and shrtr.
92my $Curdir = __PACKAGE__->curdir;
93my $Rootdir = __PACKAGE__->rootdir;
94my $Updir = __PACKAGE__->updir;
f4ae0f5e 95
479d2113
MS
96
97=head2 Methods
98
99=over 4
bab2b58e 100
dedf98bc
MS
101=item os_flavor (o)
102
103Simply says that we're Unix.
104
105=cut
106
107sub os_flavor {
108 return('Unix');
109}
110
111
f1387719 112=item c_o (o)
1e44e2bf 113
f1387719
PP
114Defines the suffix rules to compile different flavors of C files to
115object files.
1e44e2bf
PP
116
117=cut
118
f1387719
PP
119sub c_o {
120# --- Translation Sections ---
1e44e2bf 121
f1387719
PP
122 my($self) = shift;
123 return '' unless $self->needs_linking();
124 my(@m);
b207e5e2
DM
125 if (my $cpp = $Config{cpprun}) {
126 my $cpp_cmd = $self->const_cccmd;
127 $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/$cpp/;
128 push @m, '
129.c.i:
071e6b84 130 '. $cpp_cmd . ' $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c > $*.i
b207e5e2
DM
131';
132 }
f1387719 133 push @m, '
58486d1a 134.c.s:
071e6b84 135 $(CCCMD) -S $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
58486d1a
DM
136';
137 push @m, '
f1387719 138.c$(OBJ_EXT):
071e6b84 139 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.c
a0d6894c
PP
140';
141 push @m, '
f1387719 142.C$(OBJ_EXT):
071e6b84 143 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.C
f6d6199c 144' if !$Is_OS2 and !$Is_Win32 and !$Is_Dos; #Case-specific
a0d6894c 145 push @m, '
f1387719 146.cpp$(OBJ_EXT):
071e6b84 147 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cpp
1e44e2bf 148
f1387719 149.cxx$(OBJ_EXT):
071e6b84 150 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cxx
1e44e2bf 151
f1387719 152.cc$(OBJ_EXT):
071e6b84 153 $(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) $*.cc
f1387719
PP
154';
155 join "", @m;
1e44e2bf
PP
156}
157
f1387719 158=item cflags (o)
1e44e2bf 159
f1387719
PP
160Does very much the same as the cflags script in the perl
161distribution. It doesn't return the whole compiler command line, but
162initializes all of its parts. The const_cccmd method then actually
163returns the definition of the CCCMD macro which uses these parts.
1e44e2bf
PP
164
165=cut
166
f1387719 167#'
1e44e2bf 168
f1387719
PP
169sub cflags {
170 my($self,$libperl)=@_;
171 return $self->{CFLAGS} if $self->{CFLAGS};
172 return '' unless $self->needs_linking();
1e44e2bf 173
f1387719
PP
174 my($prog, $uc, $perltype, %cflags);
175 $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
176 $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
1e44e2bf 177
5869b1f1
JH
178 @cflags{qw(cc ccflags optimize shellflags)}
179 = @Config{qw(cc ccflags optimize shellflags)};
f1387719 180 my($optdebug) = "";
1e44e2bf 181
f1387719 182 $cflags{shellflags} ||= '';
1e44e2bf 183
f1387719
PP
184 my(%map) = (
185 D => '-DDEBUGGING',
186 E => '-DEMBED',
187 DE => '-DDEBUGGING -DEMBED',
188 M => '-DEMBED -DMULTIPLICITY',
189 DM => '-DDEBUGGING -DEMBED -DMULTIPLICITY',
190 );
1e44e2bf 191
f1387719
PP
192 if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
193 $uc = uc($1);
194 } else {
195 $uc = ""; # avoid warning
196 }
197 $perltype = $map{$uc} ? $map{$uc} : "";
1e44e2bf 198
f1387719
PP
199 if ($uc =~ /^D/) {
200 $optdebug = "-g";
201 }
1e44e2bf 202
1e44e2bf 203
f1387719
PP
204 my($name);
205 ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
e0678a30 206 if ($prog = $Config{$name}) {
f1387719
PP
207 # Expand hints for this extension via the shell
208 print STDOUT "Processing $name hint:\n" if $Verbose;
209 my(@o)=`cc=\"$cflags{cc}\"
210 ccflags=\"$cflags{ccflags}\"
211 optimize=\"$cflags{optimize}\"
212 perltype=\"$cflags{perltype}\"
213 optdebug=\"$cflags{optdebug}\"
f1387719
PP
214 eval '$prog'
215 echo cc=\$cc
216 echo ccflags=\$ccflags
217 echo optimize=\$optimize
218 echo perltype=\$perltype
219 echo optdebug=\$optdebug
f1387719
PP
220 `;
221 my($line);
222 foreach $line (@o){
223 chomp $line;
224 if ($line =~ /(.*?)=\s*(.*)\s*$/){
225 $cflags{$1} = $2;
226 print STDOUT " $1 = $2\n" if $Verbose;
227 } else {
228 print STDOUT "Unrecognised result from hint: '$line'\n";
229 }
230 }
231 }
1e44e2bf 232
f1387719
PP
233 if ($optdebug) {
234 $cflags{optimize} = $optdebug;
235 }
1e44e2bf 236
5869b1f1 237 for (qw(ccflags optimize perltype)) {
e0678a30 238 $cflags{$_} ||= '';
f1387719
PP
239 $cflags{$_} =~ s/^\s+//;
240 $cflags{$_} =~ s/\s+/ /g;
241 $cflags{$_} =~ s/\s+$//;
2d7e68ed 242 $self->{uc $_} ||= $cflags{$_};
f1387719 243 }
1e44e2bf 244
2aea4d40
JD
245 if ($self->{POLLUTE}) {
246 $self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
247 }
248
ee13e175
JH
249 my $pollute = '';
250 if ($Config{usemymalloc} and not $Config{bincompat5005}
251 and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
252 and $self->{PERL_MALLOC_OK}) {
253 $pollute = '$(PERL_MALLOC_DEF)';
254 }
255
fa048ccd 256 $self->{CCFLAGS} = quote_paren($self->{CCFLAGS});
9b475917 257 $self->{OPTIMIZE} = quote_paren($self->{OPTIMIZE});
ac25e0e7 258
f1387719
PP
259 return $self->{CFLAGS} = qq{
260CCFLAGS = $self->{CCFLAGS}
261OPTIMIZE = $self->{OPTIMIZE}
262PERLTYPE = $self->{PERLTYPE}
ee13e175 263MPOLLUTE = $pollute
f1387719 264};
1e44e2bf 265
1e44e2bf
PP
266}
267
f1387719 268=item clean (o)
1e44e2bf 269
f1387719 270Defines the clean target.
1e44e2bf
PP
271
272=cut
273
f1387719
PP
274sub clean {
275# --- Cleanup and Distribution Sections ---
1e44e2bf 276
f1387719
PP
277 my($self, %attribs) = @_;
278 my(@m,$dir);
279 push(@m, '
280# Delete temporary files but do not touch installed files. We don\'t delete
281# the Makefile here so a later make realclean still has a makefile to use.
1e44e2bf 282
479d2113 283clean :: clean_subdirs
f1387719 284');
f1387719
PP
285
286 my(@otherfiles) = values %{$self->{XS}}; # .c files from *.xs files
479d2113 287 if ( $Is_QNX ) {
2bfcb3f2
NA
288 my @errfiles = @{$self->{C}};
289 for ( @errfiles ) {
290 s/.c$/.err/;
291 }
292 push( @otherfiles, @errfiles, 'perlmain.err' );
293 }
f1387719 294 push(@otherfiles, $attribs{FILES}) if $attribs{FILES};
f6d6199c
MS
295 push(@otherfiles, qw[./blib $(MAKE_APERL_FILE)
296 $(INST_ARCHAUTODIR)/extralibs.all
0fdc96ff 297 $(INST_ARCHAUTODIR)/extralibs.ld
a7d1454b
RGS
298 perlmain.c tmon.out mon.out so_locations
299 blibdirs pm_to_blib
5f929d0c 300 *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
4cbec17f
JH
301 $(BOOTSTRAP) $(BASEEXT).bso
302 $(BASEEXT).def lib$(BASEEXT).def
c855ea65 303 $(BASEEXT).exp $(BASEEXT).x
f1387719 304 ]);
f6d6199c
MS
305 if( $Is_VOS ) {
306 push(@otherfiles, qw[*.kp]);
307 }
308 else {
309 push(@otherfiles, qw[core core.*perl.*.? *perl.core]);
2530b651
MS
310
311 # core.\d+
312 push(@otherfiles, map { "core." . "[0-9]"x$_ } (1..5));
f6d6199c
MS
313 }
314
479d2113 315 push @m, "\t-\$(RM_RF) @otherfiles\n";
f1387719
PP
316 # See realclean and ext/utils/make_ext for usage of Makefile.old
317 push(@m,
479d2113 318 "\t-\$(MV) \$(FIRST_MAKEFILE) \$(MAKEFILE_OLD) \$(DEV_NULL)\n");
f1387719
PP
319 push(@m,
320 "\t$attribs{POSTOP}\n") if $attribs{POSTOP};
321 join("", @m);
1e44e2bf
PP
322}
323
479d2113
MS
324
325=item clean_subdirs_target
326
327 my $make_frag = $MM->clean_subdirs_target;
328
329Returns the clean_subdirs target. This is used by the clean target to
330call clean on any subdirectories which contain Makefiles.
331
332=cut
333
334sub clean_subdirs_target {
335 my($self) = shift;
336
337 # No subdirectories, no cleaning.
338 return <<'NOOP_FRAG' unless @{$self->{DIR}};
339clean_subdirs :
340 $(NOECHO) $(NOOP)
341NOOP_FRAG
342
343
344 my $clean = "clean_subdirs :\n";
345
346 for my $dir (@{$self->{DIR}}) {
347 $clean .= sprintf <<'MAKE_FRAG', $dir;
348 -cd %s && $(TEST_F) $(FIRST_MAKEFILE) && $(MAKE) clean
349MAKE_FRAG
350 }
351
352 return $clean;
353}
354
355
f1387719 356=item const_cccmd (o)
1e44e2bf 357
f1387719
PP
358Returns the full compiler call for C programs and stores the
359definition in CONST_CCCMD.
1e44e2bf
PP
360
361=cut
362
f1387719
PP
363sub const_cccmd {
364 my($self,$libperl)=@_;
365 return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
366 return '' unless $self->needs_linking();
367 return $self->{CONST_CCCMD} =
071e6b84 368 q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
289e7e34 369 $(CCFLAGS) $(OPTIMIZE) \\
5869b1f1 370 $(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
f1387719 371 $(XS_DEFINE_VERSION)};
1e44e2bf
PP
372}
373
f1387719 374=item const_config (o)
1e44e2bf 375
f1387719
PP
376Defines a couple of constants in the Makefile that are imported from
377%Config.
1e44e2bf
PP
378
379=cut
380
f1387719
PP
381sub const_config {
382# --- Constants Sections ---
383
384 my($self) = shift;
385 my(@m,$m);
386 push(@m,"\n# These definitions are from config.sh (via $INC{'Config.pm'})\n");
387 push(@m,"\n# They may have been overridden via Makefile.PL or on the command line\n");
388 my(%once_only);
389 foreach $m (@{$self->{CONFIG}}){
390 # SITE*EXP macros are defined in &constants; avoid duplicates here
479d2113 391 next if $once_only{$m};
f8968d56
JH
392 $self->{uc $m} = quote_paren($self->{uc $m});
393 push @m, uc($m) , ' = ' , $self->{uc $m}, "\n";
f1387719
PP
394 $once_only{$m} = 1;
395 }
396 join('', @m);
1e44e2bf
PP
397}
398
f1387719 399=item const_loadlibs (o)
1e44e2bf 400
f1387719
PP
401Defines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
402L<ExtUtils::Liblist> for details.
1e44e2bf
PP
403
404=cut
405
f1387719
PP
406sub const_loadlibs {
407 my($self) = shift;
408 return "" unless $self->needs_linking;
409 my @m;
410 push @m, qq{
411# $self->{NAME} might depend on some other libraries:
412# See ExtUtils::Liblist for details
413#
414};
415 my($tmp);
416 for $tmp (qw/
417 EXTRALIBS LDLOADLIBS BSLOADLIBS LD_RUN_PATH
418 /) {
419 next unless defined $self->{$tmp};
420 push @m, "$tmp = $self->{$tmp}\n";
421 }
422 return join "", @m;
1e44e2bf
PP
423}
424
f1387719 425=item constants (o)
1e44e2bf 426
479d2113
MS
427 my $make_frag = $mm->constants;
428
429Prints out macros for lots of constants.
1e44e2bf
PP
430
431=cut
432
f1387719 433sub constants {
1e44e2bf 434 my($self) = @_;
479d2113 435 my @m = ();
1e44e2bf 436
5e719f03 437 for my $macro (qw(
1e44e2bf 438
479d2113
MS
439 AR_STATIC_ARGS DIRFILESEP
440 NAME NAME_SYM
441 VERSION VERSION_MACRO VERSION_SYM DEFINE_VERSION
442 XS_VERSION XS_VERSION_MACRO XS_DEFINE_VERSION
443 INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
5e719f03
MS
444 INST_MAN1DIR INST_MAN3DIR
445 MAN1EXT MAN3EXT
5c161494 446 INSTALLDIRS
479d2113
MS
447 DESTDIR PREFIX
448 PERLPREFIX SITEPREFIX VENDORPREFIX
5e719f03
MS
449 ),
450 (map { ("INSTALL".$_,
451 "DESTINSTALL".$_)
452 } $self->installvars),
453 qw(
479d2113
MS
454 PERL_LIB
455 PERL_ARCHLIB
5c161494 456 LIBPERL_A MYEXTLIB
479d2113
MS
457 FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE
458 PERLMAINCC PERL_SRC PERL_INC
459 PERL FULLPERL ABSPERL
460 PERLRUN FULLPERLRUN ABSPERLRUN
461 PERLRUNINST FULLPERLRUNINST ABSPERLRUNINST
462 PERL_CORE
463 PERM_RW PERM_RWX
1e44e2bf 464
5e719f03 465 ) )
5c161494 466 {
479d2113 467 next unless defined $self->{$macro};
e0678a30
MS
468
469 # pathnames can have sharp signs in them; escape them so
470 # make doesn't think it is a comment-start character.
479d2113
MS
471 $self->{$macro} =~ s/#/\\#/g;
472 push @m, "$macro = $self->{$macro}\n";
1e44e2bf
PP
473 }
474
f1387719 475 push @m, qq{
479d2113
MS
476MAKEMAKER = $self->{MAKEMAKER}
477MM_VERSION = $self->{MM_VERSION}
478MM_REVISION = $self->{MM_REVISION}
f1387719 479};
1e44e2bf 480
f1387719
PP
481 push @m, q{
482# FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
483# BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
f1387719
PP
484# PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
485# DLBASE = Basename part of dynamic library. May be just equal BASEEXT.
486};
1e44e2bf 487
479d2113 488 for my $macro (qw/
f1387719 489 FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
131aa089 490 LDFROM LINKTYPE PM_FILTER
5c161494
MS
491 / )
492 {
479d2113
MS
493 next unless defined $self->{$macro};
494 push @m, "$macro = $self->{$macro}\n";
f1387719 495 }
1e44e2bf 496
f1387719
PP
497 push @m, "
498# Handy lists of source code files:
479d2113
MS
499XS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})."
500C_FILES = ".$self->wraplist(@{$self->{C}})."
501O_FILES = ".$self->wraplist(@{$self->{O_FILES}})."
502H_FILES = ".$self->wraplist(@{$self->{H}})."
503MAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})."
504MAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})."
f1387719 505";
1e44e2bf 506
2366100d 507
f1387719 508 push @m, q{
479d2113
MS
509# Where is the Config information that we are using/depend on
510CONFIGDEP = $(PERL_ARCHLIB)$(DIRFILESEP)Config.pm $(PERL_INC)$(DIRFILESEP)config.h
511};
1e44e2bf 512
1e44e2bf 513
479d2113
MS
514 push @m, qq{
515# Where to build things
516INST_LIBDIR = $self->{INST_LIBDIR}
517INST_ARCHLIBDIR = $self->{INST_ARCHLIBDIR}
1e44e2bf 518
479d2113
MS
519INST_AUTODIR = $self->{INST_AUTODIR}
520INST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR}
1e44e2bf 521
479d2113
MS
522INST_STATIC = $self->{INST_STATIC}
523INST_DYNAMIC = $self->{INST_DYNAMIC}
524INST_BOOT = $self->{INST_BOOT}
dbc738d9 525};
1e44e2bf 526
1e44e2bf 527
479d2113
MS
528 push @m, qq{
529# Extra linker info
530EXPORT_LIST = $self->{EXPORT_LIST}
531PERL_ARCHIVE = $self->{PERL_ARCHIVE}
532PERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER}
f1387719 533};
1e44e2bf 534
5ba48348 535 push @m, "
1e44e2bf 536
479d2113 537TO_INST_PM = ".$self->wraplist(sort keys %{$self->{PM}})."
1e44e2bf 538
479d2113
MS
539PM_TO_BLIB = ".$self->wraplist(%{$self->{PM}})."
540";
1e44e2bf 541
f1387719
PP
542 join('',@m);
543}
1e44e2bf 544
479d2113 545
f1387719 546=item depend (o)
1e44e2bf 547
f1387719 548Same as macro for the depend attribute.
1e44e2bf 549
f1387719 550=cut
1e44e2bf 551
f1387719
PP
552sub depend {
553 my($self,%attribs) = @_;
554 my(@m,$key,$val);
555 while (($key,$val) = each %attribs){
556 last unless defined $key;
f6c40018 557 push @m, "$key : $val\n";
1e44e2bf 558 }
f1387719
PP
559 join "", @m;
560}
1e44e2bf 561
5e719f03
MS
562=item init_DEST
563
564 $mm->init_DEST
565
566Defines the DESTDIR and DEST* variables paralleling the INSTALL*.
567
568=cut
569
570sub init_DEST {
571 my $self = shift;
572
573 # Initialize DESTDIR
574 $self->{DESTDIR} ||= '';
575
576 # Make DEST variables.
577 foreach my $var ($self->installvars) {
578 my $destvar = 'DESTINSTALL'.$var;
579 $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')';
580 }
581}
582
583
479d2113
MS
584=item init_dist
585
586 $mm->init_dist;
1e44e2bf 587
f1387719 588Defines a lot of macros for distribution support.
1e44e2bf 589
479d2113
MS
590 macro description default
591
592 TAR tar command to use tar
593 TARFLAGS flags to pass to TAR cvf
594
595 ZIP zip command to use zip
596 ZIPFLAGS flags to pass to ZIP -r
597
598 COMPRESS compression command to gzip --best
599 use for tarfiles
600 SUFFIX suffix to put on .gz
601 compressed files
602
603 SHAR shar command to use shar
604
605 PREOP extra commands to run before
606 making the archive
607 POSTOP extra commands to run after
608 making the archive
609
610 TO_UNIX a command to convert linefeeds
611 to Unix style in your archive
612
613 CI command to checkin your ci -u
614 sources to version control
615 RCS_LABEL command to label your sources rcs -Nv$(VERSION_SYM): -q
616 just after CI is run
617
618 DIST_CP $how argument to manicopy() best
619 when the distdir is created
620
621 DIST_DEFAULT default target to use to tardist
622 create a distribution
623
624 DISTVNAME name of the resulting archive $(DISTNAME)-$(VERSION)
625 (minus suffixes)
626
627=cut
628
629sub init_dist {
630 my $self = shift;
631
632 $self->{TAR} ||= 'tar';
633 $self->{TARFLAGS} ||= 'cvf';
634 $self->{ZIP} ||= 'zip';
635 $self->{ZIPFLAGS} ||= '-r';
636 $self->{COMPRESS} ||= 'gzip --best';
637 $self->{SUFFIX} ||= '.gz';
638 $self->{SHAR} ||= 'shar';
639 $self->{PREOP} ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST
640 $self->{POSTOP} ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir
641 $self->{TO_UNIX} ||= '$(NOECHO) $(NOOP)';
642
643 $self->{CI} ||= 'ci -u';
644 $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q';
645 $self->{DIST_CP} ||= 'best';
646 $self->{DIST_DEFAULT} ||= 'tardist';
647
648 ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME};
649 $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION};
650
651}
652
653=item dist (o)
654
655 my $dist_macros = $mm->dist(%overrides);
656
657Generates a make fragment defining all the macros initialized in
658init_dist.
659
660%overrides can be used to override any of the above.
661
f1387719 662=cut
1e44e2bf 663
f1387719
PP
664sub dist {
665 my($self, %attribs) = @_;
1e44e2bf 666
f6d6199c 667 my $make = '';
479d2113
MS
668 foreach my $key (qw(
669 TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR
670 PREOP POSTOP TO_UNIX
671 CI RCS_LABEL DIST_CP DIST_DEFAULT
672 DISTNAME DISTVNAME
673 ))
674 {
675 my $value = $attribs{$key} || $self->{$key};
676 $make .= "$key = $value\n";
f6d6199c
MS
677 }
678
679 return $make;
1e44e2bf
PP
680}
681
f1387719 682=item dist_basics (o)
1e44e2bf 683
2edbd6da 684Defines the targets distclean, distcheck, skipcheck, manifest, veryclean.
1e44e2bf
PP
685
686=cut
687
f1387719
PP
688sub dist_basics {
689 my($self) = shift;
f6d6199c
MS
690
691 return <<'MAKE_FRAG';
f1387719 692distclean :: realclean distcheck
f6d6199c 693 $(NOECHO) $(NOOP)
1e44e2bf 694
f1387719 695distcheck :
f6d6199c 696 $(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck
1e44e2bf 697
f1387719 698skipcheck :
f6d6199c 699 $(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck
1e44e2bf 700
f1387719 701manifest :
f6d6199c 702 $(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
2edbd6da 703
2edbd6da
JH
704veryclean : realclean
705 $(RM_F) *~ *.orig */*~ */*.orig
f6d6199c
MS
706
707MAKE_FRAG
708
1e44e2bf
PP
709}
710
f1387719 711=item dist_ci (o)
1e44e2bf 712
f1387719 713Defines a check in target for RCS.
1e44e2bf
PP
714
715=cut
716
f1387719 717sub dist_ci {
1e44e2bf 718 my($self) = shift;
479d2113 719 return q{
f1387719 720ci :
f6d6199c 721 $(PERLRUN) "-MExtUtils::Manifest=maniread" \\
479d2113 722 -e "@all = keys %{ maniread() };" \\
431b0fc4
MS
723 -e "print(qq{Executing $(CI) @all\n}); system(qq{$(CI) @all});" \\
724 -e "print(qq{Executing $(RCS_LABEL) ...\n}); system(qq{$(RCS_LABEL) @all});"
f1387719 725};
f1387719 726}
1e44e2bf 727
f1387719 728=item dist_core (o)
1e44e2bf 729
479d2113
MS
730 my $dist_make_fragment = $MM->dist_core;
731
732Puts the targets necessary for 'make dist' together into one make
733fragment.
1e44e2bf 734
f1387719 735=cut
1e44e2bf 736
f1387719
PP
737sub dist_core {
738 my($self) = shift;
479d2113
MS
739
740 my $make_frag = '';
741 foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile
742 shdist))
743 {
744 my $method = $target.'_target';
745 $make_frag .= "\n";
746 $make_frag .= $self->$method();
747 }
748
749 return $make_frag;
750}
751
752
753=item B<dist_target>
754
755 my $make_frag = $MM->dist_target;
756
757Returns the 'dist' target to make an archive for distribution. This
758target simply checks to make sure the Makefile is up-to-date and
759depends on $(DIST_DEFAULT).
760
761=cut
762
763sub dist_target {
764 my($self) = shift;
765
766 my $date_check = $self->oneliner(<<'CODE', ['-l']);
767print 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
ad2f23df 768 if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)';
479d2113
MS
769CODE
770
771 return sprintf <<'MAKE_FRAG', $date_check;
2530b651 772dist : $(DIST_DEFAULT) $(FIRST_MAKEFILE)
479d2113
MS
773 $(NOECHO) %s
774MAKE_FRAG
775}
776
777=item B<tardist_target>
1e44e2bf 778
479d2113
MS
779 my $make_frag = $MM->tardist_target;
780
781Returns the 'tardist' target which is simply so 'make tardist' works.
782The real work is done by the dynamically named tardistfile_target()
783method, tardist should have that as a dependency.
784
785=cut
786
787sub tardist_target {
788 my($self) = shift;
789
790 return <<'MAKE_FRAG';
f1387719 791tardist : $(DISTVNAME).tar$(SUFFIX)
479d2113
MS
792 $(NOECHO) $(NOOP)
793MAKE_FRAG
794}
795
796=item B<zipdist_target>
797
798 my $make_frag = $MM->zipdist_target;
799
800Returns the 'zipdist' target which is simply so 'make zipdist' works.
801The real work is done by the dynamically named zipdistfile_target()
802method, zipdist should have that as a dependency.
803
804=cut
805
806sub zipdist_target {
807 my($self) = shift;
1e44e2bf 808
479d2113 809 return <<'MAKE_FRAG';
f1387719 810zipdist : $(DISTVNAME).zip
479d2113
MS
811 $(NOECHO) $(NOOP)
812MAKE_FRAG
813}
814
815=item B<tarfile_target>
816
817 my $make_frag = $MM->tarfile_target;
818
819The name of this target is the name of the tarball generated by
820tardist. This target does the actual work of turning the distdir into
821a tarball.
1e44e2bf 822
479d2113
MS
823=cut
824
825sub tarfile_target {
826 my($self) = shift;
827
828 return <<'MAKE_FRAG';
f1387719
PP
829$(DISTVNAME).tar$(SUFFIX) : distdir
830 $(PREOP)
831 $(TO_UNIX)
832 $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
833 $(RM_RF) $(DISTVNAME)
834 $(COMPRESS) $(DISTVNAME).tar
835 $(POSTOP)
479d2113
MS
836MAKE_FRAG
837}
838
839=item zipfile_target
1e44e2bf 840
479d2113
MS
841 my $make_frag = $MM->zipfile_target;
842
843The name of this target is the name of the zip file generated by
844zipdist. This target does the actual work of turning the distdir into
845a zip file.
846
847=cut
848
849sub zipfile_target {
850 my($self) = shift;
851
852 return <<'MAKE_FRAG';
f1387719
PP
853$(DISTVNAME).zip : distdir
854 $(PREOP)
855 $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
856 $(RM_RF) $(DISTVNAME)
857 $(POSTOP)
479d2113
MS
858MAKE_FRAG
859}
860
861=item uutardist_target
862
863 my $make_frag = $MM->uutardist_target;
864
865Converts the tarfile into a uuencoded file
866
867=cut
868
869sub uutardist_target {
870 my($self) = shift;
1e44e2bf 871
479d2113 872 return <<'MAKE_FRAG';
f1387719 873uutardist : $(DISTVNAME).tar$(SUFFIX)
479d2113
MS
874 uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu
875MAKE_FRAG
876}
877
878
879=item shdist_target
880
881 my $make_frag = $MM->shdist_target;
882
883Converts the distdir into a shell archive.
884
885=cut
886
887sub shdist_target {
888 my($self) = shift;
f4ae0f5e 889
479d2113 890 return <<'MAKE_FRAG';
f1387719
PP
891shdist : distdir
892 $(PREOP)
893 $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
894 $(RM_RF) $(DISTVNAME)
895 $(POSTOP)
479d2113 896MAKE_FRAG
f4ae0f5e
PP
897}
898
479d2113 899=item distdir
f4ae0f5e 900
f1387719
PP
901Defines the scratch directory target that will hold the distribution
902before tar-ing (or shar-ing).
1e44e2bf
PP
903
904=cut
905
479d2113
MS
906# For backwards compatibility.
907*dist_dir = *distdir;
908
909sub distdir {
f1387719 910 my($self) = shift;
f6d6199c
MS
911
912 return <<'MAKE_FRAG';
a7d1454b 913distdir : metafile metafile_addtomanifest signature
f1387719 914 $(RM_RF) $(DISTVNAME)
f6d6199c 915 $(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
68dc0745 916 -e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"
f6d6199c
MS
917
918MAKE_FRAG
919
1e44e2bf
PP
920}
921
f6d6199c 922=item dist_test
1e44e2bf 923
f1387719
PP
924Defines a target that produces the distribution in the
925scratchdirectory, and runs 'perl Makefile.PL; make ;make test' in that
926subdirectory.
1e44e2bf
PP
927
928=cut
929
f1387719 930sub dist_test {
1e44e2bf 931 my($self) = shift;
f1387719
PP
932 my @m;
933 push @m, q{
934disttest : distdir
e0678a30 935 cd $(DISTVNAME) && $(ABSPERLRUN) Makefile.PL
57b1a898
MS
936 cd $(DISTVNAME) && $(MAKE) $(PASTHRU)
937 cd $(DISTVNAME) && $(MAKE) test $(PASTHRU)
f1387719
PP
938};
939 join "", @m;
1e44e2bf
PP
940}
941
f1387719 942=item dlsyms (o)
1e44e2bf 943
f1387719
PP
944Used by AIX and VMS to define DL_FUNCS and DL_VARS and write the *.exp
945files.
1e44e2bf
PP
946
947=cut
948
f1387719
PP
949sub dlsyms {
950 my($self,%attribs) = @_;
1e44e2bf 951
479d2113 952 return '' unless ($Is_AIX && $self->needs_linking() );
1e44e2bf 953
f1387719
PP
954 my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
955 my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
762efda7 956 my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
f1387719 957 my(@m);
1e44e2bf 958
f1387719
PP
959 push(@m,"
960dynamic :: $self->{BASEEXT}.exp
1e44e2bf 961
f1387719 962") unless $self->{SKIPHASH}{'dynamic'}; # dynamic and static are subs, so...
1e44e2bf 963
f1387719
PP
964 push(@m,"
965static :: $self->{BASEEXT}.exp
1e44e2bf 966
f1387719 967") unless $self->{SKIPHASH}{'static'}; # we avoid a warning if we tick them
1e44e2bf 968
f1387719
PP
969 push(@m,"
970$self->{BASEEXT}.exp: Makefile.PL
4bfb3f62 971",' $(PERLRUN) -e \'use ExtUtils::Mksymlists; \\
f1387719 972 Mksymlists("NAME" => "',$self->{NAME},'", "DL_FUNCS" => ',
762efda7
JD
973 neatvalue($funcs), ', "FUNCLIST" => ', neatvalue($funclist),
974 ', "DL_VARS" => ', neatvalue($vars), ');\'
f1387719 975');
1e44e2bf 976
f1387719
PP
977 join('',@m);
978}
1e44e2bf 979
f1387719 980=item dynamic (o)
1e44e2bf 981
f1387719 982Defines the dynamic target.
1e44e2bf 983
f1387719 984=cut
1e44e2bf 985
f1387719
PP
986sub dynamic {
987# --- Dynamic Loading Sections ---
1e44e2bf 988
f1387719
PP
989 my($self) = shift;
990 '
479d2113
MS
991dynamic :: $(FIRST_MAKEFILE) $(INST_DYNAMIC) $(INST_BOOT)
992 $(NOECHO) $(NOOP)
f1387719
PP
993';
994}
1e44e2bf 995
f1387719 996=item dynamic_bs (o)
1e44e2bf 997
f1387719 998Defines targets for bootstrap files.
1e44e2bf 999
f1387719 1000=cut
1e44e2bf 1001
f1387719
PP
1002sub dynamic_bs {
1003 my($self, %attribs) = @_;
1004 return '
1005BOOTSTRAP =
1006' unless $self->has_link_code();
1e44e2bf 1007
479d2113
MS
1008 return <<'MAKE_FRAG';
1009BOOTSTRAP = $(BASEEXT).bs
1e44e2bf 1010
f1387719
PP
1011# As Mkbootstrap might not write a file (if none is required)
1012# we use touch to prevent make continually trying to remake it.
1013# The DynaLoader only reads a non-empty file.
a7d1454b 1014$(BOOTSTRAP): $(FIRST_MAKEFILE) $(BOOTDEP) blibdirs
479d2113
MS
1015 $(NOECHO) $(ECHO) "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
1016 $(NOECHO) $(PERLRUN) \
f6d6199c 1017 "-MExtUtils::Mkbootstrap" \
479d2113
MS
1018 -e "Mkbootstrap('$(BASEEXT)','$(BSLOADLIBS)');"
1019 $(NOECHO) $(TOUCH) $(BOOTSTRAP)
2366100d 1020 $(CHMOD) $(PERM_RW) $@
1e44e2bf 1021
a7d1454b 1022$(INST_BOOT): $(BOOTSTRAP) blibdirs
479d2113
MS
1023 $(NOECHO) $(RM_RF) $(INST_BOOT)
1024 -$(CP) $(BOOTSTRAP) $(INST_BOOT)
2366100d 1025 $(CHMOD) $(PERM_RW) $@
479d2113 1026MAKE_FRAG
f1387719 1027}
1e44e2bf 1028
f1387719 1029=item dynamic_lib (o)
1e44e2bf 1030
f1387719
PP
1031Defines how to produce the *.so (or equivalent) files.
1032
1033=cut
1034
1035sub dynamic_lib {
1036 my($self, %attribs) = @_;
1037 return '' unless $self->needs_linking(); #might be because of a subdir
1e44e2bf 1038
f1387719 1039 return '' unless $self->has_link_code;
f4ae0f5e 1040
f1387719
PP
1041 my($otherldflags) = $attribs{OTHERLDFLAGS} || "";
1042 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
1043 my($armaybe) = $attribs{ARMAYBE} || $self->{ARMAYBE} || ":";
1044 my($ldfrom) = '$(LDFROM)';
479d2113 1045 $armaybe = 'ar' if ($Is_OSF and $armaybe eq ':');
f1387719 1046 my(@m);
f07bc2fb 1047 my $ld_opt = $Is_OS2 ? '$(OPTIMIZE) ' : ''; # Useful on other systems too?
dedf98bc 1048 my $ld_fix = $Is_OS2 ? '|| ( $(RM_F) $@ && sh -c false )' : '';
f1387719
PP
1049 push(@m,'
1050# This section creates the dynamically loadable $(INST_DYNAMIC)
1051# from $(OBJECT) and possibly $(MYEXTLIB).
1052ARMAYBE = '.$armaybe.'
f07bc2fb 1053OTHERLDFLAGS = '.$ld_opt.$otherldflags.'
f1387719 1054INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
dedf98bc 1055INST_DYNAMIC_FIX = '.$ld_fix.'
f4ae0f5e 1056
a7d1454b 1057$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) blibdirs $(EXPORT_LIST) $(PERL_ARCHIVE) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP)
f1387719
PP
1058');
1059 if ($armaybe ne ':'){
1060 $ldfrom = 'tmp$(LIB_EXT)';
1061 push(@m,' $(ARMAYBE) cr '.$ldfrom.' $(OBJECT)'."\n");
1062 push(@m,' $(RANLIB) '."$ldfrom\n");
1063 }
479d2113 1064 $ldfrom = "-all $ldfrom -none" if $Is_OSF;
ff0cee69 1065
7f0187cb 1066 # The IRIX linker doesn't use LD_RUN_PATH
479d2113 1067 my $ldrun = $Is_IRIX && $self->{LD_RUN_PATH} ?
e0678a30 1068 qq{-rpath "$self->{LD_RUN_PATH}"} : '';
491527d0 1069
a84e0cef
JH
1070 # For example in AIX the shared objects/libraries from previous builds
1071 # linger quite a while in the shared dynalinker cache even when nobody
1072 # is using them. This is painful if one for instance tries to restart
1073 # a failed build because the link command will fail unnecessarily 'cos
1074 # the shared object/library is 'busy'.
1075 push(@m,' $(RM_F) $@
1076');
1077
30afd0dc 1078 my $libs = '$(LDLOADLIBS)';
ea5fc951 1079
a7d1454b 1080 if ($Is_NetBSD && $Config{'useshrplib'}) {
ea5fc951
JH
1081 # Use nothing on static perl platforms, and to the flags needed
1082 # to link against the shared libperl library on shared perl
1083 # platforms. We peek at lddlflags to see if we need -Wl,-R
1084 # or -R to add paths to the run-time library search path.
a7d1454b
RGS
1085 if ($Config{'lddlflags'} =~ /-Wl,-R/) {
1086 $libs .= ' -L$(PERL_INC) -Wl,-R$(INSTALLARCHLIB)/CORE -lperl';
1087 } elsif ($Config{'lddlflags'} =~ /-R/) {
1088 $libs .= ' -L$(PERL_INC) -R$(INSTALLARCHLIB)/CORE -lperl';
1089 }
ea5fc951
JH
1090 }
1091
2719e44e
JH
1092 push(@m,
1093' LD_RUN_PATH="$(LD_RUN_PATH)" $(LD) '.$ldrun.' $(LDDLFLAGS) '.$ldfrom.
dedf98bc 1094' $(OTHERLDFLAGS) -o $@ $(MYEXTLIB) $(PERL_ARCHIVE) '.$libs.' $(PERL_ARCHIVE_AFTER) $(EXPORT_LIST) $(INST_DYNAMIC_FIX)');
f1387719 1095 push @m, '
2366100d 1096 $(CHMOD) $(PERM_RWX) $@
f1387719 1097';
1e44e2bf
PP
1098
1099 join('',@m);
1100}
1101
f1387719 1102=item exescan
1e44e2bf 1103
f1387719 1104Deprecated method. Use libscan instead.
1e44e2bf
PP
1105
1106=cut
1107
f1387719
PP
1108sub exescan {
1109 my($self,$path) = @_;
1110 $path;
1e44e2bf
PP
1111}
1112
f1387719 1113=item extliblist
1e44e2bf 1114
f1387719
PP
1115Called by init_others, and calls ext ExtUtils::Liblist. See
1116L<ExtUtils::Liblist> for details.
1e44e2bf
PP
1117
1118=cut
1119
f1387719
PP
1120sub extliblist {
1121 my($self,$libs) = @_;
1122 require ExtUtils::Liblist;
1123 $self->ext($libs, $Verbose);
1124}
f4ae0f5e 1125
f1387719 1126=item find_perl
1e44e2bf 1127
f1387719 1128Finds the executables PERL and FULLPERL
1e44e2bf 1129
f1387719 1130=cut
1e44e2bf 1131
f1387719
PP
1132sub find_perl {
1133 my($self, $ver, $names, $dirs, $trace) = @_;
1134 my($name, $dir);
1135 if ($trace >= 2){
479d2113 1136 print "Looking for perl $ver by these names:
f1387719
PP
1137@$names
1138in these dirs:
1139@$dirs
1140";
1141 }
479d2113
MS
1142
1143 my $stderr_duped = 0;
1144 local *STDERR_COPY;
2530b651
MS
1145 unless ($Is_BSD) {
1146 if( open(STDERR_COPY, '>&STDERR') ) {
1147 $stderr_duped = 1;
1148 }
1149 else {
1150 warn <<WARNING;
479d2113
MS
1151find_perl() can't dup STDERR: $!
1152You might see some garbage while we search for Perl
1153WARNING
c4a9c615 1154 }
479d2113
MS
1155 }
1156
ec751b0b 1157 foreach $name (@$names){
479d2113
MS
1158 foreach $dir (@$dirs){
1159 next unless defined $dir; # $self->{PERL_SRC} may be undefined
1160 my ($abs, $val);
1161 if ($self->file_name_is_absolute($name)) { # /foo/bar
1162 $abs = $name;
1163 } elsif ($self->canonpath($name) eq
1164 $self->canonpath(basename($name))) { # foo
1165 $abs = $self->catfile($dir, $name);
1166 } else { # foo/bar
1167 $abs = $self->catfile($Curdir, $name);
1168 }
1169 print "Checking $abs\n" if ($trace >= 2);
1170 next unless $self->maybe_command($abs);
1171 print "Executing $abs\n" if ($trace >= 2);
1172
431b0fc4 1173 my $version_check = qq{$abs -e "require $ver; print qq{VER_OK\n}"};
2530b651 1174 # To avoid using the unportable 2>&1 to supress STDERR,
c4a9c615
AE
1175 # we close it before running the command.
1176 # However, thanks to a thread library bug in many BSDs
1177 # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
1178 # we cannot use the fancier more portable way in here
1179 # but instead need to use the traditional 2>&1 construct.
2530b651
MS
1180 if ($Is_BSD) {
1181 $val = `$version_check 2>&1`;
c4a9c615
AE
1182 } else {
1183 close STDERR if $stderr_duped;
1184 $val = `$version_check`;
1185 open STDERR, '>&STDERR_COPY' if $stderr_duped;
1186 }
479d2113
MS
1187
1188 if ($val =~ /^VER_OK/) {
1189 print "Using PERL=$abs\n" if $trace;
1190 return $abs;
1191 } elsif ($trace >= 2) {
1192 print "Result: '$val'\n";
1193 }
1194 }
1e44e2bf 1195 }
f1387719
PP
1196 print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1197 0; # false and not empty
1198}
1e44e2bf 1199
45bc4d3a
JH
1200=item find_tests
1201
1202 my $test = $mm->find_tests;
1203
1204Returns a string suitable for feeding to the shell to return all
1205tests in t/*.t.
1206
1207=cut
1208
1209sub find_tests {
1210 my($self) = shift;
1211 return 't/*.t';
1212}
1213
bab2b58e
AK
1214=back
1215
f1387719 1216=head2 Methods to actually produce chunks of text for the Makefile
1e44e2bf 1217
bab2b58e
AK
1218The methods here are called for each MakeMaker object in the order
1219specified by @ExtUtils::MakeMaker::MM_Sections.
1220
1221=over 2
f4ae0f5e 1222
84902520
TB
1223=item fixin
1224
e0678a30
MS
1225 $mm->fixin(@files);
1226
1227Inserts the sharpbang or equivalent magic number to a set of @files.
84902520
TB
1228
1229=cut
1230
1231sub fixin { # stolen from the pink Camel book, more or less
e0678a30
MS
1232 my($self, @files) = @_;
1233
1234 my($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
1235 for my $file (@files) {
dedf98bc
MS
1236 my $file_new = "$file.new";
1237 my $file_bak = "$file.bak";
1238
84902520
TB
1239 local(*FIXIN);
1240 local(*FIXOUT);
45bc4d3a 1241 open(FIXIN, $file) or croak "Can't process '$file': $!";
84902520
TB
1242 local $/ = "\n";
1243 chomp(my $line = <FIXIN>);
1244 next unless $line =~ s/^\s*\#!\s*//; # Not a shbang file.
1245 # Now figure out the interpreter name.
1246 my($cmd,$arg) = split ' ', $line, 2;
1247 $cmd =~ s!^.*/!!;
1248
1249 # Now look (in reverse) for interpreter in absolute PATH (unless perl).
e0678a30 1250 my $interpreter;
84902520 1251 if ($cmd eq "perl") {
fb73857a
PP
1252 if ($Config{startperl} =~ m,^\#!.*/perl,) {
1253 $interpreter = $Config{startperl};
1254 $interpreter =~ s,^\#!,,;
1255 } else {
1256 $interpreter = $Config{perlpath};
1257 }
84902520 1258 } else {
479d2113 1259 my(@absdirs) = reverse grep {$self->file_name_is_absolute} $self->path;
84902520
TB
1260 $interpreter = '';
1261 my($dir);
1262 foreach $dir (@absdirs) {
1263 if ($self->maybe_command($cmd)) {
1264 warn "Ignoring $interpreter in $file\n" if $Verbose && $interpreter;
479d2113 1265 $interpreter = $self->catfile($dir,$cmd);
84902520
TB
1266 }
1267 }
1268 }
1269 # Figure out how to invoke interpreter on this machine.
1270
1271 my($shb) = "";
1272 if ($interpreter) {
1273 print STDOUT "Changing sharpbang in $file to $interpreter" if $Verbose;
f5cd9d9c 1274 # this is probably value-free on DOSISH platforms
84902520
TB
1275 if ($does_shbang) {
1276 $shb .= "$Config{'sharpbang'}$interpreter";
1277 $shb .= ' ' . $arg if defined $arg;
1278 $shb .= "\n";
1279 }
1280 $shb .= qq{
1281eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}'
90248788 1282 if 0; # not running under some shell
f5cd9d9c 1283} unless $Is_Win32; # this won't work on win32, so don't
84902520
TB
1284 } else {
1285 warn "Can't find $cmd in PATH, $file unchanged"
1286 if $Verbose;
1287 next;
1288 }
1289
dedf98bc 1290 unless ( open(FIXOUT,">$file_new") ) {
84902520
TB
1291 warn "Can't create new $file: $!\n";
1292 next;
1293 }
84902520
TB
1294
1295 # Print out the new #! line (or equivalent).
1296 local $\;
1297 undef $/;
1298 print FIXOUT $shb, <FIXIN>;
1299 close FIXIN;
1300 close FIXOUT;
985777a9 1301
dedf98bc
MS
1302 chmod 0666, $file_bak;
1303 unlink $file_bak;
1304 unless ( rename($file, $file_bak) ) {
1305 warn "Can't rename $file to $file_bak: $!";
f5cd9d9c
GS
1306 next;
1307 }
dedf98bc
MS
1308 unless ( rename($file_new, $file) ) {
1309 warn "Can't rename $file_new to $file: $!";
1310 unless ( rename($file_bak, $file) ) {
1311 warn "Can't rename $file_bak back to $file either: $!";
1312 warn "Leaving $file renamed as $file_bak\n";
f5cd9d9c
GS
1313 }
1314 next;
1315 }
dedf98bc 1316 unlink $file_bak;
84902520 1317 } continue {
985777a9 1318 close(FIXIN) if fileno(FIXIN);
84902520
TB
1319 system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';;
1320 }
1321}
1322
f1387719
PP
1323=item force (o)
1324
1325Just writes FORCE:
1326
1327=cut
1e44e2bf 1328
f1387719
PP
1329sub force {
1330 my($self) = shift;
1331 '# Phony target to force checking subdirectories.
1332FORCE:
479d2113 1333 $(NOECHO) $(NOOP)
f1387719 1334';
1e44e2bf
PP
1335}
1336
f1387719 1337=item guess_name
1e44e2bf 1338
f1387719
PP
1339Guess the name of this package by examining the working directory's
1340name. MakeMaker calls this only if the developer has not supplied a
1341NAME attribute.
1e44e2bf 1342
f1387719 1343=cut
f4ae0f5e 1344
f1387719
PP
1345# ';
1346
1347sub guess_name {
1348 my($self) = @_;
1349 use Cwd 'cwd';
1350 my $name = basename(cwd());
4f44ac69 1351 $name =~ s|[\-_][\d\.\-]+\z||; # this is new with MM 5.00, we
f1387719
PP
1352 # strip minus or underline
1353 # followed by a float or some such
1354 print "Warning: Guessing NAME [$name] from current directory name.\n";
1355 $name;
1356}
1357
1358=item has_link_code
1359
1360Returns true if C, XS, MYEXTLIB or similar objects exist within this
1361object that need a compiler. Does not descend into subdirectories as
1362needs_linking() does.
f4ae0f5e
PP
1363
1364=cut
1365
f1387719
PP
1366sub has_link_code {
1367 my($self) = shift;
1368 return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1369 if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1370 $self->{HAS_LINK_CODE} = 1;
1371 return 1;
f4ae0f5e 1372 }
f1387719 1373 return $self->{HAS_LINK_CODE} = 0;
f4ae0f5e
PP
1374}
1375
cae6c631 1376
f1387719 1377=item init_dirscan
f4ae0f5e 1378
479d2113
MS
1379Scans the directory structure and initializes DIR, XS, XS_FILES, PM,
1380C, C_FILES, O_FILES, H, H_FILES, PL_FILES, MAN*PODS, EXE_FILES.
1381
1382Called by init_main.
f1387719
PP
1383
1384=cut
1385
1386sub init_dirscan { # --- File and Directory Lists (.xs .pm .pod etc)
1387 my($self) = @_;
1388 my($name, %dir, %xs, %c, %h, %ignore, %pl_files, %manifypods);
e3aa3ecb 1389 my %pm;
e0678a30
MS
1390
1391 @ignore{qw(Makefile.PL test.pl t)} = (1,1,1);
1392
1393 # ignore the distdir
1394 $Is_VMS ? $ignore{"$self->{DISTVNAME}.dir"} = 1
1395 : $ignore{$self->{DISTVNAME}} = 1;
1396
1397 @ignore{map lc, keys %ignore} = values %ignore if $Is_VMS;
1398
f6d6199c 1399 foreach $name ($self->lsdir($Curdir)){
4ecf31dc 1400 next if $name =~ /\#/;
f6d6199c 1401 next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
f1387719
PP
1402 next unless $self->libscan($name);
1403 if (-d $name){
760ac839 1404 next if -l $name; # We do not support symlinks at all
5e719f03 1405 next if $self->{NORECURS};
479d2113 1406 $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
4f44ac69
GS
1407 } elsif ($name =~ /\.xs\z/){
1408 my($c); ($c = $name) =~ s/\.xs\z/.c/;
f1387719
PP
1409 $xs{$name} = $c;
1410 $c{$c} = 1;
4f44ac69 1411 } elsif ($name =~ /\.c(pp|xx|c)?\z/i){ # .c .C .cpp .cxx .cc
f1387719
PP
1412 $c{$name} = 1
1413 unless $name =~ m/perlmain\.c/; # See MAP_TARGET
4f44ac69 1414 } elsif ($name =~ /\.h\z/i){
f1387719 1415 $h{$name} = 1;
4f44ac69
GS
1416 } elsif ($name =~ /\.PL\z/) {
1417 ($pl_files{$name} = $name) =~ s/\.PL\z// ;
933fea7f 1418 } elsif (($Is_VMS || $Is_Dos) && $name =~ /[._]pl$/i) {
918c0b2d 1419 # case-insensitive filesystem, one dot per name, so foo.h.PL
933fea7f 1420 # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
6ee623d5
GS
1421 local($/); open(PL,$name); my $txt = <PL>; close PL;
1422 if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
4f44ac69 1423 ($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
6ee623d5 1424 }
f6d6199c 1425 else {
479d2113 1426 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
f6d6199c 1427 }
4f44ac69 1428 } elsif ($name =~ /\.(p[ml]|pod)\z/){
479d2113 1429 $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
f1387719
PP
1430 }
1431 }
f4ae0f5e 1432
f1387719
PP
1433 # Some larger extensions often wish to install a number of *.pm/pl
1434 # files into the library in various locations.
f4ae0f5e 1435
f1387719
PP
1436 # The attribute PMLIBDIRS holds an array reference which lists
1437 # subdirectories which we should search for library files to
1438 # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ]. We
1439 # recursively search through the named directories (skipping any
1440 # which don't exist or contain Makefile.PL files).
f4ae0f5e 1441
f1387719
PP
1442 # For each *.pm or *.pl file found $self->libscan() is called with
1443 # the default installation path in $_[1]. The return value of
1444 # libscan defines the actual installation location. The default
1445 # libscan function simply returns the path. The file is skipped
1446 # if libscan returns false.
f4ae0f5e 1447
f1387719
PP
1448 # The default installation location passed to libscan in $_[1] is:
1449 #
1450 # ./*.pm => $(INST_LIBDIR)/*.pm
1451 # ./xyz/... => $(INST_LIBDIR)/xyz/...
1452 # ./lib/... => $(INST_LIB)/...
1453 #
1454 # In this way the 'lib' directory is seen as the root of the actual
1455 # perl library whereas the others are relative to INST_LIBDIR
1456 # (which includes PARENT_NAME). This is a subtle distinction but one
1457 # that's important for nested modules.
1e44e2bf 1458
479d2113
MS
1459 unless( $self->{PMLIBDIRS} ) {
1460 if( $Is_VMS ) {
1461 # Avoid logical name vs directory collisions
1462 $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
1463 }
1464 else {
1465 $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
1466 }
d71e5ff2 1467 }
1e44e2bf 1468
f1387719 1469 #only existing directories that aren't in $dir are allowed
1e44e2bf 1470
f1387719
PP
1471 # Avoid $_ wherever possible:
1472 # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1473 my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1474 my ($pmlibdir);
1475 @{$self->{PMLIBDIRS}} = ();
1476 foreach $pmlibdir (@pmlibdirs) {
1477 -d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1e44e2bf 1478 }
1e44e2bf 1479
f1387719
PP
1480 if (@{$self->{PMLIBDIRS}}){
1481 print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1482 if ($Verbose >= 2);
1483 require File::Find;
e0678a30
MS
1484 File::Find::find(sub {
1485 if (-d $_){
479d2113 1486 unless ($self->libscan($_)){
e0678a30
MS
1487 $File::Find::prune = 1;
1488 }
1489 return;
1490 }
1491 return if /\#/;
f6d6199c 1492 return if /~$/; # emacs temp files
431b0fc4 1493 return if /,v$/; # RCS files
f6d6199c
MS
1494
1495 my $path = $File::Find::name;
1496 my $prefix = $self->{INST_LIBDIR};
1497 my $striplibpath;
1498
1499 $prefix = $self->{INST_LIB}
1500 if ($striplibpath = $path) =~ s:^(\W*)lib\W:$1:i;
1501
479d2113 1502 my($inst) = $self->catfile($prefix,$striplibpath);
f1387719
PP
1503 local($_) = $inst; # for backwards compatibility
1504 $inst = $self->libscan($inst);
1505 print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1506 return unless $inst;
1507 $pm{$path} = $inst;
1508 }, @{$self->{PMLIBDIRS}});
1509 }
1e44e2bf 1510
479d2113
MS
1511 $self->{PM} ||= \%pm;
1512 $self->{PL_FILES} ||= \%pl_files;
1513
1514 $self->{DIR} ||= [sort keys %dir];
1515
1516 $self->{XS} ||= \%xs;
1517 $self->{C} ||= [sort keys %c];
1518 my @o_files = @{$self->{C}};
1519 $self->{O_FILES} = [grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files];
1520
1521 $self->{H} ||= [sort keys %h];
1e44e2bf 1522
f1387719 1523 # Set up names of manual pages to generate from pods
cae6c631 1524 my %pods;
f6d6199c 1525 foreach my $man (qw(MAN1 MAN3)) {
cae6c631
JD
1526 unless ($self->{"${man}PODS"}) {
1527 $self->{"${man}PODS"} = {};
e0678a30
MS
1528 $pods{$man} = 1 unless
1529 $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/;
cae6c631
JD
1530 }
1531 }
1532
f6d6199c 1533 if ($pods{MAN1}) {
f1387719
PP
1534 if ( exists $self->{EXE_FILES} ) {
1535 foreach $name (@{$self->{EXE_FILES}}) {
f1387719
PP
1536 local *FH;
1537 my($ispod)=0;
f1387719 1538 if (open(FH,"<$name")) {
f1387719 1539 while (<FH>) {
479d2113 1540 if (/^=(?:head\d+|item|pod)\b/) {
f1387719
PP
1541 $ispod=1;
1542 last;
1543 }
1544 }
f1387719
PP
1545 close FH;
1546 } else {
1547 # If it doesn't exist yet, we assume, it has pods in it
1548 $ispod = 1;
1e44e2bf 1549 }
cae6c631 1550 next unless $ispod;
cae6c631
JD
1551 if ($pods{MAN1}) {
1552 $self->{MAN1PODS}->{$name} =
479d2113 1553 $self->catfile("\$(INST_MAN1DIR)", basename($name).".\$(MAN1EXT)");
1e44e2bf 1554 }
f1387719 1555 }
1e44e2bf
PP
1556 }
1557 }
f6d6199c 1558 if ($pods{MAN3}) {
f1387719
PP
1559 my %manifypods = (); # we collect the keys first, i.e. the files
1560 # we have to convert to pod
1561 foreach $name (keys %{$self->{PM}}) {
4f44ac69 1562 if ($name =~ /\.pod\z/ ) {
f1387719 1563 $manifypods{$name} = $self->{PM}{$name};
4f44ac69 1564 } elsif ($name =~ /\.p[ml]\z/ ) {
f1387719
PP
1565 local *FH;
1566 my($ispod)=0;
f1387719 1567 if (open(FH,"<$name")) {
f1387719 1568 while (<FH>) {
479d2113 1569 if (/^=head1\s+\w+/) {
f1387719
PP
1570 $ispod=1;
1571 last;
1572 }
1573 }
f1387719
PP
1574 close FH;
1575 } else {
1576 $ispod = 1;
1577 }
1578 if( $ispod ) {
1579 $manifypods{$name} = $self->{PM}{$name};
1580 }
1581 }
1582 }
1583
1584 # Remove "Configure.pm" and similar, if it's not the only pod listed
e0678a30
MS
1585 # To force inclusion, just name it "Configure.pod", or override
1586 # MAN3PODS
f1387719 1587 foreach $name (keys %manifypods) {
40b90ac3 1588 if ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) {
f1387719
PP
1589 delete $manifypods{$name};
1590 next;
1591 }
1592 my($manpagename) = $name;
4f44ac69 1593 $manpagename =~ s/\.p(od|m|l)\z//;
479d2113 1594 # everything below lib is ok
431b0fc4 1595 unless($manpagename =~ s!^\W*lib\W+!!s) {
479d2113
MS
1596 $manpagename = $self->catfile(
1597 split(/::/,$self->{PARENT_NAME}),$manpagename
1598 );
f1387719 1599 }
cae6c631
JD
1600 if ($pods{MAN3}) {
1601 $manpagename = $self->replace_manpage_separator($manpagename);
1602 $self->{MAN3PODS}->{$name} =
479d2113 1603 $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
cae6c631 1604 }
1e44e2bf
PP
1605 }
1606 }
f1387719 1607}
1e44e2bf 1608
479d2113
MS
1609=item init_DIRFILESEP
1610
1611Using / for Unix. Called by init_main.
1612
1613=cut
1614
1615sub init_DIRFILESEP {
1616 my($self) = shift;
1617
1618 $self->{DIRFILESEP} = '/';
1619}
1620
1621
f1387719 1622=item init_main
1e44e2bf 1623
cf346138 1624Initializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
75e2e551 1625EXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
30361541 1626INSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
75e2e551 1627OBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
e0678a30 1628PERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
479d2113 1629VERSION_SYM, XS_VERSION.
f4ae0f5e 1630
f1387719 1631=cut
1e44e2bf 1632
f1387719
PP
1633sub init_main {
1634 my($self) = @_;
1e44e2bf 1635
f1387719 1636 # --- Initialize Module Name and Paths
1e44e2bf 1637
f1387719
PP
1638 # NAME = Foo::Bar::Oracle
1639 # FULLEXT = Foo/Bar/Oracle
1640 # BASEEXT = Oracle
f1387719
PP
1641 # PARENT_NAME = Foo::Bar
1642### Only UNIX:
1643### ($self->{FULLEXT} =
1644### $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
479d2113 1645 $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1e44e2bf 1646
1e44e2bf 1647
f1387719 1648 # Copied from DynaLoader:
1e44e2bf 1649
f1387719
PP
1650 my(@modparts) = split(/::/,$self->{NAME});
1651 my($modfname) = $modparts[-1];
1e44e2bf 1652
f1387719
PP
1653 # Some systems have restrictions on files names for DLL's etc.
1654 # mod2fname returns appropriate file base name (typically truncated)
1655 # It may also edit @modparts if required.
1656 if (defined &DynaLoader::mod2fname) {
1657 $modfname = &DynaLoader::mod2fname(\@modparts);
bab2b58e 1658 }
1e44e2bf 1659
4f44ac69 1660 ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
e0678a30 1661 $self->{PARENT_NAME} ||= '';
f1387719 1662
760ac839 1663 if (defined &DynaLoader::mod2fname) {
f1387719
PP
1664 # As of 5.001m, dl_os2 appends '_'
1665 $self->{DLBASE} = $modfname;
1666 } else {
1667 $self->{DLBASE} = '$(BASEEXT)';
1668 }
1669
1e44e2bf 1670
e0678a30 1671 # --- Initialize PERL_LIB, PERL_SRC
1e44e2bf 1672
f1387719
PP
1673 # *Real* information: where did we get these two from? ...
1674 my $inc_config_dir = dirname($INC{'Config.pm'});
1675 my $inc_carp_dir = dirname($INC{'Carp.pm'});
1e44e2bf 1676
f1387719
PP
1677 unless ($self->{PERL_SRC}){
1678 my($dir);
f6d6199c 1679 foreach $dir ($Updir,
479d2113
MS
1680 $self->catdir($Updir,$Updir),
1681 $self->catdir($Updir,$Updir,$Updir),
1682 $self->catdir($Updir,$Updir,$Updir,$Updir),
1683 $self->catdir($Updir,$Updir,$Updir,$Updir,$Updir))
f6d6199c 1684 {
f1387719 1685 if (
479d2113 1686 -f $self->catfile($dir,"config_h.SH")
f1387719 1687 &&
479d2113 1688 -f $self->catfile($dir,"perl.h")
f1387719 1689 &&
479d2113 1690 -f $self->catfile($dir,"lib","Exporter.pm")
f1387719
PP
1691 ) {
1692 $self->{PERL_SRC}=$dir ;
1693 last;
1694 }
1695 }
1696 }
e0678a30
MS
1697
1698 warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
1699 $self->{PERL_CORE} and !$self->{PERL_SRC};
1700
f1387719 1701 if ($self->{PERL_SRC}){
479d2113 1702 $self->{PERL_LIB} ||= $self->catdir("$self->{PERL_SRC}","lib");
1e44e2bf 1703
57b1a898
MS
1704 if (defined $Cross::platform) {
1705 $self->{PERL_ARCHLIB} =
479d2113 1706 $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform);
57b1a898 1707 $self->{PERL_INC} =
479d2113 1708 $self->catdir("$self->{PERL_SRC}","xlib",$Cross::platform,
57b1a898
MS
1709 $Is_Win32?("CORE"):());
1710 }
1711 else {
1712 $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1713 $self->{PERL_INC} = ($Is_Win32) ?
479d2113 1714 $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
57b1a898 1715 }
e2a02c1e 1716
137443ea 1717 # catch a situation that has occurred a few times in the past:
bab2b58e 1718 unless (
479d2113 1719 -s $self->catfile($self->{PERL_SRC},'cflags')
bab2b58e
AK
1720 or
1721 $Is_VMS
1722 &&
479d2113 1723 -s $self->catfile($self->{PERL_SRC},'perlshr_attr.opt')
bab2b58e
AK
1724 or
1725 $Is_Mac
137443ea
PP
1726 or
1727 $Is_Win32
bab2b58e
AK
1728 ){
1729 warn qq{
f1387719
PP
1730You cannot build extensions below the perl source tree after executing
1731a 'make clean' in the perl source tree.
1e44e2bf 1732
f1387719
PP
1733To rebuild extensions distributed with the perl source you should
1734simply Configure (to include those extensions) and then build perl as
1735normal. After installing perl the source tree can be deleted. It is
1736not needed for building extensions by running 'perl Makefile.PL'
1737usually without extra arguments.
1e44e2bf 1738
f1387719
PP
1739It is recommended that you unpack and build additional extensions away
1740from the perl source tree.
bab2b58e
AK
1741};
1742 }
f1387719
PP
1743 } else {
1744 # we should also consider $ENV{PERL5LIB} here
23614c1f 1745 my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
e0678a30
MS
1746 $self->{PERL_LIB} ||= $Config{privlibexp};
1747 $self->{PERL_ARCHLIB} ||= $Config{archlibexp};
479d2113 1748 $self->{PERL_INC} = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
f1387719 1749 my $perl_h;
23614c1f 1750
479d2113 1751 if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
23614c1f
JH
1752 and not $old){
1753 # Maybe somebody tries to build an extension with an
1754 # uninstalled Perl outside of Perl build tree
1755 my $found;
1756 for my $dir (@INC) {
479d2113 1757 $found = $dir, last if -e $self->catdir($dir, "Config.pm");
23614c1f
JH
1758 }
1759 if ($found) {
1760 my $inc = dirname $found;
479d2113 1761 if (-e $self->catdir($inc, "perl.h")) {
23614c1f
JH
1762 $self->{PERL_LIB} = $found;
1763 $self->{PERL_ARCHLIB} = $found;
1764 $self->{PERL_INC} = $inc;
1765 $self->{UNINSTALLED_PERL} = 1;
1766 print STDOUT <<EOP;
1767... Detected uninstalled Perl. Trying to continue.
1768EOP
1769 }
1770 }
a7d1454b 1771 }
f1387719 1772 }
1e44e2bf 1773
f1387719
PP
1774 # We get SITELIBEXP and SITEARCHEXP directly via
1775 # Get_from_Config. When we are running standard modules, these
1776 # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1777 # set it to "site". I prefer that INSTALLDIRS be set from outside
1778 # MakeMaker.
1779 $self->{INSTALLDIRS} ||= "site";
1e44e2bf 1780
e0678a30
MS
1781 $self->{MAN1EXT} ||= $Config{man1ext};
1782 $self->{MAN3EXT} ||= $Config{man3ext};
f1387719 1783
f1387719
PP
1784 # Get some stuff out of %Config if we haven't yet done so
1785 print STDOUT "CONFIG must be an array ref\n"
1786 if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1787 $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1788 push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
e0678a30 1789 push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
479d2113
MS
1790 my(%once_only);
1791 foreach my $m (@{$self->{CONFIG}}){
f1387719
PP
1792 next if $once_only{$m};
1793 print STDOUT "CONFIG key '$m' does not exist in Config.pm\n"
e0678a30
MS
1794 unless exists $Config{$m};
1795 $self->{uc $m} ||= $Config{$m};
f1387719 1796 $once_only{$m} = 1;
1e44e2bf 1797 }
1e44e2bf 1798
f1387719
PP
1799# This is too dangerous:
1800# if ($^O eq "next") {
1801# $self->{AR} = "libtool";
1802# $self->{AR_STATIC_ARGS} = "-o";
1803# }
1804# But I leave it as a placeholder
1e44e2bf 1805
f1387719 1806 $self->{AR_STATIC_ARGS} ||= "cr";
1e44e2bf 1807
f1387719 1808 # These should never be needed
f1387719
PP
1809 $self->{OBJ_EXT} ||= '.o';
1810 $self->{LIB_EXT} ||= '.a';
1811
1812 $self->{MAP_TARGET} ||= "perl";
1813
1814 $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1815
1816 # make a simple check if we find Exporter
1817 warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1818 (Exporter.pm not found)"
479d2113 1819 unless -f $self->catfile("$self->{PERL_LIB}","Exporter.pm") ||
f1387719 1820 $self->{NAME} eq "ExtUtils::MakeMaker";
1e44e2bf
PP
1821}
1822
f1387719 1823=item init_others
1e44e2bf 1824
60537fc0 1825Initializes EXTRALIBS, BSLOADLIBS, LDLOADLIBS, LIBS, LD_RUN_PATH, LD,
479d2113
MS
1826OBJECT, BOOTDEP, PERLMAINCC, LDFROM, LINKTYPE, SHELL, NOOP,
1827FIRST_MAKEFILE, MAKEFILE_OLD, NOECHO, RM_F, RM_RF, TEST_F,
e3aa3ecb 1828TOUCH, CP, MV, CHMOD, UMASK_NULL, ECHO, ECHO_N
1e44e2bf
PP
1829
1830=cut
1831
f1387719 1832sub init_others { # --- Initialize Other Attributes
1e44e2bf 1833 my($self) = shift;
1e44e2bf 1834
60537fc0 1835 $self->{LD} ||= 'ld';
30361541 1836
f1387719
PP
1837 # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self->{LIBS}
1838 # Lets look at $self->{LIBS} carefully: It may be an anon array, a string or
1839 # undefined. In any case we turn it into an anon array:
1e44e2bf 1840
f1387719 1841 # May check $Config{libs} too, thus not empty.
479d2113 1842 $self->{LIBS} = [$self->{LIBS}] unless ref $self->{LIBS};
f4ae0f5e 1843
479d2113 1844 $self->{LIBS} = [''] unless @{$self->{LIBS}} && defined $self->{LIBS}[0];
f1387719
PP
1845 $self->{LD_RUN_PATH} = "";
1846 my($libs);
1847 foreach $libs ( @{$self->{LIBS}} ){
1848 $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
1849 my(@libs) = $self->extliblist($libs);
1850 if ($libs[0] or $libs[1] or $libs[2]){
1851 # LD_RUN_PATH now computed by ExtUtils::Liblist
e0678a30
MS
1852 ($self->{EXTRALIBS}, $self->{BSLOADLIBS},
1853 $self->{LDLOADLIBS}, $self->{LD_RUN_PATH}) = @libs;
f1387719
PP
1854 last;
1855 }
1856 }
f4ae0f5e 1857
f1387719
PP
1858 if ( $self->{OBJECT} ) {
1859 $self->{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
1860 } else {
1861 # init_dirscan should have found out, if we have C files
1862 $self->{OBJECT} = "";
1863 $self->{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self->{C}||[]};
1e44e2bf 1864 }
f1387719
PP
1865 $self->{OBJECT} =~ s/\n+/ \\\n\t/g;
1866 $self->{BOOTDEP} = (-f "$self->{BASEEXT}_BS") ? "$self->{BASEEXT}_BS" : "";
1867 $self->{PERLMAINCC} ||= '$(CC)';
1868 $self->{LDFROM} = '$(OBJECT)' unless $self->{LDFROM};
1e44e2bf 1869
f1387719
PP
1870 # Sanity check: don't define LINKTYPE = dynamic if we're skipping
1871 # the 'dynamic' section of MM. We don't have this problem with
1872 # 'static', since we either must use it (%Config says we can't
1873 # use dynamic loading) or the caller asked for it explicitly.
1874 if (!$self->{LINKTYPE}) {
1875 $self->{LINKTYPE} = $self->{SKIPHASH}{'dynamic'}
1876 ? 'static'
e0678a30 1877 : ($Config{usedl} ? 'dynamic' : 'static');
f1387719
PP
1878 };
1879
479d2113
MS
1880 $self->{NOOP} ||= '$(SHELL) -c true';
1881 $self->{NOECHO} = '@' unless defined $self->{NOECHO};
1882
a7d1454b
RGS
1883 $self->{FIRST_MAKEFILE} ||= 'Makefile';
1884 $self->{MAKEFILE} ||= $self->{FIRST_MAKEFILE};
1885 $self->{MAKEFILE_OLD} ||= $self->{MAKEFILE}.'.old';
1886 $self->{MAKE_APERL_FILE} ||= $self->{MAKEFILE}.'.aperl';
479d2113
MS
1887
1888 $self->{SHELL} ||= $Config{sh} || '/bin/sh';
1889
1890 $self->{ECHO} ||= 'echo';
e3aa3ecb 1891 $self->{ECHO_N} ||= 'echo -n';
479d2113
MS
1892 $self->{RM_F} ||= "rm -f";
1893 $self->{RM_RF} ||= "rm -rf";
1894 $self->{TOUCH} ||= "touch";
1895 $self->{TEST_F} ||= "test -f";
1896 $self->{CP} ||= "cp";
1897 $self->{MV} ||= "mv";
1898 $self->{CHMOD} ||= "chmod";
1899 $self->{MKPATH} ||= '$(PERLRUN) "-MExtUtils::Command" -e mkpath';
1900 $self->{EQUALIZE_TIMESTAMP} ||=
1901 '$(PERLRUN) "-MExtUtils::Command" -e eqtime';
1902
1903 $self->{UNINST} ||= 0;
1904 $self->{VERBINST} ||= 0;
1905 $self->{MOD_INSTALL} ||=
1906 $self->oneliner(<<'CODE', ['-MExtUtils::Install']);
1907install({@ARGV}, '$(VERBINST)', 0, '$(UNINST)');
1908CODE
1909 $self->{DOC_INSTALL} ||=
1910 '$(PERLRUN) "-MExtUtils::Command::MM" -e perllocal_install';
1911 $self->{UNINSTALL} ||=
1912 '$(PERLRUN) "-MExtUtils::Command::MM" -e uninstall';
1913 $self->{WARN_IF_OLD_PACKLIST} ||=
1914 '$(PERLRUN) "-MExtUtils::Command::MM" -e warn_if_old_packlist';
1915
1916 $self->{UMASK_NULL} ||= "umask 0";
1917 $self->{DEV_NULL} ||= "> /dev/null 2>&1";
1918
1919 return 1;
1e44e2bf
PP
1920}
1921
e0678a30
MS
1922=item init_INST
1923
1924 $mm->init_INST;
1925
479d2113
MS
1926Called by init_main. Sets up all INST_* variables except those related
1927to XS code. Those are handled in init_xs.
e0678a30
MS
1928
1929=cut
1930
1931sub init_INST {
1932 my($self) = shift;
1933
479d2113
MS
1934 $self->{INST_ARCHLIB} ||= $self->catdir($Curdir,"blib","arch");
1935 $self->{INST_BIN} ||= $self->catdir($Curdir,'blib','bin');
e0678a30
MS
1936
1937 # INST_LIB typically pre-set if building an extension after
1938 # perl has been built and installed. Setting INST_LIB allows
1939 # you to build directly into, say $Config{privlibexp}.
1940 unless ($self->{INST_LIB}){
1941 if ($self->{PERL_CORE}) {
57b1a898
MS
1942 if (defined $Cross::platform) {
1943 $self->{INST_LIB} = $self->{INST_ARCHLIB} =
479d2113 1944 $self->catdir($self->{PERL_LIB},"..","xlib",
57b1a898
MS
1945 $Cross::platform);
1946 }
1947 else {
1948 $self->{INST_LIB} = $self->{INST_ARCHLIB} = $self->{PERL_LIB};
1949 }
e0678a30 1950 } else {
479d2113 1951 $self->{INST_LIB} = $self->catdir($Curdir,"blib","lib");
e0678a30
MS
1952 }
1953 }
1954
1955 my @parentdir = split(/::/, $self->{PARENT_NAME});
2530b651
MS
1956 $self->{INST_LIBDIR} = $self->catdir('$(INST_LIB)', @parentdir);
1957 $self->{INST_ARCHLIBDIR} = $self->catdir('$(INST_ARCHLIB)', @parentdir);
1958 $self->{INST_AUTODIR} = $self->catdir('$(INST_LIB)', 'auto',
1959 '$(FULLEXT)');
1960 $self->{INST_ARCHAUTODIR} = $self->catdir('$(INST_ARCHLIB)', 'auto',
1961 '$(FULLEXT)');
e0678a30 1962
2530b651 1963 $self->{INST_SCRIPT} ||= $self->catdir($Curdir,'blib','script');
e0678a30 1964
479d2113
MS
1965 $self->{INST_MAN1DIR} ||= $self->catdir($Curdir,'blib','man1');
1966 $self->{INST_MAN3DIR} ||= $self->catdir($Curdir,'blib','man3');
e0678a30
MS
1967
1968 return 1;
1969}
1970
1971=item init_INSTALL
1972
1973 $mm->init_INSTALL;
1974
1975Called by init_main. Sets up all INSTALL_* variables (except
479d2113 1976INSTALLDIRS) and *PREFIX.
e0678a30
MS
1977
1978=cut
1979
1980sub init_INSTALL {
1981 my($self) = shift;
1982
45bc4d3a 1983 $self->init_lib2arch;
e0678a30 1984
a7d1454b
RGS
1985 # There are often no Config.pm defaults for these new man variables so
1986 # we fall back to the old behavior which is to use installman*dir
1987 foreach my $num (1, 3) {
1988 my $k = 'installsiteman'.$num.'dir';
1989
1990 $self->{uc $k} ||= uc "\$(installman${num}dir)"
1991 unless $Config{$k};
1992 }
1993
5e719f03
MS
1994 foreach my $num (1, 3) {
1995 my $k = 'installvendorman'.$num.'dir';
1996
a7d1454b
RGS
1997 unless( $Config{$k} ) {
1998 $self->{uc $k} ||= $Config{usevendorprefix}
1999 ? uc "\$(installman${num}dir)"
2000 : '';
5e719f03 2001 }
45bc4d3a
JH
2002 }
2003
a7d1454b
RGS
2004 $self->{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
2005 unless $Config{installsitebin};
2006
2007 unless( $Config{installvendorbin} ) {
2008 $self->{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
2009 ? $Config{installbin}
2010 : '';
2011 }
2012
2013
45bc4d3a
JH
2014 my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
2015 $Config{prefixexp} || $Config{prefix} || '';
2016 my $vprefix = $Config{usevendorprefix} ? $Config{vendorprefixexp} : '';
5c161494
MS
2017 my $sprefix = $Config{siteprefixexp} || '';
2018
57b1a898
MS
2019 # 5.005_03 doesn't have a siteprefix.
2020 $sprefix = $iprefix unless $sprefix;
2021
57b1a898 2022
479d2113
MS
2023 $self->{PREFIX} ||= '';
2024
2025 if( $self->{PREFIX} ) {
2026 @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
2027 ('$(PREFIX)') x 3;
2028 }
2029 else {
2030 $self->{PERLPREFIX} ||= $iprefix;
2031 $self->{SITEPREFIX} ||= $sprefix;
2032 $self->{VENDORPREFIX} ||= $vprefix;
a7d1454b
RGS
2033
2034 # Lots of MM extension authors like to use $(PREFIX) so we
2035 # put something sensible in there no matter what.
2036 $self->{PREFIX} = '$('.uc $self->{INSTALLDIRS}.'PREFIX)';
479d2113 2037 }
5c161494 2038
5c161494
MS
2039 my $arch = $Config{archname};
2040 my $version = $Config{version};
2041
2042 # default style
479d2113 2043 my $libstyle = $Config{installstyle} || 'lib/perl5';
5c161494
MS
2044 my $manstyle = '';
2045
2046 if( $self->{LIBSTYLE} ) {
2047 $libstyle = $self->{LIBSTYLE};
2048 $manstyle = $self->{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
2049 }
2050
45bc4d3a
JH
2051 # Some systems, like VOS, set installman*dir to '' if they can't
2052 # read man pages.
2053 for my $num (1, 3) {
2054 $self->{'INSTALLMAN'.$num.'DIR'} ||= 'none'
2055 unless $Config{'installman'.$num.'dir'};
2056 }
2057
5c161494
MS
2058 my %bin_layouts =
2059 (
2060 bin => { s => $iprefix,
479d2113 2061 t => 'perl',
5c161494
MS
2062 d => 'bin' },
2063 vendorbin => { s => $vprefix,
479d2113 2064 t => 'vendor',
5c161494
MS
2065 d => 'bin' },
2066 sitebin => { s => $sprefix,
479d2113 2067 t => 'site',
5c161494
MS
2068 d => 'bin' },
2069 script => { s => $iprefix,
479d2113 2070 t => 'perl',
5c161494
MS
2071 d => 'bin' },
2072 );
2073
2074 my %man_layouts =
2075 (
2076 man1dir => { s => $iprefix,
479d2113
MS
2077 t => 'perl',
2078 d => 'man/man1',
5c161494
MS
2079 style => $manstyle, },
2080 siteman1dir => { s => $sprefix,
479d2113
MS
2081 t => 'site',
2082 d => 'man/man1',
5c161494
MS
2083 style => $manstyle, },
2084 vendorman1dir => { s => $vprefix,
479d2113
MS
2085 t => 'vendor',
2086 d => 'man/man1',
5c161494
MS
2087 style => $manstyle, },
2088
2089 man3dir => { s => $iprefix,
479d2113
MS
2090 t => 'perl',
2091 d => 'man/man3',
5c161494
MS
2092 style => $manstyle, },
2093 siteman3dir => { s => $sprefix,
479d2113
MS
2094 t => 'site',
2095 d => 'man/man3',
5c161494
MS
2096 style => $manstyle, },
2097 vendorman3dir => { s => $vprefix,
479d2113
MS
2098 t => 'vendor',
2099 d => 'man/man3',
5c161494
MS
2100 style => $manstyle, },
2101 );
2102
2103 my %lib_layouts =
2104 (
2105 privlib => { s => $iprefix,
479d2113 2106 t => 'perl',
5c161494
MS
2107 d => '',
2108 style => $libstyle, },
2109 vendorlib => { s => $vprefix,
479d2113 2110 t => 'vendor',
5c161494
MS
2111 d => '',
2112 style => $libstyle, },
2113 sitelib => { s => $sprefix,
479d2113 2114 t => 'site',
5c161494
MS
2115 d => 'site_perl',
2116 style => $libstyle, },
2117
2118 archlib => { s => $iprefix,
479d2113 2119 t => 'perl',
5c161494
MS
2120 d => "$version/$arch",
2121 style => $libstyle },
2122 vendorarch => { s => $vprefix,
479d2113 2123 t => 'vendor',
5c161494
MS
2124 d => "$version/$arch",
2125 style => $libstyle },
2126 sitearch => { s => $sprefix,
479d2113 2127 t => 'site',
5c161494
MS
2128 d => "site_perl/$version/$arch",
2129 style => $libstyle },
2130 );
2131
2132
2133 # Special case for LIB.
2134 if( $self->{LIB} ) {
2135 foreach my $var (keys %lib_layouts) {
2136 my $Installvar = uc "install$var";
2137
2138 if( $var =~ /arch/ ) {
2139 $self->{$Installvar} ||=
479d2113 2140 $self->catdir($self->{LIB}, $Config{archname});
5c161494
MS
2141 }
2142 else {
2143 $self->{$Installvar} ||= $self->{LIB};
2144 }
2145 }
e0678a30
MS
2146 }
2147
479d2113
MS
2148 my %type2prefix = ( perl => 'PERLPREFIX',
2149 site => 'SITEPREFIX',
2150 vendor => 'VENDORPREFIX'
2151 );
e0678a30 2152
5c161494
MS
2153 my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
2154 while( my($var, $layout) = each(%layouts) ) {
479d2113
MS
2155 my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
2156 my $r = '$('.$type2prefix{$t}.')';
5c161494
MS
2157
2158 print STDERR "Prefixing $var\n" if $Verbose >= 2;
2159
2160 my $installvar = "install$var";
2161 my $Installvar = uc $installvar;
2162 next if $self->{$Installvar};
2163
479d2113
MS
2164 $d = "$style/$d" if $style;
2165 $self->prefixify($installvar, $s, $r, $d);
5c161494
MS
2166
2167 print STDERR " $Installvar == $self->{$Installvar}\n"
2168 if $Verbose >= 2;
e0678a30 2169 }
5c161494 2170
479d2113
MS
2171 # Generate these if they weren't figured out.
2172 $self->{VENDORARCHEXP} ||= $self->{INSTALLVENDORARCH};
2173 $self->{VENDORLIBEXP} ||= $self->{INSTALLVENDORLIB};
2174
e0678a30
MS
2175 return 1;
2176}
2177
479d2113
MS
2178=item init_linker
2179
2180Unix has no need of special linker flags.
2181
2182=cut
2183
2184sub init_linker {
2185 my($self) = shift;
2186 $self->{PERL_ARCHIVE} ||= '';
2187 $self->{PERL_ARCHIVE_AFTER} ||= '';
2188 $self->{EXPORT_LIST} ||= '';
2189}
2190
2191
45bc4d3a
JH
2192=begin _protected
2193
2194=item init_lib2arch
2195
2196 $mm->init_lib2arch
2197
2198=end _protected
2199
2200=cut
2201
2202sub init_lib2arch {
2203 my($self) = shift;
2204
2205 # The user who requests an installation directory explicitly
2206 # should not have to tell us an architecture installation directory
2207 # as well. We look if a directory exists that is named after the
2208 # architecture. If not we take it as a sign that it should be the
2209 # same as the requested installation directory. Otherwise we take
2210 # the found one.
2211 for my $libpair ({l=>"privlib", a=>"archlib"},
2212 {l=>"sitelib", a=>"sitearch"},
2213 {l=>"vendorlib", a=>"vendorarch"},
2214 )
2215 {
2216 my $lib = "install$libpair->{l}";
2217 my $Lib = uc $lib;
2218 my $Arch = uc "install$libpair->{a}";
2219 if( $self->{$Lib} && ! $self->{$Arch} ){
2220 my($ilib) = $Config{$lib};
2221
2222 $self->prefixify($Arch,$ilib,$self->{$Lib});
2223
2224 unless (-d $self->{$Arch}) {
2225 print STDOUT "Directory $self->{$Arch} not found\n"
2226 if $Verbose;
2227 $self->{$Arch} = $self->{$Lib};
2228 }
2229 print STDOUT "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
2230 }
2231 }
2232}
2233
5c161494 2234
75e2e551
MS
2235=item init_PERL
2236
e0678a30 2237 $mm->init_PERL;
75e2e551 2238
e0678a30
MS
2239Called by init_main. Sets up ABSPERL, PERL, FULLPERL and all the
2240*PERLRUN* permutations.
75e2e551
MS
2241
2242 PERL is allowed to be miniperl
2243 FULLPERL must be a complete perl
479d2113 2244
e0678a30 2245 ABSPERL is PERL converted to an absolute path
75e2e551
MS
2246
2247 *PERLRUN contains everything necessary to run perl, find it's
2248 libraries, etc...
2249
2250 *PERLRUNINST is *PERLRUN + everything necessary to find the
2251 modules being built.
2252
2253=cut
2254
2255sub init_PERL {
2256 my($self) = shift;
2257
2258 my @defpath = ();
2259 foreach my $component ($self->{PERL_SRC}, $self->path(),
e0678a30 2260 $Config{binexp})
75e2e551
MS
2261 {
2262 push @defpath, $component if defined $component;
2263 }
2264
2265 # Build up a set of file names (not command names).
479d2113 2266 my $thisperl = $self->canonpath($^X);
30361541
JH
2267 $thisperl .= $Config{exe_ext} unless
2268 # VMS might have a file version # at the end
2269 $Is_VMS ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
2270 : $thisperl =~ m/$Config{exe_ext}$/i;
479d2113
MS
2271
2272 # We need a relative path to perl when in the core.
2273 $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
2274
75e2e551
MS
2275 my @perls = ($thisperl);
2276 push @perls, map { "$_$Config{exe_ext}" }
2277 ('perl', 'perl5', "perl$Config{version}");
2278
2279 # miniperl has priority over all but the cannonical perl when in the
2280 # core. Otherwise its a last resort.
2281 my $miniperl = "miniperl$Config{exe_ext}";
2282 if( $self->{PERL_CORE} ) {
2283 splice @perls, 1, 0, $miniperl;
2284 }
2285 else {
2286 push @perls, $miniperl;
2287 }
2288
2289 $self->{PERL} ||=
2290 $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
2291 # don't check if perl is executable, maybe they have decided to
2292 # supply switches with perl
2293
30361541
JH
2294 # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
2295 my $perl_name = 'perl';
2296 $perl_name = 'ndbgperl' if $Is_VMS &&
2297 defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
2298
2299 # XXX This logic is flawed. If "miniperl" is anywhere in the path
2300 # it will get confused. It should be fixed to work only on the filename.
75e2e551 2301 # Define 'FULLPERL' to be a non-miniperl (used in test: target)
30361541 2302 ($self->{FULLPERL} = $self->{PERL}) =~ s/miniperl/$perl_name/i
75e2e551
MS
2303 unless $self->{FULLPERL};
2304
e0678a30
MS
2305 # Little hack to get around VMS's find_perl putting "MCR" in front
2306 # sometimes.
2307 $self->{ABSPERL} = $self->{PERL};
2308 my $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
479d2113 2309 if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
e0678a30
MS
2310 $self->{ABSPERL} = '$(PERL)';
2311 }
2312 else {
479d2113 2313 $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
e0678a30
MS
2314 $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
2315 }
2316
75e2e551
MS
2317 # Are we building the core?
2318 $self->{PERL_CORE} = 0 unless exists $self->{PERL_CORE};
2319
2320 # How do we run perl?
e0678a30 2321 foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
479d2113
MS
2322 my $run = $perl.'RUN';
2323
2324 $self->{$run} = "\$($perl)";
75e2e551
MS
2325
2326 # Make sure perl can find itself before it's installed.
479d2113 2327 $self->{$run} .= q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"}
75e2e551
MS
2328 if $self->{UNINSTALLED_PERL} || $self->{PERL_CORE};
2329
2330 $self->{$perl.'RUNINST'} =
e0678a30 2331 sprintf q{$(%sRUN) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"}, $perl;
75e2e551
MS
2332 }
2333
2334 return 1;
2335}
2336
479d2113
MS
2337
2338=item init_platform (o)
2339
2340Add MM_Unix_VERSION.
2341
2342=item platform_constants (o)
2343
2344=cut
2345
2346sub init_platform {
2347 my($self) = shift;
2348
2349 $self->{MM_Unix_VERSION} = $VERSION;
2350 $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
2351 '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
2352 '-Dcalloc=Perl_calloc';
2353
2354}
2355
2356sub platform_constants {
2357 my($self) = shift;
2358 my $make_frag = '';
2359
2360 foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
2361 {
2362 next unless defined $self->{$macro};
2363 $make_frag .= "$macro = $self->{$macro}\n";
2364 }
2365
2366 return $make_frag;
2367}
2368
2369
e0678a30
MS
2370=item init_PERM
2371
2372 $mm->init_PERM
2373
2374Called by init_main. Initializes PERL_*
2375
2376=cut
2377
2378sub init_PERM {
2379 my($self) = shift;
2380
479d2113
MS
2381 $self->{PERM_RW} = 644 unless defined $self->{PERM_RW};
2382 $self->{PERM_RWX} = 755 unless defined $self->{PERM_RWX};
e0678a30
MS
2383
2384 return 1;
2385}
479d2113
MS
2386
2387
2388=item init_xs
2389
2390 $mm->init_xs
2391
2392Sets up macros having to do with XS code. Currently just INST_STATIC,
2393INST_DYNAMIC and INST_BOOT.
2394
2395=cut
2396
2397sub init_xs {
2398 my $self = shift;
2399
2400 if ($self->has_link_code()) {
2401 $self->{INST_STATIC} =
2402 $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2403 $self->{INST_DYNAMIC} =
2404 $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2405 $self->{INST_BOOT} =
2406 $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
2407 } else {
2408 $self->{INST_STATIC} = '';
2409 $self->{INST_DYNAMIC} = '';
2410 $self->{INST_BOOT} = '';
2411 }
2412}
75e2e551 2413
f1387719 2414=item install (o)
1e44e2bf 2415
f1387719 2416Defines the install target.
1e44e2bf
PP
2417
2418=cut
2419
f1387719
PP
2420sub install {
2421 my($self, %attribs) = @_;
1e44e2bf 2422 my(@m);
a5f75d66 2423
f1387719
PP
2424 push @m, q{
2425install :: all pure_install doc_install
1e44e2bf 2426
f1387719 2427install_perl :: all pure_perl_install doc_perl_install
1e44e2bf 2428
f1387719 2429install_site :: all pure_site_install doc_site_install
1e44e2bf 2430
5c161494
MS
2431install_vendor :: all pure_vendor_install doc_vendor_install
2432
f1387719 2433pure_install :: pure_$(INSTALLDIRS)_install
1e44e2bf 2434
f1387719 2435doc_install :: doc_$(INSTALLDIRS)_install
1e44e2bf 2436
f1387719 2437pure__install : pure_site_install
479d2113 2438 $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1e44e2bf 2439
f1387719 2440doc__install : doc_site_install
479d2113 2441 $(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
1e44e2bf 2442
f1387719 2443pure_perl_install ::
479d2113
MS
2444 $(NOECHO) $(MOD_INSTALL) \
2445 read }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
5e719f03
MS
2446 write }.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{ \
2447 $(INST_LIB) $(DESTINSTALLPRIVLIB) \
2448 $(INST_ARCHLIB) $(DESTINSTALLARCHLIB) \
2449 $(INST_BIN) $(DESTINSTALLBIN) \
2450 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
2451 $(INST_MAN1DIR) $(DESTINSTALLMAN1DIR) \
2452 $(INST_MAN3DIR) $(DESTINSTALLMAN3DIR)
479d2113
MS
2453 $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2454 }.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{
1e44e2bf 2455
1e44e2bf 2456
f1387719 2457pure_site_install ::
479d2113
MS
2458 $(NOECHO) $(MOD_INSTALL) \
2459 read }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
5e719f03
MS
2460 write }.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{ \
2461 $(INST_LIB) $(DESTINSTALLSITELIB) \
2462 $(INST_ARCHLIB) $(DESTINSTALLSITEARCH) \
2463 $(INST_BIN) $(DESTINSTALLSITEBIN) \
2464 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
2465 $(INST_MAN1DIR) $(DESTINSTALLSITEMAN1DIR) \
2466 $(INST_MAN3DIR) $(DESTINSTALLSITEMAN3DIR)
479d2113
MS
2467 $(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2468 }.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{
1e44e2bf 2469
5c161494 2470pure_vendor_install ::
479d2113
MS
2471 $(NOECHO) $(MOD_INSTALL) \
2472 read }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{ \
5e719f03
MS
2473 write }.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{ \
2474 $(INST_LIB) $(DESTINSTALLVENDORLIB) \
2475 $(INST_ARCHLIB) $(DESTINSTALLVENDORARCH) \
2476 $(INST_BIN) $(DESTINSTALLVENDORBIN) \
2477 $(INST_SCRIPT) $(DESTINSTALLSCRIPT) \
2478 $(INST_MAN1DIR) $(DESTINSTALLVENDORMAN1DIR) \
2479 $(INST_MAN3DIR) $(DESTINSTALLVENDORMAN3DIR)
5c161494 2480
f1387719 2481doc_perl_install ::
5e719f03
MS
2482 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2483 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
479d2113 2484 -$(NOECHO) $(DOC_INSTALL) \
dbc738d9 2485 "Module" "$(NAME)" \
f1387719
PP
2486 "installed into" "$(INSTALLPRIVLIB)" \
2487 LINKTYPE "$(LINKTYPE)" \
2488 VERSION "$(VERSION)" \
2489 EXE_FILES "$(EXE_FILES)" \
5e719f03 2490 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
1e44e2bf 2491
f1387719 2492doc_site_install ::
5e719f03
MS
2493 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2494 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
479d2113 2495 -$(NOECHO) $(DOC_INSTALL) \
dbc738d9 2496 "Module" "$(NAME)" \
f1387719
PP
2497 "installed into" "$(INSTALLSITELIB)" \
2498 LINKTYPE "$(LINKTYPE)" \
2499 VERSION "$(VERSION)" \
2500 EXE_FILES "$(EXE_FILES)" \
5e719f03 2501 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
5c161494
MS
2502
2503doc_vendor_install ::
5e719f03
MS
2504 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2505 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
479d2113
MS
2506 -$(NOECHO) $(DOC_INSTALL) \
2507 "Module" "$(NAME)" \
2508 "installed into" "$(INSTALLVENDORLIB)" \
2509 LINKTYPE "$(LINKTYPE)" \
2510 VERSION "$(VERSION)" \
2511 EXE_FILES "$(EXE_FILES)" \
5e719f03 2512 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
1e44e2bf 2513
f1387719 2514};
1e44e2bf 2515
f1387719
PP
2516 push @m, q{
2517uninstall :: uninstall_from_$(INSTALLDIRS)dirs
f4ae0f5e 2518
f1387719 2519uninstall_from_perldirs ::
479d2113 2520 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{
1e44e2bf 2521
f1387719 2522uninstall_from_sitedirs ::
479d2113
MS
2523 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{
2524
2525uninstall_from_vendordirs ::
2526 $(NOECHO) $(UNINSTALL) }.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{
f1387719 2527};
1e44e2bf 2528
f1387719
PP
2529 join("",@m);
2530}
1e44e2bf 2531
f1387719 2532=item installbin (o)
1e44e2bf 2533
85fe4bb3 2534Defines targets to make and to install EXE_FILES.
1e44e2bf 2535
f1387719 2536=cut
1e44e2bf 2537
f1387719
PP
2538sub installbin {
2539 my($self) = shift;
2540 return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
2541 return "" unless @{$self->{EXE_FILES}};
2542 my(@m, $from, $to, %fromto, @to);
f1387719 2543 for $from (@{$self->{EXE_FILES}}) {
479d2113 2544 my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
f1387719
PP
2545 local($_) = $path; # for backwards compatibility
2546 $to = $self->libscan($path);
2547 print "libscan($from) => '$to'\n" if ($Verbose >=2);
2548 $fromto{$from}=$to;
2549 }
2550 @to = values %fromto;
64964e6d
JH
2551
2552 my $fixin;
2553 if( $Is_Win32 ) {
2554 $fixin = $self->{PERL_CORE} ? '$(PERLRUN) ../../win32/bin/pl2bat.pl'
2555 : 'pl2bat.bat';
2556 }
2557 else {
2558 $fixin = q{$(PERLRUN) "-MExtUtils::MY" -e "MY->fixin(shift)"};
2559 }
2560
84902520 2561 push(@m, qq{
f1387719 2562EXE_FILES = @{$self->{EXE_FILES}}
1e44e2bf 2563
64964e6d
JH
2564FIXIN = $fixin
2565
85fe4bb3 2566pure_all :: @to
479d2113 2567 \$(NOECHO) \$(NOOP)
1e44e2bf 2568
f1387719 2569realclean ::
479d2113 2570 \$(RM_F) @to
84902520 2571});
1e44e2bf 2572
f1387719
PP
2573 while (($from,$to) = each %fromto) {
2574 last unless defined $from;
2575 my $todir = dirname($to);
2576 push @m, "
a7d1454b 2577$to: $from \$(FIRST_MAKEFILE) blibdirs
479d2113
MS
2578 \$(NOECHO) \$(RM_F) $to
2579 \$(CP) $from $to
84902520 2580 \$(FIXIN) $to
479d2113 2581 -\$(NOECHO) \$(CHMOD) \$(PERM_RWX) $to
f1387719 2582";
1e44e2bf 2583 }
f1387719
PP
2584 join "", @m;
2585}
1e44e2bf 2586
1e44e2bf 2587
f4ae0f5e 2588=item linkext (o)
1e44e2bf 2589
f4ae0f5e 2590Defines the linkext target which in turn defines the LINKTYPE.
1e44e2bf
PP
2591
2592=cut
2593
2594sub linkext {
2595 my($self, %attribs) = @_;
1e44e2bf
PP
2596 # LINKTYPE => static or dynamic or ''
2597 my($linktype) = defined $attribs{LINKTYPE} ?
2598 $attribs{LINKTYPE} : '$(LINKTYPE)';
2599 "
2600linkext :: $linktype
479d2113 2601 \$(NOECHO) \$(NOOP)
1e44e2bf
PP
2602";
2603}
2604
f1387719 2605=item lsdir
1e44e2bf 2606
f1387719
PP
2607Takes as arguments a directory name and a regular expression. Returns
2608all entries in the directory that match the regular expression.
1e44e2bf
PP
2609
2610=cut
2611
f1387719
PP
2612sub lsdir {
2613 my($self) = shift;
2614 my($dir, $regex) = @_;
2615 my(@ls);
2616 my $dh = new DirHandle;
2617 $dh->open($dir || ".") or return ();
2618 @ls = $dh->read;
2619 $dh->close;
2620 @ls = grep(/$regex/, @ls) if $regex;
2621 @ls;
2622}
2623
2624=item macro (o)
2625
2626Simple subroutine to insert the macros defined by the macro attribute
2627into the Makefile.
2628
2629=cut
2630
2631sub macro {
1e44e2bf 2632 my($self,%attribs) = @_;
f1387719
PP
2633 my(@m,$key,$val);
2634 while (($key,$val) = each %attribs){
2635 last unless defined $key;
2636 push @m, "$key = $val\n";
1e44e2bf 2637 }
f1387719
PP
2638 join "", @m;
2639}
1e44e2bf 2640
f1387719 2641=item makeaperl (o)
1e44e2bf 2642
f1387719
PP
2643Called by staticmake. Defines how to write the Makefile to produce a
2644static new perl.
2645
55497cff
PP
2646By default the Makefile produced includes all the static extensions in
2647the perl library. (Purified versions of library files, e.g.,
2648DynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2649
f1387719
PP
2650=cut
2651
2652sub makeaperl {
2653 my($self, %attribs) = @_;
2654 my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2655 @attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
1e44e2bf 2656 my(@m);
f1387719
PP
2657 push @m, "
2658# --- MakeMaker makeaperl section ---
2659MAP_TARGET = $target
2660FULLPERL = $self->{FULLPERL}
2661";
2662 return join '', @m if $self->{PARENT};
1e44e2bf 2663
f1387719 2664 my($dir) = join ":", @{$self->{DIR}};
1e44e2bf 2665
f1387719
PP
2666 unless ($self->{MAKEAPERL}) {
2667 push @m, q{
2668$(MAP_TARGET) :: static $(MAKE_APERL_FILE)
2669 $(MAKE) -f $(MAKE_APERL_FILE) $@
1e44e2bf 2670
f1387719 2671$(MAKE_APERL_FILE) : $(FIRST_MAKEFILE)
479d2113
MS
2672 $(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2673 $(NOECHO) $(PERLRUNINST) \
f1387719 2674 Makefile.PL DIR=}, $dir, q{ \
2530b651 2675 MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
f1387719 2676 MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
1e44e2bf 2677
f1387719
PP
2678 foreach (@ARGV){
2679 if( /\s/ ){
2680 s/=(.*)/='$1'/;
2681 }
2682 push @m, " \\\n\t\t$_";
2683 }
2684# push @m, map( " \\\n\t\t$_", @ARGV );
2685 push @m, "\n";
1e44e2bf 2686
f1387719
PP
2687 return join '', @m;
2688 }
1e44e2bf 2689
1e44e2bf 2690
1e44e2bf 2691
f1387719 2692 my($cccmd, $linkcmd, $lperl);
1e44e2bf 2693
1e44e2bf 2694
f1387719
PP
2695 $cccmd = $self->const_cccmd($libperl);
2696 $cccmd =~ s/^CCCMD\s*=\s*//;
f6d6199c 2697 $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
e0678a30
MS
2698 $cccmd .= " $Config{cccdlflags}"
2699 if ($Config{useshrplib} eq 'true');
f1387719 2700 $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
1e44e2bf 2701
f1387719
PP
2702 # The front matter of the linkcommand...
2703 $linkcmd = join ' ', "\$(CC)",
5869b1f1 2704 grep($_, @Config{qw(ldflags ccdlflags)});
f1387719 2705 $linkcmd =~ s/\s+/ /g;
93f9cb4b 2706 $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
1e44e2bf 2707
f1387719
PP
2708 # Which *.a files could we make use of...
2709 local(%static);
2710 require File::Find;
2711 File::Find::find(sub {
2712 return unless m/\Q$self->{LIB_EXT}\E$/;
2713 return if m/^libperl/;
55497cff
PP
2714 # Skip purified versions of libraries (e.g., DynaLoader_pure_p1_c0_032.a)
2715 return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
1e44e2bf 2716
f1387719
PP
2717 if( exists $self->{INCLUDE_EXT} ){
2718 my $found = 0;
2719 my $incl;
2720 my $xx;
2721
4f44ac69 2722 ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
f1387719
PP
2723 $xx =~ s,/?$_,,;
2724 $xx =~ s,/,::,g;
2725
2726 # Throw away anything not explicitly marked for inclusion.
2727 # DynaLoader is implied.
2728 foreach $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2729 if( $xx eq $incl ){
2730 $found++;
2731 last;
2732 }
2733 }
2734 return unless $found;
2735 }
2736 elsif( exists $self->{EXCLUDE_EXT} ){
2737 my $excl;
2738 my $xx;
1e44e2bf 2739
4f44ac69 2740 ($xx = $File::Find::name) =~ s,.*?/auto/,,s;
f1387719
PP
2741 $xx =~ s,/?$_,,;
2742 $xx =~ s,/,::,g;
1e44e2bf 2743
f1387719
PP
2744 # Throw away anything explicitly marked for exclusion
2745 foreach $excl (@{$self->{EXCLUDE_EXT}}){
2746 return if( $xx eq $excl );
2747 }
2748 }
2749
2750 # don't include the installed version of this extension. I
2751 # leave this line here, although it is not necessary anymore:
2752 # I patched minimod.PL instead, so that Miniperl.pm won't
2753 # enclude duplicates
2754
2755 # Once the patch to minimod.PL is in the distribution, I can
2756 # drop it
4f44ac69 2757 return if $File::Find::name =~ m:auto/$self->{FULLEXT}/$self->{BASEEXT}$self->{LIB_EXT}\z:;
f1387719
PP
2758 use Cwd 'cwd';
2759 $static{cwd() . "/" . $_}++;
2760 }, grep( -d $_, @{$searchdirs || []}) );
2761
2762 # We trust that what has been handed in as argument, will be buildable
2763 $static = [] unless $static;
2764 @static{@{$static}} = (1) x @{$static};
2765
2766 $extra = [] unless $extra && ref $extra eq 'ARRAY';
2767 for (sort keys %static) {
4f44ac69 2768 next unless /\Q$self->{LIB_EXT}\E\z/;
f1387719
PP
2769 $_ = dirname($_) . "/extralibs.ld";
2770 push @$extra, $_;
1e44e2bf 2771 }
1e44e2bf 2772
f6d6199c 2773 grep(s/^(.*)/"-I$1"/, @{$perlinc || []});
1e44e2bf 2774
f6d6199c
MS
2775 $target ||= "perl";
2776 $tmp ||= ".";
1e44e2bf 2777
f1387719
PP
2778# MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
2779# regenerate the Makefiles, MAP_STATIC and the dependencies for
2780# extralibs.all are computed correctly
2781 push @m, "
2782MAP_LINKCMD = $linkcmd
2783MAP_PERLINC = @{$perlinc || []}
2784MAP_STATIC = ",
2785join(" \\\n\t", reverse sort keys %static), "
1e44e2bf 2786
e0678a30 2787MAP_PRELIBS = $Config{perllibs} $Config{cryptlib}
f1387719
PP
2788";
2789
2790 if (defined $libperl) {
2791 ($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
2792 }
2793 unless ($libperl && -f $lperl) { # Ilya's code...
2794 my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
3f73c567 2795 $dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
f1387719
PP
2796 $libperl ||= "libperl$self->{LIB_EXT}";
2797 $libperl = "$dir/$libperl";
2798 $lperl ||= "libperl$self->{LIB_EXT}";
2799 $lperl = "$dir/$lperl";
ff0cee69
PP
2800
2801 if (! -f $libperl and ! -f $lperl) {
2802 # We did not find a static libperl. Maybe there is a shared one?
479d2113 2803 if ($Is_SunOS) {
e0678a30 2804 $lperl = $libperl = "$dir/$Config{libperl}";
ff0cee69 2805 # SUNOS ld does not take the full path to a shared library
479d2113 2806 $libperl = '' if $Is_SunOS4;
ff0cee69
PP
2807 }
2808 }
2809
f1387719
PP
2810 print STDOUT "Warning: $libperl not found
2811 If you're going to build a static perl binary, make sure perl is installed
2812 otherwise ignore this warning\n"
2813 unless (-f $lperl || defined($self->{PERL_SRC}));
2814 }
1e44e2bf 2815
e0678a30
MS
2816 # SUNOS ld does not take the full path to a shared library
2817 my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
2818
f1387719
PP
2819 push @m, "
2820MAP_LIBPERL = $libperl
e0678a30 2821LLIBPERL = $llibperl
f1387719 2822";
1e44e2bf 2823
f1387719 2824 push @m, "
a7d1454b 2825\$(INST_ARCHAUTODIR)/extralibs.all: blibdirs ".join(" \\\n\t", @$extra).'
479d2113
MS
2826 $(NOECHO) $(RM_F) $@
2827 $(NOECHO) $(TOUCH) $@
2828';
1e44e2bf 2829
f1387719
PP
2830 my $catfile;
2831 foreach $catfile (@$extra){
2832 push @m, "\tcat $catfile >> \$\@\n";
1e44e2bf 2833 }
1e44e2bf 2834
ff0cee69 2835push @m, "
f1387719 2836\$(MAP_TARGET) :: $tmp/perlmain\$(OBJ_EXT) \$(MAP_LIBPERL) \$(MAP_STATIC) \$(INST_ARCHAUTODIR)/extralibs.all
e0678a30 2837 \$(MAP_LINKCMD) -o \$\@ \$(OPTIMIZE) $tmp/perlmain\$(OBJ_EXT) \$(LDFROM) \$(MAP_STATIC) \$(LLIBPERL) `cat \$(INST_ARCHAUTODIR)/extralibs.all` \$(MAP_PRELIBS)
479d2113
MS
2838 \$(NOECHO) \$(ECHO) 'To install the new \"\$(MAP_TARGET)\" binary, call'
2839 \$(NOECHO) \$(ECHO) ' make -f $makefilename inst_perl MAP_TARGET=\$(MAP_TARGET)'
2840 \$(NOECHO) \$(ECHO) 'To remove the intermediate files say'
2841 \$(NOECHO) \$(ECHO) ' make -f $makefilename map_clean'
1e44e2bf 2842
f1387719
PP
2843$tmp/perlmain\$(OBJ_EXT): $tmp/perlmain.c
2844";
f6d6199c 2845 push @m, qq{\tcd $tmp && $cccmd "-I\$(PERL_INC)" perlmain.c\n};
1e44e2bf 2846
f1387719
PP
2847 push @m, qq{
2848$tmp/perlmain.c: $makefilename}, q{
479d2113
MS
2849 $(NOECHO) $(ECHO) Writing $@
2850 $(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \\
4f44ac69 2851 -e "writemain(grep s#.*/auto/##s, split(q| |, q|$(MAP_STATIC)|))" > $@t && $(MV) $@t $@
1e44e2bf 2852
f1387719 2853};
479d2113 2854 push @m, "\t", q{$(NOECHO) $(PERL) $(INSTALLSCRIPT)/fixpmain
39e571d4
ML
2855} if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
2856
1e44e2bf 2857
f1387719
PP
2858 push @m, q{
2859doc_inst_perl:
5e719f03
MS
2860 $(NOECHO) $(ECHO) Appending installation info to $(DESTINSTALLARCHLIB)/perllocal.pod
2861 -$(NOECHO) $(MKPATH) $(DESTINSTALLARCHLIB)
479d2113 2862 -$(NOECHO) $(DOC_INSTALL) \
dbc738d9 2863 "Perl binary" "$(MAP_TARGET)" \
f1387719
PP
2864 MAP_STATIC "$(MAP_STATIC)" \
2865 MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
2866 MAP_LIBPERL "$(MAP_LIBPERL)" \
5e719f03 2867 >> }.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{
1e44e2bf 2868
f1387719 2869};
1e44e2bf 2870
f1387719
PP
2871 push @m, q{
2872inst_perl: pure_inst_perl doc_inst_perl
1e44e2bf 2873
f1387719 2874pure_inst_perl: $(MAP_TARGET)
5e719f03 2875 }.$self->{CP}.q{ $(MAP_TARGET) }.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{
1e44e2bf 2876
f1387719
PP
2877clean :: map_clean
2878
2879map_clean :
2880 }.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
2881};
2882
2883 join '', @m;
1e44e2bf
PP
2884}
2885
f1387719 2886=item makefile (o)
1e44e2bf 2887
f1387719 2888Defines how to rewrite the Makefile.
1e44e2bf
PP
2889
2890=cut
2891
f1387719
PP
2892sub makefile {
2893 my($self) = shift;
2894 my @m;
2895 # We do not know what target was originally specified so we
2896 # must force a manual rerun to be sure. But as it should only
2897 # happen very rarely it is not a significant problem.
2898 push @m, '
2899$(OBJECT) : $(FIRST_MAKEFILE)
2900' if $self->{OBJECT};
1e44e2bf 2901
f1387719 2902 push @m, q{
e3aa3ecb 2903# We take a very conservative approach here, but it's worth it.
f1387719 2904# We move Makefile to Makefile.old here to avoid gnu make looping.
dedf98bc 2905$(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
479d2113
MS
2906 $(NOECHO) $(ECHO) "Makefile out-of-date with respect to $?"
2907 $(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2908 $(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2909 $(NOECHO) $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2910 -$(MAKE) -f $(MAKEFILE_OLD) clean $(DEV_NULL) || $(NOOP)
4bfb3f62 2911 $(PERLRUN) Makefile.PL }.join(" ",map(qq["$_"],@ARGV)).q{
479d2113
MS
2912 $(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2913 $(NOECHO) $(ECHO) "==> Please rerun the make command. <=="
68dc0745 2914 false
1e44e2bf 2915
1e44e2bf
PP
2916};
2917
f1387719 2918 join "", @m;
1e44e2bf
PP
2919}
2920
1e44e2bf 2921
f1387719 2922=item maybe_command
1e44e2bf 2923
f1387719 2924Returns true, if the argument is likely to be a command.
1e44e2bf
PP
2925
2926=cut
2927
f1387719
PP
2928sub maybe_command {
2929 my($self,$file) = @_;
2930 return $file if -x $file && ! -d $file;
2931 return;
1e44e2bf
PP
2932}
2933
1e44e2bf 2934
f1387719 2935=item needs_linking (o)
1e44e2bf 2936
f1387719
PP
2937Does this module need linking? Looks into subdirectory objects (see
2938also has_link_code())
1e44e2bf
PP
2939
2940=cut
2941
f1387719
PP
2942sub needs_linking {
2943 my($self) = shift;
2944 my($child,$caller);
2945 $caller = (caller(0))[3];
479d2113 2946 confess("needs_linking called too early") if
45bc4d3a 2947 $caller =~ /^ExtUtils::MakeMaker::/;
f1387719
PP
2948 return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2949 if ($self->has_link_code or $self->{MAKEAPERL}){
2950 $self->{NEEDS_LINKING} = 1;
2951 return 1;
1e44e2bf 2952 }
f1387719
PP
2953 foreach $child (keys %{$self->{CHILDREN}}) {
2954 if ($self->{CHILDREN}->{$child}->needs_linking) {
2955 $self->{NEEDS_LINKING} = 1;
2956 return 1;
2957 }
1e44e2bf 2958 }
f1387719 2959 return $self->{NEEDS_LINKING} = 0;
1e44e2bf
PP
2960}
2961
f1387719 2962=item nicetext
1e44e2bf 2963
f1387719
PP
2964misnamed method (will have to be changed). The MM_Unix method just
2965returns the argument without further processing.
2966
2967On VMS used to insure that colons marking targets are preceded by
2968space - most Unix Makes don't need this, but it's necessary under VMS
2969to distinguish the target delimiter from a colon appearing as part of
2970a filespec.
1e44e2bf
PP
2971
2972=cut
2973
f1387719
PP
2974sub nicetext {
2975 my($self,$text) = @_;
2976 $text;
2977}
1e44e2bf 2978
e0678a30
MS
2979=item parse_abstract
2980
2981parse a file and return what you think is the ABSTRACT
2982
2983=cut
2984
2985sub parse_abstract {
2986 my($self,$parsefile) = @_;
2987 my $result;
2988 local *FH;
2989 local $/ = "\n";
2990 open(FH,$parsefile) or die "Could not open '$parsefile': $!";
2991 my $inpod = 0;
2992 my $package = $self->{DISTNAME};
2993 $package =~ s/-/::/g;
2994 while (<FH>) {
2995 $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2996 next if !$inpod;
2997 chop;
2998 next unless /^($package\s-\s)(.*)/;
2999 $result = $2;
3000 last;
3001 }
3002 close FH;
3003 return $result;
3004}
3005
f1387719 3006=item parse_version
1e44e2bf 3007
5a5fd53e
GS
3008parse a file and return what you think is $VERSION in this file set to.
3009It will return the string "undef" if it can't figure out what $VERSION
afa6035d
T
3010is. $VERSION should be for all to see, so our $VERSION or plain $VERSION
3011are okay, but my $VERSION is not.
1e44e2bf 3012
f1387719
PP
3013=cut
3014
3015sub parse_version {
3016 my($self,$parsefile) = @_;
3017 my $result;
3018 local *FH;
3019 local $/ = "\n";
a7d1454b 3020 local $_;
f1387719
PP
3021 open(FH,$parsefile) or die "Could not open '$parsefile': $!";
3022 my $inpod = 0;
3023 while (<FH>) {
3024 $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
f05db7a1 3025 next if $inpod || /^\s*#/;
f1387719 3026 chop;
2530b651 3027 next unless /(?<!\\)([\$*])(([\w\:\']*)\bVERSION)\b.*\=/;
dbc738d9
PP
3028 my $eval = qq{
3029 package ExtUtils::MakeMaker::_version;
a1f8e286 3030 no strict;
bab2b58e 3031
84902520
TB
3032 local $1$2;
3033 \$$2=undef; do {
bab2b58e 3034 $_
84902520 3035 }; \$$2
dbc738d9 3036 };
57b1a898 3037 local $^W = 0;
84902520 3038 $result = eval($eval);
5a5fd53e 3039 warn "Could not eval '$eval' in $parsefile: $@" if $@;
f1387719
PP
3040 last;
3041 }
3042 close FH;
45bc4d3a
JH
3043
3044 $result = "undef" unless defined $result;
f1387719 3045 return $result;
1e44e2bf
PP
3046}
3047
1e44e2bf 3048
f1387719
PP
3049=item pasthru (o)
3050
3051Defines the string that is passed to recursive make calls in
3052subdirectories.
1e44e2bf
PP
3053
3054=cut
3055
f1387719 3056sub pasthru {
1e44e2bf 3057 my($self) = shift;
f1387719 3058 my(@m,$key);
1e44e2bf 3059
f1387719 3060 my(@pasthru);
bbce6d69
PP
3061 my($sep) = $Is_VMS ? ',' : '';
3062 $sep .= "\\\n\t";
1e44e2bf 3063
071e6b84
JH
3064 foreach $key (qw(LIB LIBPERL_A LINKTYPE PREFIX OPTIMIZE)) {
3065 push @pasthru, "$key=\"\$($key)\"";
f1387719 3066 }
f4ae0f5e 3067
289e7e34
JH
3068 foreach $key (qw(DEFINE INC)) {
3069 push @pasthru, "PASTHRU_$key=\"\$(PASTHRU_$key)\"";
3070 }
3071
bbce6d69 3072 push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
f1387719
PP
3073 join "", @m;
3074}
1e44e2bf 3075
f1387719 3076=item perl_script
1e44e2bf 3077
f1387719
PP
3078Takes one argument, a file name, and returns the file name, if the
3079argument is likely to be a perl script. On MM_Unix this is true for
3080any ordinary, readable file.
1e44e2bf
PP
3081
3082=cut
3083
f1387719
PP
3084sub perl_script {
3085 my($self,$file) = @_;
3086 return $file if -r $file && -f _;
3087 return;
1e44e2bf
PP
3088}
3089
f1387719 3090=item perldepend (o)
1e44e2bf 3091
f1387719
PP
3092Defines the dependency from all *.h files that come with the perl
3093distribution.
1e44e2bf
PP
3094
3095=cut
3096
f1387719 3097sub perldepend {
1e44e2bf 3098 my($self) = shift;
f1387719
PP
3099 my(@m);
3100 push @m, q{
3101# Check for unpropogated config.sh changes. Should never happen.
3102# We do NOT just update config.h because that is not sufficient.
3103# An out of date config.h is not fatal but complains loudly!
3104$(PERL_INC)/config.h: $(PERL_SRC)/config.sh
479d2113 3105 -$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; false
f1387719
PP
3106
3107$(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
479d2113 3108 $(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
f1387719
PP
3109 cd $(PERL_SRC) && $(MAKE) lib/Config.pm
3110} if $self->{PERL_SRC};
3111
3112 return join "", @m unless $self->needs_linking;
3113
1e44e2bf 3114 push @m, q{
f1387719 3115PERL_HDRS = \
54fc9134
GS
3116 $(PERL_INC)/EXTERN.h \
3117 $(PERL_INC)/INTERN.h \
3118 $(PERL_INC)/XSUB.h \
3119 $(PERL_INC)/av.h \
3120 $(PERL_INC)/cc_runtime.h \
3121 $(PERL_INC)/config.h \
3122 $(PERL_INC)/cop.h \
3123 $(PERL_INC)/cv.h \
3124 $(PERL_INC)/dosish.h \
3125 $(PERL_INC)/embed.h \
3126 $(PERL_INC)/embedvar.h \
3127 $(PERL_INC)/fakethr.h \
3128 $(PERL_INC)/form.h \
3129 $(PERL_INC)/gv.h \
3130 $(PERL_INC)/handy.h \
3131 $(PERL_INC)/hv.h \
3132 $(PERL_INC)/intrpvar.h \
3133 $(PERL_INC)/iperlsys.h \
3134 $(PERL_INC)/keywords.h \
3135 $(PERL_INC)/mg.h \
3136 $(PERL_INC)/nostdio.h \
54fc9134
GS
3137 $(PERL_INC)/op.h \
3138 $(PERL_INC)/opcode.h \
54fc9134
GS
3139 $(PERL_INC)/patchlevel.h \
3140 $(PERL_INC)/perl.h \
54fc9134
GS
3141 $(PERL_INC)/perlio.h \
3142 $(PERL_INC)/perlsdio.h \
3143 $(PERL_INC)/perlsfio.h \
3144 $(PERL_INC)/perlvars.h \
3145 $(PERL_INC)/perly.h \
3146 $(PERL_INC)/pp.h \
3147 $(PERL_INC)/pp_proto.h \
3148 $(PERL_INC)/proto.h \
3149 $(PERL_INC)/regcomp.h \
3150 $(PERL_INC)/regexp.h \
3151 $(PERL_INC)/regnodes.h \
3152 $(PERL_INC)/scope.h \
3153 $(PERL_INC)/sv.h \
3154 $(PERL_INC)/thrdvar.h \
3155 $(PERL_INC)/thread.h \
3156 $(PERL_INC)/unixish.h \
2530b651 3157 $(PERL_INC)/util.h
f1387719
PP
3158
3159$(OBJECT) : $(PERL_HDRS)
9b3032b7 3160} if $self->{OBJECT};
f1387719
PP
3161
3162 push @m, join(" ", values %{$self->{XS}})." : \$(XSUBPPDEPS)\n" if %{$self->{XS}};
3163
3164 join "\n", @m;
1e44e2bf
PP
3165}
3166
8f993c78 3167
2366100d
A
3168=item perm_rw (o)
3169
3170Returns the attribute C<PERM_RW> or the string C<644>.
3171Used as the string that is passed
3172to the C<chmod> command to set the permissions for read/writeable files.
32504223 3173MakeMaker chooses C<644> because it has turned out in the past that
de592821 3174relying on the umask provokes hard-to-track bug reports.
2366100d
A
3175When the return value is used by the perl function C<chmod>, it is
3176interpreted as an octal value.
3177
3178=cut
3179
3180sub perm_rw {
479d2113 3181 return shift->{PERM_RW};
2366100d
A
3182}
3183
3184=item perm_rwx (o)
3185
32504223 3186Returns the attribute C<PERM_RWX> or the string C<755>,
2366100d
A
3187i.e. the string that is passed
3188to the C<chmod> command to set the permissions for executable files.
3189See also perl_rw.
3190
3191=cut
3192
3193sub perm_rwx {
479d2113 3194 return shift->{PERM_RWX};
2366100d
A
3195}
3196
f1387719 3197=item pm_to_blib
1e44e2bf 3198
f1387719 3199Defines target that copies all files in the hash PM to their
55497cff 3200destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
1e44e2bf
PP
3201
3202=cut
3203
f1387719
PP
3204sub pm_to_blib {
3205 my $self = shift;
479d2113 3206 my($autodir) = $self->catdir('$(INST_LIB)','auto');
d2fa5cc0 3207 my $r = q{
f1387719 3208pm_to_blib: $(TO_INST_PM)
1e44e2bf 3209};
479d2113
MS
3210
3211 my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
3212pm_to_blib({\@ARGV}, '$autodir', '\$(PM_FILTER)')
3213CODE
3214
3215 my @cmds = $self->split_command($pm_to_blib, %{$self->{PM}});
3216
3217 $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
3218 $r .= q{ $(NOECHO) $(TOUCH) $@};
3219
3220 return $r;
1e44e2bf
PP
3221}
3222
f1387719 3223=item post_constants (o)
1e44e2bf 3224
f1387719
PP
3225Returns an empty string per default. Dedicated to overrides from
3226within Makefile.PL after all constants have been defined.
1e44e2bf
PP
3227
3228=cut
3229
f1387719 3230sub post_constants{
f1387719
PP
3231 "";
3232}
1e44e2bf 3233
f1387719 3234=item post_initialize (o)
1e44e2bf 3235
1fef88e7 3236Returns an empty string per default. Used in Makefile.PLs to add some
f1387719 3237chunk of text to the Makefile after the object is initialized.
1e44e2bf 3238
f1387719 3239=cut
1e44e2bf 3240
f1387719 3241sub post_initialize {
f1387719
PP
3242 "";
3243}
1e44e2bf 3244
f1387719 3245=item postamble (o)
1e44e2bf 3246
f1387719
PP
3247Returns an empty string. Can be used in Makefile.PLs to write some
3248text to the Makefile at the end.
1e44e2bf 3249
f1387719 3250=cut
1e44e2bf 3251
f1387719 3252sub postamble {
f1387719
PP
3253 "";
3254}
1e44e2bf 3255
e0678a30
MS
3256=item ppd
3257
3258Defines target that creates a PPD (Perl Package Description) file
3259for a binary distribution.
3260
3261=cut
3262
3263sub ppd {
3264 my($self) = @_;
3265
3266 if ($self->{ABSTRACT_FROM}){
3267 $self->{ABSTRACT} = $self->parse_abstract($self->{ABSTRACT_FROM}) or
45bc4d3a
JH
3268 carp "WARNING: Setting ABSTRACT via file ".
3269 "'$self->{ABSTRACT_FROM}' failed\n";
e0678a30
MS
3270 }
3271
3272 my ($pack_ver) = join ",", (split (/\./, $self->{VERSION}), (0)x4)[0..3];
3273
3274 my $abstract = $self->{ABSTRACT} || '';
3275 $abstract =~ s/\n/\\n/sg;
3276 $abstract =~ s/</&lt;/g;
3277 $abstract =~ s/>/&gt;/g;
3278
3279 my $author = $self->{AUTHOR} || '';
3280 $author =~ s/</&lt;/g;
3281 $author =~ s/>/&gt;/g;
e0678a30 3282
479d2113
MS
3283 my $ppd_xml = sprintf <<'PPD_HTML', $pack_ver, $abstract, $author;
3284<SOFTPKG NAME="$(DISTNAME)" VERSION="%s">
3285 <TITLE>$(DISTNAME)</TITLE>
3286 <ABSTRACT>%s</ABSTRACT>
3287 <AUTHOR>%s</AUTHOR>
3288PPD_HTML
e0678a30 3289
479d2113 3290 $ppd_xml .= " <IMPLEMENTATION>\n";
e0678a30
MS
3291 foreach my $prereq (sort keys %{$self->{PREREQ_PM}}) {
3292 my $pre_req = $prereq;
3293 $pre_req =~ s/::/-/g;
3294 my ($dep_ver) = join ",", (split (/\./, $self->{PREREQ_PM}{$prereq}),
3295 (0) x 4) [0 .. 3];
479d2113
MS
3296 $ppd_xml .= sprintf <<'PPD_OUT', $pre_req, $dep_ver;
3297 <DEPENDENCY NAME="%s" VERSION="%s" />
e0678a30
MS
3298PPD_OUT
3299
479d2113 3300 }
e0678a30 3301
479d2113
MS
3302 $ppd_xml .= sprintf <<'PPD_OUT', $Config{archname};
3303 <OS NAME="$(OSNAME)" />
3304 <ARCHITECTURE NAME="%s" />
3305PPD_OUT
e0678a30
MS
3306
3307 if ($self->{PPM_INSTALL_SCRIPT}) {
3308 if ($self->{PPM_INSTALL_EXEC}) {
479d2113 3309 $ppd_xml .= sprintf qq{ <INSTALL EXEC="%s">%s</INSTALL>\n},
e0678a30
MS
3310 $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
3311 }
3312 else {
479d2113 3313 $ppd_xml .= sprintf qq{ <INSTALL>%s</INSTALL>\n},
e0678a30
MS
3314 $self->{PPM_INSTALL_SCRIPT};
3315 }
3316 }
3317
3318 my ($bin_location) = $self->{BINARY_LOCATION} || '';
3319 $bin_location =~ s/\\/\\\\/g;
3320
479d2113
MS
3321 $ppd_xml .= sprintf <<'PPD_XML', $bin_location;
3322 <CODEBASE HREF="%s" />
3323 </IMPLEMENTATION>
3324</SOFTPKG>
3325PPD_XML
3326
3327 my @ppd_cmds = $self->echo($ppd_xml, '$(DISTNAME).ppd');
e0678a30 3328
479d2113
MS
3329 return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3330# Creates a PPD (Perl Package Description) for a binary distribution.
3331ppd:
3332 %s
3333PPD_OUT
e0678a30 3334
e0678a30
MS
3335}
3336
f1387719 3337=item prefixify
1e44e2bf 3338
e0678a30 3339 $MM->prefixify($var, $prefix, $new_prefix, $default);
f6d6199c 3340
e0678a30 3341Using either $MM->{uc $var} || $Config{lc $var}, it will attempt to
479d2113
MS
3342replace it's $prefix with a $new_prefix.
3343
3344Should the $prefix fail to match I<AND> a PREFIX was given as an
3345argument to WriteMakefile() it will set it to the $new_prefix +
3346$default. This is for systems whose file layouts don't neatly fit into
3347our ideas of prefixes.
1e44e2bf 3348
e0678a30
MS
3349This is for heuristics which attempt to create directory structures
3350that mirror those of the installed perl.
3351
3352For example:
3353
3354 $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3355
3356this will attempt to remove '/usr' from the front of the
3357$MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3358if necessary) and replace it with '/home/foo'. If this fails it will
3359simply use '/home/foo/man/man1'.
1e44e2bf 3360
f1387719 3361=cut
1e44e2bf 3362
f1387719 3363sub prefixify {
e0678a30
MS
3364 my($self,$var,$sprefix,$rprefix,$default) = @_;
3365
5c161494 3366 my $path = $self->{uc $var} ||
45bc4d3a 3367 $Config_Override{lc $var} || $Config{lc $var} || '';
e0678a30 3368
1b0fc073
JH
3369 $rprefix .= '/' if $sprefix =~ m|/$|;
3370
45bc4d3a
JH
3371 print STDERR " prefixify $var => $path\n" if $Verbose >= 2;
3372 print STDERR