xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm (revision fac98b93b71777a71b1e912ccaf68ce33d7b87c4)
1b39c5158Smillertpackage ExtUtils::MM_Unix;
2b39c5158Smillert
3b39c5158Smillertrequire 5.006;
4b39c5158Smillert
5b39c5158Smillertuse strict;
6eac174f2Safresh1use warnings;
7b39c5158Smillert
8b39c5158Smillertuse Carp;
9b39c5158Smillertuse ExtUtils::MakeMaker::Config;
10b39c5158Smillertuse File::Basename qw(basename dirname);
11b39c5158Smillert
12b39c5158Smillertour %Config_Override;
13b39c5158Smillert
149f11ffb7Safresh1use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562);
15b39c5158Smillert
16e0680481Safresh1# If $VERSION is in scope, parse_version() breaks
17e0680481Safresh1{
18e0680481Safresh1our $VERSION = '7.70';
1956d68f1eSafresh1$VERSION =~ tr/_//d;
20e0680481Safresh1}
21b39c5158Smillert
22b39c5158Smillertrequire ExtUtils::MM_Any;
23b39c5158Smillertour @ISA = qw(ExtUtils::MM_Any);
24b39c5158Smillert
25b39c5158Smillertmy %Is;
26b39c5158SmillertBEGIN {
27b39c5158Smillert    $Is{OS2}     = $^O eq 'os2';
28b39c5158Smillert    $Is{Win32}   = $^O eq 'MSWin32' || $Config{osname} eq 'NetWare';
29b39c5158Smillert    $Is{Dos}     = $^O eq 'dos';
30b39c5158Smillert    $Is{VMS}     = $^O eq 'VMS';
31b39c5158Smillert    $Is{OSF}     = $^O eq 'dec_osf';
32b39c5158Smillert    $Is{IRIX}    = $^O eq 'irix';
33b39c5158Smillert    $Is{NetBSD}  = $^O eq 'netbsd';
34b39c5158Smillert    $Is{Interix} = $^O eq 'interix';
35b39c5158Smillert    $Is{SunOS4}  = $^O eq 'sunos';
36b39c5158Smillert    $Is{Solaris} = $^O eq 'solaris';
37b39c5158Smillert    $Is{SunOS}   = $Is{SunOS4} || $Is{Solaris};
38e0680481Safresh1    $Is{BSD}     = ($^O =~ /^(?:free|midnight|net|open)bsd$/ or
39b39c5158Smillert                   grep( $^O eq $_, qw(bsdos interix dragonfly) )
40b39c5158Smillert                  );
41e5157e49Safresh1    $Is{Android} = $^O =~ /android/;
42e0680481Safresh1    if ( $^O eq 'darwin' ) {
4356d68f1eSafresh1      my @osvers = split /\./, $Config{osvers};
44e0680481Safresh1      if ( $^X eq '/usr/bin/perl' ) {
4556d68f1eSafresh1        $Is{ApplCor} = ( $osvers[0] >= 18 );
4656d68f1eSafresh1      }
47e0680481Safresh1      $Is{AppleRPath} = ( $osvers[0] >= 9 );
48e0680481Safresh1    }
49b39c5158Smillert}
50b39c5158Smillert
51b39c5158SmillertBEGIN {
52b39c5158Smillert    if( $Is{VMS} ) {
53b39c5158Smillert        # For things like vmsify()
54b39c5158Smillert        require VMS::Filespec;
55b39c5158Smillert        VMS::Filespec->import;
56b39c5158Smillert    }
57b39c5158Smillert}
58b39c5158Smillert
59b39c5158Smillert
60b39c5158Smillert=head1 NAME
61b39c5158Smillert
62b39c5158SmillertExtUtils::MM_Unix - methods used by ExtUtils::MakeMaker
63b39c5158Smillert
64b39c5158Smillert=head1 SYNOPSIS
65b39c5158Smillert
6656d68f1eSafresh1  require ExtUtils::MM_Unix;
67b39c5158Smillert
68b39c5158Smillert=head1 DESCRIPTION
69b39c5158Smillert
70b39c5158SmillertThe methods provided by this package are designed to be used in
7156d68f1eSafresh1conjunction with L<ExtUtils::MakeMaker>. When MakeMaker writes a
72b39c5158SmillertMakefile, it creates one or more objects that inherit their methods
7356d68f1eSafresh1from a package L<MM|ExtUtils::MM>. MM itself doesn't provide any methods, but
7456d68f1eSafresh1it ISA ExtUtils::MM_Unix class. The inheritance tree of MM lets operating
75b39c5158Smillertspecific packages take the responsibility for all the methods provided
76b39c5158Smillertby MM_Unix. We are trying to reduce the number of the necessary
77b39c5158Smillertoverrides by defining rather primitive operations within
78b39c5158SmillertExtUtils::MM_Unix.
79b39c5158Smillert
80b39c5158SmillertIf you are going to write a platform specific MM package, please try
81b39c5158Smillertto limit the necessary overrides to primitive methods, and if it is not
82b39c5158Smillertpossible to do so, let's work out how to achieve that gain.
83b39c5158Smillert
84b39c5158SmillertIf you are overriding any of these methods in your Makefile.PL (in the
85b39c5158SmillertMY class), please report that to the makemaker mailing list. We are
86b39c5158Smillerttrying to minimize the necessary method overrides and switch to data
87b39c5158Smillertdriven Makefile.PLs wherever possible. In the long run less methods
88b39c5158Smillertwill be overridable via the MY class.
89b39c5158Smillert
90b39c5158Smillert=head1 METHODS
91b39c5158Smillert
92b39c5158SmillertThe following description of methods is still under
93b39c5158Smillertdevelopment. Please refer to the code for not suitably documented
94b39c5158Smillertsections and complain loudly to the makemaker@perl.org mailing list.
95b39c5158SmillertBetter yet, provide a patch.
96b39c5158Smillert
97b39c5158SmillertNot all of the methods below are overridable in a
98b39c5158SmillertMakefile.PL. Overridable methods are marked as (o). All methods are
99b39c5158Smillertoverridable by a platform specific MM_*.pm file.
100b39c5158Smillert
10156d68f1eSafresh1Cross-platform methods are being moved into L<MM_Any|ExtUtils::MM_Any>.
10256d68f1eSafresh1If you can't find something that used to be in here, look in MM_Any.
103b39c5158Smillert
104b39c5158Smillert=cut
105b39c5158Smillert
106b39c5158Smillert# So we don't have to keep calling the methods over and over again,
107b39c5158Smillert# we have these globals to cache the values.  Faster and shrtr.
108b39c5158Smillertmy $Curdir  = __PACKAGE__->curdir;
109b39c5158Smillertmy $Updir   = __PACKAGE__->updir;
110b39c5158Smillert
111b39c5158Smillert
112b39c5158Smillert=head2 Methods
113b39c5158Smillert
114b39c5158Smillert=over 4
115b39c5158Smillert
116b39c5158Smillert=item os_flavor
117b39c5158Smillert
118b39c5158SmillertSimply says that we're Unix.
119b39c5158Smillert
120b39c5158Smillert=cut
121b39c5158Smillert
122b39c5158Smillertsub os_flavor {
123b39c5158Smillert    return('Unix');
124b39c5158Smillert}
125b39c5158Smillert
126b39c5158Smillert
127b39c5158Smillert=item c_o (o)
128b39c5158Smillert
129b39c5158SmillertDefines the suffix rules to compile different flavors of C files to
130b39c5158Smillertobject files.
131b39c5158Smillert
132b39c5158Smillert=cut
133b39c5158Smillert
134b39c5158Smillertsub c_o {
135b39c5158Smillert# --- Translation Sections ---
136b39c5158Smillert
137b39c5158Smillert    my($self) = shift;
138b39c5158Smillert    return '' unless $self->needs_linking();
139b39c5158Smillert    my(@m);
140b39c5158Smillert
141b39c5158Smillert    my $command = '$(CCCMD)';
142b39c5158Smillert    my $flags   = '$(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE)';
143b39c5158Smillert
14456d68f1eSafresh1    if ( $Is{ApplCor} ) {
14556d68f1eSafresh1        $flags =~ s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/;
14656d68f1eSafresh1    }
14756d68f1eSafresh1
148eac174f2Safresh1    if (my $cpp = $self->{CPPRUN}) {
149b39c5158Smillert        my $cpp_cmd = $self->const_cccmd;
150eac174f2Safresh1        $cpp_cmd =~ s/^CCCMD\s*=\s*\$\(CC\)/\$(CPPRUN)/;
151b39c5158Smillert        push @m, qq{
152b39c5158Smillert.c.i:
153b39c5158Smillert	$cpp_cmd $flags \$*.c > \$*.i
154b39c5158Smillert};
155b39c5158Smillert    }
156b39c5158Smillert
1579f11ffb7Safresh1    my $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*.s') : '';
1589f11ffb7Safresh1    push @m, sprintf <<'EOF', $command, $flags, $m_o;
1599f11ffb7Safresh1
160b39c5158Smillert.c.s :
1619f11ffb7Safresh1	%s -S %s $*.c %s
1629f11ffb7Safresh1EOF
163b39c5158Smillert
1649f11ffb7Safresh1    my @exts = qw(c cpp cxx cc);
1659f11ffb7Safresh1    push @exts, 'C' if !$Is{OS2} and !$Is{Win32} and !$Is{Dos}; #Case-specific
1669f11ffb7Safresh1    $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*$(OBJ_EXT)') : '';
16756d68f1eSafresh1    my $dbgout = $self->dbgoutflag;
1689f11ffb7Safresh1    for my $ext (@exts) {
16956d68f1eSafresh1	push @m, "\n.$ext\$(OBJ_EXT) :\n\t$command $flags "
17056d68f1eSafresh1            .($dbgout?"$dbgout ":'')
17156d68f1eSafresh1            ."\$*.$ext" . ( $m_o ? " $m_o" : '' ) . "\n";
1729f11ffb7Safresh1    }
173b39c5158Smillert    return join "", @m;
174b39c5158Smillert}
175b39c5158Smillert
1769f11ffb7Safresh1
1779f11ffb7Safresh1=item xs_obj_opt
1789f11ffb7Safresh1
1799f11ffb7Safresh1Takes the object file as an argument, and returns the portion of compile
1809f11ffb7Safresh1command-line that will output to the specified object file.
1819f11ffb7Safresh1
1829f11ffb7Safresh1=cut
1839f11ffb7Safresh1
1849f11ffb7Safresh1sub xs_obj_opt {
1859f11ffb7Safresh1    my ($self, $output_file) = @_;
1869f11ffb7Safresh1    "-o $output_file";
1879f11ffb7Safresh1}
1889f11ffb7Safresh1
18956d68f1eSafresh1=item dbgoutflag
19056d68f1eSafresh1
19156d68f1eSafresh1Returns a CC flag that tells the CC to emit a separate debugging symbol file
19256d68f1eSafresh1when compiling an object file.
19356d68f1eSafresh1
19456d68f1eSafresh1=cut
19556d68f1eSafresh1
19656d68f1eSafresh1sub dbgoutflag {
19756d68f1eSafresh1    '';
19856d68f1eSafresh1}
1999f11ffb7Safresh1
200b39c5158Smillert=item cflags (o)
201b39c5158Smillert
202b39c5158SmillertDoes very much the same as the cflags script in the perl
203b39c5158Smillertdistribution. It doesn't return the whole compiler command line, but
204b39c5158Smillertinitializes all of its parts. The const_cccmd method then actually
205b39c5158Smillertreturns the definition of the CCCMD macro which uses these parts.
206b39c5158Smillert
207b39c5158Smillert=cut
208b39c5158Smillert
209b39c5158Smillert#'
210b39c5158Smillert
211b39c5158Smillertsub cflags {
212b39c5158Smillert    my($self,$libperl)=@_;
213b39c5158Smillert    return $self->{CFLAGS} if $self->{CFLAGS};
214b39c5158Smillert    return '' unless $self->needs_linking();
215b39c5158Smillert
216b39c5158Smillert    my($prog, $uc, $perltype, %cflags);
217b39c5158Smillert    $libperl ||= $self->{LIBPERL_A} || "libperl$self->{LIB_EXT}" ;
218b39c5158Smillert    $libperl =~ s/\.\$\(A\)$/$self->{LIB_EXT}/;
219b39c5158Smillert
220b39c5158Smillert    @cflags{qw(cc ccflags optimize shellflags)}
221b39c5158Smillert	= @Config{qw(cc ccflags optimize shellflags)};
222b8851fccSafresh1
223b8851fccSafresh1    # Perl 5.21.4 adds the (gcc) warning (-Wall ...) and std (-std=c89)
224b8851fccSafresh1    # flags to the %Config, and the modules in the core should be built
225b8851fccSafresh1    # with the warning flags, but NOT the -std=c89 flags (the latter
226b8851fccSafresh1    # would break using any system header files that are strict C99).
227b8851fccSafresh1    my @ccextraflags = qw(ccwarnflags);
228b8851fccSafresh1    if ($ENV{PERL_CORE}) {
229b8851fccSafresh1      for my $x (@ccextraflags) {
230b8851fccSafresh1        if (exists $Config{$x}) {
231b8851fccSafresh1          $cflags{$x} = $Config{$x};
232b8851fccSafresh1        }
233b8851fccSafresh1      }
234b8851fccSafresh1    }
235b8851fccSafresh1
236b39c5158Smillert    my($optdebug) = "";
237b39c5158Smillert
238b39c5158Smillert    $cflags{shellflags} ||= '';
239b39c5158Smillert
240b39c5158Smillert    my(%map) =  (
241b39c5158Smillert		D =>   '-DDEBUGGING',
242b39c5158Smillert		E =>   '-DEMBED',
243b39c5158Smillert		DE =>  '-DDEBUGGING -DEMBED',
244b39c5158Smillert		M =>   '-DEMBED -DMULTIPLICITY',
245b39c5158Smillert		DM =>  '-DDEBUGGING -DEMBED -DMULTIPLICITY',
246b39c5158Smillert		);
247b39c5158Smillert
248b39c5158Smillert    if ($libperl =~ /libperl(\w*)\Q$self->{LIB_EXT}/){
249b39c5158Smillert	$uc = uc($1);
250b39c5158Smillert    } else {
251b39c5158Smillert	$uc = ""; # avoid warning
252b39c5158Smillert    }
253b39c5158Smillert    $perltype = $map{$uc} ? $map{$uc} : "";
254b39c5158Smillert
255b39c5158Smillert    if ($uc =~ /^D/) {
256b39c5158Smillert	$optdebug = "-g";
257b39c5158Smillert    }
258b39c5158Smillert
259b39c5158Smillert
260b39c5158Smillert    my($name);
261b39c5158Smillert    ( $name = $self->{NAME} . "_cflags" ) =~ s/:/_/g ;
262b39c5158Smillert    if ($prog = $Config{$name}) {
263b39c5158Smillert	# Expand hints for this extension via the shell
264e9ce3842Safresh1	print "Processing $name hint:\n" if $Verbose;
265b39c5158Smillert	my(@o)=`cc=\"$cflags{cc}\"
266b39c5158Smillert	  ccflags=\"$cflags{ccflags}\"
267b39c5158Smillert	  optimize=\"$cflags{optimize}\"
268b39c5158Smillert	  perltype=\"$cflags{perltype}\"
269b39c5158Smillert	  optdebug=\"$cflags{optdebug}\"
270b39c5158Smillert	  eval '$prog'
271b39c5158Smillert	  echo cc=\$cc
272b39c5158Smillert	  echo ccflags=\$ccflags
273b39c5158Smillert	  echo optimize=\$optimize
274b39c5158Smillert	  echo perltype=\$perltype
275b39c5158Smillert	  echo optdebug=\$optdebug
276b39c5158Smillert	  `;
277b39c5158Smillert	foreach my $line (@o){
278b39c5158Smillert	    chomp $line;
279b39c5158Smillert	    if ($line =~ /(.*?)=\s*(.*)\s*$/){
280b39c5158Smillert		$cflags{$1} = $2;
281e9ce3842Safresh1		print "	$1 = $2\n" if $Verbose;
282b39c5158Smillert	    } else {
283e9ce3842Safresh1		print "Unrecognised result from hint: '$line'\n";
284b39c5158Smillert	    }
285b39c5158Smillert	}
286b39c5158Smillert    }
287b39c5158Smillert
288b39c5158Smillert    if ($optdebug) {
289b39c5158Smillert	$cflags{optimize} = $optdebug;
290b39c5158Smillert    }
291b39c5158Smillert
292b39c5158Smillert    for (qw(ccflags optimize perltype)) {
293b39c5158Smillert        $cflags{$_} ||= '';
294b39c5158Smillert	$cflags{$_} =~ s/^\s+//;
295b39c5158Smillert	$cflags{$_} =~ s/\s+/ /g;
296b39c5158Smillert	$cflags{$_} =~ s/\s+$//;
297b39c5158Smillert	$self->{uc $_} ||= $cflags{$_};
298b39c5158Smillert    }
299b39c5158Smillert
300b39c5158Smillert    if ($self->{POLLUTE}) {
301b39c5158Smillert	$self->{CCFLAGS} .= ' -DPERL_POLLUTE ';
302b39c5158Smillert    }
303b39c5158Smillert
304b8851fccSafresh1    for my $x (@ccextraflags) {
305b8851fccSafresh1      next unless exists $cflags{$x};
306b8851fccSafresh1      $self->{CCFLAGS} .= $cflags{$x} =~ m!^\s! ? $cflags{$x} : ' ' . $cflags{$x};
307b8851fccSafresh1    }
308b8851fccSafresh1
309b39c5158Smillert    my $pollute = '';
310b39c5158Smillert    if ($Config{usemymalloc} and not $Config{bincompat5005}
311b39c5158Smillert	and not $Config{ccflags} =~ /-DPERL_POLLUTE_MALLOC\b/
312b39c5158Smillert	and $self->{PERL_MALLOC_OK}) {
313b39c5158Smillert	$pollute = '$(PERL_MALLOC_DEF)';
314b39c5158Smillert    }
315b39c5158Smillert
316b39c5158Smillert    return $self->{CFLAGS} = qq{
317b39c5158SmillertCCFLAGS = $self->{CCFLAGS}
318b39c5158SmillertOPTIMIZE = $self->{OPTIMIZE}
319b39c5158SmillertPERLTYPE = $self->{PERLTYPE}
320b39c5158SmillertMPOLLUTE = $pollute
321b39c5158Smillert};
322b39c5158Smillert
323b39c5158Smillert}
324b39c5158Smillert
325b39c5158Smillert
326b39c5158Smillert=item const_cccmd (o)
327b39c5158Smillert
328b39c5158SmillertReturns the full compiler call for C programs and stores the
329b39c5158Smillertdefinition in CONST_CCCMD.
330b39c5158Smillert
331b39c5158Smillert=cut
332b39c5158Smillert
333b39c5158Smillertsub const_cccmd {
334b39c5158Smillert    my($self,$libperl)=@_;
335b39c5158Smillert    return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
336b39c5158Smillert    return '' unless $self->needs_linking();
337b39c5158Smillert    return $self->{CONST_CCCMD} =
338b39c5158Smillert	q{CCCMD = $(CC) -c $(PASTHRU_INC) $(INC) \\
33948950c12Ssthen	$(CCFLAGS) $(OPTIMIZE) \\
340b39c5158Smillert	$(PERLTYPE) $(MPOLLUTE) $(DEFINE_VERSION) \\
341b39c5158Smillert	$(XS_DEFINE_VERSION)};
342b39c5158Smillert}
343b39c5158Smillert
344b39c5158Smillert=item const_config (o)
345b39c5158Smillert
346b8851fccSafresh1Sets SHELL if needed, then defines a couple of constants in the Makefile
347b8851fccSafresh1that are imported from %Config.
348b39c5158Smillert
349b39c5158Smillert=cut
350b39c5158Smillert
351b39c5158Smillertsub const_config {
352b39c5158Smillert# --- Constants Sections ---
353b39c5158Smillert
354b39c5158Smillert    my($self) = shift;
355b8851fccSafresh1    my @m = $self->specify_shell(); # Usually returns empty string
356b8851fccSafresh1    push @m, <<"END";
357b39c5158Smillert
358b39c5158Smillert# These definitions are from config.sh (via $INC{'Config.pm'}).
359b39c5158Smillert# They may have been overridden via Makefile.PL or on the command line.
360b39c5158SmillertEND
361b39c5158Smillert
362b39c5158Smillert    my(%once_only);
363b39c5158Smillert    foreach my $key (@{$self->{CONFIG}}){
364b39c5158Smillert        # SITE*EXP macros are defined in &constants; avoid duplicates here
365b39c5158Smillert        next if $once_only{$key};
366b39c5158Smillert        push @m, uc($key) , ' = ' , $self->{uc $key}, "\n";
367b39c5158Smillert        $once_only{$key} = 1;
368b39c5158Smillert    }
369b39c5158Smillert    join('', @m);
370b39c5158Smillert}
371b39c5158Smillert
372b39c5158Smillert=item const_loadlibs (o)
373b39c5158Smillert
374b39c5158SmillertDefines EXTRALIBS, LDLOADLIBS, BSLOADLIBS, LD_RUN_PATH. See
375b39c5158SmillertL<ExtUtils::Liblist> for details.
376b39c5158Smillert
377b39c5158Smillert=cut
378b39c5158Smillert
379b39c5158Smillertsub const_loadlibs {
380b39c5158Smillert    my($self) = shift;
381b39c5158Smillert    return "" unless $self->needs_linking;
382b39c5158Smillert    my @m;
383b39c5158Smillert    push @m, qq{
384b39c5158Smillert# $self->{NAME} might depend on some other libraries:
385b39c5158Smillert# See ExtUtils::Liblist for details
386b39c5158Smillert#
387b39c5158Smillert};
388b39c5158Smillert    for my $tmp (qw/
389b39c5158Smillert         EXTRALIBS LDLOADLIBS BSLOADLIBS
390b39c5158Smillert         /) {
391b39c5158Smillert        next unless defined $self->{$tmp};
392b39c5158Smillert        push @m, "$tmp = $self->{$tmp}\n";
393b39c5158Smillert    }
394b39c5158Smillert    # don't set LD_RUN_PATH if empty
395b39c5158Smillert    for my $tmp (qw/
396b39c5158Smillert         LD_RUN_PATH
397b39c5158Smillert         /) {
398b39c5158Smillert        next unless $self->{$tmp};
399b39c5158Smillert        push @m, "$tmp = $self->{$tmp}\n";
400b39c5158Smillert    }
401b39c5158Smillert    return join "", @m;
402b39c5158Smillert}
403b39c5158Smillert
404b39c5158Smillert=item constants (o)
405b39c5158Smillert
406b39c5158Smillert  my $make_frag = $mm->constants;
407b39c5158Smillert
408b39c5158SmillertPrints out macros for lots of constants.
409b39c5158Smillert
410b39c5158Smillert=cut
411b39c5158Smillert
412b39c5158Smillertsub constants {
413b39c5158Smillert    my($self) = @_;
414b39c5158Smillert    my @m = ();
415b39c5158Smillert
416b39c5158Smillert    $self->{DFSEP} = '$(DIRFILESEP)';  # alias for internal use
417b39c5158Smillert
418b39c5158Smillert    for my $macro (qw(
419b39c5158Smillert
420b39c5158Smillert              AR_STATIC_ARGS DIRFILESEP DFSEP
421b39c5158Smillert              NAME NAME_SYM
422b39c5158Smillert              VERSION    VERSION_MACRO    VERSION_SYM DEFINE_VERSION
423b39c5158Smillert              XS_VERSION XS_VERSION_MACRO             XS_DEFINE_VERSION
424b39c5158Smillert              INST_ARCHLIB INST_SCRIPT INST_BIN INST_LIB
425b39c5158Smillert              INST_MAN1DIR INST_MAN3DIR
426b39c5158Smillert              MAN1EXT      MAN3EXT
427d0bd1485Safresh1              MAN1SECTION  MAN3SECTION
428b39c5158Smillert              INSTALLDIRS INSTALL_BASE DESTDIR PREFIX
429b39c5158Smillert              PERLPREFIX      SITEPREFIX      VENDORPREFIX
430b39c5158Smillert                   ),
431b39c5158Smillert                   (map { ("INSTALL".$_,
432b39c5158Smillert                          "DESTINSTALL".$_)
433b39c5158Smillert                        } $self->installvars),
434b39c5158Smillert                   qw(
435b39c5158Smillert              PERL_LIB
436b8851fccSafresh1              PERL_ARCHLIB PERL_ARCHLIBDEP
437b39c5158Smillert              LIBPERL_A MYEXTLIB
438b39c5158Smillert              FIRST_MAKEFILE MAKEFILE_OLD MAKE_APERL_FILE
439b8851fccSafresh1              PERLMAINCC PERL_SRC PERL_INC PERL_INCDEP
440b39c5158Smillert              PERL            FULLPERL          ABSPERL
441b39c5158Smillert              PERLRUN         FULLPERLRUN       ABSPERLRUN
442b39c5158Smillert              PERLRUNINST     FULLPERLRUNINST   ABSPERLRUNINST
443b39c5158Smillert              PERL_CORE
444b39c5158Smillert              PERM_DIR PERM_RW PERM_RWX
445b39c5158Smillert
446b39c5158Smillert	      ) )
447b39c5158Smillert    {
448b39c5158Smillert	next unless defined $self->{$macro};
449b39c5158Smillert
450b39c5158Smillert        # pathnames can have sharp signs in them; escape them so
451b39c5158Smillert        # make doesn't think it is a comment-start character.
452b39c5158Smillert        $self->{$macro} =~ s/#/\\#/g;
453b8851fccSafresh1	$self->{$macro} = $self->quote_dep($self->{$macro})
454b8851fccSafresh1	  if $ExtUtils::MakeMaker::macro_dep{$macro};
455b39c5158Smillert	push @m, "$macro = $self->{$macro}\n";
456b39c5158Smillert    }
457b39c5158Smillert
458b39c5158Smillert    push @m, qq{
459b39c5158SmillertMAKEMAKER   = $self->{MAKEMAKER}
460b39c5158SmillertMM_VERSION  = $self->{MM_VERSION}
461b39c5158SmillertMM_REVISION = $self->{MM_REVISION}
462b39c5158Smillert};
463b39c5158Smillert
464b39c5158Smillert    push @m, q{
465b39c5158Smillert# FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
466b39c5158Smillert# BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
467b39c5158Smillert# PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
468b39c5158Smillert# DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
469b39c5158Smillert};
470b39c5158Smillert
471b39c5158Smillert    for my $macro (qw/
472b39c5158Smillert              MAKE
473b39c5158Smillert	      FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
474b39c5158Smillert	      LDFROM LINKTYPE BOOTDEP
475b39c5158Smillert	      /	)
476b39c5158Smillert    {
477b39c5158Smillert	next unless defined $self->{$macro};
478b39c5158Smillert	push @m, "$macro = $self->{$macro}\n";
479b39c5158Smillert    }
480b39c5158Smillert
481b39c5158Smillert    push @m, "
482b39c5158Smillert# Handy lists of source code files:
483b39c5158SmillertXS_FILES = ".$self->wraplist(sort keys %{$self->{XS}})."
4849f11ffb7Safresh1C_FILES  = ".$self->wraplist(sort @{$self->{C}})."
4859f11ffb7Safresh1O_FILES  = ".$self->wraplist(sort @{$self->{O_FILES}})."
4869f11ffb7Safresh1H_FILES  = ".$self->wraplist(sort @{$self->{H}})."
487b39c5158SmillertMAN1PODS = ".$self->wraplist(sort keys %{$self->{MAN1PODS}})."
488b39c5158SmillertMAN3PODS = ".$self->wraplist(sort keys %{$self->{MAN3PODS}})."
489b39c5158Smillert";
490b39c5158Smillert
49156d68f1eSafresh1    push @m, q{
49256d68f1eSafresh1SDKROOT := $(shell xcrun --show-sdk-path)
49356d68f1eSafresh1PERL_SYSROOT = $(SDKROOT)
49456d68f1eSafresh1} if $Is{ApplCor} && $self->{'PERL_INC'} =~ m!^/System/Library/Perl/!;
49556d68f1eSafresh1
49656d68f1eSafresh1    push @m, q{
49756d68f1eSafresh1# Where is the Config information that we are using/depend on
49856d68f1eSafresh1CONFIGDEP = $(PERL_ARCHLIBDEP)$(DFSEP)Config.pm $(PERL_SYSROOT)$(PERL_INCDEP)$(DFSEP)config.h
49956d68f1eSafresh1} if $Is{ApplCor};
500b39c5158Smillert
501b39c5158Smillert    push @m, q{
502b39c5158Smillert# Where is the Config information that we are using/depend on
503b8851fccSafresh1CONFIGDEP = $(PERL_ARCHLIBDEP)$(DFSEP)Config.pm $(PERL_INCDEP)$(DFSEP)config.h
50456d68f1eSafresh1} if -e $self->catfile( $self->{PERL_INC}, 'config.h' ) && !$Is{ApplCor};
505b39c5158Smillert
506b39c5158Smillert    push @m, qq{
507b39c5158Smillert# Where to build things
508b39c5158SmillertINST_LIBDIR      = $self->{INST_LIBDIR}
509b39c5158SmillertINST_ARCHLIBDIR  = $self->{INST_ARCHLIBDIR}
510b39c5158Smillert
511b39c5158SmillertINST_AUTODIR     = $self->{INST_AUTODIR}
512b39c5158SmillertINST_ARCHAUTODIR = $self->{INST_ARCHAUTODIR}
513b39c5158Smillert
514b39c5158SmillertINST_STATIC      = $self->{INST_STATIC}
515b39c5158SmillertINST_DYNAMIC     = $self->{INST_DYNAMIC}
516b39c5158SmillertINST_BOOT        = $self->{INST_BOOT}
517b39c5158Smillert};
518b39c5158Smillert
519b39c5158Smillert    push @m, qq{
520b39c5158Smillert# Extra linker info
521b39c5158SmillertEXPORT_LIST        = $self->{EXPORT_LIST}
522b39c5158SmillertPERL_ARCHIVE       = $self->{PERL_ARCHIVE}
523b8851fccSafresh1PERL_ARCHIVEDEP    = $self->{PERL_ARCHIVEDEP}
524b39c5158SmillertPERL_ARCHIVE_AFTER = $self->{PERL_ARCHIVE_AFTER}
525b39c5158Smillert};
526b39c5158Smillert
527b39c5158Smillert    push @m, "
528b39c5158Smillert
5299f11ffb7Safresh1TO_INST_PM = ".$self->wraplist(map $self->quote_dep($_), sort keys %{$self->{PM}})."\n";
530b39c5158Smillert
531b39c5158Smillert    join('',@m);
532b39c5158Smillert}
533b39c5158Smillert
534b39c5158Smillert
535b39c5158Smillert=item depend (o)
536b39c5158Smillert
537b39c5158SmillertSame as macro for the depend attribute.
538b39c5158Smillert
539b39c5158Smillert=cut
540b39c5158Smillert
541b39c5158Smillertsub depend {
542b39c5158Smillert    my($self,%attribs) = @_;
543b39c5158Smillert    my(@m,$key,$val);
5449f11ffb7Safresh1    for my $key (sort keys %attribs){
5459f11ffb7Safresh1	my $val = $attribs{$key};
5469f11ffb7Safresh1	next unless defined $key and defined $val;
547b39c5158Smillert	push @m, "$key : $val\n";
548b39c5158Smillert    }
549b39c5158Smillert    join "", @m;
550b39c5158Smillert}
551b39c5158Smillert
552b39c5158Smillert
553b39c5158Smillert=item init_DEST
554b39c5158Smillert
555b39c5158Smillert  $mm->init_DEST
556b39c5158Smillert
557b39c5158SmillertDefines the DESTDIR and DEST* variables paralleling the INSTALL*.
558b39c5158Smillert
559b39c5158Smillert=cut
560b39c5158Smillert
561b39c5158Smillertsub init_DEST {
562b39c5158Smillert    my $self = shift;
563b39c5158Smillert
564b39c5158Smillert    # Initialize DESTDIR
565b39c5158Smillert    $self->{DESTDIR} ||= '';
566b39c5158Smillert
567b39c5158Smillert    # Make DEST variables.
568b39c5158Smillert    foreach my $var ($self->installvars) {
569b39c5158Smillert        my $destvar = 'DESTINSTALL'.$var;
570b39c5158Smillert        $self->{$destvar} ||= '$(DESTDIR)$(INSTALL'.$var.')';
571b39c5158Smillert    }
572b39c5158Smillert}
573b39c5158Smillert
574b39c5158Smillert
575b39c5158Smillert=item init_dist
576b39c5158Smillert
577b39c5158Smillert  $mm->init_dist;
578b39c5158Smillert
579b39c5158SmillertDefines a lot of macros for distribution support.
580b39c5158Smillert
581b39c5158Smillert  macro         description                     default
582b39c5158Smillert
583b39c5158Smillert  TAR           tar command to use              tar
584b39c5158Smillert  TARFLAGS      flags to pass to TAR            cvf
585b39c5158Smillert
586b39c5158Smillert  ZIP           zip command to use              zip
587b39c5158Smillert  ZIPFLAGS      flags to pass to ZIP            -r
588b39c5158Smillert
589b39c5158Smillert  COMPRESS      compression command to          gzip --best
590b39c5158Smillert                use for tarfiles
591b39c5158Smillert  SUFFIX        suffix to put on                .gz
592b39c5158Smillert                compressed files
593b39c5158Smillert
594b39c5158Smillert  SHAR          shar command to use             shar
595b39c5158Smillert
596b39c5158Smillert  PREOP         extra commands to run before
597b39c5158Smillert                making the archive
598b39c5158Smillert  POSTOP        extra commands to run after
599b39c5158Smillert                making the archive
600b39c5158Smillert
601b39c5158Smillert  TO_UNIX       a command to convert linefeeds
602b39c5158Smillert                to Unix style in your archive
603b39c5158Smillert
604b39c5158Smillert  CI            command to checkin your         ci -u
605b39c5158Smillert                sources to version control
606b39c5158Smillert  RCS_LABEL     command to label your sources   rcs -Nv$(VERSION_SYM): -q
607b39c5158Smillert                just after CI is run
608b39c5158Smillert
609b39c5158Smillert  DIST_CP       $how argument to manicopy()     best
610b39c5158Smillert                when the distdir is created
611b39c5158Smillert
612b39c5158Smillert  DIST_DEFAULT  default target to use to        tardist
613b39c5158Smillert                create a distribution
614b39c5158Smillert
615b39c5158Smillert  DISTVNAME     name of the resulting archive   $(DISTNAME)-$(VERSION)
616b39c5158Smillert                (minus suffixes)
617b39c5158Smillert
618b39c5158Smillert=cut
619b39c5158Smillert
620b39c5158Smillertsub init_dist {
621b39c5158Smillert    my $self = shift;
622b39c5158Smillert
623b39c5158Smillert    $self->{TAR}      ||= 'tar';
624b39c5158Smillert    $self->{TARFLAGS} ||= 'cvf';
625b39c5158Smillert    $self->{ZIP}      ||= 'zip';
626b39c5158Smillert    $self->{ZIPFLAGS} ||= '-r';
627b39c5158Smillert    $self->{COMPRESS} ||= 'gzip --best';
628b39c5158Smillert    $self->{SUFFIX}   ||= '.gz';
629b39c5158Smillert    $self->{SHAR}     ||= 'shar';
630b39c5158Smillert    $self->{PREOP}    ||= '$(NOECHO) $(NOOP)'; # eg update MANIFEST
631b39c5158Smillert    $self->{POSTOP}   ||= '$(NOECHO) $(NOOP)'; # eg remove the distdir
632b39c5158Smillert    $self->{TO_UNIX}  ||= '$(NOECHO) $(NOOP)';
633b39c5158Smillert
634b39c5158Smillert    $self->{CI}       ||= 'ci -u';
635b39c5158Smillert    $self->{RCS_LABEL}||= 'rcs -Nv$(VERSION_SYM): -q';
636b39c5158Smillert    $self->{DIST_CP}  ||= 'best';
637b39c5158Smillert    $self->{DIST_DEFAULT} ||= 'tardist';
638b39c5158Smillert
639b39c5158Smillert    ($self->{DISTNAME} = $self->{NAME}) =~ s{::}{-}g unless $self->{DISTNAME};
640b39c5158Smillert    $self->{DISTVNAME} ||= $self->{DISTNAME}.'-'.$self->{VERSION};
641b39c5158Smillert}
642b39c5158Smillert
643b39c5158Smillert=item dist (o)
644b39c5158Smillert
645b39c5158Smillert  my $dist_macros = $mm->dist(%overrides);
646b39c5158Smillert
647b39c5158SmillertGenerates a make fragment defining all the macros initialized in
648b39c5158Smillertinit_dist.
649b39c5158Smillert
650b39c5158Smillert%overrides can be used to override any of the above.
651b39c5158Smillert
652b39c5158Smillert=cut
653b39c5158Smillert
654b39c5158Smillertsub dist {
655b39c5158Smillert    my($self, %attribs) = @_;
656b39c5158Smillert
657b39c5158Smillert    my $make = '';
658e5157e49Safresh1    if ( $attribs{SUFFIX} && $attribs{SUFFIX} !~ m!^\.! ) {
659e5157e49Safresh1      $attribs{SUFFIX} = '.' . $attribs{SUFFIX};
660e5157e49Safresh1    }
661b39c5158Smillert    foreach my $key (qw(
662b39c5158Smillert            TAR TARFLAGS ZIP ZIPFLAGS COMPRESS SUFFIX SHAR
663b39c5158Smillert            PREOP POSTOP TO_UNIX
664b39c5158Smillert            CI RCS_LABEL DIST_CP DIST_DEFAULT
665b39c5158Smillert            DISTNAME DISTVNAME
666b39c5158Smillert           ))
667b39c5158Smillert    {
668b39c5158Smillert        my $value = $attribs{$key} || $self->{$key};
669b39c5158Smillert        $make .= "$key = $value\n";
670b39c5158Smillert    }
671b39c5158Smillert
672b39c5158Smillert    return $make;
673b39c5158Smillert}
674b39c5158Smillert
675b39c5158Smillert=item dist_basics (o)
676b39c5158Smillert
677b39c5158SmillertDefines the targets distclean, distcheck, skipcheck, manifest, veryclean.
678b39c5158Smillert
679b39c5158Smillert=cut
680b39c5158Smillert
681b39c5158Smillertsub dist_basics {
682b39c5158Smillert    my($self) = shift;
683b39c5158Smillert
684b39c5158Smillert    return <<'MAKE_FRAG';
685b39c5158Smillertdistclean :: realclean distcheck
686b39c5158Smillert	$(NOECHO) $(NOOP)
687b39c5158Smillert
688b39c5158Smillertdistcheck :
689b39c5158Smillert	$(PERLRUN) "-MExtUtils::Manifest=fullcheck" -e fullcheck
690b39c5158Smillert
691b39c5158Smillertskipcheck :
692b39c5158Smillert	$(PERLRUN) "-MExtUtils::Manifest=skipcheck" -e skipcheck
693b39c5158Smillert
694b39c5158Smillertmanifest :
695b39c5158Smillert	$(PERLRUN) "-MExtUtils::Manifest=mkmanifest" -e mkmanifest
696b39c5158Smillert
697b39c5158Smillertveryclean : realclean
698b39c5158Smillert	$(RM_F) *~ */*~ *.orig */*.orig *.bak */*.bak *.old */*.old
699b39c5158Smillert
700b39c5158SmillertMAKE_FRAG
701b39c5158Smillert
702b39c5158Smillert}
703b39c5158Smillert
704b39c5158Smillert=item dist_ci (o)
705b39c5158Smillert
706b39c5158SmillertDefines a check in target for RCS.
707b39c5158Smillert
708b39c5158Smillert=cut
709b39c5158Smillert
710b39c5158Smillertsub dist_ci {
711b39c5158Smillert    my($self) = shift;
712b8851fccSafresh1    return sprintf "ci :\n\t%s\n", $self->oneliner(<<'EOF', [qw(-MExtUtils::Manifest=maniread)]);
713b8851fccSafresh1@all = sort keys %{ maniread() };
714b8851fccSafresh1print(qq{Executing $(CI) @all\n});
715b8851fccSafresh1system(qq{$(CI) @all}) == 0 or die $!;
716b8851fccSafresh1print(qq{Executing $(RCS_LABEL) ...\n});
717b8851fccSafresh1system(qq{$(RCS_LABEL) @all}) == 0 or die $!;
718b8851fccSafresh1EOF
719b39c5158Smillert}
720b39c5158Smillert
721b39c5158Smillert=item dist_core (o)
722b39c5158Smillert
723b39c5158Smillert  my $dist_make_fragment = $MM->dist_core;
724b39c5158Smillert
725b39c5158SmillertPuts the targets necessary for 'make dist' together into one make
726b39c5158Smillertfragment.
727b39c5158Smillert
728b39c5158Smillert=cut
729b39c5158Smillert
730b39c5158Smillertsub dist_core {
731b39c5158Smillert    my($self) = shift;
732b39c5158Smillert
733b39c5158Smillert    my $make_frag = '';
734b39c5158Smillert    foreach my $target (qw(dist tardist uutardist tarfile zipdist zipfile
735b39c5158Smillert                           shdist))
736b39c5158Smillert    {
737b39c5158Smillert        my $method = $target.'_target';
738b39c5158Smillert        $make_frag .= "\n";
739b39c5158Smillert        $make_frag .= $self->$method();
740b39c5158Smillert    }
741b39c5158Smillert
742b39c5158Smillert    return $make_frag;
743b39c5158Smillert}
744b39c5158Smillert
745b39c5158Smillert
746b39c5158Smillert=item B<dist_target>
747b39c5158Smillert
748b39c5158Smillert  my $make_frag = $MM->dist_target;
749b39c5158Smillert
750b39c5158SmillertReturns the 'dist' target to make an archive for distribution.  This
751b39c5158Smillerttarget simply checks to make sure the Makefile is up-to-date and
752b39c5158Smillertdepends on $(DIST_DEFAULT).
753b39c5158Smillert
754b39c5158Smillert=cut
755b39c5158Smillert
756b39c5158Smillertsub dist_target {
757b39c5158Smillert    my($self) = shift;
758b39c5158Smillert
759b39c5158Smillert    my $date_check = $self->oneliner(<<'CODE', ['-l']);
760b39c5158Smillertprint 'Warning: Makefile possibly out of date with $(VERSION_FROM)'
761b39c5158Smillert    if -e '$(VERSION_FROM)' and -M '$(VERSION_FROM)' < -M '$(FIRST_MAKEFILE)';
762b39c5158SmillertCODE
763b39c5158Smillert
764b39c5158Smillert    return sprintf <<'MAKE_FRAG', $date_check;
765b39c5158Smillertdist : $(DIST_DEFAULT) $(FIRST_MAKEFILE)
766b39c5158Smillert	$(NOECHO) %s
767b39c5158SmillertMAKE_FRAG
768b39c5158Smillert}
769b39c5158Smillert
770b39c5158Smillert=item B<tardist_target>
771b39c5158Smillert
772b39c5158Smillert  my $make_frag = $MM->tardist_target;
773b39c5158Smillert
774b39c5158SmillertReturns the 'tardist' target which is simply so 'make tardist' works.
775b39c5158SmillertThe real work is done by the dynamically named tardistfile_target()
776b39c5158Smillertmethod, tardist should have that as a dependency.
777b39c5158Smillert
778b39c5158Smillert=cut
779b39c5158Smillert
780b39c5158Smillertsub tardist_target {
781b39c5158Smillert    my($self) = shift;
782b39c5158Smillert
783b39c5158Smillert    return <<'MAKE_FRAG';
784b39c5158Smillerttardist : $(DISTVNAME).tar$(SUFFIX)
785b39c5158Smillert	$(NOECHO) $(NOOP)
786b39c5158SmillertMAKE_FRAG
787b39c5158Smillert}
788b39c5158Smillert
789b39c5158Smillert=item B<zipdist_target>
790b39c5158Smillert
791b39c5158Smillert  my $make_frag = $MM->zipdist_target;
792b39c5158Smillert
793b39c5158SmillertReturns the 'zipdist' target which is simply so 'make zipdist' works.
794b39c5158SmillertThe real work is done by the dynamically named zipdistfile_target()
795b39c5158Smillertmethod, zipdist should have that as a dependency.
796b39c5158Smillert
797b39c5158Smillert=cut
798b39c5158Smillert
799b39c5158Smillertsub zipdist_target {
800b39c5158Smillert    my($self) = shift;
801b39c5158Smillert
802b39c5158Smillert    return <<'MAKE_FRAG';
803b39c5158Smillertzipdist : $(DISTVNAME).zip
804b39c5158Smillert	$(NOECHO) $(NOOP)
805b39c5158SmillertMAKE_FRAG
806b39c5158Smillert}
807b39c5158Smillert
808b39c5158Smillert=item B<tarfile_target>
809b39c5158Smillert
810b39c5158Smillert  my $make_frag = $MM->tarfile_target;
811b39c5158Smillert
812b39c5158SmillertThe name of this target is the name of the tarball generated by
813b39c5158Smillerttardist.  This target does the actual work of turning the distdir into
814b39c5158Smillerta tarball.
815b39c5158Smillert
816b39c5158Smillert=cut
817b39c5158Smillert
818b39c5158Smillertsub tarfile_target {
819b39c5158Smillert    my($self) = shift;
820b39c5158Smillert
821b39c5158Smillert    return <<'MAKE_FRAG';
822b39c5158Smillert$(DISTVNAME).tar$(SUFFIX) : distdir
823b39c5158Smillert	$(PREOP)
824b39c5158Smillert	$(TO_UNIX)
825b39c5158Smillert	$(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
826b39c5158Smillert	$(RM_RF) $(DISTVNAME)
827b39c5158Smillert	$(COMPRESS) $(DISTVNAME).tar
828e5157e49Safresh1	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)'
829b39c5158Smillert	$(POSTOP)
830b39c5158SmillertMAKE_FRAG
831b39c5158Smillert}
832b39c5158Smillert
833b39c5158Smillert=item zipfile_target
834b39c5158Smillert
835b39c5158Smillert  my $make_frag = $MM->zipfile_target;
836b39c5158Smillert
837b39c5158SmillertThe name of this target is the name of the zip file generated by
838b39c5158Smillertzipdist.  This target does the actual work of turning the distdir into
839b39c5158Smillerta zip file.
840b39c5158Smillert
841b39c5158Smillert=cut
842b39c5158Smillert
843b39c5158Smillertsub zipfile_target {
844b39c5158Smillert    my($self) = shift;
845b39c5158Smillert
846b39c5158Smillert    return <<'MAKE_FRAG';
847b39c5158Smillert$(DISTVNAME).zip : distdir
848b39c5158Smillert	$(PREOP)
849b39c5158Smillert	$(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
850b39c5158Smillert	$(RM_RF) $(DISTVNAME)
851e5157e49Safresh1	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).zip'
852b39c5158Smillert	$(POSTOP)
853b39c5158SmillertMAKE_FRAG
854b39c5158Smillert}
855b39c5158Smillert
856b39c5158Smillert=item uutardist_target
857b39c5158Smillert
858b39c5158Smillert  my $make_frag = $MM->uutardist_target;
859b39c5158Smillert
860b39c5158SmillertConverts the tarfile into a uuencoded file
861b39c5158Smillert
862b39c5158Smillert=cut
863b39c5158Smillert
864b39c5158Smillertsub uutardist_target {
865b39c5158Smillert    my($self) = shift;
866b39c5158Smillert
867b39c5158Smillert    return <<'MAKE_FRAG';
868b39c5158Smillertuutardist : $(DISTVNAME).tar$(SUFFIX)
869b39c5158Smillert	uuencode $(DISTVNAME).tar$(SUFFIX) $(DISTVNAME).tar$(SUFFIX) > $(DISTVNAME).tar$(SUFFIX)_uu
870e5157e49Safresh1	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).tar$(SUFFIX)_uu'
871b39c5158SmillertMAKE_FRAG
872b39c5158Smillert}
873b39c5158Smillert
874b39c5158Smillert
875b39c5158Smillert=item shdist_target
876b39c5158Smillert
877b39c5158Smillert  my $make_frag = $MM->shdist_target;
878b39c5158Smillert
879b39c5158SmillertConverts the distdir into a shell archive.
880b39c5158Smillert
881b39c5158Smillert=cut
882b39c5158Smillert
883b39c5158Smillertsub shdist_target {
884b39c5158Smillert    my($self) = shift;
885b39c5158Smillert
886b39c5158Smillert    return <<'MAKE_FRAG';
887b39c5158Smillertshdist : distdir
888b39c5158Smillert	$(PREOP)
889b39c5158Smillert	$(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
890b39c5158Smillert	$(RM_RF) $(DISTVNAME)
891e5157e49Safresh1	$(NOECHO) $(ECHO) 'Created $(DISTVNAME).shar'
892b39c5158Smillert	$(POSTOP)
893b39c5158SmillertMAKE_FRAG
894b39c5158Smillert}
895b39c5158Smillert
896b39c5158Smillert
897b39c5158Smillert=item dlsyms (o)
898b39c5158Smillert
899b39c5158SmillertUsed by some OS' to define DL_FUNCS and DL_VARS and write the *.exp files.
900b39c5158Smillert
901b39c5158SmillertNormally just returns an empty string.
902b39c5158Smillert
903b39c5158Smillert=cut
904b39c5158Smillert
905b39c5158Smillertsub dlsyms {
906b39c5158Smillert    return '';
907b39c5158Smillert}
908b39c5158Smillert
909b39c5158Smillert
910b39c5158Smillert=item dynamic_bs (o)
911b39c5158Smillert
912b39c5158SmillertDefines targets for bootstrap files.
913b39c5158Smillert
914b39c5158Smillert=cut
915b39c5158Smillert
916b39c5158Smillertsub dynamic_bs {
917b39c5158Smillert    my($self, %attribs) = @_;
9189f11ffb7Safresh1    return "\nBOOTSTRAP =\n" unless $self->has_link_code();
9199f11ffb7Safresh1    my @exts;
9209f11ffb7Safresh1    if ($self->{XSMULTI}) {
9219f11ffb7Safresh1	@exts = $self->_xs_list_basenames;
9229f11ffb7Safresh1    } else {
9239f11ffb7Safresh1	@exts = '$(BASEEXT)';
9249f11ffb7Safresh1    }
9259f11ffb7Safresh1    return join "\n",
9269f11ffb7Safresh1        "BOOTSTRAP = @{[map { qq{$_.bs} } @exts]}\n",
9279f11ffb7Safresh1        map { $self->_xs_make_bs($_) } @exts;
9289f11ffb7Safresh1}
929b39c5158Smillert
9309f11ffb7Safresh1sub _xs_make_bs {
9319f11ffb7Safresh1    my ($self, $basename) = @_;
9329f11ffb7Safresh1    my ($v, $d, $f) = File::Spec->splitpath($basename);
9339f11ffb7Safresh1    my @d = File::Spec->splitdir($d);
9349f11ffb7Safresh1    shift @d if $self->{XSMULTI} and $d[0] eq 'lib';
9359f11ffb7Safresh1    my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
9369f11ffb7Safresh1    $instdir = '$(INST_ARCHAUTODIR)' if $basename eq '$(BASEEXT)';
9379f11ffb7Safresh1    my $instfile = $self->catfile($instdir, "$f.bs");
9389f11ffb7Safresh1    my $exists = "$instdir\$(DFSEP).exists"; # match blibdirs_target
9399f11ffb7Safresh1    #                                 1          2          3
9409f11ffb7Safresh1    return _sprintf562 <<'MAKE_FRAG', $basename, $instfile, $exists;
941b39c5158Smillert# As Mkbootstrap might not write a file (if none is required)
942b39c5158Smillert# we use touch to prevent make continually trying to remake it.
943b39c5158Smillert# The DynaLoader only reads a non-empty file.
9449f11ffb7Safresh1%1$s.bs : $(FIRST_MAKEFILE) $(BOOTDEP)
9459f11ffb7Safresh1	$(NOECHO) $(ECHO) "Running Mkbootstrap for %1$s ($(BSLOADLIBS))"
946b39c5158Smillert	$(NOECHO) $(PERLRUN) \
947b39c5158Smillert		"-MExtUtils::Mkbootstrap" \
9489f11ffb7Safresh1		-e "Mkbootstrap('%1$s','$(BSLOADLIBS)');"
9499f11ffb7Safresh1	$(NOECHO) $(TOUCH) "%1$s.bs"
9509f11ffb7Safresh1	$(CHMOD) $(PERM_RW) "%1$s.bs"
9519f11ffb7Safresh1
9529f11ffb7Safresh1%2$s : %1$s.bs %3$s
9539f11ffb7Safresh1	$(NOECHO) $(RM_RF) %2$s
9549f11ffb7Safresh1	- $(CP_NONEMPTY) %1$s.bs %2$s $(PERM_RW)
955b39c5158SmillertMAKE_FRAG
956b39c5158Smillert}
957b39c5158Smillert
958b39c5158Smillert=item dynamic_lib (o)
959b39c5158Smillert
960b39c5158SmillertDefines how to produce the *.so (or equivalent) files.
961b39c5158Smillert
962b39c5158Smillert=cut
963b39c5158Smillert
964b39c5158Smillertsub dynamic_lib {
965b39c5158Smillert    my($self, %attribs) = @_;
966b39c5158Smillert    return '' unless $self->needs_linking(); #might be because of a subdir
967b39c5158Smillert    return '' unless $self->has_link_code;
9689f11ffb7Safresh1    my @m = $self->xs_dynamic_lib_macros(\%attribs);
9699f11ffb7Safresh1    my @libs;
9709f11ffb7Safresh1    my $dlsyms_ext = eval { $self->xs_dlsyms_ext };
9719f11ffb7Safresh1    if ($self->{XSMULTI}) {
9729f11ffb7Safresh1        my @exts = $self->_xs_list_basenames;
9739f11ffb7Safresh1        for my $ext (@exts) {
9749f11ffb7Safresh1            my ($v, $d, $f) = File::Spec->splitpath($ext);
9759f11ffb7Safresh1            my @d = File::Spec->splitdir($d);
9769f11ffb7Safresh1            shift @d if $d[0] eq 'lib';
97756d68f1eSafresh1            pop @d if $d[$#d] eq '';
9789f11ffb7Safresh1            my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
979b39c5158Smillert
9809f11ffb7Safresh1            # Dynamic library names may need special handling.
9819f11ffb7Safresh1            eval { require DynaLoader };
9829f11ffb7Safresh1            if (defined &DynaLoader::mod2fname) {
9839f11ffb7Safresh1                $f = &DynaLoader::mod2fname([@d, $f]);
9849f11ffb7Safresh1            }
9859f11ffb7Safresh1
9869f11ffb7Safresh1            my $instfile = $self->catfile($instdir, "$f.\$(DLEXT)");
9879f11ffb7Safresh1            my $objfile = $self->_xsbuild_value('xs', $ext, 'OBJECT');
9889f11ffb7Safresh1            $objfile = "$ext\$(OBJ_EXT)" unless defined $objfile;
9899f11ffb7Safresh1            my $ldfrom = $self->_xsbuild_value('xs', $ext, 'LDFROM');
9909f11ffb7Safresh1            $ldfrom = $objfile unless defined $ldfrom;
9919f11ffb7Safresh1            my $exportlist = "$ext.def";
9929f11ffb7Safresh1            my @libchunk = ($objfile, $instfile, $instdir, $ldfrom, $exportlist);
9939f11ffb7Safresh1            push @libchunk, $dlsyms_ext ? $ext.$dlsyms_ext : undef;
9949f11ffb7Safresh1            push @libs, \@libchunk;
9959f11ffb7Safresh1        }
9969f11ffb7Safresh1    } else {
9979f11ffb7Safresh1        my @libchunk = qw($(OBJECT) $(INST_DYNAMIC) $(INST_ARCHAUTODIR) $(LDFROM) $(EXPORT_LIST));
9989f11ffb7Safresh1        push @libchunk, $dlsyms_ext ? '$(BASEEXT)'.$dlsyms_ext : undef;
9999f11ffb7Safresh1        @libs = (\@libchunk);
10009f11ffb7Safresh1    }
10019f11ffb7Safresh1    push @m, map { $self->xs_make_dynamic_lib(\%attribs, @$_); } @libs;
10029f11ffb7Safresh1
10039f11ffb7Safresh1    return join("\n",@m);
10049f11ffb7Safresh1}
10059f11ffb7Safresh1
10069f11ffb7Safresh1=item xs_dynamic_lib_macros
10079f11ffb7Safresh1
10089f11ffb7Safresh1Defines the macros for the C<dynamic_lib> section.
10099f11ffb7Safresh1
10109f11ffb7Safresh1=cut
10119f11ffb7Safresh1
10129f11ffb7Safresh1sub xs_dynamic_lib_macros {
10139f11ffb7Safresh1    my ($self, $attribs) = @_;
10149f11ffb7Safresh1    my $otherldflags = $attribs->{OTHERLDFLAGS} || "";
10159f11ffb7Safresh1    my $inst_dynamic_dep = $attribs->{INST_DYNAMIC_DEP} || "";
10169f11ffb7Safresh1    my $armaybe = $self->_xs_armaybe($attribs);
1017b39c5158Smillert    my $ld_opt = $Is{OS2} ? '$(OPTIMIZE) ' : ''; # Useful on other systems too?
1018b39c5158Smillert    my $ld_fix = $Is{OS2} ? '|| ( $(RM_F) $@ && sh -c false )' : '';
10199f11ffb7Safresh1    sprintf <<'EOF', $armaybe, $ld_opt.$otherldflags, $inst_dynamic_dep, $ld_fix;
10209f11ffb7Safresh1# This section creates the dynamically loadable objects from relevant
10219f11ffb7Safresh1# objects and possibly $(MYEXTLIB).
10229f11ffb7Safresh1ARMAYBE = %s
10239f11ffb7Safresh1OTHERLDFLAGS = %s
10249f11ffb7Safresh1INST_DYNAMIC_DEP = %s
10259f11ffb7Safresh1INST_DYNAMIC_FIX = %s
10269f11ffb7Safresh1EOF
10279f11ffb7Safresh1}
1028b39c5158Smillert
10299f11ffb7Safresh1sub _xs_armaybe {
10309f11ffb7Safresh1    my ($self, $attribs) = @_;
10319f11ffb7Safresh1    my $armaybe = $attribs->{ARMAYBE} || $self->{ARMAYBE} || ":";
10329f11ffb7Safresh1    $armaybe = 'ar' if ($Is{OSF} and $armaybe eq ':');
10339f11ffb7Safresh1    $armaybe;
10349f11ffb7Safresh1}
10359f11ffb7Safresh1
10369f11ffb7Safresh1=item xs_make_dynamic_lib
10379f11ffb7Safresh1
10389f11ffb7Safresh1Defines the recipes for the C<dynamic_lib> section.
10399f11ffb7Safresh1
10409f11ffb7Safresh1=cut
10419f11ffb7Safresh1
10429f11ffb7Safresh1sub xs_make_dynamic_lib {
10439f11ffb7Safresh1    my ($self, $attribs, $object, $to, $todir, $ldfrom, $exportlist, $dlsyms) = @_;
10449f11ffb7Safresh1    $exportlist = '' if $exportlist ne '$(EXPORT_LIST)';
10459f11ffb7Safresh1    my $armaybe = $self->_xs_armaybe($attribs);
10469f11ffb7Safresh1    my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(PERL_ARCHIVE_AFTER) $(INST_DYNAMIC_DEP) %s'."\n", $to, $object, $todir, $exportlist, ($dlsyms || '');
10479f11ffb7Safresh1    my $dlsyms_arg = $self->xs_dlsyms_arg($dlsyms);
1048b39c5158Smillert    if ($armaybe ne ':'){
1049b39c5158Smillert        $ldfrom = 'tmp$(LIB_EXT)';
10509f11ffb7Safresh1        push(@m,"	\$(ARMAYBE) cr $ldfrom $object\n");
10519f11ffb7Safresh1        push(@m,"	\$(RANLIB) $ldfrom\n");
1052b39c5158Smillert    }
1053b39c5158Smillert    $ldfrom = "-all $ldfrom -none" if $Is{OSF};
1054b39c5158Smillert
1055eac174f2Safresh1    my $ldrun = '';
1056b39c5158Smillert    # The IRIX linker doesn't use LD_RUN_PATH
1057eac174f2Safresh1    if ( $self->{LD_RUN_PATH} ) {
1058eac174f2Safresh1        if ( $Is{IRIX} ) {
1059eac174f2Safresh1            $ldrun = qq{-rpath "$self->{LD_RUN_PATH}"};
1060eac174f2Safresh1        }
1061e0680481Safresh1        elsif ( $^O eq 'darwin' && $Is{AppleRPath} ) {
1062eac174f2Safresh1            # both clang and gcc support -Wl,-rpath, but only clang supports
1063eac174f2Safresh1            # -rpath so by using -Wl,-rpath we avoid having to check for the
1064eac174f2Safresh1            # type of compiler
1065eac174f2Safresh1            $ldrun = qq{-Wl,-rpath,"$self->{LD_RUN_PATH}"};
1066eac174f2Safresh1        }
1067eac174f2Safresh1    }
1068b39c5158Smillert
1069b39c5158Smillert    # For example in AIX the shared objects/libraries from previous builds
1070b39c5158Smillert    # linger quite a while in the shared dynalinker cache even when nobody
1071b39c5158Smillert    # is using them.  This is painful if one for instance tries to restart
1072b39c5158Smillert    # a failed build because the link command will fail unnecessarily 'cos
1073b39c5158Smillert    # the shared object/library is 'busy'.
10749f11ffb7Safresh1    push(@m,"	\$(RM_F) \$\@\n");
1075b39c5158Smillert
1076b39c5158Smillert    my $libs = '$(LDLOADLIBS)';
1077e5157e49Safresh1    if (($Is{NetBSD} || $Is{Interix} || $Is{Android}) && $Config{'useshrplib'} eq 'true') {
1078b39c5158Smillert        # Use nothing on static perl platforms, and to the flags needed
1079b39c5158Smillert        # to link against the shared libperl library on shared perl
1080b39c5158Smillert        # platforms.  We peek at lddlflags to see if we need -Wl,-R
1081b39c5158Smillert        # or -R to add paths to the run-time library search path.
1082b39c5158Smillert        if ($Config{'lddlflags'} =~ /-Wl,-R/) {
1083b8851fccSafresh1            $libs .= ' "-L$(PERL_INC)" "-Wl,-R$(INSTALLARCHLIB)/CORE" "-Wl,-R$(PERL_ARCHLIB)/CORE" -lperl';
1084b39c5158Smillert        } elsif ($Config{'lddlflags'} =~ /-R/) {
1085b8851fccSafresh1            $libs .= ' "-L$(PERL_INC)" "-R$(INSTALLARCHLIB)/CORE" "-R$(PERL_ARCHLIB)/CORE" -lperl';
1086e5157e49Safresh1        } elsif ( $Is{Android} ) {
1087e5157e49Safresh1            # The Android linker will not recognize symbols from
1088e5157e49Safresh1            # libperl unless the module explicitly depends on it.
1089b8851fccSafresh1            $libs .= ' "-L$(PERL_INC)" -lperl';
1090b39c5158Smillert        }
1091b39c5158Smillert    }
1092b39c5158Smillert
1093b39c5158Smillert    my $ld_run_path_shell = "";
1094b39c5158Smillert    if ($self->{LD_RUN_PATH} ne "") {
1095b39c5158Smillert        $ld_run_path_shell = 'LD_RUN_PATH="$(LD_RUN_PATH)" ';
1096b39c5158Smillert    }
1097b39c5158Smillert
10989f11ffb7Safresh1    push @m, sprintf <<'MAKE', $ld_run_path_shell, $ldrun, $dlsyms_arg, $ldfrom, $self->xs_obj_opt('$@'), $libs, $exportlist;
10999f11ffb7Safresh1	%s$(LD) %s $(LDDLFLAGS) %s %s $(OTHERLDFLAGS) %s $(MYEXTLIB) \
11009f11ffb7Safresh1	  $(PERL_ARCHIVE) %s $(PERL_ARCHIVE_AFTER) %s \
1101b39c5158Smillert	  $(INST_DYNAMIC_FIX)
1102b39c5158Smillert	$(CHMOD) $(PERM_RWX) $@
1103b39c5158SmillertMAKE
11049f11ffb7Safresh1    join '', @m;
1105b39c5158Smillert}
1106b39c5158Smillert
1107b39c5158Smillert=item exescan
1108b39c5158Smillert
1109b39c5158SmillertDeprecated method. Use libscan instead.
1110b39c5158Smillert
1111b39c5158Smillert=cut
1112b39c5158Smillert
1113b39c5158Smillertsub exescan {
1114b39c5158Smillert    my($self,$path) = @_;
1115b39c5158Smillert    $path;
1116b39c5158Smillert}
1117b39c5158Smillert
1118b39c5158Smillert=item extliblist
1119b39c5158Smillert
1120b39c5158SmillertCalled by init_others, and calls ext ExtUtils::Liblist. See
1121b39c5158SmillertL<ExtUtils::Liblist> for details.
1122b39c5158Smillert
1123b39c5158Smillert=cut
1124b39c5158Smillert
1125b39c5158Smillertsub extliblist {
1126b39c5158Smillert    my($self,$libs) = @_;
1127b39c5158Smillert    require ExtUtils::Liblist;
1128b39c5158Smillert    $self->ext($libs, $Verbose);
1129b39c5158Smillert}
1130b39c5158Smillert
1131b39c5158Smillert=item find_perl
1132b39c5158Smillert
1133b39c5158SmillertFinds the executables PERL and FULLPERL
1134b39c5158Smillert
1135b39c5158Smillert=cut
1136b39c5158Smillert
1137b39c5158Smillertsub find_perl {
1138b39c5158Smillert    my($self, $ver, $names, $dirs, $trace) = @_;
1139b39c5158Smillert    if ($trace >= 2){
1140b39c5158Smillert        print "Looking for perl $ver by these names:
1141b39c5158Smillert@$names
1142b39c5158Smillertin these dirs:
1143b39c5158Smillert@$dirs
1144b39c5158Smillert";
1145b39c5158Smillert    }
1146b39c5158Smillert
1147b39c5158Smillert    my $stderr_duped = 0;
1148b39c5158Smillert    local *STDERR_COPY;
1149b39c5158Smillert
1150b39c5158Smillert    unless ($Is{BSD}) {
1151b39c5158Smillert        # >& and lexical filehandles together give 5.6.2 indigestion
1152b39c5158Smillert        if( open(STDERR_COPY, '>&STDERR') ) {  ## no critic
1153b39c5158Smillert            $stderr_duped = 1;
1154b39c5158Smillert        }
1155b39c5158Smillert        else {
1156b39c5158Smillert            warn <<WARNING;
1157b39c5158Smillertfind_perl() can't dup STDERR: $!
1158b39c5158SmillertYou might see some garbage while we search for Perl
1159b39c5158SmillertWARNING
1160b39c5158Smillert        }
1161b39c5158Smillert    }
1162b39c5158Smillert
1163b39c5158Smillert    foreach my $name (@$names){
11649f11ffb7Safresh1        my ($abs, $use_dir);
1165b39c5158Smillert        if ($self->file_name_is_absolute($name)) {     # /foo/bar
1166b39c5158Smillert            $abs = $name;
1167b39c5158Smillert        } elsif ($self->canonpath($name) eq
1168b39c5158Smillert                 $self->canonpath(basename($name))) {  # foo
11699f11ffb7Safresh1            $use_dir = 1;
1170b39c5158Smillert        } else {                                            # foo/bar
1171b39c5158Smillert            $abs = $self->catfile($Curdir, $name);
1172b39c5158Smillert        }
11739f11ffb7Safresh1        foreach my $dir ($use_dir ? @$dirs : 1){
11749f11ffb7Safresh1            next unless defined $dir; # $self->{PERL_SRC} may be undefined
11759f11ffb7Safresh1
11769f11ffb7Safresh1            $abs = $self->catfile($dir, $name)
11779f11ffb7Safresh1                if $use_dir;
11789f11ffb7Safresh1
1179b39c5158Smillert            print "Checking $abs\n" if ($trace >= 2);
1180b39c5158Smillert            next unless $self->maybe_command($abs);
1181b39c5158Smillert            print "Executing $abs\n" if ($trace >= 2);
1182b39c5158Smillert
11839f11ffb7Safresh1            my $val;
1184b8851fccSafresh1            my $version_check = qq{"$abs" -le "require $ver; print qq{VER_OK}"};
1185b39c5158Smillert
1186b39c5158Smillert            # To avoid using the unportable 2>&1 to suppress STDERR,
1187b39c5158Smillert            # we close it before running the command.
1188b39c5158Smillert            # However, thanks to a thread library bug in many BSDs
1189b39c5158Smillert            # ( http://www.freebsd.org/cgi/query-pr.cgi?pr=51535 )
1190b39c5158Smillert            # we cannot use the fancier more portable way in here
1191b39c5158Smillert            # but instead need to use the traditional 2>&1 construct.
1192b39c5158Smillert            if ($Is{BSD}) {
1193b39c5158Smillert                $val = `$version_check 2>&1`;
1194b39c5158Smillert            } else {
1195b39c5158Smillert                close STDERR if $stderr_duped;
1196b39c5158Smillert                $val = `$version_check`;
1197b39c5158Smillert
1198b39c5158Smillert                # 5.6.2's 3-arg open doesn't work with >&
1199b39c5158Smillert                open STDERR, ">&STDERR_COPY"  ## no critic
1200b39c5158Smillert                        if $stderr_duped;
1201b39c5158Smillert            }
1202b39c5158Smillert
1203b39c5158Smillert            if ($val =~ /^VER_OK/m) {
1204b39c5158Smillert                print "Using PERL=$abs\n" if $trace;
1205b39c5158Smillert                return $abs;
1206b39c5158Smillert            } elsif ($trace >= 2) {
1207b39c5158Smillert                print "Result: '$val' ".($? >> 8)."\n";
1208b39c5158Smillert            }
1209b39c5158Smillert        }
1210b39c5158Smillert    }
1211e9ce3842Safresh1    print "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
1212b39c5158Smillert    0; # false and not empty
1213b39c5158Smillert}
1214b39c5158Smillert
1215b39c5158Smillert
1216b39c5158Smillert=item fixin
1217b39c5158Smillert
1218b39c5158Smillert  $mm->fixin(@files);
1219b39c5158Smillert
1220b39c5158SmillertInserts the sharpbang or equivalent magic number to a set of @files.
1221b39c5158Smillert
1222b39c5158Smillert=cut
1223b39c5158Smillert
1224b39c5158Smillertsub fixin {    # stolen from the pink Camel book, more or less
1225b39c5158Smillert    my ( $self, @files ) = @_;
1226b39c5158Smillert
1227b39c5158Smillert    for my $file (@files) {
1228b39c5158Smillert        my $file_new = "$file.new";
1229b39c5158Smillert        my $file_bak = "$file.bak";
1230b39c5158Smillert
1231b39c5158Smillert        open( my $fixin, '<', $file ) or croak "Can't process '$file': $!";
1232b39c5158Smillert        local $/ = "\n";
1233b39c5158Smillert        chomp( my $line = <$fixin> );
1234e5157e49Safresh1        next unless $line =~ s/^\s*\#!\s*//;    # Not a shebang file.
1235b39c5158Smillert
123648950c12Ssthen        my $shb = $self->_fixin_replace_shebang( $file, $line );
123748950c12Ssthen        next unless defined $shb;
1238b39c5158Smillert
1239b39c5158Smillert        open( my $fixout, ">", "$file_new" ) or do {
1240b39c5158Smillert            warn "Can't create new $file: $!\n";
1241b39c5158Smillert            next;
1242b39c5158Smillert        };
1243b39c5158Smillert
1244b39c5158Smillert        # Print out the new #! line (or equivalent).
1245b39c5158Smillert        local $\;
1246b39c5158Smillert        local $/;
1247b39c5158Smillert        print $fixout $shb, <$fixin>;
1248b39c5158Smillert        close $fixin;
1249b39c5158Smillert        close $fixout;
1250b39c5158Smillert
1251b39c5158Smillert        chmod 0666, $file_bak;
1252b39c5158Smillert        unlink $file_bak;
1253b39c5158Smillert        unless ( _rename( $file, $file_bak ) ) {
1254b39c5158Smillert            warn "Can't rename $file to $file_bak: $!";
1255b39c5158Smillert            next;
1256b39c5158Smillert        }
1257b39c5158Smillert        unless ( _rename( $file_new, $file ) ) {
1258b39c5158Smillert            warn "Can't rename $file_new to $file: $!";
1259b39c5158Smillert            unless ( _rename( $file_bak, $file ) ) {
1260b39c5158Smillert                warn "Can't rename $file_bak back to $file either: $!";
1261b39c5158Smillert                warn "Leaving $file renamed as $file_bak\n";
1262b39c5158Smillert            }
1263b39c5158Smillert            next;
1264b39c5158Smillert        }
1265b39c5158Smillert        unlink $file_bak;
1266b39c5158Smillert    }
1267b39c5158Smillert    continue {
1268b39c5158Smillert        system("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';
1269b39c5158Smillert    }
1270b39c5158Smillert}
1271b39c5158Smillert
1272b39c5158Smillert
1273b39c5158Smillertsub _rename {
1274b39c5158Smillert    my($old, $new) = @_;
1275b39c5158Smillert
1276b39c5158Smillert    foreach my $file ($old, $new) {
1277b39c5158Smillert        if( $Is{VMS} and basename($file) !~ /\./ ) {
1278b39c5158Smillert            # rename() in 5.8.0 on VMS will not rename a file if it
1279b39c5158Smillert            # does not contain a dot yet it returns success.
1280b39c5158Smillert            $file = "$file.";
1281b39c5158Smillert        }
1282b39c5158Smillert    }
1283b39c5158Smillert
1284b39c5158Smillert    return rename($old, $new);
1285b39c5158Smillert}
1286b39c5158Smillert
128748950c12Ssthensub _fixin_replace_shebang {
128848950c12Ssthen    my ( $self, $file, $line ) = @_;
128948950c12Ssthen
129048950c12Ssthen    # Now figure out the interpreter name.
129156d68f1eSafresh1    my ( $origcmd, $arg ) = split ' ', $line, 2;
129256d68f1eSafresh1    (my $cmd = $origcmd) =~ s!^.*/!!;
129348950c12Ssthen
129448950c12Ssthen    # Now look (in reverse) for interpreter in absolute PATH (unless perl).
129548950c12Ssthen    my $interpreter;
129656d68f1eSafresh1    if ( defined $ENV{PERL_MM_SHEBANG} && $ENV{PERL_MM_SHEBANG} eq "relocatable" ) {
129756d68f1eSafresh1        $interpreter = "/usr/bin/env perl";
129856d68f1eSafresh1    }
129956d68f1eSafresh1    elsif ( $cmd =~ m{^perl(?:\z|[^a-z])} ) {
130048950c12Ssthen        if ( $Config{startperl} =~ m,^\#!.*/perl, ) {
130148950c12Ssthen            $interpreter = $Config{startperl};
130248950c12Ssthen            $interpreter =~ s,^\#!,,;
130348950c12Ssthen        }
130448950c12Ssthen        else {
130548950c12Ssthen            $interpreter = $Config{perlpath};
130648950c12Ssthen        }
130748950c12Ssthen    }
130848950c12Ssthen    else {
130948950c12Ssthen        my (@absdirs)
131048950c12Ssthen            = reverse grep { $self->file_name_is_absolute($_) } $self->path;
131148950c12Ssthen        $interpreter = '';
131248950c12Ssthen
131348950c12Ssthen        foreach my $dir (@absdirs) {
13149f11ffb7Safresh1            my $maybefile = $self->catfile($dir,$cmd);
13159f11ffb7Safresh1            if ( $self->maybe_command($maybefile) ) {
131648950c12Ssthen                warn "Ignoring $interpreter in $file\n"
131748950c12Ssthen                    if $Verbose && $interpreter;
13189f11ffb7Safresh1                $interpreter = $maybefile;
131948950c12Ssthen            }
132048950c12Ssthen        }
132156d68f1eSafresh1
132256d68f1eSafresh1        # If the shebang is absolute and exists in PATH, but was not
132356d68f1eSafresh1        # the first one found, leave it alone if it's actually the
132456d68f1eSafresh1        # same file as first one.  This avoids packages built on
132556d68f1eSafresh1        # merged-/usr systems with /usr/bin before /bin in the path
132656d68f1eSafresh1        # breaking when installed on systems without merged /usr
132756d68f1eSafresh1        if ($origcmd ne $interpreter and $self->file_name_is_absolute($origcmd)) {
132856d68f1eSafresh1            my $origdir = dirname($origcmd);
132956d68f1eSafresh1            if ($self->maybe_command($origcmd) && grep { $_ eq $origdir } @absdirs) {
133056d68f1eSafresh1                my ($odev, $oino) = stat $origcmd;
133156d68f1eSafresh1                my ($idev, $iino) = stat $interpreter;
1332eac174f2Safresh1                if ($odev == $idev && $oino eq $iino) {
133356d68f1eSafresh1                    warn "$origcmd is the same as $interpreter, leaving alone"
133456d68f1eSafresh1                        if $Verbose;
133556d68f1eSafresh1                    $interpreter = $origcmd;
133656d68f1eSafresh1                }
133756d68f1eSafresh1            }
133856d68f1eSafresh1        }
133948950c12Ssthen    }
134048950c12Ssthen
134148950c12Ssthen    # Figure out how to invoke interpreter on this machine.
134248950c12Ssthen
134348950c12Ssthen    my ($does_shbang) = $Config{'sharpbang'} =~ /^\s*\#\!/;
134448950c12Ssthen    my ($shb) = "";
134548950c12Ssthen    if ($interpreter) {
1346e9ce3842Safresh1        print "Changing sharpbang in $file to $interpreter"
134748950c12Ssthen            if $Verbose;
134848950c12Ssthen         # this is probably value-free on DOSISH platforms
134948950c12Ssthen        if ($does_shbang) {
135048950c12Ssthen            $shb .= "$Config{'sharpbang'}$interpreter";
135148950c12Ssthen            $shb .= ' ' . $arg if defined $arg;
135248950c12Ssthen            $shb .= "\n";
135348950c12Ssthen        }
135448950c12Ssthen    }
135548950c12Ssthen    else {
135648950c12Ssthen        warn "Can't find $cmd in PATH, $file unchanged"
135748950c12Ssthen            if $Verbose;
1358e9ce3842Safresh1        return;
135948950c12Ssthen    }
136048950c12Ssthen    return $shb
136148950c12Ssthen}
1362b39c5158Smillert
1363b39c5158Smillert=item force (o)
1364b39c5158Smillert
1365b39c5158SmillertWrites an empty FORCE: target.
1366b39c5158Smillert
1367b39c5158Smillert=cut
1368b39c5158Smillert
1369b39c5158Smillertsub force {
1370b39c5158Smillert    my($self) = shift;
1371b39c5158Smillert    '# Phony target to force checking subdirectories.
1372b39c5158SmillertFORCE :
1373b39c5158Smillert	$(NOECHO) $(NOOP)
1374b39c5158Smillert';
1375b39c5158Smillert}
1376b39c5158Smillert
1377b39c5158Smillert=item guess_name
1378b39c5158Smillert
1379b39c5158SmillertGuess the name of this package by examining the working directory's
1380b39c5158Smillertname. MakeMaker calls this only if the developer has not supplied a
1381b39c5158SmillertNAME attribute.
1382b39c5158Smillert
1383b39c5158Smillert=cut
1384b39c5158Smillert
1385b39c5158Smillert# ';
1386b39c5158Smillert
1387b39c5158Smillertsub guess_name {
1388b39c5158Smillert    my($self) = @_;
1389b39c5158Smillert    use Cwd 'cwd';
1390b39c5158Smillert    my $name = basename(cwd());
1391b39c5158Smillert    $name =~ s|[\-_][\d\.\-]+\z||;  # this is new with MM 5.00, we
1392b39c5158Smillert                                    # strip minus or underline
1393b39c5158Smillert                                    # followed by a float or some such
1394b39c5158Smillert    print "Warning: Guessing NAME [$name] from current directory name.\n";
1395b39c5158Smillert    $name;
1396b39c5158Smillert}
1397b39c5158Smillert
1398b39c5158Smillert=item has_link_code
1399b39c5158Smillert
1400b39c5158SmillertReturns true if C, XS, MYEXTLIB or similar objects exist within this
1401b39c5158Smillertobject that need a compiler. Does not descend into subdirectories as
1402b39c5158Smillertneeds_linking() does.
1403b39c5158Smillert
1404b39c5158Smillert=cut
1405b39c5158Smillert
1406b39c5158Smillertsub has_link_code {
1407b39c5158Smillert    my($self) = shift;
1408b39c5158Smillert    return $self->{HAS_LINK_CODE} if defined $self->{HAS_LINK_CODE};
1409b39c5158Smillert    if ($self->{OBJECT} or @{$self->{C} || []} or $self->{MYEXTLIB}){
1410b39c5158Smillert	$self->{HAS_LINK_CODE} = 1;
1411b39c5158Smillert	return 1;
1412b39c5158Smillert    }
1413b39c5158Smillert    return $self->{HAS_LINK_CODE} = 0;
1414b39c5158Smillert}
1415b39c5158Smillert
1416b39c5158Smillert
1417b39c5158Smillert=item init_dirscan
1418b39c5158Smillert
1419b39c5158SmillertScans the directory structure and initializes DIR, XS, XS_FILES,
1420b39c5158SmillertC, C_FILES, O_FILES, H, H_FILES, PL_FILES, EXE_FILES.
1421b39c5158Smillert
1422b39c5158SmillertCalled by init_main.
1423b39c5158Smillert
1424b39c5158Smillert=cut
1425b39c5158Smillert
1426b39c5158Smillertsub init_dirscan {	# --- File and Directory Lists (.xs .pm .pod etc)
1427b39c5158Smillert    my($self) = @_;
1428e5157e49Safresh1    my(%dir, %xs, %c, %o, %h, %pl_files, %pm);
1429b39c5158Smillert
1430b39c5158Smillert    my %ignore = map {( $_ => 1 )} qw(Makefile.PL Build.PL test.pl t);
1431b39c5158Smillert
1432b39c5158Smillert    # ignore the distdir
1433b39c5158Smillert    $Is{VMS} ? $ignore{"$self->{DISTVNAME}.dir"} = 1
1434b39c5158Smillert            : $ignore{$self->{DISTVNAME}} = 1;
1435b39c5158Smillert
1436e5157e49Safresh1    my $distprefix = $Is{VMS} ? qr/^\Q$self->{DISTNAME}\E-v?[\d\.]+\.dir$/i
1437e5157e49Safresh1                              : qr/^\Q$self->{DISTNAME}\E-v?[\d\.]+$/;
1438e5157e49Safresh1
1439b39c5158Smillert    @ignore{map lc, keys %ignore} = values %ignore if $Is{VMS};
1440b39c5158Smillert
1441e5157e49Safresh1    if ( defined $self->{XS} and !defined $self->{C} ) {
1442e5157e49Safresh1	my @c_files = grep { m/\.c(pp|xx)?\z/i } values %{$self->{XS}};
1443e5157e49Safresh1	my @o_files = grep { m/(?:.(?:o(?:bj)?)|\$\(OBJ_EXT\))\z/i } values %{$self->{XS}};
1444e5157e49Safresh1	%c = map { $_ => 1 } @c_files;
1445e5157e49Safresh1	%o = map { $_ => 1 } @o_files;
1446e5157e49Safresh1    }
1447e5157e49Safresh1
1448b39c5158Smillert    foreach my $name ($self->lsdir($Curdir)){
1449b39c5158Smillert	next if $name =~ /\#/;
1450e5157e49Safresh1	next if $name =~ $distprefix && -d $name;
1451e9ce3842Safresh1	$name = lc($name) if $Is{VMS};
1452b39c5158Smillert	next if $name eq $Curdir or $name eq $Updir or $ignore{$name};
1453b39c5158Smillert	next unless $self->libscan($name);
1454b39c5158Smillert	if (-d $name){
1455b39c5158Smillert	    next if -l $name; # We do not support symlinks at all
1456b39c5158Smillert            next if $self->{NORECURS};
1457b39c5158Smillert	    $dir{$name} = $name if (-f $self->catfile($name,"Makefile.PL"));
1458b39c5158Smillert	} elsif ($name =~ /\.xs\z/){
1459b39c5158Smillert	    my($c); ($c = $name) =~ s/\.xs\z/.c/;
1460b39c5158Smillert	    $xs{$name} = $c;
1461b39c5158Smillert	    $c{$c} = 1;
1462b39c5158Smillert	} elsif ($name =~ /\.c(pp|xx|c)?\z/i){  # .c .C .cpp .cxx .cc
1463b39c5158Smillert	    $c{$name} = 1
1464b39c5158Smillert		unless $name =~ m/perlmain\.c/; # See MAP_TARGET
1465b39c5158Smillert	} elsif ($name =~ /\.h\z/i){
1466b39c5158Smillert	    $h{$name} = 1;
1467b39c5158Smillert	} elsif ($name =~ /\.PL\z/) {
1468b39c5158Smillert	    ($pl_files{$name} = $name) =~ s/\.PL\z// ;
1469b39c5158Smillert	} elsif (($Is{VMS} || $Is{Dos}) && $name =~ /[._]pl$/i) {
1470b39c5158Smillert	    # case-insensitive filesystem, one dot per name, so foo.h.PL
1471b39c5158Smillert	    # under Unix appears as foo.h_pl under VMS or fooh.pl on Dos
1472b39c5158Smillert	    local($/); open(my $pl, '<', $name); my $txt = <$pl>; close $pl;
1473b39c5158Smillert	    if ($txt =~ /Extracting \S+ \(with variable substitutions/) {
1474b39c5158Smillert		($pl_files{$name} = $name) =~ s/[._]pl\z//i ;
1475b39c5158Smillert	    }
1476b39c5158Smillert	    else {
1477b39c5158Smillert                $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
1478b39c5158Smillert            }
1479b39c5158Smillert	} elsif ($name =~ /\.(p[ml]|pod)\z/){
1480b39c5158Smillert	    $pm{$name} = $self->catfile($self->{INST_LIBDIR},$name);
1481b39c5158Smillert	}
1482b39c5158Smillert    }
1483b39c5158Smillert
1484b39c5158Smillert    $self->{PL_FILES}   ||= \%pl_files;
1485b39c5158Smillert    $self->{DIR}        ||= [sort keys %dir];
1486b39c5158Smillert    $self->{XS}         ||= \%xs;
1487b39c5158Smillert    $self->{C}          ||= [sort keys %c];
1488b39c5158Smillert    $self->{H}          ||= [sort keys %h];
1489b39c5158Smillert    $self->{PM}         ||= \%pm;
1490b39c5158Smillert
1491b39c5158Smillert    my @o_files = @{$self->{C}};
1492e5157e49Safresh1    %o = (%o, map { $_ => 1 } grep s/\.c(pp|xx|c)?\z/$self->{OBJ_EXT}/i, @o_files);
1493e5157e49Safresh1    $self->{O_FILES} = [sort keys %o];
1494b39c5158Smillert}
1495b39c5158Smillert
1496b39c5158Smillert
1497b39c5158Smillert=item init_MANPODS
1498b39c5158Smillert
1499b39c5158SmillertDetermines if man pages should be generated and initializes MAN1PODS
1500b39c5158Smillertand MAN3PODS as appropriate.
1501b39c5158Smillert
1502b39c5158Smillert=cut
1503b39c5158Smillert
1504b39c5158Smillertsub init_MANPODS {
1505b39c5158Smillert    my $self = shift;
1506b39c5158Smillert
1507b39c5158Smillert    # Set up names of manual pages to generate from pods
1508b39c5158Smillert    foreach my $man (qw(MAN1 MAN3)) {
1509b39c5158Smillert        if ( $self->{"${man}PODS"}
1510b39c5158Smillert             or $self->{"INSTALL${man}DIR"} =~ /^(none|\s*)$/
1511b39c5158Smillert        ) {
1512b39c5158Smillert            $self->{"${man}PODS"} ||= {};
1513b39c5158Smillert        }
1514b39c5158Smillert        else {
1515b39c5158Smillert            my $init_method = "init_${man}PODS";
1516b39c5158Smillert            $self->$init_method();
1517b39c5158Smillert        }
1518b39c5158Smillert    }
1519d0bd1485Safresh1
1520d0bd1485Safresh1    # logic similar to picking man${num}ext in perl's Configure script
1521d0bd1485Safresh1    foreach my $num (1,3) {
1522d0bd1485Safresh1        my $installdirs = uc $self->{INSTALLDIRS};
1523d0bd1485Safresh1        $installdirs = '' if $installdirs eq 'PERL';
152456d68f1eSafresh1        my @mandirs = File::Spec->splitdir( $self->_expand_macros(
152556d68f1eSafresh1            $self->{ "INSTALL${installdirs}MAN${num}DIR" } ) );
152656d68f1eSafresh1        my $mandir = pop @mandirs;
1527d0bd1485Safresh1        my $section = $num;
1528d0bd1485Safresh1
1529d0bd1485Safresh1        foreach ($num, "${num}p", "${num}pm", qw< l n o C L >, "L$num") {
153056d68f1eSafresh1            if ( $mandir =~ /^(?:man|cat)$_$/ ) {
1531d0bd1485Safresh1                $section = $_;
1532d0bd1485Safresh1                last;
1533d0bd1485Safresh1            }
1534d0bd1485Safresh1        }
1535d0bd1485Safresh1
1536d0bd1485Safresh1        $self->{"MAN${num}SECTION"} = $section;
1537d0bd1485Safresh1    }
1538b39c5158Smillert}
1539b39c5158Smillert
1540b39c5158Smillert
1541b39c5158Smillertsub _has_pod {
1542b39c5158Smillert    my($self, $file) = @_;
1543b39c5158Smillert
1544b39c5158Smillert    my($ispod)=0;
1545b39c5158Smillert    if (open( my $fh, '<', $file )) {
1546b39c5158Smillert        while (<$fh>) {
1547b39c5158Smillert            if (/^=(?:head\d+|item|pod)\b/) {
1548b39c5158Smillert                $ispod=1;
1549b39c5158Smillert                last;
1550b39c5158Smillert            }
1551b39c5158Smillert        }
1552b39c5158Smillert        close $fh;
1553b39c5158Smillert    } else {
1554b39c5158Smillert        # If it doesn't exist yet, we assume, it has pods in it
1555b39c5158Smillert        $ispod = 1;
1556b39c5158Smillert    }
1557b39c5158Smillert
1558b39c5158Smillert    return $ispod;
1559b39c5158Smillert}
1560b39c5158Smillert
1561b39c5158Smillert
1562b39c5158Smillert=item init_MAN1PODS
1563b39c5158Smillert
1564b39c5158SmillertInitializes MAN1PODS from the list of EXE_FILES.
1565b39c5158Smillert
1566b39c5158Smillert=cut
1567b39c5158Smillert
1568b39c5158Smillertsub init_MAN1PODS {
1569b39c5158Smillert    my($self) = @_;
1570b39c5158Smillert
1571b39c5158Smillert    if ( exists $self->{EXE_FILES} ) {
1572b39c5158Smillert	foreach my $name (@{$self->{EXE_FILES}}) {
1573b39c5158Smillert	    next unless $self->_has_pod($name);
1574b39c5158Smillert
1575b39c5158Smillert	    $self->{MAN1PODS}->{$name} =
1576b39c5158Smillert		$self->catfile("\$(INST_MAN1DIR)",
1577b39c5158Smillert			       basename($name).".\$(MAN1EXT)");
1578b39c5158Smillert	}
1579b39c5158Smillert    }
1580b39c5158Smillert}
1581b39c5158Smillert
1582b39c5158Smillert
1583b39c5158Smillert=item init_MAN3PODS
1584b39c5158Smillert
1585b39c5158SmillertInitializes MAN3PODS from the list of PM files.
1586b39c5158Smillert
1587b39c5158Smillert=cut
1588b39c5158Smillert
1589b39c5158Smillertsub init_MAN3PODS {
1590b39c5158Smillert    my $self = shift;
1591b39c5158Smillert
1592b39c5158Smillert    my %manifypods = (); # we collect the keys first, i.e. the files
1593b39c5158Smillert                         # we have to convert to pod
1594b39c5158Smillert
1595b39c5158Smillert    foreach my $name (keys %{$self->{PM}}) {
1596b39c5158Smillert	if ($name =~ /\.pod\z/ ) {
1597b39c5158Smillert	    $manifypods{$name} = $self->{PM}{$name};
1598b39c5158Smillert	} elsif ($name =~ /\.p[ml]\z/ ) {
1599b39c5158Smillert	    if( $self->_has_pod($name) ) {
1600b39c5158Smillert		$manifypods{$name} = $self->{PM}{$name};
1601b39c5158Smillert	    }
1602b39c5158Smillert	}
1603b39c5158Smillert    }
1604b39c5158Smillert
1605b39c5158Smillert    my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1606b39c5158Smillert
1607b39c5158Smillert    # Remove "Configure.pm" and similar, if it's not the only pod listed
1608b39c5158Smillert    # To force inclusion, just name it "Configure.pod", or override
1609b39c5158Smillert    # MAN3PODS
1610b39c5158Smillert    foreach my $name (keys %manifypods) {
16119f11ffb7Safresh1	if (
16129f11ffb7Safresh1            ($self->{PERL_CORE} and $name =~ /(config|setup).*\.pm/is) or
16139f11ffb7Safresh1            ( $name =~ m/^README\.pod$/i ) # don't manify top-level README.pod
16149f11ffb7Safresh1        ) {
1615b39c5158Smillert	    delete $manifypods{$name};
1616b39c5158Smillert	    next;
1617b39c5158Smillert	}
1618b39c5158Smillert	my($manpagename) = $name;
1619b39c5158Smillert	$manpagename =~ s/\.p(od|m|l)\z//;
1620b39c5158Smillert	# everything below lib is ok
1621b39c5158Smillert	unless($manpagename =~ s!^\W*($parentlibs_re)\W+!!s) {
1622b39c5158Smillert	    $manpagename = $self->catfile(
1623b39c5158Smillert	        split(/::/,$self->{PARENT_NAME}),$manpagename
1624b39c5158Smillert	    );
1625b39c5158Smillert	}
1626b39c5158Smillert	$manpagename = $self->replace_manpage_separator($manpagename);
1627b39c5158Smillert	$self->{MAN3PODS}->{$name} =
1628b39c5158Smillert	    $self->catfile("\$(INST_MAN3DIR)", "$manpagename.\$(MAN3EXT)");
1629b39c5158Smillert    }
1630b39c5158Smillert}
1631b39c5158Smillert
1632b39c5158Smillert
1633b39c5158Smillert=item init_PM
1634b39c5158Smillert
1635b39c5158SmillertInitializes PMLIBDIRS and PM from PMLIBDIRS.
1636b39c5158Smillert
1637b39c5158Smillert=cut
1638b39c5158Smillert
1639b39c5158Smillertsub init_PM {
1640b39c5158Smillert    my $self = shift;
1641b39c5158Smillert
1642b39c5158Smillert    # Some larger extensions often wish to install a number of *.pm/pl
1643b39c5158Smillert    # files into the library in various locations.
1644b39c5158Smillert
1645b39c5158Smillert    # The attribute PMLIBDIRS holds an array reference which lists
1646b39c5158Smillert    # subdirectories which we should search for library files to
1647b39c5158Smillert    # install. PMLIBDIRS defaults to [ 'lib', $self->{BASEEXT} ].  We
1648b39c5158Smillert    # recursively search through the named directories (skipping any
1649b39c5158Smillert    # which don't exist or contain Makefile.PL files).
1650b39c5158Smillert
1651b39c5158Smillert    # For each *.pm or *.pl file found $self->libscan() is called with
1652b39c5158Smillert    # the default installation path in $_[1]. The return value of
1653b39c5158Smillert    # libscan defines the actual installation location.  The default
1654b39c5158Smillert    # libscan function simply returns the path.  The file is skipped
1655b39c5158Smillert    # if libscan returns false.
1656b39c5158Smillert
1657b39c5158Smillert    # The default installation location passed to libscan in $_[1] is:
1658b39c5158Smillert    #
1659b39c5158Smillert    #  ./*.pm		=> $(INST_LIBDIR)/*.pm
1660b39c5158Smillert    #  ./xyz/...	=> $(INST_LIBDIR)/xyz/...
1661b39c5158Smillert    #  ./lib/...	=> $(INST_LIB)/...
1662b39c5158Smillert    #
1663b39c5158Smillert    # In this way the 'lib' directory is seen as the root of the actual
1664b39c5158Smillert    # perl library whereas the others are relative to INST_LIBDIR
1665b39c5158Smillert    # (which includes PARENT_NAME). This is a subtle distinction but one
1666b39c5158Smillert    # that's important for nested modules.
1667b39c5158Smillert
1668b39c5158Smillert    unless( $self->{PMLIBDIRS} ) {
1669b39c5158Smillert        if( $Is{VMS} ) {
1670b39c5158Smillert            # Avoid logical name vs directory collisions
1671b39c5158Smillert            $self->{PMLIBDIRS} = ['./lib', "./$self->{BASEEXT}"];
1672b39c5158Smillert        }
1673b39c5158Smillert        else {
1674b39c5158Smillert            $self->{PMLIBDIRS} = ['lib', $self->{BASEEXT}];
1675b39c5158Smillert        }
1676b39c5158Smillert    }
1677b39c5158Smillert
1678b39c5158Smillert    #only existing directories that aren't in $dir are allowed
1679b39c5158Smillert
1680b39c5158Smillert    # Avoid $_ wherever possible:
1681b39c5158Smillert    # @{$self->{PMLIBDIRS}} = grep -d && !$dir{$_}, @{$self->{PMLIBDIRS}};
1682b39c5158Smillert    my (@pmlibdirs) = @{$self->{PMLIBDIRS}};
1683b39c5158Smillert    @{$self->{PMLIBDIRS}} = ();
1684b39c5158Smillert    my %dir = map { ($_ => $_) } @{$self->{DIR}};
1685b39c5158Smillert    foreach my $pmlibdir (@pmlibdirs) {
1686b39c5158Smillert	-d $pmlibdir && !$dir{$pmlibdir} && push @{$self->{PMLIBDIRS}}, $pmlibdir;
1687b39c5158Smillert    }
1688b39c5158Smillert
1689b39c5158Smillert    unless( $self->{PMLIBPARENTDIRS} ) {
1690b39c5158Smillert	@{$self->{PMLIBPARENTDIRS}} = ('lib');
1691b39c5158Smillert    }
1692b39c5158Smillert
1693b39c5158Smillert    return if $self->{PM} and $self->{ARGS}{PM};
1694b39c5158Smillert
1695b39c5158Smillert    if (@{$self->{PMLIBDIRS}}){
1696b39c5158Smillert	print "Searching PMLIBDIRS: @{$self->{PMLIBDIRS}}\n"
1697b39c5158Smillert	    if ($Verbose >= 2);
1698b39c5158Smillert	require File::Find;
1699b39c5158Smillert        File::Find::find(sub {
1700b39c5158Smillert            if (-d $_){
1701b39c5158Smillert                unless ($self->libscan($_)){
1702b39c5158Smillert                    $File::Find::prune = 1;
1703b39c5158Smillert                }
1704b39c5158Smillert                return;
1705b39c5158Smillert            }
1706b39c5158Smillert            return if /\#/;
1707b39c5158Smillert            return if /~$/;             # emacs temp files
1708b39c5158Smillert            return if /,v$/;            # RCS files
1709b39c5158Smillert            return if m{\.swp$};        # vim swap files
1710b39c5158Smillert
1711b39c5158Smillert	    my $path   = $File::Find::name;
1712b39c5158Smillert            my $prefix = $self->{INST_LIBDIR};
1713b39c5158Smillert            my $striplibpath;
1714b39c5158Smillert
1715b39c5158Smillert	    my $parentlibs_re = join '|', @{$self->{PMLIBPARENTDIRS}};
1716b39c5158Smillert	    $prefix =  $self->{INST_LIB}
1717b39c5158Smillert                if ($striplibpath = $path) =~ s{^(\W*)($parentlibs_re)\W}
1718b39c5158Smillert	                                       {$1}i;
1719b39c5158Smillert
1720b39c5158Smillert	    my($inst) = $self->catfile($prefix,$striplibpath);
1721b39c5158Smillert	    local($_) = $inst; # for backwards compatibility
1722b39c5158Smillert	    $inst = $self->libscan($inst);
1723b39c5158Smillert	    print "libscan($path) => '$inst'\n" if ($Verbose >= 2);
1724b39c5158Smillert	    return unless $inst;
17259f11ffb7Safresh1	    if ($self->{XSMULTI} and $inst =~ /\.xs\z/) {
17269f11ffb7Safresh1		my($base); ($base = $path) =~ s/\.xs\z//;
17279f11ffb7Safresh1		$self->{XS}{$path} = "$base.c";
17289f11ffb7Safresh1		push @{$self->{C}}, "$base.c";
17299f11ffb7Safresh1		push @{$self->{O_FILES}}, "$base$self->{OBJ_EXT}";
17309f11ffb7Safresh1	    } else {
1731b39c5158Smillert		$self->{PM}{$path} = $inst;
17329f11ffb7Safresh1	    }
1733b39c5158Smillert	}, @{$self->{PMLIBDIRS}});
1734b39c5158Smillert    }
1735b39c5158Smillert}
1736b39c5158Smillert
1737b39c5158Smillert
1738b39c5158Smillert=item init_DIRFILESEP
1739b39c5158Smillert
1740b39c5158SmillertUsing / for Unix.  Called by init_main.
1741b39c5158Smillert
1742b39c5158Smillert=cut
1743b39c5158Smillert
1744b39c5158Smillertsub init_DIRFILESEP {
1745b39c5158Smillert    my($self) = shift;
1746b39c5158Smillert
1747b39c5158Smillert    $self->{DIRFILESEP} = '/';
1748b39c5158Smillert}
1749b39c5158Smillert
1750b39c5158Smillert
1751b39c5158Smillert=item init_main
1752b39c5158Smillert
1753b39c5158SmillertInitializes AR, AR_STATIC_ARGS, BASEEXT, CONFIG, DISTNAME, DLBASE,
1754b39c5158SmillertEXE_EXT, FULLEXT, FULLPERL, FULLPERLRUN, FULLPERLRUNINST, INST_*,
1755b39c5158SmillertINSTALL*, INSTALLDIRS, LIB_EXT, LIBPERL_A, MAP_TARGET, NAME,
1756b39c5158SmillertOBJ_EXT, PARENT_NAME, PERL, PERL_ARCHLIB, PERL_INC, PERL_LIB,
1757b39c5158SmillertPERL_SRC, PERLRUN, PERLRUNINST, PREFIX, VERSION,
1758b39c5158SmillertVERSION_SYM, XS_VERSION.
1759b39c5158Smillert
1760b39c5158Smillert=cut
1761b39c5158Smillert
1762b39c5158Smillertsub init_main {
1763b39c5158Smillert    my($self) = @_;
1764b39c5158Smillert
1765b39c5158Smillert    # --- Initialize Module Name and Paths
1766b39c5158Smillert
1767b39c5158Smillert    # NAME    = Foo::Bar::Oracle
1768b39c5158Smillert    # FULLEXT = Foo/Bar/Oracle
1769b39c5158Smillert    # BASEEXT = Oracle
1770b39c5158Smillert    # PARENT_NAME = Foo::Bar
1771b39c5158Smillert### Only UNIX:
1772b39c5158Smillert###    ($self->{FULLEXT} =
1773b39c5158Smillert###     $self->{NAME}) =~ s!::!/!g ; #eg. BSD/Foo/Socket
1774b39c5158Smillert    $self->{FULLEXT} = $self->catdir(split /::/, $self->{NAME});
1775b39c5158Smillert
1776b39c5158Smillert
1777b39c5158Smillert    # Copied from DynaLoader:
1778b39c5158Smillert
1779b39c5158Smillert    my(@modparts) = split(/::/,$self->{NAME});
1780b39c5158Smillert    my($modfname) = $modparts[-1];
1781b39c5158Smillert
1782b39c5158Smillert    # Some systems have restrictions on files names for DLL's etc.
1783b39c5158Smillert    # mod2fname returns appropriate file base name (typically truncated)
1784b39c5158Smillert    # It may also edit @modparts if required.
1785e5157e49Safresh1    # We require DynaLoader to make sure that mod2fname is loaded
1786e5157e49Safresh1    eval { require DynaLoader };
1787b39c5158Smillert    if (defined &DynaLoader::mod2fname) {
1788b39c5158Smillert        $modfname = &DynaLoader::mod2fname(\@modparts);
1789b39c5158Smillert    }
1790b39c5158Smillert
1791b39c5158Smillert    ($self->{PARENT_NAME}, $self->{BASEEXT}) = $self->{NAME} =~ m!(?:([\w:]+)::)?(\w+)\z! ;
1792b39c5158Smillert    $self->{PARENT_NAME} ||= '';
1793b39c5158Smillert
1794b39c5158Smillert    if (defined &DynaLoader::mod2fname) {
1795b39c5158Smillert	# As of 5.001m, dl_os2 appends '_'
1796b39c5158Smillert	$self->{DLBASE} = $modfname;
1797b39c5158Smillert    } else {
1798b39c5158Smillert	$self->{DLBASE} = '$(BASEEXT)';
1799b39c5158Smillert    }
1800b39c5158Smillert
1801b39c5158Smillert
1802b39c5158Smillert    # --- Initialize PERL_LIB, PERL_SRC
1803b39c5158Smillert
1804b39c5158Smillert    # *Real* information: where did we get these two from? ...
1805b39c5158Smillert    my $inc_config_dir = dirname($INC{'Config.pm'});
1806b39c5158Smillert    my $inc_carp_dir   = dirname($INC{'Carp.pm'});
1807b39c5158Smillert
1808b39c5158Smillert    unless ($self->{PERL_SRC}){
1809b39c5158Smillert        foreach my $dir_count (1..8) { # 8 is the VMS limit for nesting
1810b39c5158Smillert            my $dir = $self->catdir(($Updir) x $dir_count);
1811b39c5158Smillert
1812b39c5158Smillert            if (-f $self->catfile($dir,"config_h.SH")   &&
1813b39c5158Smillert                -f $self->catfile($dir,"perl.h")        &&
1814b39c5158Smillert                -f $self->catfile($dir,"lib","strict.pm")
1815b39c5158Smillert            ) {
1816b39c5158Smillert                $self->{PERL_SRC}=$dir ;
1817b39c5158Smillert                last;
1818b39c5158Smillert            }
1819b39c5158Smillert        }
1820b39c5158Smillert    }
1821b39c5158Smillert
1822b39c5158Smillert    warn "PERL_CORE is set but I can't find your PERL_SRC!\n" if
1823b39c5158Smillert      $self->{PERL_CORE} and !$self->{PERL_SRC};
1824b39c5158Smillert
1825b39c5158Smillert    if ($self->{PERL_SRC}){
1826b39c5158Smillert	$self->{PERL_LIB}     ||= $self->catdir("$self->{PERL_SRC}","lib");
1827b39c5158Smillert
1828b39c5158Smillert        $self->{PERL_ARCHLIB} = $self->{PERL_LIB};
1829b39c5158Smillert        $self->{PERL_INC}     = ($Is{Win32}) ?
1830b39c5158Smillert            $self->catdir($self->{PERL_LIB},"CORE") : $self->{PERL_SRC};
1831b39c5158Smillert
1832b39c5158Smillert	# catch a situation that has occurred a few times in the past:
1833b39c5158Smillert	unless (
1834b39c5158Smillert		-s $self->catfile($self->{PERL_SRC},'cflags')
1835b39c5158Smillert		or
1836b39c5158Smillert		$Is{VMS}
1837b39c5158Smillert		&&
1838b39c5158Smillert		-s $self->catfile($self->{PERL_SRC},'vmsish.h')
1839b39c5158Smillert		or
1840b39c5158Smillert		$Is{Win32}
1841b39c5158Smillert	       ){
1842b39c5158Smillert	    warn qq{
1843b39c5158SmillertYou cannot build extensions below the perl source tree after executing
1844b39c5158Smillerta 'make clean' in the perl source tree.
1845b39c5158Smillert
1846b39c5158SmillertTo rebuild extensions distributed with the perl source you should
1847b39c5158Smillertsimply Configure (to include those extensions) and then build perl as
1848b39c5158Smillertnormal. After installing perl the source tree can be deleted. It is
1849b39c5158Smillertnot needed for building extensions by running 'perl Makefile.PL'
1850b39c5158Smillertusually without extra arguments.
1851b39c5158Smillert
1852b39c5158SmillertIt is recommended that you unpack and build additional extensions away
1853b39c5158Smillertfrom the perl source tree.
1854b39c5158Smillert};
1855b39c5158Smillert	}
1856b39c5158Smillert    } else {
1857b39c5158Smillert	# we should also consider $ENV{PERL5LIB} here
1858b39c5158Smillert        my $old = $self->{PERL_LIB} || $self->{PERL_ARCHLIB} || $self->{PERL_INC};
1859b39c5158Smillert	$self->{PERL_LIB}     ||= $Config{privlibexp};
1860b39c5158Smillert	$self->{PERL_ARCHLIB} ||= $Config{archlibexp};
1861b39c5158Smillert	$self->{PERL_INC}     = $self->catdir("$self->{PERL_ARCHLIB}","CORE"); # wild guess for now
1862b39c5158Smillert	my $perl_h;
1863b39c5158Smillert
1864b39c5158Smillert	if (not -f ($perl_h = $self->catfile($self->{PERL_INC},"perl.h"))
1865b39c5158Smillert	    and not $old){
1866b39c5158Smillert	    # Maybe somebody tries to build an extension with an
1867b39c5158Smillert	    # uninstalled Perl outside of Perl build tree
1868b39c5158Smillert	    my $lib;
1869b39c5158Smillert	    for my $dir (@INC) {
1870b39c5158Smillert	      $lib = $dir, last if -e $self->catfile($dir, "Config.pm");
1871b39c5158Smillert	    }
1872b39c5158Smillert	    if ($lib) {
1873b39c5158Smillert              # Win32 puts its header files in /perl/src/lib/CORE.
1874b39c5158Smillert              # Unix leaves them in /perl/src.
1875b39c5158Smillert	      my $inc = $Is{Win32} ? $self->catdir($lib, "CORE" )
1876b39c5158Smillert                                  : dirname $lib;
1877b39c5158Smillert	      if (-e $self->catfile($inc, "perl.h")) {
1878b39c5158Smillert		$self->{PERL_LIB}	   = $lib;
1879b39c5158Smillert		$self->{PERL_ARCHLIB}	   = $lib;
1880b39c5158Smillert		$self->{PERL_INC}	   = $inc;
1881b39c5158Smillert		$self->{UNINSTALLED_PERL}  = 1;
1882e9ce3842Safresh1		print <<EOP;
1883b39c5158Smillert... Detected uninstalled Perl.  Trying to continue.
1884b39c5158SmillertEOP
1885b39c5158Smillert	      }
1886b39c5158Smillert	    }
1887b39c5158Smillert	}
1888b39c5158Smillert    }
1889b39c5158Smillert
1890e5157e49Safresh1    if ($Is{Android}) {
1891e5157e49Safresh1    	# Android fun times!
1892e5157e49Safresh1    	# ../../perl -I../../lib -MFile::Glob -e1 works
1893e5157e49Safresh1    	# ../../../perl -I../../../lib -MFile::Glob -e1 fails to find
1894e5157e49Safresh1    	# the .so for File::Glob.
1895e5157e49Safresh1    	# This always affects core perl, but may also affect an installed
1896e5157e49Safresh1    	# perl built with -Duserelocatableinc.
1897e5157e49Safresh1    	$self->{PERL_LIB} = File::Spec->rel2abs($self->{PERL_LIB});
1898e5157e49Safresh1    	$self->{PERL_ARCHLIB} = File::Spec->rel2abs($self->{PERL_ARCHLIB});
1899e5157e49Safresh1    }
1900b8851fccSafresh1    $self->{PERL_INCDEP} = $self->{PERL_INC};
1901b8851fccSafresh1    $self->{PERL_ARCHLIBDEP} = $self->{PERL_ARCHLIB};
1902e5157e49Safresh1
1903b39c5158Smillert    # We get SITELIBEXP and SITEARCHEXP directly via
1904b39c5158Smillert    # Get_from_Config. When we are running standard modules, these
1905b39c5158Smillert    # won't matter, we will set INSTALLDIRS to "perl". Otherwise we
1906b39c5158Smillert    # set it to "site". I prefer that INSTALLDIRS be set from outside
1907b39c5158Smillert    # MakeMaker.
1908b39c5158Smillert    $self->{INSTALLDIRS} ||= "site";
1909b39c5158Smillert
1910b39c5158Smillert    $self->{MAN1EXT} ||= $Config{man1ext};
1911b39c5158Smillert    $self->{MAN3EXT} ||= $Config{man3ext};
1912b39c5158Smillert
1913b39c5158Smillert    # Get some stuff out of %Config if we haven't yet done so
1914e9ce3842Safresh1    print "CONFIG must be an array ref\n"
1915b39c5158Smillert        if ($self->{CONFIG} and ref $self->{CONFIG} ne 'ARRAY');
1916b39c5158Smillert    $self->{CONFIG} = [] unless (ref $self->{CONFIG});
1917b39c5158Smillert    push(@{$self->{CONFIG}}, @ExtUtils::MakeMaker::Get_from_Config);
1918b39c5158Smillert    push(@{$self->{CONFIG}}, 'shellflags') if $Config{shellflags};
1919b39c5158Smillert    my(%once_only);
1920b39c5158Smillert    foreach my $m (@{$self->{CONFIG}}){
1921b39c5158Smillert        next if $once_only{$m};
1922e9ce3842Safresh1        print "CONFIG key '$m' does not exist in Config.pm\n"
1923b39c5158Smillert                unless exists $Config{$m};
1924b39c5158Smillert        $self->{uc $m} ||= $Config{$m};
1925b39c5158Smillert        $once_only{$m} = 1;
1926b39c5158Smillert    }
1927b39c5158Smillert
1928b39c5158Smillert# This is too dangerous:
1929b39c5158Smillert#    if ($^O eq "next") {
1930b39c5158Smillert#	$self->{AR} = "libtool";
1931b39c5158Smillert#	$self->{AR_STATIC_ARGS} = "-o";
1932b39c5158Smillert#    }
1933b39c5158Smillert# But I leave it as a placeholder
1934b39c5158Smillert
1935b39c5158Smillert    $self->{AR_STATIC_ARGS} ||= "cr";
1936b39c5158Smillert
1937b39c5158Smillert    # These should never be needed
1938b39c5158Smillert    $self->{OBJ_EXT} ||= '.o';
1939b39c5158Smillert    $self->{LIB_EXT} ||= '.a';
1940b39c5158Smillert
1941b39c5158Smillert    $self->{MAP_TARGET} ||= "perl";
1942b39c5158Smillert
1943b39c5158Smillert    $self->{LIBPERL_A} ||= "libperl$self->{LIB_EXT}";
1944b39c5158Smillert
1945b39c5158Smillert    # make a simple check if we find strict
1946b39c5158Smillert    warn "Warning: PERL_LIB ($self->{PERL_LIB}) seems not to be a perl library directory
1947b39c5158Smillert        (strict.pm not found)"
1948b39c5158Smillert        unless -f $self->catfile("$self->{PERL_LIB}","strict.pm") ||
1949b39c5158Smillert               $self->{NAME} eq "ExtUtils::MakeMaker";
1950b39c5158Smillert}
1951b39c5158Smillert
195248950c12Ssthen=item init_tools
1953b39c5158Smillert
195448950c12SsthenInitializes tools to use their common (and faster) Unix commands.
1955b39c5158Smillert
1956b39c5158Smillert=cut
1957b39c5158Smillert
195848950c12Ssthensub init_tools {
195948950c12Ssthen    my $self = shift;
1960b39c5158Smillert
1961b39c5158Smillert    $self->{ECHO}       ||= 'echo';
1962b39c5158Smillert    $self->{ECHO_N}     ||= 'echo -n';
1963b39c5158Smillert    $self->{RM_F}       ||= "rm -f";
1964b39c5158Smillert    $self->{RM_RF}      ||= "rm -rf";
1965b39c5158Smillert    $self->{TOUCH}      ||= "touch";
1966b39c5158Smillert    $self->{TEST_F}     ||= "test -f";
1967e5157e49Safresh1    $self->{TEST_S}     ||= "test -s";
1968b39c5158Smillert    $self->{CP}         ||= "cp";
1969b39c5158Smillert    $self->{MV}         ||= "mv";
1970b39c5158Smillert    $self->{CHMOD}      ||= "chmod";
1971b39c5158Smillert    $self->{FALSE}      ||= 'false';
1972b39c5158Smillert    $self->{TRUE}       ||= 'true';
1973b39c5158Smillert
1974b39c5158Smillert    $self->{LD}         ||= 'ld';
1975b39c5158Smillert
197648950c12Ssthen    return $self->SUPER::init_tools(@_);
1977b39c5158Smillert
197848950c12Ssthen    # After SUPER::init_tools so $Config{shell} has a
1979b39c5158Smillert    # chance to get set.
1980b39c5158Smillert    $self->{SHELL}      ||= '/bin/sh';
1981b39c5158Smillert
198248950c12Ssthen    return;
1983b39c5158Smillert}
1984b39c5158Smillert
1985b39c5158Smillert
1986b39c5158Smillert=item init_linker
1987b39c5158Smillert
1988b39c5158SmillertUnix has no need of special linker flags.
1989b39c5158Smillert
1990b39c5158Smillert=cut
1991b39c5158Smillert
1992b39c5158Smillertsub init_linker {
1993b39c5158Smillert    my($self) = shift;
1994b39c5158Smillert    $self->{PERL_ARCHIVE} ||= '';
1995b8851fccSafresh1    $self->{PERL_ARCHIVEDEP} ||= '';
1996b39c5158Smillert    $self->{PERL_ARCHIVE_AFTER} ||= '';
1997b39c5158Smillert    $self->{EXPORT_LIST}  ||= '';
1998b39c5158Smillert}
1999b39c5158Smillert
2000b39c5158Smillert
2001b39c5158Smillert=begin _protected
2002b39c5158Smillert
2003b39c5158Smillert=item init_lib2arch
2004b39c5158Smillert
2005b39c5158Smillert    $mm->init_lib2arch
2006b39c5158Smillert
2007b39c5158Smillert=end _protected
2008b39c5158Smillert
2009b39c5158Smillert=cut
2010b39c5158Smillert
2011b39c5158Smillertsub init_lib2arch {
2012b39c5158Smillert    my($self) = shift;
2013b39c5158Smillert
2014b39c5158Smillert    # The user who requests an installation directory explicitly
2015b39c5158Smillert    # should not have to tell us an architecture installation directory
2016b39c5158Smillert    # as well. We look if a directory exists that is named after the
2017b39c5158Smillert    # architecture. If not we take it as a sign that it should be the
2018b39c5158Smillert    # same as the requested installation directory. Otherwise we take
2019b39c5158Smillert    # the found one.
2020b39c5158Smillert    for my $libpair ({l=>"privlib",   a=>"archlib"},
2021b39c5158Smillert                     {l=>"sitelib",   a=>"sitearch"},
2022b39c5158Smillert                     {l=>"vendorlib", a=>"vendorarch"},
2023b39c5158Smillert                    )
2024b39c5158Smillert    {
2025b39c5158Smillert        my $lib = "install$libpair->{l}";
2026b39c5158Smillert        my $Lib = uc $lib;
2027b39c5158Smillert        my $Arch = uc "install$libpair->{a}";
2028b39c5158Smillert        if( $self->{$Lib} && ! $self->{$Arch} ){
2029b39c5158Smillert            my($ilib) = $Config{$lib};
2030b39c5158Smillert
2031b39c5158Smillert            $self->prefixify($Arch,$ilib,$self->{$Lib});
2032b39c5158Smillert
2033b39c5158Smillert            unless (-d $self->{$Arch}) {
2034e9ce3842Safresh1                print "Directory $self->{$Arch} not found\n"
2035b39c5158Smillert                  if $Verbose;
2036b39c5158Smillert                $self->{$Arch} = $self->{$Lib};
2037b39c5158Smillert            }
2038e9ce3842Safresh1            print "Defaulting $Arch to $self->{$Arch}\n" if $Verbose;
2039b39c5158Smillert        }
2040b39c5158Smillert    }
2041b39c5158Smillert}
2042b39c5158Smillert
2043b39c5158Smillert
2044b39c5158Smillert=item init_PERL
2045b39c5158Smillert
2046b39c5158Smillert    $mm->init_PERL;
2047b39c5158Smillert
2048b39c5158SmillertCalled by init_main.  Sets up ABSPERL, PERL, FULLPERL and all the
2049b39c5158Smillert*PERLRUN* permutations.
2050b39c5158Smillert
2051b39c5158Smillert    PERL is allowed to be miniperl
2052b39c5158Smillert    FULLPERL must be a complete perl
2053b39c5158Smillert
2054b39c5158Smillert    ABSPERL is PERL converted to an absolute path
2055b39c5158Smillert
2056b39c5158Smillert    *PERLRUN contains everything necessary to run perl, find it's
2057b39c5158Smillert         libraries, etc...
2058b39c5158Smillert
2059b39c5158Smillert    *PERLRUNINST is *PERLRUN + everything necessary to find the
2060b39c5158Smillert         modules being built.
2061b39c5158Smillert
2062b39c5158Smillert=cut
2063b39c5158Smillert
2064b39c5158Smillertsub init_PERL {
2065b39c5158Smillert    my($self) = shift;
2066b39c5158Smillert
2067b39c5158Smillert    my @defpath = ();
2068b39c5158Smillert    foreach my $component ($self->{PERL_SRC}, $self->path(),
2069b39c5158Smillert                           $Config{binexp})
2070b39c5158Smillert    {
2071b39c5158Smillert	push @defpath, $component if defined $component;
2072b39c5158Smillert    }
2073b39c5158Smillert
2074b39c5158Smillert    # Build up a set of file names (not command names).
2075b39c5158Smillert    my $thisperl = $self->canonpath($^X);
2076b39c5158Smillert    $thisperl .= $Config{exe_ext} unless
2077b39c5158Smillert                # VMS might have a file version # at the end
2078b39c5158Smillert      $Is{VMS} ? $thisperl =~ m/$Config{exe_ext}(;\d+)?$/i
2079b39c5158Smillert              : $thisperl =~ m/$Config{exe_ext}$/i;
2080b39c5158Smillert
2081b39c5158Smillert    # We need a relative path to perl when in the core.
2082b39c5158Smillert    $thisperl = $self->abs2rel($thisperl) if $self->{PERL_CORE};
2083b39c5158Smillert
2084b39c5158Smillert    my @perls = ($thisperl);
2085b39c5158Smillert    push @perls, map { "$_$Config{exe_ext}" }
2086e5157e49Safresh1                     ("perl$Config{version}", 'perl5', 'perl');
2087b39c5158Smillert
2088e5157e49Safresh1    # miniperl has priority over all but the canonical perl when in the
2089b39c5158Smillert    # core.  Otherwise its a last resort.
2090b39c5158Smillert    my $miniperl = "miniperl$Config{exe_ext}";
2091b39c5158Smillert    if( $self->{PERL_CORE} ) {
2092b39c5158Smillert        splice @perls, 1, 0, $miniperl;
2093b39c5158Smillert    }
2094b39c5158Smillert    else {
2095b39c5158Smillert        push @perls, $miniperl;
2096b39c5158Smillert    }
2097b39c5158Smillert
2098b39c5158Smillert    $self->{PERL} ||=
2099b39c5158Smillert        $self->find_perl(5.0, \@perls, \@defpath, $Verbose );
2100b8851fccSafresh1
2101b8851fccSafresh1    my $perl = $self->{PERL};
2102b8851fccSafresh1    $perl =~ s/^"//;
2103b8851fccSafresh1    my $has_mcr = $perl =~ s/^MCR\s*//;
2104b8851fccSafresh1    my $perlflags = '';
2105b8851fccSafresh1    my $stripped_perl;
2106b8851fccSafresh1    while ($perl) {
2107b8851fccSafresh1	($stripped_perl = $perl) =~ s/"$//;
2108b8851fccSafresh1	last if -x $stripped_perl;
2109b8851fccSafresh1	last unless $perl =~ s/(\s+\S+)$//;
2110b8851fccSafresh1	$perlflags = $1.$perlflags;
2111b8851fccSafresh1    }
2112b8851fccSafresh1    $self->{PERL} = $stripped_perl;
2113b8851fccSafresh1    $self->{PERL} = 'MCR '.$self->{PERL} if $has_mcr || $Is{VMS};
2114b39c5158Smillert
2115b39c5158Smillert    # When built for debugging, VMS doesn't create perl.exe but ndbgperl.exe.
2116b39c5158Smillert    my $perl_name = 'perl';
2117b39c5158Smillert    $perl_name = 'ndbgperl' if $Is{VMS} &&
2118b39c5158Smillert      defined $Config{usevmsdebug} && $Config{usevmsdebug} eq 'define';
2119b39c5158Smillert
2120b39c5158Smillert    # XXX This logic is flawed.  If "miniperl" is anywhere in the path
2121b39c5158Smillert    # it will get confused.  It should be fixed to work only on the filename.
2122b39c5158Smillert    # Define 'FULLPERL' to be a non-miniperl (used in test: target)
2123b8851fccSafresh1    unless ($self->{FULLPERL}) {
2124b8851fccSafresh1      ($self->{FULLPERL} = $self->{PERL}) =~ s/\Q$miniperl\E$/$perl_name$Config{exe_ext}/i;
2125b8851fccSafresh1      $self->{FULLPERL} = qq{"$self->{FULLPERL}"}.$perlflags;
2126b8851fccSafresh1    }
2127b8851fccSafresh1    # Can't have an image name with quotes, and findperl will have
2128b8851fccSafresh1    # already escaped spaces.
2129b8851fccSafresh1    $self->{FULLPERL} =~ tr/"//d if $Is{VMS};
2130b39c5158Smillert
213156d68f1eSafresh1    # `dmake` can fail for image (aka, executable) names which start with double-quotes
213256d68f1eSafresh1    # * push quote inward by at least one character (or the drive prefix, if present)
213356d68f1eSafresh1    # * including any initial directory separator preserves the `file_name_is_absolute` property
213456d68f1eSafresh1    $self->{FULLPERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');
213556d68f1eSafresh1
2136b39c5158Smillert    # Little hack to get around VMS's find_perl putting "MCR" in front
2137b39c5158Smillert    # sometimes.
2138b39c5158Smillert    $self->{ABSPERL} = $self->{PERL};
2139b8851fccSafresh1    $has_mcr = $self->{ABSPERL} =~ s/^MCR\s*//;
2140b39c5158Smillert    if( $self->file_name_is_absolute($self->{ABSPERL}) ) {
2141b39c5158Smillert        $self->{ABSPERL} = '$(PERL)';
2142b39c5158Smillert    }
2143b39c5158Smillert    else {
2144b39c5158Smillert        $self->{ABSPERL} = $self->rel2abs($self->{ABSPERL});
2145b39c5158Smillert
2146b39c5158Smillert        # Quote the perl command if it contains whitespace
2147b39c5158Smillert        $self->{ABSPERL} = $self->quote_literal($self->{ABSPERL})
2148b39c5158Smillert          if $self->{ABSPERL} =~ /\s/;
2149b39c5158Smillert
2150b39c5158Smillert        $self->{ABSPERL} = 'MCR '.$self->{ABSPERL} if $has_mcr;
2151b39c5158Smillert    }
2152b8851fccSafresh1    $self->{PERL} = qq{"$self->{PERL}"}.$perlflags;
2153b8851fccSafresh1
2154b8851fccSafresh1    # Can't have an image name with quotes, and findperl will have
2155b8851fccSafresh1    # already escaped spaces.
2156b8851fccSafresh1    $self->{PERL} =~ tr/"//d if $Is{VMS};
2157b39c5158Smillert
215856d68f1eSafresh1    # `dmake` can fail for image (aka, executable) names which start with double-quotes
215956d68f1eSafresh1    # * push quote inward by at least one character (or the drive prefix, if present)
216056d68f1eSafresh1    # * including any initial directory separator preserves the `file_name_is_absolute` property
216156d68f1eSafresh1    $self->{PERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');
216256d68f1eSafresh1
2163b39c5158Smillert    # Are we building the core?
2164b39c5158Smillert    $self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
2165b39c5158Smillert    $self->{PERL_CORE} = 0               unless defined $self->{PERL_CORE};
2166b39c5158Smillert
21679f11ffb7Safresh1    # Make sure perl can find itself before it's installed.
21689f11ffb7Safresh1    my $lib_paths = $self->{UNINSTALLED_PERL} || $self->{PERL_CORE}
21699f11ffb7Safresh1        ? ( $self->{PERL_ARCHLIB} && $self->{PERL_LIB} && $self->{PERL_ARCHLIB} ne $self->{PERL_LIB} ) ?
21709f11ffb7Safresh1            q{ "-I$(PERL_LIB)" "-I$(PERL_ARCHLIB)"} : q{ "-I$(PERL_LIB)"}
21719f11ffb7Safresh1        : undef;
21729f11ffb7Safresh1    my $inst_lib_paths = $self->{INST_ARCHLIB} ne $self->{INST_LIB}
21739f11ffb7Safresh1        ? 'RUN)'.$perlflags.' "-I$(INST_ARCHLIB)" "-I$(INST_LIB)"'
21749f11ffb7Safresh1        : 'RUN)'.$perlflags.' "-I$(INST_LIB)"';
2175b39c5158Smillert    # How do we run perl?
2176b39c5158Smillert    foreach my $perl (qw(PERL FULLPERL ABSPERL)) {
2177b39c5158Smillert        my $run  = $perl.'RUN';
2178b39c5158Smillert
2179b8851fccSafresh1        $self->{$run}  = qq{\$($perl)};
21809f11ffb7Safresh1        $self->{$run} .= $lib_paths if $lib_paths;
2181b39c5158Smillert
21829f11ffb7Safresh1        $self->{$perl.'RUNINST'} = '$('.$perl.$inst_lib_paths;
2183b39c5158Smillert    }
2184b39c5158Smillert
2185b39c5158Smillert    return 1;
2186b39c5158Smillert}
2187b39c5158Smillert
2188b39c5158Smillert
2189b39c5158Smillert=item init_platform
2190b39c5158Smillert
2191b39c5158Smillert=item platform_constants
2192b39c5158Smillert
2193b39c5158SmillertAdd MM_Unix_VERSION.
2194b39c5158Smillert
2195b39c5158Smillert=cut
2196b39c5158Smillert
2197b39c5158Smillertsub init_platform {
2198b39c5158Smillert    my($self) = shift;
2199b39c5158Smillert
2200e0680481Safresh1    $self->{MM_Unix_VERSION} = our $VERSION;
2201b39c5158Smillert    $self->{PERL_MALLOC_DEF} = '-DPERL_EXTMALLOC_DEF -Dmalloc=Perl_malloc '.
2202b39c5158Smillert                               '-Dfree=Perl_mfree -Drealloc=Perl_realloc '.
2203b39c5158Smillert                               '-Dcalloc=Perl_calloc';
2204b39c5158Smillert
2205b39c5158Smillert}
2206b39c5158Smillert
2207b39c5158Smillertsub platform_constants {
2208b39c5158Smillert    my($self) = shift;
2209b39c5158Smillert    my $make_frag = '';
2210b39c5158Smillert
2211b39c5158Smillert    foreach my $macro (qw(MM_Unix_VERSION PERL_MALLOC_DEF))
2212b39c5158Smillert    {
2213b39c5158Smillert        next unless defined $self->{$macro};
2214b39c5158Smillert        $make_frag .= "$macro = $self->{$macro}\n";
2215b39c5158Smillert    }
2216b39c5158Smillert
2217b39c5158Smillert    return $make_frag;
2218b39c5158Smillert}
2219b39c5158Smillert
2220b39c5158Smillert
2221b39c5158Smillert=item init_PERM
2222b39c5158Smillert
2223b39c5158Smillert  $mm->init_PERM
2224b39c5158Smillert
2225b39c5158SmillertCalled by init_main.  Initializes PERL_*
2226b39c5158Smillert
2227b39c5158Smillert=cut
2228b39c5158Smillert
2229b39c5158Smillertsub init_PERM {
2230b39c5158Smillert    my($self) = shift;
2231b39c5158Smillert
2232*fac98b93Safresh1    my $perm_dir = $self->{PERL_CORE} ? 770 : 755;
2233*fac98b93Safresh1    $self->{PERM_DIR} = $perm_dir  unless defined $self->{PERM_DIR};
2234b39c5158Smillert    $self->{PERM_RW}  = 644  unless defined $self->{PERM_RW};
2235b39c5158Smillert    $self->{PERM_RWX} = 755  unless defined $self->{PERM_RWX};
2236b39c5158Smillert
2237b39c5158Smillert    return 1;
2238b39c5158Smillert}
2239b39c5158Smillert
2240b39c5158Smillert
2241b39c5158Smillert=item init_xs
2242b39c5158Smillert
2243b39c5158Smillert    $mm->init_xs
2244b39c5158Smillert
2245b39c5158SmillertSets up macros having to do with XS code.  Currently just INST_STATIC,
2246b39c5158SmillertINST_DYNAMIC and INST_BOOT.
2247b39c5158Smillert
2248b39c5158Smillert=cut
2249b39c5158Smillert
2250b39c5158Smillertsub init_xs {
2251b39c5158Smillert    my $self = shift;
2252b39c5158Smillert
2253b39c5158Smillert    if ($self->has_link_code()) {
2254b39c5158Smillert        $self->{INST_STATIC}  =
2255b39c5158Smillert          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT)$(LIB_EXT)');
2256b39c5158Smillert        $self->{INST_DYNAMIC} =
2257b39c5158Smillert          $self->catfile('$(INST_ARCHAUTODIR)', '$(DLBASE).$(DLEXT)');
2258b39c5158Smillert        $self->{INST_BOOT}    =
2259b39c5158Smillert          $self->catfile('$(INST_ARCHAUTODIR)', '$(BASEEXT).bs');
22609f11ffb7Safresh1	if ($self->{XSMULTI}) {
22619f11ffb7Safresh1	    my @exts = $self->_xs_list_basenames;
22629f11ffb7Safresh1	    my (@statics, @dynamics, @boots);
22639f11ffb7Safresh1	    for my $ext (@exts) {
22649f11ffb7Safresh1		my ($v, $d, $f) = File::Spec->splitpath($ext);
22659f11ffb7Safresh1		my @d = File::Spec->splitdir($d);
22669f11ffb7Safresh1		shift @d if defined $d[0] and $d[0] eq 'lib';
226756d68f1eSafresh1		pop @d if $d[$#d] eq '';
22689f11ffb7Safresh1		my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
22699f11ffb7Safresh1		my $instfile = $self->catfile($instdir, $f);
22709f11ffb7Safresh1		push @statics, "$instfile\$(LIB_EXT)";
22719f11ffb7Safresh1
22729f11ffb7Safresh1                # Dynamic library names may need special handling.
22739f11ffb7Safresh1                my $dynfile = $instfile;
22749f11ffb7Safresh1                eval { require DynaLoader };
22759f11ffb7Safresh1                if (defined &DynaLoader::mod2fname) {
22769f11ffb7Safresh1                    $dynfile = $self->catfile($instdir, &DynaLoader::mod2fname([@d, $f]));
22779f11ffb7Safresh1                }
22789f11ffb7Safresh1
22799f11ffb7Safresh1		push @dynamics, "$dynfile.\$(DLEXT)";
22809f11ffb7Safresh1		push @boots, "$instfile.bs";
22819f11ffb7Safresh1	    }
22829f11ffb7Safresh1	    $self->{INST_STATIC} = join ' ', @statics;
22839f11ffb7Safresh1	    $self->{INST_DYNAMIC} = join ' ', @dynamics;
22849f11ffb7Safresh1	    $self->{INST_BOOT} = join ' ', @boots;
22859f11ffb7Safresh1	}
2286b39c5158Smillert    } else {
2287b39c5158Smillert        $self->{INST_STATIC}  = '';
2288b39c5158Smillert        $self->{INST_DYNAMIC} = '';
2289b39c5158Smillert        $self->{INST_BOOT}    = '';
2290b39c5158Smillert    }
2291b39c5158Smillert}
2292b39c5158Smillert
2293b39c5158Smillert=item install (o)
2294b39c5158Smillert
2295b39c5158SmillertDefines the install target.
2296b39c5158Smillert
2297b39c5158Smillert=cut
2298b39c5158Smillert
2299b39c5158Smillertsub install {
2300b39c5158Smillert    my($self, %attribs) = @_;
2301b39c5158Smillert    my(@m);
2302b39c5158Smillert
2303b39c5158Smillert    push @m, q{
2304b39c5158Smillertinstall :: pure_install doc_install
2305b39c5158Smillert	$(NOECHO) $(NOOP)
2306b39c5158Smillert
2307b39c5158Smillertinstall_perl :: pure_perl_install doc_perl_install
2308b39c5158Smillert	$(NOECHO) $(NOOP)
2309b39c5158Smillert
2310b39c5158Smillertinstall_site :: pure_site_install doc_site_install
2311b39c5158Smillert	$(NOECHO) $(NOOP)
2312b39c5158Smillert
2313b39c5158Smillertinstall_vendor :: pure_vendor_install doc_vendor_install
2314b39c5158Smillert	$(NOECHO) $(NOOP)
2315b39c5158Smillert
2316b39c5158Smillertpure_install :: pure_$(INSTALLDIRS)_install
2317b39c5158Smillert	$(NOECHO) $(NOOP)
2318b39c5158Smillert
2319b39c5158Smillertdoc_install :: doc_$(INSTALLDIRS)_install
2320b39c5158Smillert	$(NOECHO) $(NOOP)
2321b39c5158Smillert
2322b39c5158Smillertpure__install : pure_site_install
2323b39c5158Smillert	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2324b39c5158Smillert
2325b39c5158Smillertdoc__install : doc_site_install
2326b39c5158Smillert	$(NOECHO) $(ECHO) INSTALLDIRS not defined, defaulting to INSTALLDIRS=site
2327b39c5158Smillert
2328b39c5158Smillertpure_perl_install :: all
2329b39c5158Smillert	$(NOECHO) $(MOD_INSTALL) \
2330e5157e49Safresh1};
2331e5157e49Safresh1
2332e5157e49Safresh1    push @m,
2333b8851fccSafresh1q{		read "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2334b8851fccSafresh1		write "}.$self->catfile('$(DESTINSTALLARCHLIB)','auto','$(FULLEXT)','.packlist').q{" \
2335e5157e49Safresh1} unless $self->{NO_PACKLIST};
2336e5157e49Safresh1
2337e5157e49Safresh1    push @m,
2338b8851fccSafresh1q{		"$(INST_LIB)" "$(DESTINSTALLPRIVLIB)" \
2339b8851fccSafresh1		"$(INST_ARCHLIB)" "$(DESTINSTALLARCHLIB)" \
2340b8851fccSafresh1		"$(INST_BIN)" "$(DESTINSTALLBIN)" \
2341b8851fccSafresh1		"$(INST_SCRIPT)" "$(DESTINSTALLSCRIPT)" \
2342b8851fccSafresh1		"$(INST_MAN1DIR)" "$(DESTINSTALLMAN1DIR)" \
2343b8851fccSafresh1		"$(INST_MAN3DIR)" "$(DESTINSTALLMAN3DIR)"
2344b39c5158Smillert	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2345b8851fccSafresh1		"}.$self->catdir('$(SITEARCHEXP)','auto','$(FULLEXT)').q{"
2346b39c5158Smillert
2347b39c5158Smillert
2348b39c5158Smillertpure_site_install :: all
2349b39c5158Smillert	$(NOECHO) $(MOD_INSTALL) \
2350e5157e49Safresh1};
2351e5157e49Safresh1    push @m,
2352b8851fccSafresh1q{		read "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2353b8851fccSafresh1		write "}.$self->catfile('$(DESTINSTALLSITEARCH)','auto','$(FULLEXT)','.packlist').q{" \
2354e5157e49Safresh1} unless $self->{NO_PACKLIST};
2355e5157e49Safresh1
2356e5157e49Safresh1    push @m,
2357b8851fccSafresh1q{		"$(INST_LIB)" "$(DESTINSTALLSITELIB)" \
2358b8851fccSafresh1		"$(INST_ARCHLIB)" "$(DESTINSTALLSITEARCH)" \
2359b8851fccSafresh1		"$(INST_BIN)" "$(DESTINSTALLSITEBIN)" \
2360b8851fccSafresh1		"$(INST_SCRIPT)" "$(DESTINSTALLSITESCRIPT)" \
2361b8851fccSafresh1		"$(INST_MAN1DIR)" "$(DESTINSTALLSITEMAN1DIR)" \
2362b8851fccSafresh1		"$(INST_MAN3DIR)" "$(DESTINSTALLSITEMAN3DIR)"
2363b39c5158Smillert	$(NOECHO) $(WARN_IF_OLD_PACKLIST) \
2364b8851fccSafresh1		"}.$self->catdir('$(PERL_ARCHLIB)','auto','$(FULLEXT)').q{"
2365b39c5158Smillert
2366b39c5158Smillertpure_vendor_install :: all
2367b39c5158Smillert	$(NOECHO) $(MOD_INSTALL) \
2368e5157e49Safresh1};
2369e5157e49Safresh1    push @m,
2370b8851fccSafresh1q{		read "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{" \
2371b8851fccSafresh1		write "}.$self->catfile('$(DESTINSTALLVENDORARCH)','auto','$(FULLEXT)','.packlist').q{" \
2372e5157e49Safresh1} unless $self->{NO_PACKLIST};
2373e5157e49Safresh1
2374e5157e49Safresh1    push @m,
2375b8851fccSafresh1q{		"$(INST_LIB)" "$(DESTINSTALLVENDORLIB)" \
2376b8851fccSafresh1		"$(INST_ARCHLIB)" "$(DESTINSTALLVENDORARCH)" \
2377b8851fccSafresh1		"$(INST_BIN)" "$(DESTINSTALLVENDORBIN)" \
2378b8851fccSafresh1		"$(INST_SCRIPT)" "$(DESTINSTALLVENDORSCRIPT)" \
2379b8851fccSafresh1		"$(INST_MAN1DIR)" "$(DESTINSTALLVENDORMAN1DIR)" \
2380b8851fccSafresh1		"$(INST_MAN3DIR)" "$(DESTINSTALLVENDORMAN3DIR)"
2381b39c5158Smillert
2382e5157e49Safresh1};
2383e5157e49Safresh1
2384e5157e49Safresh1    push @m, q{
2385e5157e49Safresh1doc_perl_install :: all
2386e5157e49Safresh1	$(NOECHO) $(NOOP)
2387e5157e49Safresh1
2388e5157e49Safresh1doc_site_install :: all
2389e5157e49Safresh1	$(NOECHO) $(NOOP)
2390e5157e49Safresh1
2391e5157e49Safresh1doc_vendor_install :: all
2392e5157e49Safresh1	$(NOECHO) $(NOOP)
2393e5157e49Safresh1
2394e5157e49Safresh1} if $self->{NO_PERLLOCAL};
2395e5157e49Safresh1
2396e5157e49Safresh1    push @m, q{
2397b39c5158Smillertdoc_perl_install :: all
2398b8851fccSafresh1	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2399b8851fccSafresh1	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2400b39c5158Smillert	-$(NOECHO) $(DOC_INSTALL) \
2401b39c5158Smillert		"Module" "$(NAME)" \
24029f11ffb7Safresh1		"installed into" "$(INSTALLPRIVLIB)" \
2403b39c5158Smillert		LINKTYPE "$(LINKTYPE)" \
2404b39c5158Smillert		VERSION "$(VERSION)" \
2405b39c5158Smillert		EXE_FILES "$(EXE_FILES)" \
2406b8851fccSafresh1		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2407b39c5158Smillert
2408b39c5158Smillertdoc_site_install :: all
2409b8851fccSafresh1	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2410b8851fccSafresh1	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2411b39c5158Smillert	-$(NOECHO) $(DOC_INSTALL) \
2412b39c5158Smillert		"Module" "$(NAME)" \
24139f11ffb7Safresh1		"installed into" "$(INSTALLSITELIB)" \
2414b39c5158Smillert		LINKTYPE "$(LINKTYPE)" \
2415b39c5158Smillert		VERSION "$(VERSION)" \
2416b39c5158Smillert		EXE_FILES "$(EXE_FILES)" \
2417b8851fccSafresh1		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2418b39c5158Smillert
2419b39c5158Smillertdoc_vendor_install :: all
2420b8851fccSafresh1	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
2421b8851fccSafresh1	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
2422b39c5158Smillert	-$(NOECHO) $(DOC_INSTALL) \
2423b39c5158Smillert		"Module" "$(NAME)" \
24249f11ffb7Safresh1		"installed into" "$(INSTALLVENDORLIB)" \
2425b39c5158Smillert		LINKTYPE "$(LINKTYPE)" \
2426b39c5158Smillert		VERSION "$(VERSION)" \
2427b39c5158Smillert		EXE_FILES "$(EXE_FILES)" \
2428b8851fccSafresh1		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
2429b39c5158Smillert
2430e5157e49Safresh1} unless $self->{NO_PERLLOCAL};
2431b39c5158Smillert
2432b39c5158Smillert    push @m, q{
2433b39c5158Smillertuninstall :: uninstall_from_$(INSTALLDIRS)dirs
2434b39c5158Smillert	$(NOECHO) $(NOOP)
2435b39c5158Smillert
2436b39c5158Smillertuninstall_from_perldirs ::
2437b8851fccSafresh1	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(PERL_ARCHLIB)','auto','$(FULLEXT)','.packlist').q{"
2438b39c5158Smillert
2439b39c5158Smillertuninstall_from_sitedirs ::
2440b8851fccSafresh1	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(SITEARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2441b39c5158Smillert
2442b39c5158Smillertuninstall_from_vendordirs ::
2443b8851fccSafresh1	$(NOECHO) $(UNINSTALL) "}.$self->catfile('$(VENDORARCHEXP)','auto','$(FULLEXT)','.packlist').q{"
2444b39c5158Smillert};
2445b39c5158Smillert
2446b39c5158Smillert    join("",@m);
2447b39c5158Smillert}
2448b39c5158Smillert
2449b39c5158Smillert=item installbin (o)
2450b39c5158Smillert
2451b39c5158SmillertDefines targets to make and to install EXE_FILES.
2452b39c5158Smillert
2453b39c5158Smillert=cut
2454b39c5158Smillert
2455b39c5158Smillertsub installbin {
2456b39c5158Smillert    my($self) = shift;
2457b39c5158Smillert
2458b39c5158Smillert    return "" unless $self->{EXE_FILES} && ref $self->{EXE_FILES} eq "ARRAY";
24599f11ffb7Safresh1    my @exefiles = sort @{$self->{EXE_FILES}};
2460b39c5158Smillert    return "" unless @exefiles;
2461b39c5158Smillert
2462b39c5158Smillert    @exefiles = map vmsify($_), @exefiles if $Is{VMS};
2463b39c5158Smillert
2464b39c5158Smillert    my %fromto;
2465b39c5158Smillert    for my $from (@exefiles) {
2466b39c5158Smillert	my($path)= $self->catfile('$(INST_SCRIPT)', basename($from));
2467b39c5158Smillert
2468b39c5158Smillert	local($_) = $path; # for backwards compatibility
2469b39c5158Smillert	my $to = $self->libscan($path);
2470b39c5158Smillert	print "libscan($from) => '$to'\n" if ($Verbose >=2);
2471b39c5158Smillert
2472b39c5158Smillert        $to = vmsify($to) if $Is{VMS};
2473b39c5158Smillert	$fromto{$from} = $to;
2474b39c5158Smillert    }
24759f11ffb7Safresh1    my @to   = sort values %fromto;
2476b39c5158Smillert
2477b39c5158Smillert    my @m;
2478b39c5158Smillert    push(@m, qq{
2479b39c5158SmillertEXE_FILES = @exefiles
2480b39c5158Smillert
2481b39c5158Smillertpure_all :: @to
2482b39c5158Smillert	\$(NOECHO) \$(NOOP)
2483b39c5158Smillert
2484b39c5158Smillertrealclean ::
2485b39c5158Smillert});
2486b39c5158Smillert
2487b39c5158Smillert    # realclean can get rather large.
2488b39c5158Smillert    push @m, map "\t$_\n", $self->split_command('$(RM_F)', @to);
2489b39c5158Smillert    push @m, "\n";
2490b39c5158Smillert
2491b39c5158Smillert    # A target for each exe file.
24929f11ffb7Safresh1    my @froms = sort keys %fromto;
24939f11ffb7Safresh1    for my $from (@froms) {
24949f11ffb7Safresh1        #                              1      2
24959f11ffb7Safresh1        push @m, _sprintf562 <<'MAKE', $from, $fromto{$from};
24969f11ffb7Safresh1%2$s : %1$s $(FIRST_MAKEFILE) $(INST_SCRIPT)$(DFSEP).exists $(INST_BIN)$(DFSEP).exists
24979f11ffb7Safresh1	$(NOECHO) $(RM_F) %2$s
24989f11ffb7Safresh1	$(CP) %1$s %2$s
24999f11ffb7Safresh1	$(FIXIN) %2$s
25009f11ffb7Safresh1	-$(NOECHO) $(CHMOD) $(PERM_RWX) %2$s
2501b39c5158Smillert
2502b39c5158SmillertMAKE
2503b39c5158Smillert
2504b39c5158Smillert    }
2505b39c5158Smillert
2506b39c5158Smillert    join "", @m;
2507b39c5158Smillert}
2508b39c5158Smillert
2509b39c5158Smillert=item linkext (o)
2510b39c5158Smillert
2511b39c5158SmillertDefines the linkext target which in turn defines the LINKTYPE.
2512b39c5158Smillert
2513b39c5158Smillert=cut
2514b39c5158Smillert
25159f11ffb7Safresh1# LINKTYPE => static or dynamic or ''
2516b39c5158Smillertsub linkext {
2517b39c5158Smillert    my($self, %attribs) = @_;
25189f11ffb7Safresh1    my $linktype = $attribs{LINKTYPE};
25199f11ffb7Safresh1    $linktype = $self->{LINKTYPE} unless defined $linktype;
25209f11ffb7Safresh1    if (defined $linktype and $linktype eq '') {
25219f11ffb7Safresh1        warn "Warning: LINKTYPE set to '', no longer necessary\n";
25229f11ffb7Safresh1    }
25239f11ffb7Safresh1    $linktype = '$(LINKTYPE)' unless defined $linktype;
2524b39c5158Smillert    "
2525b39c5158Smillertlinkext :: $linktype
2526b39c5158Smillert	\$(NOECHO) \$(NOOP)
2527b39c5158Smillert";
2528b39c5158Smillert}
2529b39c5158Smillert
2530b39c5158Smillert=item lsdir
2531b39c5158Smillert
2532b39c5158SmillertTakes as arguments a directory name and a regular expression. Returns
2533b39c5158Smillertall entries in the directory that match the regular expression.
2534b39c5158Smillert
2535b39c5158Smillert=cut
2536b39c5158Smillert
2537b39c5158Smillertsub lsdir {
25389f11ffb7Safresh1    #  $self
25399f11ffb7Safresh1    my(undef, $dir, $regex) = @_;
25409f11ffb7Safresh1    opendir(my $dh, defined($dir) ? $dir : ".")
25419f11ffb7Safresh1        or return;
25429f11ffb7Safresh1    my @ls = readdir $dh;
25439f11ffb7Safresh1    closedir $dh;
25449f11ffb7Safresh1    @ls = grep(/$regex/, @ls) if defined $regex;
2545b39c5158Smillert    @ls;
2546b39c5158Smillert}
2547b39c5158Smillert
2548b39c5158Smillert=item macro (o)
2549b39c5158Smillert
2550b39c5158SmillertSimple subroutine to insert the macros defined by the macro attribute
2551b39c5158Smillertinto the Makefile.
2552b39c5158Smillert
2553b39c5158Smillert=cut
2554b39c5158Smillert
2555b39c5158Smillertsub macro {
2556b39c5158Smillert    my($self,%attribs) = @_;
25579f11ffb7Safresh1    my @m;
25589f11ffb7Safresh1    foreach my $key (sort keys %attribs) {
25599f11ffb7Safresh1	my $val = $attribs{$key};
2560b39c5158Smillert	push @m, "$key = $val\n";
2561b39c5158Smillert    }
2562b39c5158Smillert    join "", @m;
2563b39c5158Smillert}
2564b39c5158Smillert
2565b39c5158Smillert=item makeaperl (o)
2566b39c5158Smillert
2567b39c5158SmillertCalled by staticmake. Defines how to write the Makefile to produce a
2568b39c5158Smillertstatic new perl.
2569b39c5158Smillert
2570b39c5158SmillertBy default the Makefile produced includes all the static extensions in
2571b39c5158Smillertthe perl library. (Purified versions of library files, e.g.,
2572b39c5158SmillertDynaLoader_pure_p1_c0_032.a are automatically ignored to avoid link errors.)
2573b39c5158Smillert
2574b39c5158Smillert=cut
2575b39c5158Smillert
2576b39c5158Smillertsub makeaperl {
2577b39c5158Smillert    my($self, %attribs) = @_;
2578b39c5158Smillert    my($makefilename, $searchdirs, $static, $extra, $perlinc, $target, $tmp, $libperl) =
2579b39c5158Smillert	@attribs{qw(MAKE DIRS STAT EXTRA INCL TARGET TMP LIBPERL)};
25809f11ffb7Safresh1    s/^(.*)/"-I$1"/ for @{$perlinc || []};
2581b39c5158Smillert    my(@m);
2582b39c5158Smillert    push @m, "
2583b39c5158Smillert# --- MakeMaker makeaperl section ---
2584b39c5158SmillertMAP_TARGET    = $target
2585b39c5158SmillertFULLPERL      = $self->{FULLPERL}
25869f11ffb7Safresh1MAP_PERLINC   = @{$perlinc || []}
2587b39c5158Smillert";
2588b39c5158Smillert    return join '', @m if $self->{PARENT};
2589b39c5158Smillert
2590b39c5158Smillert    my($dir) = join ":", @{$self->{DIR}};
2591b39c5158Smillert
2592b39c5158Smillert    unless ($self->{MAKEAPERL}) {
2593b39c5158Smillert	push @m, q{
25949f11ffb7Safresh1$(MAP_TARGET) :: $(MAKE_APERL_FILE)
2595b39c5158Smillert	$(MAKE) $(USEMAKEFILE) $(MAKE_APERL_FILE) $@
2596b39c5158Smillert
25979f11ffb7Safresh1$(MAKE_APERL_FILE) : static $(FIRST_MAKEFILE) pm_to_blib
2598b39c5158Smillert	$(NOECHO) $(ECHO) Writing \"$(MAKE_APERL_FILE)\" for this $(MAP_TARGET)
2599b39c5158Smillert	$(NOECHO) $(PERLRUNINST) \
2600b8851fccSafresh1		Makefile.PL DIR="}, $dir, q{" \
2601b39c5158Smillert		MAKEFILE=$(MAKE_APERL_FILE) LINKTYPE=static \
2602b39c5158Smillert		MAKEAPERL=1 NORECURS=1 CCCDLFLAGS=};
2603b39c5158Smillert
2604b39c5158Smillert	foreach (@ARGV){
26059f11ffb7Safresh1		my $arg = $_; # avoid lvalue aliasing
26069f11ffb7Safresh1		if ( $arg =~ /(^.*?=)(.*['\s].*)/ ) {
26079f11ffb7Safresh1			$arg = $1 . $self->quote_literal($2);
2608b39c5158Smillert		}
26099f11ffb7Safresh1		push @m, " \\\n\t\t$arg";
2610b39c5158Smillert	}
2611b39c5158Smillert	push @m, "\n";
2612b39c5158Smillert
2613b39c5158Smillert	return join '', @m;
2614b39c5158Smillert    }
2615b39c5158Smillert
26169f11ffb7Safresh1    my $cccmd = $self->const_cccmd($libperl);
2617b39c5158Smillert    $cccmd =~ s/^CCCMD\s*=\s*//;
2618b39c5158Smillert    $cccmd =~ s/\$\(INC\)/ "-I$self->{PERL_INC}" /;
2619b39c5158Smillert    $cccmd .= " $Config{cccdlflags}"
2620b39c5158Smillert	if ($Config{useshrplib} eq 'true');
2621b39c5158Smillert    $cccmd =~ s/\(CC\)/\(PERLMAINCC\)/;
2622b39c5158Smillert
2623b39c5158Smillert    # The front matter of the linkcommand...
26249f11ffb7Safresh1    my $linkcmd = join ' ', "\$(CC)",
2625b39c5158Smillert	    grep($_, @Config{qw(ldflags ccdlflags)});
2626b39c5158Smillert    $linkcmd =~ s/\s+/ /g;
2627b39c5158Smillert    $linkcmd =~ s,(perl\.exp),\$(PERL_INC)/$1,;
2628b39c5158Smillert
2629b39c5158Smillert    # Which *.a files could we make use of...
26309f11ffb7Safresh1    my $staticlib21 = $self->_find_static_libs($searchdirs);
26319f11ffb7Safresh1    # We trust that what has been handed in as argument, will be buildable
26329f11ffb7Safresh1    $static = [] unless $static;
26339f11ffb7Safresh1    @$staticlib21{@{$static}} = (1) x @{$static};
26349f11ffb7Safresh1
26359f11ffb7Safresh1    $extra = [] unless $extra && ref $extra eq 'ARRAY';
26369f11ffb7Safresh1    for (sort keys %$staticlib21) {
26379f11ffb7Safresh1	next unless /\Q$self->{LIB_EXT}\E\z/;
26389f11ffb7Safresh1	$_ = dirname($_) . "/extralibs.ld";
26399f11ffb7Safresh1	push @$extra, $_;
26409f11ffb7Safresh1    }
26419f11ffb7Safresh1
26429f11ffb7Safresh1    s/^(.*)/"-I$1"/ for @{$perlinc || []};
26439f11ffb7Safresh1
26449f11ffb7Safresh1    $target ||= "perl";
26459f11ffb7Safresh1    $tmp    ||= ".";
26469f11ffb7Safresh1
26479f11ffb7Safresh1# MAP_STATIC doesn't look into subdirs yet. Once "all" is made and we
26489f11ffb7Safresh1# regenerate the Makefiles, MAP_STATIC and the dependencies for
26499f11ffb7Safresh1# extralibs.all are computed correctly
26509f11ffb7Safresh1    my @map_static = reverse sort keys %$staticlib21;
26519f11ffb7Safresh1    push @m, "
26529f11ffb7Safresh1MAP_LINKCMD   = $linkcmd
26539f11ffb7Safresh1MAP_STATIC    = ", join(" \\\n\t", map { qq{"$_"} } @map_static), "
26549f11ffb7Safresh1MAP_STATICDEP = ", join(' ', map { $self->quote_dep($_) } @map_static), "
26559f11ffb7Safresh1
26569f11ffb7Safresh1MAP_PRELIBS   = $Config{perllibs} $Config{cryptlib}
26579f11ffb7Safresh1";
26589f11ffb7Safresh1
26599f11ffb7Safresh1    my $lperl;
26609f11ffb7Safresh1    if (defined $libperl) {
26619f11ffb7Safresh1	($lperl = $libperl) =~ s/\$\(A\)/$self->{LIB_EXT}/;
26629f11ffb7Safresh1    }
26639f11ffb7Safresh1    unless ($libperl && -f $lperl) { # Ilya's code...
26649f11ffb7Safresh1	my $dir = $self->{PERL_SRC} || "$self->{PERL_ARCHLIB}/CORE";
26659f11ffb7Safresh1	$dir = "$self->{PERL_ARCHLIB}/.." if $self->{UNINSTALLED_PERL};
26669f11ffb7Safresh1	$libperl ||= "libperl$self->{LIB_EXT}";
26679f11ffb7Safresh1	$libperl   = "$dir/$libperl";
26689f11ffb7Safresh1	$lperl   ||= "libperl$self->{LIB_EXT}";
26699f11ffb7Safresh1	$lperl     = "$dir/$lperl";
26709f11ffb7Safresh1
26719f11ffb7Safresh1        if (! -f $libperl and ! -f $lperl) {
26729f11ffb7Safresh1          # We did not find a static libperl. Maybe there is a shared one?
26739f11ffb7Safresh1          if ($Is{SunOS}) {
26749f11ffb7Safresh1            $lperl  = $libperl = "$dir/$Config{libperl}";
26759f11ffb7Safresh1            # SUNOS ld does not take the full path to a shared library
26769f11ffb7Safresh1            $libperl = '' if $Is{SunOS4};
26779f11ffb7Safresh1          }
26789f11ffb7Safresh1        }
26799f11ffb7Safresh1
26809f11ffb7Safresh1	print <<EOF unless -f $lperl || defined($self->{PERL_SRC});
26819f11ffb7Safresh1Warning: $libperl not found
26829f11ffb7Safresh1If you're going to build a static perl binary, make sure perl is installed
26839f11ffb7Safresh1otherwise ignore this warning
26849f11ffb7Safresh1EOF
26859f11ffb7Safresh1    }
26869f11ffb7Safresh1
26879f11ffb7Safresh1    # SUNOS ld does not take the full path to a shared library
26889f11ffb7Safresh1    my $llibperl = $libperl ? '$(MAP_LIBPERL)' : '-lperl';
26899f11ffb7Safresh1    my $libperl_dep = $self->quote_dep($libperl);
26909f11ffb7Safresh1
26919f11ffb7Safresh1    push @m, "
26929f11ffb7Safresh1MAP_LIBPERL = $libperl
26939f11ffb7Safresh1MAP_LIBPERLDEP = $libperl_dep
26949f11ffb7Safresh1LLIBPERL    = $llibperl
26959f11ffb7Safresh1";
26969f11ffb7Safresh1
26979f11ffb7Safresh1    push @m, '
26989f11ffb7Safresh1$(INST_ARCHAUTODIR)/extralibs.all : $(INST_ARCHAUTODIR)$(DFSEP).exists '.join(" \\\n\t", @$extra).'
26999f11ffb7Safresh1	$(NOECHO) $(RM_F)  $@
27009f11ffb7Safresh1	$(NOECHO) $(TOUCH) $@
27019f11ffb7Safresh1';
27029f11ffb7Safresh1
27039f11ffb7Safresh1    foreach my $catfile (@$extra){
27049f11ffb7Safresh1	push @m, "\tcat $catfile >> \$\@\n";
27059f11ffb7Safresh1    }
27069f11ffb7Safresh1
27079f11ffb7Safresh1    my $ldfrom = $self->{XSMULTI} ? '' : '$(LDFROM)';
27089f11ffb7Safresh1    #                             1     2                        3        4
27099f11ffb7Safresh1    push @m, _sprintf562 <<'EOF', $tmp, $ldfrom, $self->xs_obj_opt('$@'), $makefilename;
27109f11ffb7Safresh1$(MAP_TARGET) :: %1$s/perlmain$(OBJ_EXT) $(MAP_LIBPERLDEP) $(MAP_STATICDEP) $(INST_ARCHAUTODIR)/extralibs.all
27119f11ffb7Safresh1	$(MAP_LINKCMD) %2$s $(OPTIMIZE) %1$s/perlmain$(OBJ_EXT) %3$s $(MAP_STATIC) "$(LLIBPERL)" `cat $(INST_ARCHAUTODIR)/extralibs.all` $(MAP_PRELIBS)
27129f11ffb7Safresh1	$(NOECHO) $(ECHO) "To install the new '$(MAP_TARGET)' binary, call"
27139f11ffb7Safresh1	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s inst_perl MAP_TARGET=$(MAP_TARGET)"
27149f11ffb7Safresh1	$(NOECHO) $(ECHO) "    $(MAKE) $(USEMAKEFILE) %4$s map_clean"
27159f11ffb7Safresh1
27169f11ffb7Safresh1%1$s/perlmain\$(OBJ_EXT): %1$s/perlmain.c
27179f11ffb7Safresh1EOF
27189f11ffb7Safresh1    push @m, "\t".$self->cd($tmp, qq[$cccmd "-I\$(PERL_INC)" perlmain.c])."\n";
27199f11ffb7Safresh1
27209f11ffb7Safresh1    my $maybe_DynaLoader = $Config{usedl} ? 'q(DynaLoader)' : '';
27219f11ffb7Safresh1    push @m, _sprintf562 <<'EOF', $tmp, $makefilename, $maybe_DynaLoader;
27229f11ffb7Safresh1
27239f11ffb7Safresh1%1$s/perlmain.c: %2$s
27249f11ffb7Safresh1	$(NOECHO) $(ECHO) Writing $@
27259f11ffb7Safresh1	$(NOECHO) $(PERL) $(MAP_PERLINC) "-MExtUtils::Miniperl" \
27269f11ffb7Safresh1		-e "writemain(grep(s#.*/auto/##s, @ARGV), %3$s)" $(MAP_STATIC) > $@t
27279f11ffb7Safresh1	$(MV) $@t $@
27289f11ffb7Safresh1
27299f11ffb7Safresh1EOF
27309f11ffb7Safresh1    push @m, "\t", q{$(NOECHO) $(PERL) "$(INSTALLSCRIPT)/fixpmain"
27319f11ffb7Safresh1} if (defined (&Dos::UseLFN) && Dos::UseLFN()==0);
27329f11ffb7Safresh1
27339f11ffb7Safresh1
27349f11ffb7Safresh1    push @m, q{
27359f11ffb7Safresh1doc_inst_perl :
27369f11ffb7Safresh1	$(NOECHO) $(ECHO) Appending installation info to "$(DESTINSTALLARCHLIB)/perllocal.pod"
27379f11ffb7Safresh1	-$(NOECHO) $(MKPATH) "$(DESTINSTALLARCHLIB)"
27389f11ffb7Safresh1	-$(NOECHO) $(DOC_INSTALL) \
27399f11ffb7Safresh1		"Perl binary" "$(MAP_TARGET)" \
27409f11ffb7Safresh1		MAP_STATIC "$(MAP_STATIC)" \
27419f11ffb7Safresh1		MAP_EXTRA "`cat $(INST_ARCHAUTODIR)/extralibs.all`" \
27429f11ffb7Safresh1		MAP_LIBPERL "$(MAP_LIBPERL)" \
27439f11ffb7Safresh1		>> "}.$self->catfile('$(DESTINSTALLARCHLIB)','perllocal.pod').q{"
27449f11ffb7Safresh1
27459f11ffb7Safresh1};
27469f11ffb7Safresh1
27479f11ffb7Safresh1    push @m, q{
27489f11ffb7Safresh1inst_perl : pure_inst_perl doc_inst_perl
27499f11ffb7Safresh1
27509f11ffb7Safresh1pure_inst_perl : $(MAP_TARGET)
27519f11ffb7Safresh1	}.$self->{CP}.q{ $(MAP_TARGET) "}.$self->catfile('$(DESTINSTALLBIN)','$(MAP_TARGET)').q{"
27529f11ffb7Safresh1
27539f11ffb7Safresh1clean :: map_clean
27549f11ffb7Safresh1
27559f11ffb7Safresh1map_clean :
27569f11ffb7Safresh1	}.$self->{RM_F}.qq{ $tmp/perlmain\$(OBJ_EXT) $tmp/perlmain.c \$(MAP_TARGET) $makefilename \$(INST_ARCHAUTODIR)/extralibs.all
27579f11ffb7Safresh1};
27589f11ffb7Safresh1
27599f11ffb7Safresh1    join '', @m;
27609f11ffb7Safresh1}
27619f11ffb7Safresh1
27629f11ffb7Safresh1# utility method
27639f11ffb7Safresh1sub _find_static_libs {
27649f11ffb7Safresh1    my ($self, $searchdirs) = @_;
27659f11ffb7Safresh1    # don't use File::Spec here because on Win32 F::F still uses "/"
27669f11ffb7Safresh1    my $installed_version = join('/',
27679f11ffb7Safresh1	'auto', $self->{FULLEXT}, "$self->{BASEEXT}$self->{LIB_EXT}"
27689f11ffb7Safresh1    );
27699f11ffb7Safresh1    my %staticlib21;
2770b39c5158Smillert    require File::Find;
2771b39c5158Smillert    File::Find::find(sub {
27729f11ffb7Safresh1	if ($File::Find::name =~ m{/auto/share\z}) {
27739f11ffb7Safresh1	    # in a subdir of auto/share, prune because e.g.
27749f11ffb7Safresh1	    # Alien::pkgconfig uses File::ShareDir to put .a files
27759f11ffb7Safresh1	    # there. do not want
27769f11ffb7Safresh1	    $File::Find::prune = 1;
27779f11ffb7Safresh1	    return;
27789f11ffb7Safresh1	}
27799f11ffb7Safresh1
2780b39c5158Smillert	return unless m/\Q$self->{LIB_EXT}\E$/;
2781b39c5158Smillert
27829f11ffb7Safresh1	return unless -f 'extralibs.ld'; # this checks is a "proper" XS installation
27839f11ffb7Safresh1
2784b39c5158Smillert        # Skip perl's libraries.
2785b39c5158Smillert        return if m/^libperl/ or m/^perl\Q$self->{LIB_EXT}\E$/;
2786b39c5158Smillert
2787b39c5158Smillert	# Skip purified versions of libraries
2788b39c5158Smillert        # (e.g., DynaLoader_pure_p1_c0_032.a)
2789b39c5158Smillert	return if m/_pure_\w+_\w+_\w+\.\w+$/ and -f "$File::Find::dir/.pure";
2790b39c5158Smillert
2791b39c5158Smillert	if( exists $self->{INCLUDE_EXT} ){
2792b39c5158Smillert		my $found = 0;
2793b39c5158Smillert
2794b39c5158Smillert		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2795b39c5158Smillert		$xx =~ s,/?$_,,;
2796b39c5158Smillert		$xx =~ s,/,::,g;
2797b39c5158Smillert
2798b39c5158Smillert		# Throw away anything not explicitly marked for inclusion.
2799b39c5158Smillert		# DynaLoader is implied.
2800b39c5158Smillert		foreach my $incl ((@{$self->{INCLUDE_EXT}},'DynaLoader')){
2801b39c5158Smillert			if( $xx eq $incl ){
2802b39c5158Smillert				$found++;
2803b39c5158Smillert				last;
2804b39c5158Smillert			}
2805b39c5158Smillert		}
2806b39c5158Smillert		return unless $found;
2807b39c5158Smillert	}
2808b39c5158Smillert	elsif( exists $self->{EXCLUDE_EXT} ){
2809b39c5158Smillert		(my $xx = $File::Find::name) =~ s,.*?/auto/,,s;
2810b39c5158Smillert		$xx =~ s,/?$_,,;
2811b39c5158Smillert		$xx =~ s,/,::,g;
2812b39c5158Smillert
2813b39c5158Smillert		# Throw away anything explicitly marked for exclusion
2814b39c5158Smillert		foreach my $excl (@{$self->{EXCLUDE_EXT}}){
2815b39c5158Smillert			return if( $xx eq $excl );
2816b39c5158Smillert		}
2817b39c5158Smillert	}
2818b39c5158Smillert
2819b39c5158Smillert	# don't include the installed version of this extension. I
2820b39c5158Smillert	# leave this line here, although it is not necessary anymore:
2821b39c5158Smillert	# I patched minimod.PL instead, so that Miniperl.pm won't
2822e5157e49Safresh1	# include duplicates
2823b39c5158Smillert
2824b39c5158Smillert	# Once the patch to minimod.PL is in the distribution, I can
2825b39c5158Smillert	# drop it
28269f11ffb7Safresh1	return if $File::Find::name =~ m:\Q$installed_version\E\z:;
28279f11ffb7Safresh1	return if !$self->xs_static_lib_is_xs($_);
2828b39c5158Smillert	use Cwd 'cwd';
28299f11ffb7Safresh1	$staticlib21{cwd() . "/" . $_}++;
28309f11ffb7Safresh1    }, grep( -d $_, map { $self->catdir($_, 'auto') } @{$searchdirs || []}) );
28319f11ffb7Safresh1    return \%staticlib21;
2832b39c5158Smillert}
2833b39c5158Smillert
28349f11ffb7Safresh1=item xs_static_lib_is_xs (o)
2835b39c5158Smillert
28369f11ffb7Safresh1Called by a utility method of makeaperl. Checks whether a given file
28379f11ffb7Safresh1is an XS library by seeing whether it defines any symbols starting
283856d68f1eSafresh1with C<boot_> (with an optional leading underscore - needed on MacOS).
2839b39c5158Smillert
28409f11ffb7Safresh1=cut
2841b39c5158Smillert
28429f11ffb7Safresh1sub xs_static_lib_is_xs {
28439f11ffb7Safresh1    my ($self, $libfile) = @_;
28449f11ffb7Safresh1    my $devnull = File::Spec->devnull;
284556d68f1eSafresh1    return `nm $libfile 2>$devnull` =~ /\b_?boot_/;
2846b39c5158Smillert}
2847b39c5158Smillert
2848b39c5158Smillert=item makefile (o)
2849b39c5158Smillert
2850b39c5158SmillertDefines how to rewrite the Makefile.
2851b39c5158Smillert
2852b39c5158Smillert=cut
2853b39c5158Smillert
2854b39c5158Smillertsub makefile {
2855b39c5158Smillert    my($self) = shift;
2856b39c5158Smillert    my $m;
2857b39c5158Smillert    # We do not know what target was originally specified so we
2858b39c5158Smillert    # must force a manual rerun to be sure. But as it should only
2859b39c5158Smillert    # happen very rarely it is not a significant problem.
2860b39c5158Smillert    $m = '
2861b39c5158Smillert$(OBJECT) : $(FIRST_MAKEFILE)
2862b39c5158Smillert
2863b39c5158Smillert' if $self->{OBJECT};
2864b39c5158Smillert
2865b39c5158Smillert    my $newer_than_target = $Is{VMS} ? '$(MMS$SOURCE_LIST)' : '$?';
2866b39c5158Smillert    my $mpl_args = join " ", map qq["$_"], @ARGV;
2867e5157e49Safresh1    my $cross = '';
2868e5157e49Safresh1    if (defined $::Cross::platform) {
2869e5157e49Safresh1        # Inherited from win32/buildext.pl
2870e5157e49Safresh1        $cross = "-MCross=$::Cross::platform ";
2871e5157e49Safresh1    }
2872e5157e49Safresh1    $m .= sprintf <<'MAKE_FRAG', $newer_than_target, $cross, $mpl_args;
2873b39c5158Smillert# We take a very conservative approach here, but it's worth it.
2874b39c5158Smillert# We move Makefile to Makefile.old here to avoid gnu make looping.
2875b39c5158Smillert$(FIRST_MAKEFILE) : Makefile.PL $(CONFIGDEP)
2876b39c5158Smillert	$(NOECHO) $(ECHO) "Makefile out-of-date with respect to %s"
2877b39c5158Smillert	$(NOECHO) $(ECHO) "Cleaning current config before rebuilding Makefile..."
2878b39c5158Smillert	-$(NOECHO) $(RM_F) $(MAKEFILE_OLD)
2879b39c5158Smillert	-$(NOECHO) $(MV)   $(FIRST_MAKEFILE) $(MAKEFILE_OLD)
2880b39c5158Smillert	- $(MAKE) $(USEMAKEFILE) $(MAKEFILE_OLD) clean $(DEV_NULL)
2881e5157e49Safresh1	$(PERLRUN) %sMakefile.PL %s
2882b39c5158Smillert	$(NOECHO) $(ECHO) "==> Your Makefile has been rebuilt. <=="
2883b39c5158Smillert	$(NOECHO) $(ECHO) "==> Please rerun the $(MAKE) command.  <=="
2884b39c5158Smillert	$(FALSE)
2885b39c5158Smillert
2886b39c5158SmillertMAKE_FRAG
2887b39c5158Smillert
2888b39c5158Smillert    return $m;
2889b39c5158Smillert}
2890b39c5158Smillert
2891b39c5158Smillert
2892b39c5158Smillert=item maybe_command
2893b39c5158Smillert
2894b39c5158SmillertReturns true, if the argument is likely to be a command.
2895b39c5158Smillert
2896b39c5158Smillert=cut
2897b39c5158Smillert
2898b39c5158Smillertsub maybe_command {
2899b39c5158Smillert    my($self,$file) = @_;
2900b39c5158Smillert    return $file if -x $file && ! -d $file;
2901b39c5158Smillert    return;
2902b39c5158Smillert}
2903b39c5158Smillert
2904b39c5158Smillert
2905b39c5158Smillert=item needs_linking (o)
2906b39c5158Smillert
2907b39c5158SmillertDoes this module need linking? Looks into subdirectory objects (see
2908b39c5158Smillertalso has_link_code())
2909b39c5158Smillert
2910b39c5158Smillert=cut
2911b39c5158Smillert
2912b39c5158Smillertsub needs_linking {
2913b39c5158Smillert    my($self) = shift;
2914b39c5158Smillert
2915b39c5158Smillert    my $caller = (caller(0))[3];
2916b39c5158Smillert    confess("needs_linking called too early") if
2917b39c5158Smillert      $caller =~ /^ExtUtils::MakeMaker::/;
2918b39c5158Smillert    return $self->{NEEDS_LINKING} if defined $self->{NEEDS_LINKING};
2919b39c5158Smillert    if ($self->has_link_code or $self->{MAKEAPERL}){
2920b39c5158Smillert	$self->{NEEDS_LINKING} = 1;
2921b39c5158Smillert	return 1;
2922b39c5158Smillert    }
2923b39c5158Smillert    foreach my $child (keys %{$self->{CHILDREN}}) {
2924b39c5158Smillert	if ($self->{CHILDREN}->{$child}->needs_linking) {
2925b39c5158Smillert	    $self->{NEEDS_LINKING} = 1;
2926b39c5158Smillert	    return 1;
2927b39c5158Smillert	}
2928b39c5158Smillert    }
2929b39c5158Smillert    return $self->{NEEDS_LINKING} = 0;
2930b39c5158Smillert}
2931b39c5158Smillert
2932b39c5158Smillert
2933b39c5158Smillert=item parse_abstract
2934b39c5158Smillert
2935b39c5158Smillertparse a file and return what you think is the ABSTRACT
2936b39c5158Smillert
2937b39c5158Smillert=cut
2938b39c5158Smillert
2939b39c5158Smillertsub parse_abstract {
2940b39c5158Smillert    my($self,$parsefile) = @_;
2941b39c5158Smillert    my $result;
2942b39c5158Smillert
2943b39c5158Smillert    local $/ = "\n";
2944b39c5158Smillert    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
29459f11ffb7Safresh1    binmode $fh;
2946b39c5158Smillert    my $inpod = 0;
2947b8851fccSafresh1    my $pod_encoding;
2948b39c5158Smillert    my $package = $self->{DISTNAME};
2949b39c5158Smillert    $package =~ s/-/::/g;
2950b39c5158Smillert    while (<$fh>) {
2951b39c5158Smillert        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
2952b39c5158Smillert        next if !$inpod;
29539f11ffb7Safresh1        s#\r*\n\z##; # handle CRLF input
2954b8851fccSafresh1
2955b8851fccSafresh1        if ( /^=encoding\s*(.*)$/i ) {
2956b8851fccSafresh1            $pod_encoding = $1;
2957b8851fccSafresh1        }
2958b8851fccSafresh1
2959e5157e49Safresh1        if ( /^($package(?:\.pm)? \s+ -+ \s+)(.*)/x ) {
2960b39c5158Smillert          $result = $2;
2961e5157e49Safresh1          next;
2962e5157e49Safresh1        }
2963e5157e49Safresh1        next unless $result;
2964b8851fccSafresh1
2965e5157e49Safresh1        if ( $result && ( /^\s*$/ || /^\=/ ) ) {
2966b39c5158Smillert          last;
2967b39c5158Smillert        }
2968e5157e49Safresh1        $result = join ' ', $result, $_;
2969e5157e49Safresh1    }
2970b39c5158Smillert    close $fh;
2971b39c5158Smillert
297256d68f1eSafresh1    if ( $pod_encoding and !( "$]" < 5.008 or !$Config{useperlio} ) ) {
2973b8851fccSafresh1        # Have to wrap in an eval{} for when running under PERL_CORE
2974b8851fccSafresh1        # Encode isn't available during build phase and parsing
2975b8851fccSafresh1        # ABSTRACT isn't important there
2976b8851fccSafresh1        eval {
2977b8851fccSafresh1          require Encode;
2978b8851fccSafresh1          $result = Encode::decode($pod_encoding, $result);
2979b8851fccSafresh1        }
2980b8851fccSafresh1    }
2981b8851fccSafresh1
2982b39c5158Smillert    return $result;
2983b39c5158Smillert}
2984b39c5158Smillert
2985b39c5158Smillert=item parse_version
2986b39c5158Smillert
2987b39c5158Smillert    my $version = MM->parse_version($file);
2988b39c5158Smillert
2989b39c5158SmillertParse a $file and return what $VERSION is set to by the first assignment.
2990b39c5158SmillertIt will return the string "undef" if it can't figure out what $VERSION
2991b39c5158Smillertis. $VERSION should be for all to see, so C<our $VERSION> or plain $VERSION
2992b39c5158Smillertare okay, but C<my $VERSION> is not.
2993b39c5158Smillert
299456d68f1eSafresh1C<package Foo VERSION> is also checked for.  The first version
2995b39c5158Smillertdeclaration found is used, but this may change as it differs from how
2996b39c5158SmillertPerl does it.
2997b39c5158Smillert
2998b39c5158Smillertparse_version() will try to C<use version> before checking for
2999b39c5158SmillertC<$VERSION> so the following will work.
3000b39c5158Smillert
3001b39c5158Smillert    $VERSION = qv(1.2.3);
3002b39c5158Smillert
3003b39c5158Smillert=cut
3004b39c5158Smillert
3005b39c5158Smillertsub parse_version {
3006b39c5158Smillert    my($self,$parsefile) = @_;
3007b39c5158Smillert    my $result;
3008b39c5158Smillert
3009b39c5158Smillert    local $/ = "\n";
3010b39c5158Smillert    local $_;
3011b39c5158Smillert    open(my $fh, '<', $parsefile) or die "Could not open '$parsefile': $!";
3012b39c5158Smillert    my $inpod = 0;
3013b39c5158Smillert    while (<$fh>) {
3014b39c5158Smillert        $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod;
3015b39c5158Smillert        next if $inpod || /^\s*#/;
3016b39c5158Smillert        chop;
301748950c12Ssthen        next if /^\s*(if|unless|elsif)/;
30189f11ffb7Safresh1        if ( m{^ \s* package \s+ \w[\w\:\']* \s+ (v?[0-9._]+) \s* (;|\{)  }x ) {
3019eac174f2Safresh1            no warnings;
3020b39c5158Smillert            $result = $1;
3021b39c5158Smillert        }
3022e5157e49Safresh1        elsif ( m{(?<!\\) ([\$*]) (([\w\:\']*) \bVERSION)\b .* (?<![<>=!])\=[^=]}x ) {
3023e5157e49Safresh1			$result = $self->get_version($parsefile, $1, $2);
3024e5157e49Safresh1        }
3025e5157e49Safresh1        else {
3026e5157e49Safresh1          next;
3027e5157e49Safresh1        }
3028e5157e49Safresh1        last if defined $result;
3029e5157e49Safresh1    }
3030e5157e49Safresh1    close $fh;
3031e5157e49Safresh1
3032e5157e49Safresh1    if ( defined $result && $result !~ /^v?[\d_\.]+$/ ) {
3033e5157e49Safresh1      require version;
3034b8851fccSafresh1      my $normal = eval { version->new( $result ) };
3035e5157e49Safresh1      $result = $normal if defined $normal;
3036e5157e49Safresh1    }
3037eac174f2Safresh1    if ( defined $result ) {
3038eac174f2Safresh1      $result = "undef" unless $result =~ m!^v?[\d_\.]+$!
3039eac174f2Safresh1                        or eval { version->parse( $result ) };
3040eac174f2Safresh1    }
3041e5157e49Safresh1    $result = "undef" unless defined $result;
3042e5157e49Safresh1    return $result;
3043e5157e49Safresh1}
3044e5157e49Safresh1
3045b8851fccSafresh1sub get_version {
3046e5157e49Safresh1    my ($self, $parsefile, $sigil, $name) = @_;
3047b8851fccSafresh1    my $line = $_; # from the while() loop in parse_version
3048b8851fccSafresh1    {
3049b39c5158Smillert        package ExtUtils::MakeMaker::_version;
3050b8851fccSafresh1        undef *version; # in case of unexpected version() sub
3051b8851fccSafresh1        eval {
3052b39c5158Smillert            require version;
3053b8851fccSafresh1            version::->import;
3054b39c5158Smillert        };
3055b8851fccSafresh1        no strict;
3056eac174f2Safresh1        no warnings;
3057b8851fccSafresh1        local *{$name};
3058b8851fccSafresh1        $line = $1 if $line =~ m{^(.+)}s;
3059b8851fccSafresh1        eval($line); ## no critic
3060b8851fccSafresh1        return ${$name};
3061b39c5158Smillert    }
3062b8851fccSafresh1}
3063b39c5158Smillert
3064b39c5158Smillert=item pasthru (o)
3065b39c5158Smillert
3066b39c5158SmillertDefines the string that is passed to recursive make calls in
30679f11ffb7Safresh1subdirectories. The variables like C<PASTHRU_DEFINE> are used in each
30689f11ffb7Safresh1level, and passed downwards on the command-line with e.g. the value of
30699f11ffb7Safresh1that level's DEFINE. Example:
30709f11ffb7Safresh1
30719f11ffb7Safresh1    # Level 0 has DEFINE = -Dfunky
30729f11ffb7Safresh1    # This code will define level 0's PASTHRU=PASTHRU_DEFINE="$(DEFINE)
30739f11ffb7Safresh1    #     $(PASTHRU_DEFINE)"
30749f11ffb7Safresh1    # Level 0's $(CCCMD) will include macros $(DEFINE) and $(PASTHRU_DEFINE)
30759f11ffb7Safresh1    # So will level 1's, so when level 1 compiles, it will get right values
30769f11ffb7Safresh1    # And so ad infinitum
3077b39c5158Smillert
3078b39c5158Smillert=cut
3079b39c5158Smillert
3080b39c5158Smillertsub pasthru {
3081b39c5158Smillert    my($self) = shift;
3082b39c5158Smillert    my(@m);
3083b39c5158Smillert
3084b39c5158Smillert    my(@pasthru);
3085b39c5158Smillert    my($sep) = $Is{VMS} ? ',' : '';
3086b39c5158Smillert    $sep .= "\\\n\t";
3087b39c5158Smillert
3088b39c5158Smillert    foreach my $key (qw(LIB LIBPERL_A LINKTYPE OPTIMIZE
3089b39c5158Smillert                     PREFIX INSTALL_BASE)
3090b39c5158Smillert                 )
3091b39c5158Smillert    {
3092b39c5158Smillert        next unless defined $self->{$key};
3093b39c5158Smillert	push @pasthru, "$key=\"\$($key)\"";
3094b39c5158Smillert    }
3095b39c5158Smillert
3096b39c5158Smillert    foreach my $key (qw(DEFINE INC)) {
30979f11ffb7Safresh1        # default to the make var
30989f11ffb7Safresh1        my $val = qq{\$($key)};
30999f11ffb7Safresh1        # expand within perl if given since need to use quote_literal
31009f11ffb7Safresh1        # since INC might include space-protecting ""!
31019f11ffb7Safresh1        chomp($val = $self->{$key}) if defined $self->{$key};
31029f11ffb7Safresh1        $val .= " \$(PASTHRU_$key)";
31039f11ffb7Safresh1        my $quoted = $self->quote_literal($val);
31049f11ffb7Safresh1        push @pasthru, qq{PASTHRU_$key=$quoted};
3105b39c5158Smillert    }
3106b39c5158Smillert
3107b39c5158Smillert    push @m, "\nPASTHRU = ", join ($sep, @pasthru), "\n";
3108b39c5158Smillert    join "", @m;
3109b39c5158Smillert}
3110b39c5158Smillert
3111b39c5158Smillert=item perl_script
3112b39c5158Smillert
3113b39c5158SmillertTakes one argument, a file name, and returns the file name, if the
3114b39c5158Smillertargument is likely to be a perl script. On MM_Unix this is true for
3115b39c5158Smillertany ordinary, readable file.
3116b39c5158Smillert
3117b39c5158Smillert=cut
3118b39c5158Smillert
3119b39c5158Smillertsub perl_script {
3120b39c5158Smillert    my($self,$file) = @_;
3121b39c5158Smillert    return $file if -r $file && -f _;
3122b39c5158Smillert    return;
3123b39c5158Smillert}
3124b39c5158Smillert
3125b39c5158Smillert=item perldepend (o)
3126b39c5158Smillert
3127b39c5158SmillertDefines the dependency from all *.h files that come with the perl
3128b39c5158Smillertdistribution.
3129b39c5158Smillert
3130b39c5158Smillert=cut
3131b39c5158Smillert
3132b39c5158Smillertsub perldepend {
3133b39c5158Smillert    my($self) = shift;
3134b39c5158Smillert    my(@m);
3135b39c5158Smillert
3136b39c5158Smillert    my $make_config = $self->cd('$(PERL_SRC)', '$(MAKE) lib/Config.pm');
3137b39c5158Smillert
3138b39c5158Smillert    push @m, sprintf <<'MAKE_FRAG', $make_config if $self->{PERL_SRC};
3139b39c5158Smillert# Check for unpropogated config.sh changes. Should never happen.
3140b39c5158Smillert# We do NOT just update config.h because that is not sufficient.
3141b39c5158Smillert# An out of date config.h is not fatal but complains loudly!
3142b8851fccSafresh1$(PERL_INCDEP)/config.h: $(PERL_SRC)/config.sh
3143b39c5158Smillert	-$(NOECHO) $(ECHO) "Warning: $(PERL_INC)/config.h out of date with $(PERL_SRC)/config.sh"; $(FALSE)
3144b39c5158Smillert
3145b39c5158Smillert$(PERL_ARCHLIB)/Config.pm: $(PERL_SRC)/config.sh
3146b39c5158Smillert	$(NOECHO) $(ECHO) "Warning: $(PERL_ARCHLIB)/Config.pm may be out of date with $(PERL_SRC)/config.sh"
3147b39c5158Smillert	%s
3148b39c5158SmillertMAKE_FRAG
3149b39c5158Smillert
3150b39c5158Smillert    return join "", @m unless $self->needs_linking;
3151b39c5158Smillert
3152e9ce3842Safresh1    if ($self->{OBJECT}) {
3153e9ce3842Safresh1        # Need to add an object file dependency on the perl headers.
3154e9ce3842Safresh1        # this is very important for XS modules in perl.git development.
3155e9ce3842Safresh1        push @m, $self->_perl_header_files_fragment("/"); # Directory separator between $(PERL_INC)/header.h
3156e9ce3842Safresh1    }
3157b39c5158Smillert
3158b8851fccSafresh1    push @m, join(" ", sort values %{$self->{XS}})." : \$(XSUBPPDEPS)\n"  if %{$self->{XS}};
3159b39c5158Smillert
3160e9ce3842Safresh1    return join "\n", @m;
3161b39c5158Smillert}
3162b39c5158Smillert
3163b39c5158Smillert
3164b39c5158Smillert=item pm_to_blib
3165b39c5158Smillert
3166b39c5158SmillertDefines target that copies all files in the hash PM to their
3167b39c5158Smillertdestination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
3168b39c5158Smillert
3169b39c5158Smillert=cut
3170b39c5158Smillert
3171b39c5158Smillertsub pm_to_blib {
3172b39c5158Smillert    my $self = shift;
3173b39c5158Smillert    my($autodir) = $self->catdir('$(INST_LIB)','auto');
3174b39c5158Smillert    my $r = q{
3175b39c5158Smillertpm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM)
3176b39c5158Smillert};
3177b39c5158Smillert
3178b39c5158Smillert    # VMS will swallow '' and PM_FILTER is often empty.  So use q[]
3179b39c5158Smillert    my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
3180b39c5158Smillertpm_to_blib({\@ARGV}, '$autodir', q[\$(PM_FILTER)], '\$(PERM_DIR)')
3181b39c5158SmillertCODE
3182b39c5158Smillert
3183e5157e49Safresh1    my @cmds = $self->split_command($pm_to_blib,
31849f11ffb7Safresh1                  map { ($self->quote_literal($_) => $self->quote_literal($self->{PM}->{$_})) } sort keys %{$self->{PM}});
3185b39c5158Smillert
3186b39c5158Smillert    $r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
3187b39c5158Smillert    $r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
3188b39c5158Smillert
3189b39c5158Smillert    return $r;
3190b39c5158Smillert}
3191b39c5158Smillert
3192b39c5158Smillert# transform dot-separated version string into comma-separated quadruple
3193b39c5158Smillert# examples:  '1.2.3.4.5' => '1,2,3,4'
3194b39c5158Smillert#            '1.2.3'     => '1,2,3,0'
3195b39c5158Smillertsub _ppd_version {
3196b39c5158Smillert    my ($self, $string) = @_;
3197b39c5158Smillert    return join ',', ((split /\./, $string), (0) x 4)[0..3];
3198b39c5158Smillert}
3199b39c5158Smillert
3200b39c5158Smillert=item ppd
3201b39c5158Smillert
3202b39c5158SmillertDefines target that creates a PPD (Perl Package Description) file
3203b39c5158Smillertfor a binary distribution.
3204b39c5158Smillert
3205b39c5158Smillert=cut
3206b39c5158Smillert
3207b39c5158Smillertsub ppd {
3208b39c5158Smillert    my($self) = @_;
3209b39c5158Smillert
3210b39c5158Smillert    my $abstract = $self->{ABSTRACT} || '';
3211b39c5158Smillert    $abstract =~ s/\n/\\n/sg;
3212b39c5158Smillert    $abstract =~ s/</&lt;/g;
3213b39c5158Smillert    $abstract =~ s/>/&gt;/g;
3214b39c5158Smillert
32159f11ffb7Safresh1    my $author = join(', ',@{ ref $self->{AUTHOR} eq 'ARRAY' ? $self->{AUTHOR} : [ $self->{AUTHOR} || '']});
3216b39c5158Smillert    $author =~ s/</&lt;/g;
3217b39c5158Smillert    $author =~ s/>/&gt;/g;
3218b39c5158Smillert
32199f11ffb7Safresh1    my $ppd_file = "$self->{DISTNAME}.ppd";
322048950c12Ssthen
32219f11ffb7Safresh1    my @ppd_chunks = qq(<SOFTPKG NAME="$self->{DISTNAME}" VERSION="$self->{VERSION}">\n);
322248950c12Ssthen
32239f11ffb7Safresh1    push @ppd_chunks, sprintf <<'PPD_HTML', $abstract, $author;
3224b39c5158Smillert    <ABSTRACT>%s</ABSTRACT>
3225b39c5158Smillert    <AUTHOR>%s</AUTHOR>
3226b39c5158SmillertPPD_HTML
3227b39c5158Smillert
32289f11ffb7Safresh1    push @ppd_chunks, "    <IMPLEMENTATION>\n";
3229b39c5158Smillert    if ( $self->{MIN_PERL_VERSION} ) {
3230b39c5158Smillert        my $min_perl_version = $self->_ppd_version($self->{MIN_PERL_VERSION});
32319f11ffb7Safresh1        push @ppd_chunks, sprintf <<'PPD_PERLVERS', $min_perl_version;
3232b39c5158Smillert        <PERLCORE VERSION="%s" />
3233b39c5158SmillertPPD_PERLVERS
3234b39c5158Smillert
3235b39c5158Smillert    }
3236b39c5158Smillert
3237b39c5158Smillert    # Don't add "perl" to requires.  perl dependencies are
3238b39c5158Smillert    # handles by ARCHITECTURE.
3239b39c5158Smillert    my %prereqs = %{$self->{PREREQ_PM}};
3240b39c5158Smillert    delete $prereqs{perl};
3241b39c5158Smillert
3242b39c5158Smillert    # Build up REQUIRE
3243b39c5158Smillert    foreach my $prereq (sort keys %prereqs) {
3244b39c5158Smillert        my $name = $prereq;
3245b39c5158Smillert        $name .= '::' unless $name =~ /::/;
3246b8851fccSafresh1        my $version = $prereqs{$prereq};
3247b39c5158Smillert
3248b39c5158Smillert        my %attrs = ( NAME => $name );
3249b39c5158Smillert        $attrs{VERSION} = $version if $version;
3250b8851fccSafresh1        my $attrs = join " ", map { qq[$_="$attrs{$_}"] } sort keys %attrs;
32519f11ffb7Safresh1        push @ppd_chunks, qq(        <REQUIRE $attrs />\n);
3252b39c5158Smillert    }
3253b39c5158Smillert
3254b39c5158Smillert    my $archname = $Config{archname};
3255eac174f2Safresh1
3256b39c5158Smillert    # archname did not change from 5.6 to 5.8, but those versions may
3257b39c5158Smillert    # not be not binary compatible so now we append the part of the
3258b39c5158Smillert    # version that changes when binary compatibility may change
3259eac174f2Safresh1    if ("$]" >= 5.008) {
3260eac174f2Safresh1        $archname .= "-$Config{api_revision}.$Config{api_version}";
3261b39c5158Smillert    }
32629f11ffb7Safresh1    push @ppd_chunks, sprintf <<'PPD_OUT', $archname;
3263b39c5158Smillert        <ARCHITECTURE NAME="%s" />
3264b39c5158SmillertPPD_OUT
3265b39c5158Smillert
3266b39c5158Smillert    if ($self->{PPM_INSTALL_SCRIPT}) {
3267b39c5158Smillert        if ($self->{PPM_INSTALL_EXEC}) {
32689f11ffb7Safresh1            push @ppd_chunks, sprintf qq{        <INSTALL EXEC="%s">%s</INSTALL>\n},
3269b39c5158Smillert                  $self->{PPM_INSTALL_EXEC}, $self->{PPM_INSTALL_SCRIPT};
3270b39c5158Smillert        }
3271b39c5158Smillert        else {
32729f11ffb7Safresh1            push @ppd_chunks, sprintf qq{        <INSTALL>%s</INSTALL>\n},
3273b39c5158Smillert                  $self->{PPM_INSTALL_SCRIPT};
3274b39c5158Smillert        }
3275b39c5158Smillert    }
3276b39c5158Smillert
3277e5157e49Safresh1    if ($self->{PPM_UNINSTALL_SCRIPT}) {
3278e5157e49Safresh1        if ($self->{PPM_UNINSTALL_EXEC}) {
32799f11ffb7Safresh1            push @ppd_chunks, sprintf qq{        <UNINSTALL EXEC="%s">%s</UNINSTALL>\n},
3280e5157e49Safresh1                  $self->{PPM_UNINSTALL_EXEC}, $self->{PPM_UNINSTALL_SCRIPT};
3281e5157e49Safresh1        }
3282e5157e49Safresh1        else {
32839f11ffb7Safresh1            push @ppd_chunks, sprintf qq{        <UNINSTALL>%s</UNINSTALL>\n},
3284e5157e49Safresh1                  $self->{PPM_UNINSTALL_SCRIPT};
3285e5157e49Safresh1        }
3286e5157e49Safresh1    }
3287e5157e49Safresh1
3288b39c5158Smillert    my ($bin_location) = $self->{BINARY_LOCATION} || '';
3289b39c5158Smillert    $bin_location =~ s/\\/\\\\/g;
3290b39c5158Smillert
32919f11ffb7Safresh1    push @ppd_chunks, sprintf <<'PPD_XML', $bin_location;
3292b39c5158Smillert        <CODEBASE HREF="%s" />
3293b39c5158Smillert    </IMPLEMENTATION>
3294b39c5158Smillert</SOFTPKG>
3295b39c5158SmillertPPD_XML
3296b39c5158Smillert
32979f11ffb7Safresh1    my @ppd_cmds = $self->stashmeta(join('', @ppd_chunks), $ppd_file);
3298b39c5158Smillert
3299b39c5158Smillert    return sprintf <<'PPD_OUT', join "\n\t", @ppd_cmds;
3300b39c5158Smillert# Creates a PPD (Perl Package Description) for a binary distribution.
3301b39c5158Smillertppd :
3302b39c5158Smillert	%s
3303b39c5158SmillertPPD_OUT
3304b39c5158Smillert
3305b39c5158Smillert}
3306b39c5158Smillert
3307b39c5158Smillert=item prefixify
3308b39c5158Smillert
3309b39c5158Smillert  $MM->prefixify($var, $prefix, $new_prefix, $default);
3310b39c5158Smillert
3311b39c5158SmillertUsing either $MM->{uc $var} || $Config{lc $var}, it will attempt to
3312b39c5158Smillertreplace it's $prefix with a $new_prefix.
3313b39c5158Smillert
3314b39c5158SmillertShould the $prefix fail to match I<AND> a PREFIX was given as an
3315b39c5158Smillertargument to WriteMakefile() it will set it to the $new_prefix +
3316b39c5158Smillert$default.  This is for systems whose file layouts don't neatly fit into
3317b39c5158Smillertour ideas of prefixes.
3318b39c5158Smillert
3319b39c5158SmillertThis is for heuristics which attempt to create directory structures
3320b39c5158Smillertthat mirror those of the installed perl.
3321b39c5158Smillert
3322b39c5158SmillertFor example:
3323b39c5158Smillert
3324b39c5158Smillert    $MM->prefixify('installman1dir', '/usr', '/home/foo', 'man/man1');
3325b39c5158Smillert
3326b39c5158Smillertthis will attempt to remove '/usr' from the front of the
3327b39c5158Smillert$MM->{INSTALLMAN1DIR} path (initializing it to $Config{installman1dir}
3328b39c5158Smillertif necessary) and replace it with '/home/foo'.  If this fails it will
3329b39c5158Smillertsimply use '/home/foo/man/man1'.
3330b39c5158Smillert
3331b39c5158Smillert=cut
3332b39c5158Smillert
3333b39c5158Smillertsub prefixify {
3334b39c5158Smillert    my($self,$var,$sprefix,$rprefix,$default) = @_;
3335b39c5158Smillert
3336b39c5158Smillert    my $path = $self->{uc $var} ||
3337b39c5158Smillert               $Config_Override{lc $var} || $Config{lc $var} || '';
3338b39c5158Smillert
3339b39c5158Smillert    $rprefix .= '/' if $sprefix =~ m|/$|;
3340b39c5158Smillert
3341e9ce3842Safresh1    warn "  prefixify $var => $path\n" if $Verbose >= 2;
3342e9ce3842Safresh1    warn "    from $sprefix to $rprefix\n" if $Verbose >= 2;
3343b39c5158Smillert
3344b39c5158Smillert    if( $self->{ARGS}{PREFIX} &&
3345b39c5158Smillert        $path !~ s{^\Q$sprefix\E\b}{$rprefix}s )
3346b39c5158Smillert    {
3347b39c5158Smillert
3348e9ce3842Safresh1        warn "    cannot prefix, using default.\n" if $Verbose >= 2;
3349e9ce3842Safresh1        warn "    no default!\n" if !$default && $Verbose >= 2;
3350b39c5158Smillert
3351b39c5158Smillert        $path = $self->catdir($rprefix, $default) if $default;
3352b39c5158Smillert    }
3353b39c5158Smillert
3354b39c5158Smillert    print "    now $path\n" if $Verbose >= 2;
3355b39c5158Smillert    return $self->{uc $var} = $path;
3356b39c5158Smillert}
3357b39c5158Smillert
3358b39c5158Smillert
3359b39c5158Smillert=item processPL (o)
3360b39c5158Smillert
3361b39c5158SmillertDefines targets to run *.PL files.
3362b39c5158Smillert
3363b39c5158Smillert=cut
3364b39c5158Smillert
3365b39c5158Smillertsub processPL {
3366b39c5158Smillert    my $self = shift;
3367b39c5158Smillert    my $pl_files = $self->{PL_FILES};
3368b39c5158Smillert
3369b39c5158Smillert    return "" unless $pl_files;
3370b39c5158Smillert
3371b39c5158Smillert    my $m = '';
3372b39c5158Smillert    foreach my $plfile (sort keys %$pl_files) {
337356d68f1eSafresh1        my $targets = $pl_files->{$plfile};
337456d68f1eSafresh1        my $list =
337556d68f1eSafresh1            ref($targets) eq 'HASH'  ? [ sort keys %$targets ] :
337656d68f1eSafresh1            ref($targets) eq 'ARRAY' ? $pl_files->{$plfile}   :
337756d68f1eSafresh1            [$pl_files->{$plfile}];
3378b39c5158Smillert
3379b39c5158Smillert        foreach my $target (@$list) {
3380b39c5158Smillert            if( $Is{VMS} ) {
3381b39c5158Smillert                $plfile = vmsify($self->eliminate_macros($plfile));
3382b39c5158Smillert                $target = vmsify($self->eliminate_macros($target));
3383b39c5158Smillert            }
3384b39c5158Smillert
3385b39c5158Smillert            # Normally a .PL file runs AFTER pm_to_blib so it can have
3386b39c5158Smillert            # blib in its @INC and load the just built modules.  BUT if
3387b39c5158Smillert            # the generated module is something in $(TO_INST_PM) which
3388b39c5158Smillert            # pm_to_blib depends on then it can't depend on pm_to_blib
3389b39c5158Smillert            # else we have a dependency loop.
3390b39c5158Smillert            my $pm_dep;
3391b39c5158Smillert            my $perlrun;
3392b39c5158Smillert            if( defined $self->{PM}{$target} ) {
3393b39c5158Smillert                $pm_dep  = '';
3394b39c5158Smillert                $perlrun = 'PERLRUN';
3395b39c5158Smillert            }
3396b39c5158Smillert            else {
3397b39c5158Smillert                $pm_dep  = 'pm_to_blib';
3398b39c5158Smillert                $perlrun = 'PERLRUNINST';
3399b39c5158Smillert            }
3400b39c5158Smillert
340156d68f1eSafresh1            my $extra_inputs = '';
340256d68f1eSafresh1            if( ref($targets) eq 'HASH' ) {
340356d68f1eSafresh1                my $inputs = ref($targets->{$target})
340456d68f1eSafresh1                    ? $targets->{$target}
340556d68f1eSafresh1                    : [$targets->{$target}];
340656d68f1eSafresh1
340756d68f1eSafresh1                for my $input (@$inputs) {
340856d68f1eSafresh1                    if( $Is{VMS} ) {
340956d68f1eSafresh1                        $input = vmsify($self->eliminate_macros($input));
341056d68f1eSafresh1                    }
341156d68f1eSafresh1                    $extra_inputs .= ' '.$input;
341256d68f1eSafresh1                }
341356d68f1eSafresh1            }
341456d68f1eSafresh1
3415b39c5158Smillert            $m .= <<MAKE_FRAG;
3416b39c5158Smillert
34179f11ffb7Safresh1pure_all :: $target
3418b39c5158Smillert	\$(NOECHO) \$(NOOP)
3419b39c5158Smillert
342056d68f1eSafresh1$target :: $plfile $pm_dep $extra_inputs
342156d68f1eSafresh1	\$($perlrun) $plfile $target $extra_inputs
3422b39c5158SmillertMAKE_FRAG
3423b39c5158Smillert
3424b39c5158Smillert        }
3425b39c5158Smillert    }
3426b39c5158Smillert
3427b39c5158Smillert    return $m;
3428b39c5158Smillert}
3429b39c5158Smillert
3430b8851fccSafresh1=item specify_shell
3431b8851fccSafresh1
3432b8851fccSafresh1Specify SHELL if needed - not done on Unix.
3433b8851fccSafresh1
3434b8851fccSafresh1=cut
3435b8851fccSafresh1
3436b8851fccSafresh1sub specify_shell {
3437b8851fccSafresh1  return '';
3438b8851fccSafresh1}
3439b8851fccSafresh1
3440b39c5158Smillert=item quote_paren
3441b39c5158Smillert
3442b39c5158SmillertBackslashes parentheses C<()> in command line arguments.
3443b39c5158SmillertDoesn't handle recursive Makefile C<$(...)> constructs,
3444b39c5158Smillertbut handles simple ones.
3445b39c5158Smillert
3446b39c5158Smillert=cut
3447b39c5158Smillert
3448b39c5158Smillertsub quote_paren {
3449b39c5158Smillert    my $arg = shift;
3450b39c5158Smillert    $arg =~ s{\$\((.+?)\)}{\$\\\\($1\\\\)}g;	# protect $(...)
3451b39c5158Smillert    $arg =~ s{(?<!\\)([()])}{\\$1}g;		# quote unprotected
3452b39c5158Smillert    $arg =~ s{\$\\\\\((.+?)\\\\\)}{\$($1)}g;	# unprotect $(...)
3453b39c5158Smillert    return $arg;
3454b39c5158Smillert}
3455b39c5158Smillert
3456b39c5158Smillert=item replace_manpage_separator
3457b39c5158Smillert
3458b39c5158Smillert  my $man_name = $MM->replace_manpage_separator($file_path);
3459b39c5158Smillert
3460b39c5158SmillertTakes the name of a package, which may be a nested package, in the
3461b39c5158Smillertform 'Foo/Bar.pm' and replaces the slash with C<::> or something else
3462b39c5158Smillertsafe for a man page file name.  Returns the replacement.
3463b39c5158Smillert
3464b39c5158Smillert=cut
3465b39c5158Smillert
3466b39c5158Smillertsub replace_manpage_separator {
3467b39c5158Smillert    my($self,$man) = @_;
3468b39c5158Smillert
3469b39c5158Smillert    $man =~ s,/+,::,g;
3470b39c5158Smillert    return $man;
3471b39c5158Smillert}
3472b39c5158Smillert
3473b39c5158Smillert
3474b39c5158Smillert=item cd
3475b39c5158Smillert
3476b39c5158Smillert=cut
3477b39c5158Smillert
3478b39c5158Smillertsub cd {
3479b39c5158Smillert    my($self, $dir, @cmds) = @_;
3480b39c5158Smillert
3481b39c5158Smillert    # No leading tab and no trailing newline makes for easier embedding
3482b39c5158Smillert    my $make_frag = join "\n\t", map { "cd $dir && $_" } @cmds;
3483b39c5158Smillert
3484b39c5158Smillert    return $make_frag;
3485b39c5158Smillert}
3486b39c5158Smillert
3487b39c5158Smillert=item oneliner
3488b39c5158Smillert
3489b39c5158Smillert=cut
3490b39c5158Smillert
3491b39c5158Smillertsub oneliner {
3492b39c5158Smillert    my($self, $cmd, $switches) = @_;
3493b39c5158Smillert    $switches = [] unless defined $switches;
3494b39c5158Smillert
3495b39c5158Smillert    # Strip leading and trailing newlines
3496b39c5158Smillert    $cmd =~ s{^\n+}{};
3497b39c5158Smillert    $cmd =~ s{\n+$}{};
3498b39c5158Smillert
3499b39c5158Smillert    my @cmds = split /\n/, $cmd;
3500b39c5158Smillert    $cmd = join " \n\t  -e ", map $self->quote_literal($_), @cmds;
3501b39c5158Smillert    $cmd = $self->escape_newlines($cmd);
3502b39c5158Smillert
3503b39c5158Smillert    $switches = join ' ', @$switches;
3504b39c5158Smillert
3505b39c5158Smillert    return qq{\$(ABSPERLRUN) $switches -e $cmd --};
3506b39c5158Smillert}
3507b39c5158Smillert
3508b39c5158Smillert
3509b39c5158Smillert=item quote_literal
3510b39c5158Smillert
3511b8851fccSafresh1Quotes macro literal value suitable for being used on a command line so
3512b8851fccSafresh1that when expanded by make, will be received by command as given to
3513b8851fccSafresh1this method:
3514b8851fccSafresh1
3515b8851fccSafresh1  my $quoted = $mm->quote_literal(q{it isn't});
3516b8851fccSafresh1  # returns:
3517b8851fccSafresh1  #   'it isn'\''t'
3518b8851fccSafresh1  print MAKEFILE "target:\n\techo $quoted\n";
3519b8851fccSafresh1  # when run "make target", will output:
3520b8851fccSafresh1  #   it isn't
3521b8851fccSafresh1
3522b39c5158Smillert=cut
3523b39c5158Smillert
3524b39c5158Smillertsub quote_literal {
352548950c12Ssthen    my($self, $text, $opts) = @_;
352648950c12Ssthen    $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
3527b39c5158Smillert
352848950c12Ssthen    # Quote single quotes
3529b39c5158Smillert    $text =~ s{'}{'\\''}g;
3530b39c5158Smillert
353148950c12Ssthen    $text = $opts->{allow_variables}
353248950c12Ssthen      ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
353348950c12Ssthen
3534b39c5158Smillert    return "'$text'";
3535b39c5158Smillert}
3536b39c5158Smillert
3537b39c5158Smillert
3538b39c5158Smillert=item escape_newlines
3539b39c5158Smillert
3540b39c5158Smillert=cut
3541b39c5158Smillert
3542b39c5158Smillertsub escape_newlines {
3543b39c5158Smillert    my($self, $text) = @_;
3544b39c5158Smillert
3545b39c5158Smillert    $text =~ s{\n}{\\\n}g;
3546b39c5158Smillert
3547b39c5158Smillert    return $text;
3548b39c5158Smillert}
3549b39c5158Smillert
3550b39c5158Smillert
3551b39c5158Smillert=item max_exec_len
3552b39c5158Smillert
355356d68f1eSafresh1Using L<POSIX>::ARG_MAX.  Otherwise falling back to 4096.
3554b39c5158Smillert
3555b39c5158Smillert=cut
3556b39c5158Smillert
3557b39c5158Smillertsub max_exec_len {
3558b39c5158Smillert    my $self = shift;
3559b39c5158Smillert
3560b39c5158Smillert    if (!defined $self->{_MAX_EXEC_LEN}) {
3561b39c5158Smillert        if (my $arg_max = eval { require POSIX;  &POSIX::ARG_MAX }) {
3562b39c5158Smillert            $self->{_MAX_EXEC_LEN} = $arg_max;
3563b39c5158Smillert        }
3564b39c5158Smillert        else {      # POSIX minimum exec size
3565b39c5158Smillert            $self->{_MAX_EXEC_LEN} = 4096;
3566b39c5158Smillert        }
3567b39c5158Smillert    }
3568b39c5158Smillert
3569b39c5158Smillert    return $self->{_MAX_EXEC_LEN};
3570b39c5158Smillert}
3571b39c5158Smillert
3572b39c5158Smillert
3573b39c5158Smillert=item static (o)
3574b39c5158Smillert
3575b39c5158SmillertDefines the static target.
3576b39c5158Smillert
3577b39c5158Smillert=cut
3578b39c5158Smillert
3579b39c5158Smillertsub static {
3580b39c5158Smillert# --- Static Loading Sections ---
3581b39c5158Smillert
3582b39c5158Smillert    my($self) = shift;
3583b39c5158Smillert    '
3584b39c5158Smillert## $(INST_PM) has been moved to the all: target.
3585b39c5158Smillert## It remains here for awhile to allow for old usage: "make static"
3586b39c5158Smillertstatic :: $(FIRST_MAKEFILE) $(INST_STATIC)
3587b39c5158Smillert	$(NOECHO) $(NOOP)
3588b39c5158Smillert';
3589b39c5158Smillert}
3590b39c5158Smillert
3591b39c5158Smillertsub static_lib {
3592b39c5158Smillert    my($self) = @_;
3593b39c5158Smillert    return '' unless $self->has_link_code;
3594b39c5158Smillert    my(@m);
35959f11ffb7Safresh1    my @libs;
35969f11ffb7Safresh1    if ($self->{XSMULTI}) {
35979f11ffb7Safresh1	for my $ext ($self->_xs_list_basenames) {
35989f11ffb7Safresh1	    my ($v, $d, $f) = File::Spec->splitpath($ext);
35999f11ffb7Safresh1	    my @d = File::Spec->splitdir($d);
36009f11ffb7Safresh1	    shift @d if $d[0] eq 'lib';
36019f11ffb7Safresh1	    my $instdir = $self->catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
36029f11ffb7Safresh1	    my $instfile = $self->catfile($instdir, "$f\$(LIB_EXT)");
36039f11ffb7Safresh1	    my $objfile = "$ext\$(OBJ_EXT)";
36049f11ffb7Safresh1	    push @libs, [ $objfile, $instfile, $instdir ];
36059f11ffb7Safresh1	}
36069f11ffb7Safresh1    } else {
36079f11ffb7Safresh1	@libs = ([ qw($(OBJECT) $(INST_STATIC) $(INST_ARCHAUTODIR)) ]);
36089f11ffb7Safresh1    }
36099f11ffb7Safresh1    push @m, map { $self->xs_make_static_lib(@$_); } @libs;
36109f11ffb7Safresh1    join "\n", @m;
36119f11ffb7Safresh1}
3612b39c5158Smillert
36139f11ffb7Safresh1=item xs_make_static_lib
3614b39c5158Smillert
36159f11ffb7Safresh1Defines the recipes for the C<static_lib> section.
36169f11ffb7Safresh1
36179f11ffb7Safresh1=cut
36189f11ffb7Safresh1
36199f11ffb7Safresh1sub xs_make_static_lib {
36209f11ffb7Safresh1    my ($self, $from, $to, $todir) = @_;
36219f11ffb7Safresh1    my @m = sprintf '%s: %s $(MYEXTLIB) %s$(DFSEP).exists'."\n", $to, $from, $todir;
36229f11ffb7Safresh1    push @m, "\t\$(RM_F) \"\$\@\"\n";
36239f11ffb7Safresh1    push @m, $self->static_lib_fixtures;
36249f11ffb7Safresh1    push @m, $self->static_lib_pure_cmd($from);
36259f11ffb7Safresh1    push @m, "\t\$(CHMOD) \$(PERM_RWX) \$\@\n";
36269f11ffb7Safresh1    push @m, $self->static_lib_closures($todir);
36279f11ffb7Safresh1    join '', @m;
36289f11ffb7Safresh1}
36299f11ffb7Safresh1
36309f11ffb7Safresh1=item static_lib_closures
36319f11ffb7Safresh1
36329f11ffb7Safresh1Records C<$(EXTRALIBS)> in F<extralibs.ld> and F<$(PERL_SRC)/ext.libs>.
36339f11ffb7Safresh1
36349f11ffb7Safresh1=cut
36359f11ffb7Safresh1
36369f11ffb7Safresh1sub static_lib_closures {
36379f11ffb7Safresh1    my ($self, $todir) = @_;
36389f11ffb7Safresh1    my @m = sprintf <<'MAKE_FRAG', $todir;
36399f11ffb7Safresh1	$(NOECHO) $(ECHO) "$(EXTRALIBS)" > %s$(DFSEP)extralibs.ld
36409f11ffb7Safresh1MAKE_FRAG
36419f11ffb7Safresh1    # Old mechanism - still available:
36429f11ffb7Safresh1    push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
36439f11ffb7Safresh1	$(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)$(DFSEP)ext.libs
36449f11ffb7Safresh1MAKE_FRAG
36459f11ffb7Safresh1    @m;
36469f11ffb7Safresh1}
36479f11ffb7Safresh1
36489f11ffb7Safresh1=item static_lib_fixtures
36499f11ffb7Safresh1
36509f11ffb7Safresh1Handles copying C<$(MYEXTLIB)> as starter for final static library that
36519f11ffb7Safresh1then gets added to.
36529f11ffb7Safresh1
36539f11ffb7Safresh1=cut
36549f11ffb7Safresh1
36559f11ffb7Safresh1sub static_lib_fixtures {
36569f11ffb7Safresh1    my ($self) = @_;
3657b39c5158Smillert    # If this extension has its own library (eg SDBM_File)
3658b39c5158Smillert    # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
36599f11ffb7Safresh1    return unless $self->{MYEXTLIB};
36609f11ffb7Safresh1    "\t\$(CP) \$(MYEXTLIB) \"\$\@\"\n";
36619f11ffb7Safresh1}
3662b39c5158Smillert
36639f11ffb7Safresh1=item static_lib_pure_cmd
36649f11ffb7Safresh1
36659f11ffb7Safresh1Defines how to run the archive utility.
36669f11ffb7Safresh1
36679f11ffb7Safresh1=cut
36689f11ffb7Safresh1
36699f11ffb7Safresh1sub static_lib_pure_cmd {
36709f11ffb7Safresh1    my ($self, $from) = @_;
3671b39c5158Smillert    my $ar;
3672b39c5158Smillert    if (exists $self->{FULL_AR} && -x $self->{FULL_AR}) {
3673b39c5158Smillert        # Prefer the absolute pathed ar if available so that PATH
3674b39c5158Smillert        # doesn't confuse us.  Perl itself is built with the full_ar.
3675b39c5158Smillert        $ar = 'FULL_AR';
3676b39c5158Smillert    } else {
3677b39c5158Smillert        $ar = 'AR';
3678b39c5158Smillert    }
36799f11ffb7Safresh1    sprintf <<'MAKE_FRAG', $ar, $from;
36809f11ffb7Safresh1	$(%s) $(AR_STATIC_ARGS) "$@" %s
36819f11ffb7Safresh1	$(RANLIB) "$@"
3682b39c5158SmillertMAKE_FRAG
3683b39c5158Smillert}
3684b39c5158Smillert
3685b39c5158Smillert=item staticmake (o)
3686b39c5158Smillert
3687b39c5158SmillertCalls makeaperl.
3688b39c5158Smillert
3689b39c5158Smillert=cut
3690b39c5158Smillert
3691b39c5158Smillertsub staticmake {
3692b39c5158Smillert    my($self, %attribs) = @_;
3693b39c5158Smillert    my(@static);
3694b39c5158Smillert
3695b39c5158Smillert    my(@searchdirs)=($self->{PERL_ARCHLIB}, $self->{SITEARCHEXP},  $self->{INST_ARCHLIB});
3696b39c5158Smillert
3697b39c5158Smillert    # And as it's not yet built, we add the current extension
3698b39c5158Smillert    # but only if it has some C code (or XS code, which implies C code)
3699b39c5158Smillert    if (@{$self->{C}}) {
3700b39c5158Smillert	@static = $self->catfile($self->{INST_ARCHLIB},
3701b39c5158Smillert				 "auto",
3702b39c5158Smillert				 $self->{FULLEXT},
3703b39c5158Smillert				 "$self->{BASEEXT}$self->{LIB_EXT}"
3704b39c5158Smillert				);
3705b39c5158Smillert    }
3706b39c5158Smillert
3707b39c5158Smillert    # Either we determine now, which libraries we will produce in the
3708b39c5158Smillert    # subdirectories or we do it at runtime of the make.
3709b39c5158Smillert
3710b39c5158Smillert    # We could ask all subdir objects, but I cannot imagine, why it
3711b39c5158Smillert    # would be necessary.
3712b39c5158Smillert
3713b39c5158Smillert    # Instead we determine all libraries for the new perl at
3714b39c5158Smillert    # runtime.
3715b39c5158Smillert    my(@perlinc) = ($self->{INST_ARCHLIB}, $self->{INST_LIB}, $self->{PERL_ARCHLIB}, $self->{PERL_LIB});
3716b39c5158Smillert
3717b39c5158Smillert    $self->makeaperl(MAKE	=> $self->{MAKEFILE},
3718b39c5158Smillert		     DIRS	=> \@searchdirs,
3719b39c5158Smillert		     STAT	=> \@static,
3720b39c5158Smillert		     INCL	=> \@perlinc,
3721b39c5158Smillert		     TARGET	=> $self->{MAP_TARGET},
3722b39c5158Smillert		     TMP	=> "",
3723b39c5158Smillert		     LIBPERL	=> $self->{LIBPERL_A}
3724b39c5158Smillert		    );
3725b39c5158Smillert}
3726b39c5158Smillert
3727b39c5158Smillert=item subdir_x (o)
3728b39c5158Smillert
3729b39c5158SmillertHelper subroutine for subdirs
3730b39c5158Smillert
3731b39c5158Smillert=cut
3732b39c5158Smillert
3733b39c5158Smillertsub subdir_x {
3734b39c5158Smillert    my($self, $subdir) = @_;
3735b39c5158Smillert
3736b39c5158Smillert    my $subdir_cmd = $self->cd($subdir,
3737b39c5158Smillert      '$(MAKE) $(USEMAKEFILE) $(FIRST_MAKEFILE) all $(PASTHRU)'
3738b39c5158Smillert    );
3739b39c5158Smillert    return sprintf <<'EOT', $subdir_cmd;
3740b39c5158Smillert
3741b39c5158Smillertsubdirs ::
3742b39c5158Smillert	$(NOECHO) %s
3743b39c5158SmillertEOT
3744b39c5158Smillert
3745b39c5158Smillert}
3746b39c5158Smillert
3747b39c5158Smillert=item subdirs (o)
3748b39c5158Smillert
3749b39c5158SmillertDefines targets to process subdirectories.
3750b39c5158Smillert
3751b39c5158Smillert=cut
3752b39c5158Smillert
3753b39c5158Smillertsub subdirs {
3754b39c5158Smillert# --- Sub-directory Sections ---
3755b39c5158Smillert    my($self) = shift;
3756b39c5158Smillert    my(@m);
3757b39c5158Smillert    # This method provides a mechanism to automatically deal with
3758b39c5158Smillert    # subdirectories containing further Makefile.PL scripts.
3759b39c5158Smillert    # It calls the subdir_x() method for each subdirectory.
3760b39c5158Smillert    foreach my $dir (@{$self->{DIR}}){
37619f11ffb7Safresh1	push @m, $self->subdir_x($dir);
3762b39c5158Smillert####	print "Including $dir subdirectory\n";
3763b39c5158Smillert    }
3764b39c5158Smillert    if (@m){
37659f11ffb7Safresh1	unshift @m, <<'EOF';
37669f11ffb7Safresh1
3767b39c5158Smillert# The default clean, realclean and test targets in this Makefile
3768b39c5158Smillert# have automatically been given entries for each subdir.
3769b39c5158Smillert
37709f11ffb7Safresh1EOF
3771b39c5158Smillert    } else {
3772b39c5158Smillert	push(@m, "\n# none")
3773b39c5158Smillert    }
3774b39c5158Smillert    join('',@m);
3775b39c5158Smillert}
3776b39c5158Smillert
3777b39c5158Smillert=item test (o)
3778b39c5158Smillert
3779b39c5158SmillertDefines the test targets.
3780b39c5158Smillert
3781b39c5158Smillert=cut
3782b39c5158Smillert
3783b39c5158Smillertsub test {
3784b39c5158Smillert    my($self, %attribs) = @_;
3785b39c5158Smillert    my $tests = $attribs{TESTS} || '';
3786e5157e49Safresh1    if (!$tests && -d 't' && defined $attribs{RECURSIVE_TEST_FILES}) {
3787e5157e49Safresh1        $tests = $self->find_tests_recursive;
3788e5157e49Safresh1    }
3789e5157e49Safresh1    elsif (!$tests && -d 't') {
3790b39c5158Smillert        $tests = $self->find_tests;
3791b39c5158Smillert    }
3792b8851fccSafresh1    # have to do this because nmake is broken
3793b8851fccSafresh1    $tests =~ s!/!\\!g if $self->is_make_type('nmake');
3794b39c5158Smillert    # note: 'test.pl' name is also hardcoded in init_dirscan()
37959f11ffb7Safresh1    my @m;
37969f11ffb7Safresh1    my $default_testtype = $Config{usedl} ? 'dynamic' : 'static';
37979f11ffb7Safresh1    push @m, <<EOF;
3798b39c5158SmillertTEST_VERBOSE=0
3799b39c5158SmillertTEST_TYPE=test_\$(LINKTYPE)
3800b39c5158SmillertTEST_FILE = test.pl
3801b39c5158SmillertTEST_FILES = $tests
3802b39c5158SmillertTESTDB_SW = -d
3803b39c5158Smillert
3804b39c5158Smillerttestdb :: testdb_\$(LINKTYPE)
3805b39c5158Smillert	\$(NOECHO) \$(NOOP)
3806b39c5158Smillert
38079f11ffb7Safresh1test :: \$(TEST_TYPE)
38089f11ffb7Safresh1	\$(NOECHO) \$(NOOP)
3809b39c5158Smillert
3810b39c5158Smillert# Occasionally we may face this degenerate target:
38119f11ffb7Safresh1test_ : test_$default_testtype
38129f11ffb7Safresh1	\$(NOECHO) \$(NOOP)
3813b39c5158Smillert
38149f11ffb7Safresh1EOF
38159f11ffb7Safresh1
38169f11ffb7Safresh1    for my $linktype (qw(dynamic static)) {
38179f11ffb7Safresh1        my $directdeps = join ' ', grep !$self->{SKIPHASH}{$_}, $linktype, "pure_all"; # no depend on a linktype if SKIPped
38189f11ffb7Safresh1        push @m, "subdirs-test_$linktype :: $directdeps\n";
38199f11ffb7Safresh1        foreach my $dir (@{ $self->{DIR} }) {
38209f11ffb7Safresh1            my $test = $self->cd($dir, "\$(MAKE) test_$linktype \$(PASTHRU)");
38219f11ffb7Safresh1            push @m, "\t\$(NOECHO) $test\n";
3822b39c5158Smillert        }
38239f11ffb7Safresh1        push @m, "\n";
38249f11ffb7Safresh1        if ($tests or -f "test.pl") {
38259f11ffb7Safresh1            for my $testspec ([ '', '' ], [ 'db', ' $(TESTDB_SW)' ]) {
38269f11ffb7Safresh1                my ($db, $switch) = @$testspec;
38279f11ffb7Safresh1                my ($command, $deps);
38289f11ffb7Safresh1                # if testdb, build all but don't test all
38299f11ffb7Safresh1                $deps = $db eq 'db' ? $directdeps : "subdirs-test_$linktype";
38309f11ffb7Safresh1                if ($linktype eq 'static' and $self->needs_linking) {
38319f11ffb7Safresh1                    my $target = File::Spec->rel2abs('$(MAP_TARGET)');
38329f11ffb7Safresh1                    $command = qq{"$target" \$(MAP_PERLINC)};
38339f11ffb7Safresh1                    $deps .= ' $(MAP_TARGET)';
38349f11ffb7Safresh1                } else {
38359f11ffb7Safresh1                    $command = '$(FULLPERLRUN)' . $switch;
38369f11ffb7Safresh1                }
38379f11ffb7Safresh1                push @m, "test${db}_$linktype :: $deps\n";
38389f11ffb7Safresh1                if ($db eq 'db') {
38399f11ffb7Safresh1                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
38409f11ffb7Safresh1                } else {
38419f11ffb7Safresh1                    push @m, $self->test_via_script($command, '$(TEST_FILE)')
38429f11ffb7Safresh1                        if -f "test.pl";
38439f11ffb7Safresh1                    push @m, $self->test_via_harness($command, '$(TEST_FILES)')
38449f11ffb7Safresh1                        if $tests;
38459f11ffb7Safresh1                }
38469f11ffb7Safresh1                push @m, "\n";
38479f11ffb7Safresh1            }
38489f11ffb7Safresh1        } else {
38499f11ffb7Safresh1            push @m, _sprintf562 <<'EOF', $linktype;
38509f11ffb7Safresh1testdb_%1$s test_%1$s :: subdirs-test_%1$s
38519f11ffb7Safresh1	$(NOECHO) $(ECHO) 'No tests defined for $(NAME) extension.'
38529f11ffb7Safresh1
38539f11ffb7Safresh1EOF
38549f11ffb7Safresh1        }
38559f11ffb7Safresh1    }
38569f11ffb7Safresh1
38579f11ffb7Safresh1    join "", @m;
3858b39c5158Smillert}
3859b39c5158Smillert
3860b39c5158Smillert=item test_via_harness (override)
3861b39c5158Smillert
3862b39c5158SmillertFor some reason which I forget, Unix machines like to have
3863b39c5158SmillertPERL_DL_NONLAZY set for tests.
3864b39c5158Smillert
3865b39c5158Smillert=cut
3866b39c5158Smillert
3867b39c5158Smillertsub test_via_harness {
3868b39c5158Smillert    my($self, $perl, $tests) = @_;
3869b39c5158Smillert    return $self->SUPER::test_via_harness("PERL_DL_NONLAZY=1 $perl", $tests);
3870b39c5158Smillert}
3871b39c5158Smillert
3872b39c5158Smillert=item test_via_script (override)
3873b39c5158Smillert
3874b39c5158SmillertAgain, the PERL_DL_NONLAZY thing.
3875b39c5158Smillert
3876b39c5158Smillert=cut
3877b39c5158Smillert
3878b39c5158Smillertsub test_via_script {
3879b39c5158Smillert    my($self, $perl, $script) = @_;
3880b39c5158Smillert    return $self->SUPER::test_via_script("PERL_DL_NONLAZY=1 $perl", $script);
3881b39c5158Smillert}
3882b39c5158Smillert
3883b39c5158Smillert
3884b39c5158Smillert=item tool_xsubpp (o)
3885b39c5158Smillert
3886b39c5158SmillertDetermines typemaps, xsubpp version, prototype behaviour.
3887b39c5158Smillert
3888b39c5158Smillert=cut
3889b39c5158Smillert
3890b39c5158Smillertsub tool_xsubpp {
3891b39c5158Smillert    my($self) = shift;
3892b39c5158Smillert    return "" unless $self->needs_linking;
3893b39c5158Smillert
3894b39c5158Smillert    my $xsdir;
3895b39c5158Smillert    my @xsubpp_dirs = @INC;
3896b39c5158Smillert
3897b39c5158Smillert    # Make sure we pick up the new xsubpp if we're building perl.
3898b39c5158Smillert    unshift @xsubpp_dirs, $self->{PERL_LIB} if $self->{PERL_CORE};
3899b39c5158Smillert
3900e5157e49Safresh1    my $foundxsubpp = 0;
3901b39c5158Smillert    foreach my $dir (@xsubpp_dirs) {
3902b39c5158Smillert        $xsdir = $self->catdir($dir, 'ExtUtils');
3903b39c5158Smillert        if( -r $self->catfile($xsdir, "xsubpp") ) {
3904e5157e49Safresh1            $foundxsubpp = 1;
3905b39c5158Smillert            last;
3906b39c5158Smillert        }
3907b39c5158Smillert    }
3908e5157e49Safresh1    die "ExtUtils::MM_Unix::tool_xsubpp : Can't find xsubpp" if !$foundxsubpp;
3909b39c5158Smillert
39109f11ffb7Safresh1    my $tmdir   = $self->catdir($self->{PERL_LIB},"ExtUtils");
3911b39c5158Smillert    my(@tmdeps) = $self->catfile($tmdir,'typemap');
3912b39c5158Smillert    if( $self->{TYPEMAPS} ){
3913b39c5158Smillert        foreach my $typemap (@{$self->{TYPEMAPS}}){
3914b39c5158Smillert            if( ! -f  $typemap ) {
3915b39c5158Smillert                warn "Typemap $typemap not found.\n";
3916b39c5158Smillert            }
3917b39c5158Smillert            else {
39189f11ffb7Safresh1                $typemap = vmsify($typemap) if $Is{VMS};
3919b39c5158Smillert                push(@tmdeps, $typemap);
3920b39c5158Smillert            }
3921b39c5158Smillert        }
3922b39c5158Smillert    }
3923b39c5158Smillert    push(@tmdeps, "typemap") if -f "typemap";
39249f11ffb7Safresh1    # absolutised because with deep-located typemaps, eg "lib/XS/typemap",
39259f11ffb7Safresh1    # if xsubpp is called from top level with
39269f11ffb7Safresh1    #     $(XSUBPP) ... -typemap "lib/XS/typemap" "lib/XS/Test.xs"
39279f11ffb7Safresh1    # it says:
39289f11ffb7Safresh1    #     Can't find lib/XS/type map in (fulldir)/lib/XS
39299f11ffb7Safresh1    # because ExtUtils::ParseXS::process_file chdir's to .xs file's
39309f11ffb7Safresh1    # location. This is the only way to get all specified typemaps used,
39319f11ffb7Safresh1    # wherever located.
39329f11ffb7Safresh1    my @tmargs = map { '-typemap '.$self->quote_literal(File::Spec->rel2abs($_)) } @tmdeps;
3933b8851fccSafresh1    $_ = $self->quote_dep($_) for @tmdeps;
3934b39c5158Smillert    if( exists $self->{XSOPT} ){
3935b39c5158Smillert        unshift( @tmargs, $self->{XSOPT} );
3936b39c5158Smillert    }
3937b39c5158Smillert
3938b39c5158Smillert    if ($Is{VMS}                          &&
3939b39c5158Smillert        $Config{'ldflags'}               &&
3940b39c5158Smillert        $Config{'ldflags'} =~ m!/Debug!i &&
3941b39c5158Smillert        (!exists($self->{XSOPT}) || $self->{XSOPT} !~ /linenumbers/)
3942b39c5158Smillert       )
3943b39c5158Smillert    {
3944b39c5158Smillert        unshift(@tmargs,'-nolinenumbers');
3945b39c5158Smillert    }
3946b39c5158Smillert
3947b39c5158Smillert
3948b39c5158Smillert    $self->{XSPROTOARG} = "" unless defined $self->{XSPROTOARG};
3949b8851fccSafresh1    my $xsdirdep = $self->quote_dep($xsdir);
3950b8851fccSafresh1    # -dep for use when dependency not command
3951b39c5158Smillert
3952b39c5158Smillert    return qq{
3953b39c5158SmillertXSUBPPDIR = $xsdir
3954b8851fccSafresh1XSUBPP = "\$(XSUBPPDIR)\$(DFSEP)xsubpp"
3955b39c5158SmillertXSUBPPRUN = \$(PERLRUN) \$(XSUBPP)
3956b39c5158SmillertXSPROTOARG = $self->{XSPROTOARG}
3957b8851fccSafresh1XSUBPPDEPS = @tmdeps $xsdirdep\$(DFSEP)xsubpp
3958b39c5158SmillertXSUBPPARGS = @tmargs
3959b39c5158SmillertXSUBPP_EXTRA_ARGS =
3960b39c5158Smillert};
3961b8851fccSafresh1}
3962b39c5158Smillert
3963b39c5158Smillert
3964b39c5158Smillert=item all_target
3965b39c5158Smillert
3966b39c5158SmillertBuild man pages, too
3967b39c5158Smillert
3968b39c5158Smillert=cut
3969b39c5158Smillert
3970b39c5158Smillertsub all_target {
3971b39c5158Smillert    my $self = shift;
3972b39c5158Smillert
3973b39c5158Smillert    return <<'MAKE_EXT';
3974b39c5158Smillertall :: pure_all manifypods
3975b39c5158Smillert	$(NOECHO) $(NOOP)
3976b39c5158SmillertMAKE_EXT
3977b39c5158Smillert}
3978b39c5158Smillert
3979b39c5158Smillert=item top_targets (o)
3980b39c5158Smillert
3981b39c5158SmillertDefines the targets all, subdirs, config, and O_FILES
3982b39c5158Smillert
3983b39c5158Smillert=cut
3984b39c5158Smillert
3985b39c5158Smillertsub top_targets {
3986b39c5158Smillert# --- Target Sections ---
3987b39c5158Smillert
3988b39c5158Smillert    my($self) = shift;
3989b39c5158Smillert    my(@m);
3990b39c5158Smillert
3991b39c5158Smillert    push @m, $self->all_target, "\n" unless $self->{SKIPHASH}{'all'};
3992b39c5158Smillert
39939f11ffb7Safresh1    push @m, sprintf <<'EOF';
3994b39c5158Smillertpure_all :: config pm_to_blib subdirs linkext
3995b39c5158Smillert	$(NOECHO) $(NOOP)
3996b39c5158Smillert
3997b39c5158Smillertsubdirs :: $(MYEXTLIB)
3998b39c5158Smillert	$(NOECHO) $(NOOP)
3999b39c5158Smillert
4000b39c5158Smillertconfig :: $(FIRST_MAKEFILE) blibdirs
4001b39c5158Smillert	$(NOECHO) $(NOOP)
40029f11ffb7Safresh1EOF
4003b39c5158Smillert
4004b39c5158Smillert    push @m, '
4005b39c5158Smillert$(O_FILES) : $(H_FILES)
4006b39c5158Smillert' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
4007b39c5158Smillert
4008b39c5158Smillert    push @m, q{
4009b39c5158Smillerthelp :
4010b39c5158Smillert	perldoc ExtUtils::MakeMaker
4011b39c5158Smillert};
4012b39c5158Smillert
4013b39c5158Smillert    join('',@m);
4014b39c5158Smillert}
4015b39c5158Smillert
4016b39c5158Smillert=item writedoc
4017b39c5158Smillert
4018b39c5158SmillertObsolete, deprecated method. Not used since Version 5.21.
4019b39c5158Smillert
4020b39c5158Smillert=cut
4021b39c5158Smillert
4022b39c5158Smillertsub writedoc {
4023b39c5158Smillert# --- perllocal.pod section ---
4024b39c5158Smillert    my($self,$what,$name,@attribs)=@_;
40259f11ffb7Safresh1    my $time = gmtime($ENV{SOURCE_DATE_EPOCH} || time);
4026b39c5158Smillert    print "=head2 $time: $what C<$name>\n\n=over 4\n\n=item *\n\n";
4027b39c5158Smillert    print join "\n\n=item *\n\n", map("C<$_>",@attribs);
4028b39c5158Smillert    print "\n\n=back\n\n";
4029b39c5158Smillert}
4030b39c5158Smillert
4031b39c5158Smillert=item xs_c (o)
4032b39c5158Smillert
4033b39c5158SmillertDefines the suffix rules to compile XS files to C.
4034b39c5158Smillert
4035b39c5158Smillert=cut
4036b39c5158Smillert
4037b39c5158Smillertsub xs_c {
4038b39c5158Smillert    my($self) = shift;
4039b39c5158Smillert    return '' unless $self->needs_linking();
4040b39c5158Smillert    '
4041b39c5158Smillert.xs.c:
40429f11ffb7Safresh1	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $(XSUBPP_EXTRA_ARGS) $*.xs > $*.xsc
40439f11ffb7Safresh1	$(MV) $*.xsc $*.c
4044b39c5158Smillert';
4045b39c5158Smillert}
4046b39c5158Smillert
4047b39c5158Smillert=item xs_cpp (o)
4048b39c5158Smillert
4049b39c5158SmillertDefines the suffix rules to compile XS files to C++.
4050b39c5158Smillert
4051b39c5158Smillert=cut
4052b39c5158Smillert
4053b39c5158Smillertsub xs_cpp {
4054b39c5158Smillert    my($self) = shift;
4055b39c5158Smillert    return '' unless $self->needs_linking();
4056b39c5158Smillert    '
4057b39c5158Smillert.xs.cpp:
40589f11ffb7Safresh1	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
40599f11ffb7Safresh1	$(MV) $*.xsc $*.cpp
4060b39c5158Smillert';
4061b39c5158Smillert}
4062b39c5158Smillert
4063b39c5158Smillert=item xs_o (o)
4064b39c5158Smillert
40659f11ffb7Safresh1Defines suffix rules to go from XS to object files directly. This was
40669f11ffb7Safresh1originally only intended for broken make implementations, but is now
40679f11ffb7Safresh1necessary for per-XS file under C<XSMULTI>, since each XS file might
40689f11ffb7Safresh1have an individual C<$(VERSION)>.
4069b39c5158Smillert
4070b39c5158Smillert=cut
4071b39c5158Smillert
40729f11ffb7Safresh1sub xs_o {
40739f11ffb7Safresh1    my ($self) = @_;
4074b39c5158Smillert    return '' unless $self->needs_linking();
40759f11ffb7Safresh1    my $m_o = $self->{XSMULTI} ? $self->xs_obj_opt('$*$(OBJ_EXT)') : '';
407656d68f1eSafresh1    my $dbgout = $self->dbgoutflag;
407756d68f1eSafresh1    $dbgout = $dbgout ? "$dbgout " : '';
40789f11ffb7Safresh1    my $frag = '';
40799f11ffb7Safresh1    # dmake makes noise about ambiguous rule
408056d68f1eSafresh1    $frag .= sprintf <<'EOF', $dbgout, $m_o unless $self->is_make_type('dmake');
4081b39c5158Smillert.xs$(OBJ_EXT) :
40829f11ffb7Safresh1	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
40839f11ffb7Safresh1	$(MV) $*.xsc $*.c
408456d68f1eSafresh1	$(CCCMD) $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) $(DEFINE) %s$*.c %s
40859f11ffb7Safresh1EOF
40869f11ffb7Safresh1    if ($self->{XSMULTI}) {
40879f11ffb7Safresh1	for my $ext ($self->_xs_list_basenames) {
40889f11ffb7Safresh1	    my $pmfile = "$ext.pm";
40899f11ffb7Safresh1	    croak "$ext.xs has no matching $pmfile: $!" unless -f $pmfile;
40909f11ffb7Safresh1	    my $version = $self->parse_version($pmfile);
40919f11ffb7Safresh1	    my $cccmd = $self->{CONST_CCCMD};
40929f11ffb7Safresh1	    $cccmd =~ s/^\s*CCCMD\s*=\s*//;
40939f11ffb7Safresh1	    $cccmd =~ s/\$\(DEFINE_VERSION\)/-DVERSION=\\"$version\\"/;
40949f11ffb7Safresh1	    $cccmd =~ s/\$\(XS_DEFINE_VERSION\)/-DXS_VERSION=\\"$version\\"/;
40959f11ffb7Safresh1            $self->_xsbuild_replace_macro($cccmd, 'xs', $ext, 'INC');
40969f11ffb7Safresh1            my $define = '$(DEFINE)';
40979f11ffb7Safresh1            $self->_xsbuild_replace_macro($define, 'xs', $ext, 'DEFINE');
409856d68f1eSafresh1            #                             1     2       3     4        5
409956d68f1eSafresh1            $frag .= _sprintf562 <<'EOF', $ext, $cccmd, $m_o, $define, $dbgout;
41009f11ffb7Safresh1
41019f11ffb7Safresh1%1$s$(OBJ_EXT): %1$s.xs
41029f11ffb7Safresh1	$(XSUBPPRUN) $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.xsc
41039f11ffb7Safresh1	$(MV) $*.xsc $*.c
410456d68f1eSafresh1	%2$s $(CCCDLFLAGS) "-I$(PERL_INC)" $(PASTHRU_DEFINE) %4$s %5$s$*.c %3$s
41059f11ffb7Safresh1EOF
41069f11ffb7Safresh1	}
41079f11ffb7Safresh1    }
410856d68f1eSafresh1    $frag =~ s/"-I(\$\(PERL_INC\))"/-iwithsysroot "$1"/sg if $Is{ApplCor};
41099f11ffb7Safresh1    $frag;
4110b39c5158Smillert}
4111b39c5158Smillert
41129f11ffb7Safresh1# param gets modified
41139f11ffb7Safresh1sub _xsbuild_replace_macro {
41149f11ffb7Safresh1    my ($self, undef, $xstype, $ext, $varname) = @_;
41159f11ffb7Safresh1    my $value = $self->_xsbuild_value($xstype, $ext, $varname);
41169f11ffb7Safresh1    return unless defined $value;
41179f11ffb7Safresh1    $_[1] =~ s/\$\($varname\)/$value/;
41189f11ffb7Safresh1}
41199f11ffb7Safresh1
41209f11ffb7Safresh1sub _xsbuild_value {
41219f11ffb7Safresh1    my ($self, $xstype, $ext, $varname) = @_;
41229f11ffb7Safresh1    return $self->{XSBUILD}{$xstype}{$ext}{$varname}
41239f11ffb7Safresh1        if $self->{XSBUILD}{$xstype}{$ext}{$varname};
41249f11ffb7Safresh1    return $self->{XSBUILD}{$xstype}{all}{$varname}
41259f11ffb7Safresh1        if $self->{XSBUILD}{$xstype}{all}{$varname};
41269f11ffb7Safresh1    ();
41279f11ffb7Safresh1}
4128b39c5158Smillert
4129b39c5158Smillert1;
4130b39c5158Smillert
4131b39c5158Smillert=back
4132b39c5158Smillert
4133b39c5158Smillert=head1 SEE ALSO
4134b39c5158Smillert
4135b39c5158SmillertL<ExtUtils::MakeMaker>
4136b39c5158Smillert
4137b39c5158Smillert=cut
4138b39c5158Smillert
4139b39c5158Smillert__END__
4140