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