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