<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package ExtUtils::MM_Any;

use strict;
use warnings;
our $VERSION = '7.70';
$VERSION =~ tr/_//d;

use Carp;
use File::Spec;
use File::Basename;
BEGIN { our @ISA = qw(File::Spec); }

# We need $Verbose
use ExtUtils::MakeMaker qw($Verbose neatvalue _sprintf562);

use ExtUtils::MakeMaker::Config;


# So we don't have to keep calling the methods over and over again,
# we have these globals to cache the values.  Faster and shrtr.
my $Curdir  = __PACKAGE__-&gt;curdir;
#my $Updir   = __PACKAGE__-&gt;updir;

my $METASPEC_URL = 'https://metacpan.org/pod/CPAN::Meta::Spec';
my $METASPEC_V = 2;

=head1 NAME

ExtUtils::MM_Any - Platform-agnostic MM methods

=head1 SYNOPSIS

  FOR INTERNAL USE ONLY!

  package ExtUtils::MM_SomeOS;

  # Temporarily, you have to subclass both.  Put MM_Any first.
  require ExtUtils::MM_Any;
  require ExtUtils::MM_Unix;
  @ISA = qw(ExtUtils::MM_Any ExtUtils::Unix);

=head1 DESCRIPTION

B&lt;FOR INTERNAL USE ONLY!&gt;

ExtUtils::MM_Any is a superclass for the ExtUtils::MM_* set of
modules.  It contains methods which are either inherently
cross-platform or are written in a cross-platform manner.

Subclass off of ExtUtils::MM_Any I&lt;and&gt; L&lt;ExtUtils::MM_Unix&gt;.  This is a
temporary solution.

B&lt;THIS MAY BE TEMPORARY!&gt;


=head1 METHODS

Any methods marked I&lt;Abstract&gt; must be implemented by subclasses.


=head2 Cross-platform helper methods

These are methods which help writing cross-platform code.



=head3 os_flavor  I&lt;Abstract&gt;

    my @os_flavor = $mm-&gt;os_flavor;

@os_flavor is the style of operating system this is, usually
corresponding to the MM_*.pm file we're using.

The first element of @os_flavor is the major family (ie. Unix,
Windows, VMS, OS/2, etc...) and the rest are sub families.

Some examples:

    Cygwin98       ('Unix',  'Cygwin', 'Cygwin9x')
    Windows        ('Win32')
    Win98          ('Win32', 'Win9x')
    Linux          ('Unix',  'Linux')
    MacOS X        ('Unix',  'Darwin', 'MacOS', 'MacOS X')
    OS/2           ('OS/2')

This is used to write code for styles of operating system.
See os_flavor_is() for use.


=head3 os_flavor_is

    my $is_this_flavor = $mm-&gt;os_flavor_is($this_flavor);
    my $is_this_flavor = $mm-&gt;os_flavor_is(@one_of_these_flavors);

Checks to see if the current operating system is one of the given flavors.

This is useful for code like:

    if( $mm-&gt;os_flavor_is('Unix') ) {
        $out = `foo 2&gt;&amp;1`;
    }
    else {
        $out = `foo`;
    }

=cut

sub os_flavor_is {
    my $self = shift;
    my %flavors = map { ($_ =&gt; 1) } $self-&gt;os_flavor;
    return (grep { $flavors{$_} } @_) ? 1 : 0;
}


=head3 can_load_xs

    my $can_load_xs = $self-&gt;can_load_xs;

Returns true if we have the ability to load XS.

This is important because miniperl, used to build XS modules in the
core, can not load XS.

=cut

sub can_load_xs {
    return defined &amp;DynaLoader::boot_DynaLoader ? 1 : 0;
}


=head3 can_run

  use ExtUtils::MM;
  my $runnable = MM-&gt;can_run($Config{make});

If called in a scalar context it will return the full path to the binary
you asked for if it was found, or C&lt;undef&gt; if it was not.

If called in a list context, it will return a list of the full paths to instances
of the binary where found in C&lt;PATH&gt;, or an empty list if it was not found.

Copied from L&lt;IPC::Cmd|IPC::Cmd/"$path = can_run( PROGRAM );"&gt;, but modified into
a method (and removed C&lt;$INSTANCES&gt; capability).

=cut

sub can_run {
    my ($self, $command) = @_;

    # a lot of VMS executables have a symbol defined
    # check those first
    if ( $^O eq 'VMS' ) {
        require VMS::DCLsym;
        my $syms = VMS::DCLsym-&gt;new;
        return $command if scalar $syms-&gt;getsym( uc $command );
    }

    my @possibles;

    if( File::Spec-&gt;file_name_is_absolute($command) ) {
        return $self-&gt;maybe_command($command);

    } else {
        for my $dir (
            File::Spec-&gt;path,
            File::Spec-&gt;curdir
        ) {
            next if ! $dir || ! -d $dir;
            my $abs = File::Spec-&gt;catfile($self-&gt;os_flavor_is('Win32') ? Win32::GetShortPathName( $dir ) : $dir, $command);
            push @possibles, $abs if $abs = $self-&gt;maybe_command($abs);
        }
    }
    return @possibles if wantarray;
    return shift @possibles;
}


=head3 can_redirect_error

  $useredirect = MM-&gt;can_redirect_error;

True if on an OS where qx operator (or backticks) can redirect C&lt;STDERR&gt;
onto C&lt;STDOUT&gt;.

=cut

sub can_redirect_error {
  my $self = shift;
  $self-&gt;os_flavor_is('Unix')
      or ($self-&gt;os_flavor_is('Win32') and !$self-&gt;os_flavor_is('Win9x'))
      or $self-&gt;os_flavor_is('OS/2')
}


=head3 is_make_type

    my $is_dmake = $self-&gt;is_make_type('dmake');

Returns true if C&lt;&lt; $self-&gt;make &gt;&gt; is the given type; possibilities are:

  gmake    GNU make
  dmake
  nmake
  bsdmake  BSD pmake-derived

=cut

my %maketype2true;
# undocumented - so t/cd.t can still do its thing
sub _clear_maketype_cache { %maketype2true = () }

sub is_make_type {
    my($self, $type) = @_;
    return $maketype2true{$type} if defined $maketype2true{$type};
    (undef, undef, my $make_basename) = $self-&gt;splitpath($self-&gt;make);
    return $maketype2true{$type} = 1
        if $make_basename =~ /\b$type\b/i; # executable's filename
    return $maketype2true{$type} = 0
        if $make_basename =~ /\b[gdn]make\b/i; # Never fall through for dmake/nmake/gmake
    # now have to run with "-v" and guess
    my $redirect = $self-&gt;can_redirect_error ? '2&gt;&amp;1' : '';
    my $make = $self-&gt;make || $self-&gt;{MAKE};
    my $minus_v = `"$make" -v $redirect`;
    return $maketype2true{$type} = 1
        if $type eq 'gmake' and $minus_v =~ /GNU make/i;
    return $maketype2true{$type} = 1
        if $type eq 'bsdmake'
      and $minus_v =~ /^usage: make \[-BeikNnqrstWwX\]/im;
    $maketype2true{$type} = 0; # it wasn't whatever you asked
}


=head3 can_dep_space

    my $can_dep_space = $self-&gt;can_dep_space;

Returns true if C&lt;make&gt; can handle (probably by quoting)
dependencies that contain a space. Currently known true for GNU make,
false for BSD pmake derivative.

=cut

my $cached_dep_space;
sub can_dep_space {
    my $self = shift;
    return $cached_dep_space if defined $cached_dep_space;
    return $cached_dep_space = 1 if $self-&gt;is_make_type('gmake');
    return $cached_dep_space = 0 if $self-&gt;is_make_type('dmake'); # only on W32
    return $cached_dep_space = 0 if $self-&gt;is_make_type('bsdmake');
    return $cached_dep_space = 0; # assume no
}


=head3 quote_dep

  $text = $mm-&gt;quote_dep($text);

Method that protects Makefile single-value constants (mainly filenames),
so that make will still treat them as single values even if they
inconveniently have spaces in. If the make program being used cannot
achieve such protection and the given text would need it, throws an
exception.

=cut

sub quote_dep {
    my ($self, $arg) = @_;
    die &lt;&lt;EOF if $arg =~ / / and not $self-&gt;can_dep_space;
Tried to use make dependency with space for make that can't:
  '$arg'
EOF
    $arg =~ s/( )/\\$1/g; # how GNU make does it
    return $arg;
}


=head3 split_command

    my @cmds = $MM-&gt;split_command($cmd, @args);

Most OS have a maximum command length they can execute at once.  Large
modules can easily generate commands well past that limit.  Its
necessary to split long commands up into a series of shorter commands.

C&lt;split_command&gt; will return a series of @cmds each processing part of
the args.  Collectively they will process all the arguments.  Each
individual line in @cmds will not be longer than the
$self-&gt;max_exec_len being careful to take into account macro expansion.

$cmd should include any switches and repeated initial arguments.

If no @args are given, no @cmds will be returned.

Pairs of arguments will always be preserved in a single command, this
is a heuristic for things like pm_to_blib and pod2man which work on
pairs of arguments.  This makes things like this safe:

    $self-&gt;split_command($cmd, %pod2man);


=cut

sub split_command {
    my($self, $cmd, @args) = @_;

    my @cmds = ();
    return(@cmds) unless @args;

    # If the command was given as a here-doc, there's probably a trailing
    # newline.
    chomp $cmd;

    # set aside 30% for macro expansion.
    my $len_left = int($self-&gt;max_exec_len * 0.70);
    $len_left -= length $self-&gt;_expand_macros($cmd);

    do {
        my $arg_str = '';
        my @next_args;
        while( @next_args = splice(@args, 0, 2) ) {
            # Two at a time to preserve pairs.
            my $next_arg_str = "\t  ". join ' ', @next_args, "\n";

            if( !length $arg_str ) {
                $arg_str .= $next_arg_str
            }
            elsif( length($arg_str) + length($next_arg_str) &gt; $len_left ) {
                unshift @args, @next_args;
                last;
            }
            else {
                $arg_str .= $next_arg_str;
            }
        }
        chop $arg_str;

        push @cmds, $self-&gt;escape_newlines("$cmd \n$arg_str");
    } while @args;

    return @cmds;
}


sub _expand_macros {
    my($self, $cmd) = @_;

    $cmd =~ s{\$\((\w+)\)}{
        defined $self-&gt;{$1} ? $self-&gt;{$1} : "\$($1)"
    }e;
    return $cmd;
}


=head3 make_type

Returns a suitable string describing the type of makefile being written.

=cut

# override if this isn't suitable!
sub make_type { return 'Unix-style'; }


=head3 stashmeta

    my @recipelines = $MM-&gt;stashmeta($text, $file);

Generates a set of C&lt;@recipelines&gt; which will result in the literal
C&lt;$text&gt; ending up in literal C&lt;$file&gt; when the recipe is executed. Call
it once, with all the text you want in C&lt;$file&gt;. Make macros will not
be expanded, so the locations will be fixed at configure-time, not
at build-time.

=cut

sub stashmeta {
    my($self, $text, $file) = @_;
    $self-&gt;echo($text, $file, { allow_variables =&gt; 0, append =&gt; 0 });
}


=head3 echo

    my @commands = $MM-&gt;echo($text);
    my @commands = $MM-&gt;echo($text, $file);
    my @commands = $MM-&gt;echo($text, $file, \%opts);

Generates a set of @commands which print the $text to a $file.

If $file is not given, output goes to STDOUT.

If $opts{append} is true the $file will be appended to rather than
overwritten.  Default is to overwrite.

If $opts{allow_variables} is true, make variables of the form
C&lt;$(...)&gt; will not be escaped.  Other C&lt;$&gt; will.  Default is to escape
all C&lt;$&gt;.

Example of use:

    my $make = join '', map "\t$_\n", $MM-&gt;echo($text, $file);

=cut

sub echo {
    my($self, $text, $file, $opts) = @_;

    # Compatibility with old options
    if( !ref $opts ) {
        my $append = $opts;
        $opts = { append =&gt; $append || 0 };
    }
    $opts-&gt;{allow_variables} = 0 unless defined $opts-&gt;{allow_variables};

    my $ql_opts = { allow_variables =&gt; $opts-&gt;{allow_variables} };
    my @cmds = map { '$(NOECHO) $(ECHO) '.$self-&gt;quote_literal($_, $ql_opts) }
               split /\n/, $text;
    if( $file ) {
        my $redirect = $opts-&gt;{append} ? '&gt;&gt;' : '&gt;';
        $cmds[0] .= " $redirect $file";
        $_ .= " &gt;&gt; $file" foreach @cmds[1..$#cmds];
    }

    return @cmds;
}


=head3 wraplist

  my $args = $mm-&gt;wraplist(@list);

Takes an array of items and turns them into a well-formatted list of
arguments.  In most cases this is simply something like:

    FOO \
    BAR \
    BAZ

=cut

sub wraplist {
    my $self = shift;
    return join " \\\n\t", @_;
}


=head3 maketext_filter

    my $filter_make_text = $mm-&gt;maketext_filter($make_text);

The text of the Makefile is run through this method before writing to
disk.  It allows systems a chance to make portability fixes to the
Makefile.

By default it does nothing.

This method is protected and not intended to be called outside of
MakeMaker.

=cut

sub maketext_filter { return $_[1] }


=head3 cd  I&lt;Abstract&gt;

  my $subdir_cmd = $MM-&gt;cd($subdir, @cmds);

This will generate a make fragment which runs the @cmds in the given
$dir.  The rough equivalent to this, except cross platform.

  cd $subdir &amp;&amp; $cmd

Currently $dir can only go down one level.  "foo" is fine.  "foo/bar" is
not.  "../foo" is right out.

The resulting $subdir_cmd has no leading tab nor trailing newline.  This
makes it easier to embed in a make string.  For example.

      my $make = sprintf &lt;&lt;'CODE', $subdir_cmd;
  foo :
      $(ECHO) what
      %s
      $(ECHO) mouche
  CODE


=head3 oneliner  I&lt;Abstract&gt;

  my $oneliner = $MM-&gt;oneliner($perl_code);
  my $oneliner = $MM-&gt;oneliner($perl_code, \@switches);

This will generate a perl one-liner safe for the particular platform
you're on based on the given $perl_code and @switches (a -e is
assumed) suitable for using in a make target.  It will use the proper
shell quoting and escapes.

$(PERLRUN) will be used as perl.

Any newlines in $perl_code will be escaped.  Leading and trailing
newlines will be stripped.  Makes this idiom much easier:

    my $code = $MM-&gt;oneliner(&lt;&lt;'CODE', [...switches...]);
some code here
another line here
CODE

Usage might be something like:

    # an echo emulation
    $oneliner = $MM-&gt;oneliner('print "Foo\n"');
    $make = '$oneliner &gt; somefile';

Dollar signs in the $perl_code will be protected from make using the
C&lt;quote_literal&gt; method, unless they are recognised as being a make
variable, C&lt;$(varname)&gt;, in which case they will be left for make
to expand. Remember to quote make macros else it might be used as a
bareword. For example:

    # Assign the value of the $(VERSION_FROM) make macro to $vf.
    $oneliner = $MM-&gt;oneliner('$vf = "$(VERSION_FROM)"');

Its currently very simple and may be expanded sometime in the figure
to include more flexible code and switches.


=head3 quote_literal  I&lt;Abstract&gt;

    my $safe_text = $MM-&gt;quote_literal($text);
    my $safe_text = $MM-&gt;quote_literal($text, \%options);

This will quote $text so it is interpreted literally in the shell.

For example, on Unix this would escape any single-quotes in $text and
put single-quotes around the whole thing.

If $options{allow_variables} is true it will leave C&lt;'$(FOO)'&gt; make
variables untouched.  If false they will be escaped like any other
C&lt;$&gt;.  Defaults to true.

=head3 escape_dollarsigns

    my $escaped_text = $MM-&gt;escape_dollarsigns($text);

Escapes stray C&lt;$&gt; so they are not interpreted as make variables.

It lets by C&lt;$(...)&gt;.

=cut

sub escape_dollarsigns {
    my($self, $text) = @_;

    # Escape dollar signs which are not starting a variable
    $text =~ s{\$ (?!\() }{\$\$}gx;

    return $text;
}


=head3 escape_all_dollarsigns

    my $escaped_text = $MM-&gt;escape_all_dollarsigns($text);

Escapes all C&lt;$&gt; so they are not interpreted as make variables.

=cut

sub escape_all_dollarsigns {
    my($self, $text) = @_;

    # Escape dollar signs
    $text =~ s{\$}{\$\$}gx;

    return $text;
}


=head3 escape_newlines  I&lt;Abstract&gt;

    my $escaped_text = $MM-&gt;escape_newlines($text);

Shell escapes newlines in $text.


=head3 max_exec_len  I&lt;Abstract&gt;

    my $max_exec_len = $MM-&gt;max_exec_len;

Calculates the maximum command size the OS can exec.  Effectively,
this is the max size of a shell command line.

=for _private
$self-&gt;{_MAX_EXEC_LEN} is set by this method, but only for testing purposes.


=head3 make

    my $make = $MM-&gt;make;

Returns the make variant we're generating the Makefile for.  This attempts
to do some normalization on the information from %Config or the user.

=cut

sub make {
    my $self = shift;

    my $make = lc $self-&gt;{MAKE};

    # Truncate anything like foomake6 to just foomake.
    $make =~ s/^(\w+make).*/$1/;

    # Turn gnumake into gmake.
    $make =~ s/^gnu/g/;

    return $make;
}


=head2 Targets

These are methods which produce make targets.


=head3 all_target

Generate the default target 'all'.

=cut

sub all_target {
    my $self = shift;

    return &lt;&lt;'MAKE_EXT';
all :: pure_all
	$(NOECHO) $(NOOP)
MAKE_EXT

}


=head3 blibdirs_target

    my $make_frag = $mm-&gt;blibdirs_target;

Creates the blibdirs target which creates all the directories we use
in blib/.

The blibdirs.ts target is deprecated.  Depend on blibdirs instead.


=cut

sub _xs_list_basenames {
    my ($self) = @_;
    map { (my $b = $_) =~ s/\.xs$//; $b } sort keys %{ $self-&gt;{XS} };
}

sub blibdirs_target {
    my $self = shift;

    my @dirs = map { uc "\$(INST_$_)" } qw(libdir archlib
                                           autodir archautodir
                                           bin script
                                           man1dir man3dir
                                          );
    if ($self-&gt;{XSMULTI}) {
        for my $ext ($self-&gt;_xs_list_basenames) {
            my ($v, $d, $f) = File::Spec-&gt;splitpath($ext);
            my @d = File::Spec-&gt;splitdir($d);
            shift @d if $d[0] eq 'lib';
            push @dirs, $self-&gt;catdir('$(INST_ARCHLIB)', 'auto', @d, $f);
	}
    }

    my @exists = map { $_.'$(DFSEP).exists' } @dirs;

    my $make = sprintf &lt;&lt;'MAKE', join(' ', @exists);
blibdirs : %s
	$(NOECHO) $(NOOP)

# Backwards compat with 6.18 through 6.25
blibdirs.ts : blibdirs
	$(NOECHO) $(NOOP)

MAKE

    $make .= $self-&gt;dir_target(@dirs);

    return $make;
}


=head3 clean (o)

Defines the clean target.

=cut

sub clean {
# --- Cleanup and Distribution Sections ---

    my($self, %attribs) = @_;
    my @m;
    push(@m, '
# Delete temporary files but do not touch installed files. We don\'t delete
# the Makefile here so a later make realclean still has a makefile to use.

clean :: clean_subdirs
');

    my @files = sort values %{$self-&gt;{XS}}; # .c files from *.xs files
    push @files, map {
	my $file = $_;
	map { $file.$_ } $self-&gt;{OBJ_EXT}, qw(.def _def.old .bs .bso .exp .base);
    } $self-&gt;_xs_list_basenames;
    my @dirs  = qw(blib);

    # Normally these are all under blib but they might have been
    # redefined.
    # XXX normally this would be a good idea, but the Perl core sets
    # INST_LIB = ../../lib rather than actually installing the files.
    # So a "make clean" in an ext/ directory would blow away lib.
    # Until the core is adjusted let's leave this out.
#     push @dirs, qw($(INST_ARCHLIB) $(INST_LIB)
#                    $(INST_BIN) $(INST_SCRIPT)
#                    $(INST_MAN1DIR) $(INST_MAN3DIR)
#                    $(INST_LIBDIR) $(INST_ARCHLIBDIR) $(INST_AUTODIR)
#                    $(INST_STATIC) $(INST_DYNAMIC)
#                 );


    if( $attribs{FILES} ) {
        # Use @dirs because we don't know what's in here.
        push @dirs, ref $attribs{FILES}                ?
                        @{$attribs{FILES}}             :
                        split /\s+/, $attribs{FILES}   ;
    }

    push(@files, qw[$(MAKE_APERL_FILE)
                    MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations
                    blibdirs.ts pm_to_blib pm_to_blib.ts
                    *$(OBJ_EXT) *$(LIB_EXT) perl.exe perl perl$(EXE_EXT)
                    $(BOOTSTRAP) $(BASEEXT).bso
                    $(BASEEXT).def lib$(BASEEXT).def
                    $(BASEEXT).exp $(BASEEXT).x
                   ]);

    push(@files, $self-&gt;catfile('$(INST_ARCHAUTODIR)','extralibs.all'));
    push(@files, $self-&gt;catfile('$(INST_ARCHAUTODIR)','extralibs.ld'));

    # core files
    if ($^O eq 'vos') {
        push(@files, qw[perl*.kp]);
    }
    else {
        push(@files, qw[core core.*perl.*.? *perl.core]);
    }

    push(@files, map { "core." . "[0-9]"x$_ } (1..5));

    # OS specific things to clean up.  Use @dirs since we don't know
    # what might be in here.
    push @dirs, $self-&gt;extra_clean_files;

    # Occasionally files are repeated several times from different sources
    { my(%f) = map { ($_ =&gt; 1) } @files; @files = sort keys %f; }
    { my(%d) = map { ($_ =&gt; 1) } @dirs;  @dirs  = sort keys %d; }

    push @m, map "\t$_\n", $self-&gt;split_command('- $(RM_F)',  @files);
    push @m, map "\t$_\n", $self-&gt;split_command('- $(RM_RF)', @dirs);

    # Leave Makefile.old around for realclean
    push @m, &lt;&lt;'MAKE';
	  $(NOECHO) $(RM_F) $(MAKEFILE_OLD)
	- $(MV) $(FIRST_MAKEFILE) $(MAKEFILE_OLD) $(DEV_NULL)
MAKE

    push(@m, "\t$attribs{POSTOP}\n")   if $attribs{POSTOP};

    join("", @m);
}


=head3 clean_subdirs_target

  my $make_frag = $MM-&gt;clean_subdirs_target;

Returns the clean_subdirs target.  This is used by the clean target to
call clean on any subdirectories which contain Makefiles.

=cut

sub clean_subdirs_target {
    my($self) = shift;

    # No subdirectories, no cleaning.
    return &lt;&lt;'NOOP_FRAG' unless @{$self-&gt;{DIR}};
clean_subdirs :
	$(NOECHO) $(NOOP)
NOOP_FRAG


    my $clean = "clean_subdirs :\n";

    for my $dir (@{$self-&gt;{DIR}}) {
        my $subclean = $self-&gt;oneliner(sprintf &lt;&lt;'CODE', $dir);
exit 0 unless chdir '%s';  system '$(MAKE) clean' if -f '$(FIRST_MAKEFILE)';
CODE

        $clean .= "\t$subclean\n";
    }

    return $clean;
}


=head3 dir_target

    my $make_frag = $mm-&gt;dir_target(@directories);

Generates targets to create the specified directories and set its
permission to PERM_DIR.

Because depending on a directory to just ensure it exists doesn't work
too well (the modified time changes too often) dir_target() creates a
.exists file in the created directory.  It is this you should depend on.
For portability purposes you should use the $(DIRFILESEP) macro rather
than a '/' to separate the directory from the file.

    yourdirectory$(DIRFILESEP).exists

=cut

sub dir_target {
    my($self, @dirs) = @_;

    my $make = '';
    foreach my $dir (@dirs) {
        $make .= sprintf &lt;&lt;'MAKE', ($dir) x 4;
%s$(DFSEP).exists :: Makefile.PL
	$(NOECHO) $(MKPATH) %s
	$(NOECHO) $(CHMOD) $(PERM_DIR) %s
	$(NOECHO) $(TOUCH) %s$(DFSEP).exists

MAKE

    }

    return $make;
}


=head3 distdir

Defines the scratch directory target that will hold the distribution
before tar-ing (or shar-ing).

=cut

# For backwards compatibility.
*dist_dir = *distdir;

sub distdir {
    my($self) = shift;

    my $meta_target = $self-&gt;{NO_META} ? '' : 'distmeta';
    my $sign_target = !$self-&gt;{SIGN}   ? '' : 'distsignature';

    return sprintf &lt;&lt;'MAKE_FRAG', $meta_target, $sign_target;
create_distdir :
	$(RM_RF) $(DISTVNAME)
	$(PERLRUN) "-MExtUtils::Manifest=manicopy,maniread" \
		-e "manicopy(maniread(),'$(DISTVNAME)', '$(DIST_CP)');"

distdir : create_distdir %s %s
	$(NOECHO) $(NOOP)

MAKE_FRAG

}


=head3 dist_test

Defines a target that produces the distribution in the
scratch directory, and runs 'perl Makefile.PL; make ;make test' in that
subdirectory.

=cut

sub dist_test {
    my($self) = shift;

    my $mpl_args = join " ", map qq["$_"], @ARGV;

    my $test = $self-&gt;cd('$(DISTVNAME)',
                         '$(ABSPERLRUN) Makefile.PL '.$mpl_args,
                         '$(MAKE) $(PASTHRU)',
                         '$(MAKE) test $(PASTHRU)'
                        );

    return sprintf &lt;&lt;'MAKE_FRAG', $test;
disttest : distdir
	%s

MAKE_FRAG


}


=head3 xs_dlsyms_arg

Returns command-line arg(s) to linker for file listing dlsyms to export.
Defaults to returning empty string, can be overridden by e.g. AIX.

=cut

sub xs_dlsyms_arg {
    return '';
}

=head3 xs_dlsyms_ext

Returns file-extension for C&lt;xs_make_dlsyms&gt; method's output file,
including any "." character.

=cut

sub xs_dlsyms_ext {
    die "Pure virtual method";
}

=head3 xs_dlsyms_extra

Returns any extra text to be prepended to the C&lt;$extra&gt; argument of
C&lt;xs_make_dlsyms&gt;.

=cut

sub xs_dlsyms_extra {
    '';
}

=head3 xs_dlsyms_iterator

Iterates over necessary shared objects, calling C&lt;xs_make_dlsyms&gt; method
for each with appropriate arguments.

=cut

sub xs_dlsyms_iterator {
    my ($self, $attribs) = @_;
    if ($self-&gt;{XSMULTI}) {
        my @m;
        for my $ext ($self-&gt;_xs_list_basenames) {
            my @parts = File::Spec-&gt;splitdir($ext);
            shift @parts if $parts[0] eq 'lib';
            my $name = join '::', @parts;
            push @m, $self-&gt;xs_make_dlsyms(
                $attribs,
                $ext . $self-&gt;xs_dlsyms_ext,
                "$ext.xs",
                $name,
                $parts[-1],
                {}, [], {}, [],
                $self-&gt;xs_dlsyms_extra . q!, 'FILE' =&gt; ! . neatvalue($ext),
            );
        }
        return join "\n", @m;
    } else {
        return $self-&gt;xs_make_dlsyms(
            $attribs,
            $self-&gt;{BASEEXT} . $self-&gt;xs_dlsyms_ext,
            'Makefile.PL',
            $self-&gt;{NAME},
            $self-&gt;{DLBASE},
            $attribs-&gt;{DL_FUNCS} || $self-&gt;{DL_FUNCS} || {},
            $attribs-&gt;{FUNCLIST} || $self-&gt;{FUNCLIST} || [],
            $attribs-&gt;{IMPORTS} || $self-&gt;{IMPORTS} || {},
            $attribs-&gt;{DL_VARS} || $self-&gt;{DL_VARS} || [],
            $self-&gt;xs_dlsyms_extra,
        );
    }
}

=head3 xs_make_dlsyms

    $self-&gt;xs_make_dlsyms(
        \%attribs, # hashref from %attribs in caller
        "$self-&gt;{BASEEXT}.def", # output file for Makefile target
        'Makefile.PL', # dependency
        $self-&gt;{NAME}, # shared object's "name"
        $self-&gt;{DLBASE}, # last ::-separated part of name
        $attribs{DL_FUNCS} || $self-&gt;{DL_FUNCS} || {}, # various params
        $attribs{FUNCLIST} || $self-&gt;{FUNCLIST} || [],
        $attribs{IMPORTS} || $self-&gt;{IMPORTS} || {},
        $attribs{DL_VARS} || $self-&gt;{DL_VARS} || [],
        # optional extra param that will be added as param to Mksymlists
    );

Utility method that returns Makefile snippet to call C&lt;Mksymlists&gt;.

=cut

sub xs_make_dlsyms {
    my ($self, $attribs, $target, $dep, $name, $dlbase, $funcs, $funclist, $imports, $vars, $extra) = @_;
    my @m = (
     "\n$target: $dep\n",
     q!	$(PERLRUN) -MExtUtils::Mksymlists \\
     -e "Mksymlists('NAME'=&gt;\"!, $name,
     q!\", 'DLBASE' =&gt; '!,$dlbase,
     # The above two lines quoted differently to work around
     # a bug in the 4DOS/4NT command line interpreter.  The visible
     # result of the bug was files named q('extension_name',) *with the
     # single quotes and the comma* in the extension build directories.
     q!', 'DL_FUNCS' =&gt; !,neatvalue($funcs),
     q!, 'FUNCLIST' =&gt; !,neatvalue($funclist),
     q!, 'IMPORTS' =&gt; !,neatvalue($imports),
     q!, 'DL_VARS' =&gt; !, neatvalue($vars)
    );
    push @m, $extra if defined $extra;
    push @m, qq!);"\n!;
    join '', @m;
}

=head3 dynamic (o)

Defines the dynamic target.

=cut

sub dynamic {
# --- Dynamic Loading Sections ---

    my($self) = shift;
    '
dynamic :: $(FIRST_MAKEFILE) config $(INST_BOOT) $(INST_DYNAMIC)
	$(NOECHO) $(NOOP)
';
}


=head3 makemakerdflt_target

  my $make_frag = $mm-&gt;makemakerdflt_target

Returns a make fragment with the makemakerdeflt_target specified.
This target is the first target in the Makefile, is the default target
and simply points off to 'all' just in case any make variant gets
confused or something gets snuck in before the real 'all' target.

=cut

sub makemakerdflt_target {
    return &lt;&lt;'MAKE_FRAG';
makemakerdflt : all
	$(NOECHO) $(NOOP)
MAKE_FRAG

}


=head3 manifypods_target

  my $manifypods_target = $self-&gt;manifypods_target;

Generates the manifypods target.  This target generates man pages from
all POD files in MAN1PODS and MAN3PODS.

=cut

sub manifypods_target {
    my($self) = shift;

    my $man1pods      = '';
    my $man3pods      = '';
    my $dependencies  = '';

    # populate manXpods &amp; dependencies:
    foreach my $name (sort keys %{$self-&gt;{MAN1PODS}}, sort keys %{$self-&gt;{MAN3PODS}}) {
        $dependencies .= " \\\n\t$name";
    }

    my $manify = &lt;&lt;END;
manifypods : pure_all config $dependencies
END

    my @man_cmds;
    foreach my $num (qw(1 3)) {
        my $pods = $self-&gt;{"MAN${num}PODS"};
        my $p2m = sprintf &lt;&lt;'CMD', "\$(MAN${num}SECTION)", "$]" &gt; 5.008 ? " -u" : "";
	$(NOECHO) $(POD2MAN) --section=%s --perm_rw=$(PERM_RW)%s
CMD
        push @man_cmds, $self-&gt;split_command($p2m, map {($_,$pods-&gt;{$_})} sort keys %$pods);
    }

    $manify .= "\t\$(NOECHO) \$(NOOP)\n" unless @man_cmds;
    $manify .= join '', map { "$_\n" } @man_cmds;

    return $manify;
}

{
    my $has_cpan_meta;
    sub _has_cpan_meta {
        return $has_cpan_meta if defined $has_cpan_meta;
        return $has_cpan_meta = !!eval {
            require CPAN::Meta;
            CPAN::Meta-&gt;VERSION(2.112150);
            1;
        };
    }
}

=head3 metafile_target

    my $target = $mm-&gt;metafile_target;

Generate the metafile target.

Writes the file META.yml (YAML encoded meta-data) and META.json
(JSON encoded meta-data) about the module in the distdir.
The format follows Module::Build's as closely as possible.

=cut

sub metafile_target {
    my $self = shift;
    return &lt;&lt;'MAKE_FRAG' if $self-&gt;{NO_META} or ! _has_cpan_meta();
metafile :
	$(NOECHO) $(NOOP)
MAKE_FRAG

    my $metadata   = $self-&gt;metafile_data(
        $self-&gt;{META_ADD}   || {},
        $self-&gt;{META_MERGE} || {},
    );

    my $meta = $self-&gt;_fix_metadata_before_conversion( $metadata );

    my @write_metayml = $self-&gt;stashmeta(
      $meta-&gt;as_string({version =&gt; "1.4"}), 'META_new.yml'
    );
    my @write_metajson = $self-&gt;stashmeta(
      $meta-&gt;as_string({version =&gt; "2.0"}), 'META_new.json'
    );

    my $metayml = join("\n\t", @write_metayml);
    my $metajson = join("\n\t", @write_metajson);
    return sprintf &lt;&lt;'MAKE_FRAG', $metayml, $metajson;
metafile : create_distdir
	$(NOECHO) $(ECHO) Generating META.yml
	%s
	-$(NOECHO) $(MV) META_new.yml $(DISTVNAME)/META.yml
	$(NOECHO) $(ECHO) Generating META.json
	%s
	-$(NOECHO) $(MV) META_new.json $(DISTVNAME)/META.json
MAKE_FRAG

}

=begin private

=head3 _fix_metadata_before_conversion

    $mm-&gt;_fix_metadata_before_conversion( \%metadata );

Fixes errors in the metadata before it's handed off to L&lt;CPAN::Meta&gt; for
conversion. This hopefully results in something that can be used further
on, no guarantee is made though.

=end private

=cut

sub _fix_metadata_before_conversion {
    my ( $self, $metadata ) = @_;

    # we should never be called unless this already passed but
    # prefer to be defensive in case somebody else calls this

    return unless _has_cpan_meta;

    my $bad_version = $metadata-&gt;{version} &amp;&amp;
                      !CPAN::Meta::Validator-&gt;new-&gt;version( 'version', $metadata-&gt;{version} );
    # just delete all invalid versions
    if( $bad_version ) {
        warn "Can't parse version '$metadata-&gt;{version}'\n";
        $metadata-&gt;{version} = '';
    }

    my $validator2 = CPAN::Meta::Validator-&gt;new( $metadata );
    my @errors;
    push @errors, $validator2-&gt;errors if !$validator2-&gt;is_valid;
    my $validator14 = CPAN::Meta::Validator-&gt;new(
        {
            %$metadata,
            'meta-spec' =&gt; { version =&gt; 1.4 },
        }
    );
    push @errors, $validator14-&gt;errors if !$validator14-&gt;is_valid;
    # fix non-camelcase custom resource keys (only other trick we know)
    for my $error ( @errors ) {
        my ( $key ) = ( $error =~ /Custom resource '(.*)' must be in CamelCase./ );
        next if !$key;

        # first try to remove all non-alphabetic chars
        ( my $new_key = $key ) =~ s/[^_a-zA-Z]//g;

        # if that doesn't work, uppercase first one
        $new_key = ucfirst $new_key if !$validator14-&gt;custom_1( $new_key );

        # copy to new key if that worked
        $metadata-&gt;{resources}{$new_key} = $metadata-&gt;{resources}{$key}
          if $validator14-&gt;custom_1( $new_key );

        # and delete old one in any case
        delete $metadata-&gt;{resources}{$key};
    }

    # paper over validation issues, but still complain, necessary because
    # there's no guarantee that the above will fix ALL errors
    my $meta = eval { CPAN::Meta-&gt;create( $metadata, { lazy_validation =&gt; 1 } ) };
    warn $@ if $@ and
               $@ !~ /encountered CODE.*, but JSON can only represent references to arrays or hashes/;

    # use the original metadata straight if the conversion failed
    # or if it can't be stringified.
    if( !$meta                                                  ||
        !eval { $meta-&gt;as_string( { version =&gt; $METASPEC_V } ) }      ||
        !eval { $meta-&gt;as_string }
    ) {
        $meta = bless $metadata, 'CPAN::Meta';
    }

    my $now_license = $meta-&gt;as_struct({ version =&gt; 2 })-&gt;{license};
    if ($self-&gt;{LICENSE} and $self-&gt;{LICENSE} ne 'unknown' and
        @{$now_license} == 1 and $now_license-&gt;[0] eq 'unknown'
    ) {
        warn "Invalid LICENSE value '$self-&gt;{LICENSE}' ignored\n";
    }

    $meta;
}


=begin private

=head3 _sort_pairs

    my @pairs = _sort_pairs($sort_sub, \%hash);

Sorts the pairs of a hash based on keys ordered according
to C&lt;$sort_sub&gt;.

=end private

=cut

sub _sort_pairs {
    my $sort  = shift;
    my $pairs = shift;
    return map  { $_ =&gt; $pairs-&gt;{$_} }
           sort $sort
           keys %$pairs;
}


# Taken from Module::Build::Base
sub _hash_merge {
    my ($self, $h, $k, $v) = @_;
    if (ref $h-&gt;{$k} eq 'ARRAY') {
        push @{$h-&gt;{$k}}, ref $v ? @$v : $v;
    } elsif (ref $h-&gt;{$k} eq 'HASH') {
        $self-&gt;_hash_merge($h-&gt;{$k}, $_, $v-&gt;{$_}) foreach keys %$v;
    } else {
        $h-&gt;{$k} = $v;
    }
}


=head3 metafile_data

    my $metadata_hashref = $mm-&gt;metafile_data(\%meta_add, \%meta_merge);

Returns the data which MakeMaker turns into the META.yml file 
and the META.json file. It is always in version 2.0 of the format.

Values of %meta_add will overwrite any existing metadata in those
keys.  %meta_merge will be merged with them.

=cut

sub metafile_data {
    my $self = shift;
    my($meta_add, $meta_merge) = @_;

    $meta_add ||= {};
    $meta_merge ||= {};

    my $version = _normalize_version($self-&gt;{VERSION});
    my $release_status = ($version =~ /_/) ? 'unstable' : 'stable';
    my %meta = (
        # required
        abstract     =&gt; $self-&gt;{ABSTRACT} || 'unknown',
        author       =&gt; defined($self-&gt;{AUTHOR}) ? $self-&gt;{AUTHOR} : ['unknown'],
        dynamic_config =&gt; 1,
        generated_by =&gt; "ExtUtils::MakeMaker version $ExtUtils::MakeMaker::VERSION",
        license      =&gt; [ $self-&gt;{LICENSE} || 'unknown' ],
        'meta-spec'  =&gt; {
            url         =&gt; $METASPEC_URL,
            version     =&gt; $METASPEC_V,
        },
        name         =&gt; $self-&gt;{DISTNAME},
        release_status =&gt; $release_status,
        version      =&gt; $version,

        # optional
        no_index     =&gt; { directory =&gt; [qw(t inc)] },
    );
    $self-&gt;_add_requirements_to_meta(\%meta);

    if (!eval { require JSON::PP; require CPAN::Meta::Converter; CPAN::Meta::Converter-&gt;VERSION(2.141170) }) {
      return \%meta;
    }

    # needs to be based on the original version
    my $v1_add = _metaspec_version($meta_add) !~ /^2/;

    my ($add_v, $merge_v) = map _metaspec_version($_), $meta_add, $meta_merge;
    for my $frag ($meta_add, $meta_merge) {
        my $def_v = $frag == $meta_add ? $merge_v : $add_v;
        $frag = CPAN::Meta::Converter-&gt;new($frag, default_version =&gt; $def_v)-&gt;upgrade_fragment;
    }

    # if we upgraded a 1.x _ADD fragment, we gave it a prereqs key that
    # will override all prereqs, which is more than the user asked for;
    # instead, we'll go inside the prereqs and override all those
    while( my($key, $val) = each %$meta_add ) {
        if ($v1_add and $key eq 'prereqs') {
            $meta{$key}{$_} = $val-&gt;{$_} for keys %$val;
        } elsif ($key ne 'meta-spec') {
            $meta{$key} = $val;
        }
    }

    while( my($key, $val) = each %$meta_merge ) {
        next if $key eq 'meta-spec';
        $self-&gt;_hash_merge(\%meta, $key, $val);
    }

    return \%meta;
}


=begin private

=cut

sub _add_requirements_to_meta {
    my ( $self, $meta ) = @_;
    # Check the original args so we can tell between the user setting it
    # to an empty hash and it just being initialized.
    $meta-&gt;{prereqs}{configure}{requires} = $self-&gt;{ARGS}{CONFIGURE_REQUIRES}
        ? $self-&gt;{CONFIGURE_REQUIRES}
        : { 'ExtUtils::MakeMaker' =&gt; 0, };
    $meta-&gt;{prereqs}{build}{requires} = $self-&gt;{ARGS}{BUILD_REQUIRES}
        ? $self-&gt;{BUILD_REQUIRES}
        : { 'ExtUtils::MakeMaker' =&gt; 0, };
    $meta-&gt;{prereqs}{test}{requires} = $self-&gt;{TEST_REQUIRES}
        if $self-&gt;{ARGS}{TEST_REQUIRES};
    $meta-&gt;{prereqs}{runtime}{requires} = $self-&gt;{PREREQ_PM}
        if $self-&gt;{ARGS}{PREREQ_PM};
    $meta-&gt;{prereqs}{runtime}{requires}{perl} = _normalize_version($self-&gt;{MIN_PERL_VERSION})
        if $self-&gt;{MIN_PERL_VERSION};
}

# spec version of given fragment - if not given, assume 1.4
sub _metaspec_version {
  my ( $meta ) = @_;
  return $meta-&gt;{'meta-spec'}-&gt;{version}
    if defined $meta-&gt;{'meta-spec'}
       and defined $meta-&gt;{'meta-spec'}-&gt;{version};
  return '1.4';
}

sub _add_requirements_to_meta_v1_4 {
    my ( $self, $meta ) = @_;
    # Check the original args so we can tell between the user setting it
    # to an empty hash and it just being initialized.
    if( $self-&gt;{ARGS}{CONFIGURE_REQUIRES} ) {
        $meta-&gt;{configure_requires} = $self-&gt;{CONFIGURE_REQUIRES};
    } else {
        $meta-&gt;{configure_requires} = {
            'ExtUtils::MakeMaker'       =&gt; 0,
        };
    }
    if( $self-&gt;{ARGS}{BUILD_REQUIRES} ) {
        $meta-&gt;{build_requires} = $self-&gt;{BUILD_REQUIRES};
    } else {
        $meta-&gt;{build_requires} = {
            'ExtUtils::MakeMaker'       =&gt; 0,
        };
    }
    if( $self-&gt;{ARGS}{TEST_REQUIRES} ) {
        $meta-&gt;{build_requires} = {
          %{ $meta-&gt;{build_requires} },
          %{ $self-&gt;{TEST_REQUIRES} },
        };
    }
    $meta-&gt;{requires} = $self-&gt;{PREREQ_PM}
        if defined $self-&gt;{PREREQ_PM};
    $meta-&gt;{requires}{perl} = _normalize_version($self-&gt;{MIN_PERL_VERSION})
        if $self-&gt;{MIN_PERL_VERSION};
}

# Adapted from Module::Build::Base
sub _normalize_version {
  my ($version) = @_;
  $version = 0 unless defined $version;

  if ( ref $version eq 'version' ) { # version objects
    $version = $version-&gt;stringify;
  }
  elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots
    # normalize string tuples without "v": "1.2.3" -&gt; "v1.2.3"
    $version = "v$version";
  }
  else {
    # leave alone
  }
  return $version;
}

=head3 _dump_hash

    $yaml = _dump_hash(\%options, %hash);

Implements a fake YAML dumper for a hash given
as a list of pairs. No quoting/escaping is done. Keys
are supposed to be strings. Values are undef, strings,
hash refs or array refs of strings.

Supported options are:

    delta =&gt; STR - indentation delta
    use_header =&gt; BOOL - whether to include a YAML header
    indent =&gt; STR - a string of spaces
          default: ''

    max_key_length =&gt; INT - maximum key length used to align
        keys and values of the same hash
        default: 20
    key_sort =&gt; CODE - a sort sub
            It may be undef, which means no sorting by keys
        default: sub { lc $a cmp lc $b }

    customs =&gt; HASH - special options for certain keys
           (whose values are hashes themselves)
        may contain: max_key_length, key_sort, customs

=end private

=cut

sub _dump_hash {
    croak "first argument should be a hash ref" unless ref $_[0] eq 'HASH';
    my $options = shift;
    my %hash = @_;

    # Use a list to preserve order.
    my @pairs;

    my $k_sort
        = exists $options-&gt;{key_sort} ? $options-&gt;{key_sort}
                                      : sub { lc $a cmp lc $b };
    if ($k_sort) {
        croak "'key_sort' should be a coderef" unless ref $k_sort eq 'CODE';
        @pairs = _sort_pairs($k_sort, \%hash);
    } else { # list of pairs, no sorting
        @pairs = @_;
    }

    my $yaml     = $options-&gt;{use_header} ? "--- #YAML:1.0\n" : '';
    my $indent   = $options-&gt;{indent} || '';
    my $k_length = min(
        ($options-&gt;{max_key_length} || 20),
        max(map { length($_) + 1 } grep { !ref $hash{$_} } keys %hash)
    );
    my $customs  = $options-&gt;{customs} || {};

    # printf format for key
    my $k_format = "%-${k_length}s";

    while( @pairs ) {
        my($key, $val) = splice @pairs, 0, 2;
        $val = '~' unless defined $val;
        if(ref $val eq 'HASH') {
            if ( keys %$val ) {
                my %k_options = ( # options for recursive call
                    delta =&gt; $options-&gt;{delta},
                    use_header =&gt; 0,
                    indent =&gt; $indent . $options-&gt;{delta},
                );
                if (exists $customs-&gt;{$key}) {
                    my %k_custom = %{$customs-&gt;{$key}};
                    foreach my $k (qw(key_sort max_key_length customs)) {
                        $k_options{$k} = $k_custom{$k} if exists $k_custom{$k};
                    }
                }
                $yaml .= $indent . "$key:\n"
                  . _dump_hash(\%k_options, %$val);
            }
            else {
                $yaml .= $indent . "$key:  {}\n";
            }
        }
        elsif (ref $val eq 'ARRAY') {
            if( @$val ) {
                $yaml .= $indent . "$key:\n";

                for (@$val) {
                    croak "only nested arrays of non-refs are supported" if ref $_;
                    $yaml .= $indent . $options-&gt;{delta} . "- $_\n";
                }
            }
            else {
                $yaml .= $indent . "$key:  []\n";
            }
        }
        elsif( ref $val and !blessed($val) ) {
            croak "only nested hashes, arrays and objects are supported";
        }
        else {  # if it's an object, just stringify it
            $yaml .= $indent . sprintf "$k_format  %s\n", "$key:", $val;
        }
    };

    return $yaml;

}

sub blessed {
    return eval { $_[0]-&gt;isa("UNIVERSAL"); };
}

sub max {
    return (sort { $b &lt;=&gt; $a } @_)[0];
}

sub min {
    return (sort { $a &lt;=&gt; $b } @_)[0];
}

=head3 metafile_file

    my $meta_yml = $mm-&gt;metafile_file(@metadata_pairs);

Turns the @metadata_pairs into YAML.

This method does not implement a complete YAML dumper, being limited
to dump a hash with values which are strings, undef's or nested hashes
and arrays of strings. No quoting/escaping is done.

=cut

sub metafile_file {
    my $self = shift;

    my %dump_options = (
        use_header =&gt; 1,
        delta      =&gt; ' ' x 4,
        key_sort   =&gt; undef,
    );
    return _dump_hash(\%dump_options, @_);

}


=head3 distmeta_target

    my $make_frag = $mm-&gt;distmeta_target;

Generates the distmeta target to add META.yml and META.json to the MANIFEST
in the distdir.

=cut

sub distmeta_target {
    my $self = shift;

    my @add_meta = (
      $self-&gt;oneliner(&lt;&lt;'CODE', ['-MExtUtils::Manifest=maniadd']),
exit unless -e q{META.yml};
eval { maniadd({q{META.yml} =&gt; q{Module YAML meta-data (added by MakeMaker)}}) }
    or die "Could not add META.yml to MANIFEST: ${'@'}"
CODE
      $self-&gt;oneliner(&lt;&lt;'CODE', ['-MExtUtils::Manifest=maniadd'])
exit unless -f q{META.json};
eval { maniadd({q{META.json} =&gt; q{Module JSON meta-data (added by MakeMaker)}}) }
    or die "Could not add META.json to MANIFEST: ${'@'}"
CODE
    );

    my @add_meta_to_distdir = map { $self-&gt;cd('$(DISTVNAME)', $_) } @add_meta;

    return sprintf &lt;&lt;'MAKE', @add_meta_to_distdir;
distmeta : create_distdir metafile
	$(NOECHO) %s
	$(NOECHO) %s

MAKE

}


=head3 mymeta

    my $mymeta = $mm-&gt;mymeta;

Generate MYMETA information as a hash either from an existing CPAN Meta file
(META.json or META.yml) or from internal data.

=cut

sub mymeta {
    my $self = shift;
    my $file = shift || ''; # for testing

    my $mymeta = $self-&gt;_mymeta_from_meta($file);
    my $v2 = 1;

    unless ( $mymeta ) {
        $mymeta = $self-&gt;metafile_data(
            $self-&gt;{META_ADD}   || {},
            $self-&gt;{META_MERGE} || {},
        );
        $v2 = 0;
    }

    # Overwrite the non-configure dependency hashes
    $self-&gt;_add_requirements_to_meta($mymeta);

    $mymeta-&gt;{dynamic_config} = 0;

    return $mymeta;
}


sub _mymeta_from_meta {
    my $self = shift;
    my $metafile = shift || ''; # for testing

    return unless _has_cpan_meta();

    my $meta;
    for my $file ( $metafile, "META.json", "META.yml" ) {
      next unless -e $file;
      eval {
          $meta = CPAN::Meta-&gt;load_file($file)-&gt;as_struct( { version =&gt; 2 } );
      };
      last if $meta;
    }
    return unless $meta;

    # META.yml before 6.25_01 cannot be trusted.  META.yml lived in the source directory.
    # There was a good chance the author accidentally uploaded a stale META.yml if they
    # rolled their own tarball rather than using "make dist".
    if ($meta-&gt;{generated_by} &amp;&amp;
        $meta-&gt;{generated_by} =~ /ExtUtils::MakeMaker version ([\d\._]+)/) {
        my $eummv = do { no warnings; $1+0; };
        if ($eummv &lt; 6.2501) {
            return;
        }
    }

    return $meta;
}

=head3 write_mymeta

    $self-&gt;write_mymeta( $mymeta );

Write MYMETA information to MYMETA.json and MYMETA.yml.

=cut

sub write_mymeta {
    my $self = shift;
    my $mymeta = shift;

    return unless _has_cpan_meta();

    my $meta_obj = $self-&gt;_fix_metadata_before_conversion( $mymeta );

    $meta_obj-&gt;save( 'MYMETA.json', { version =&gt; "2.0" } );
    $meta_obj-&gt;save( 'MYMETA.yml', { version =&gt; "1.4" } );
    return 1;
}

=head3 realclean (o)

Defines the realclean target.

=cut

sub realclean {
    my($self, %attribs) = @_;

    my @dirs  = qw($(DISTVNAME));
    my @files = qw($(FIRST_MAKEFILE) $(MAKEFILE_OLD));

    # Special exception for the perl core where INST_* is not in blib.
    # This cleans up the files built from the ext/ directory (all XS).
    if( $self-&gt;{PERL_CORE} ) {
        push @dirs, qw($(INST_AUTODIR) $(INST_ARCHAUTODIR));
        push @files, values %{$self-&gt;{PM}};
    }

    if( $self-&gt;has_link_code ){
        push @files, qw($(OBJECT));
    }

    if( $attribs{FILES} ) {
        if( ref $attribs{FILES} ) {
            push @dirs, @{ $attribs{FILES} };
        }
        else {
            push @dirs, split /\s+/, $attribs{FILES};
        }
    }

    # Occasionally files are repeated several times from different sources
    { my(%f) = map { ($_ =&gt; 1) } @files;  @files = sort keys %f; }
    { my(%d) = map { ($_ =&gt; 1) } @dirs;   @dirs  = sort keys %d; }

    my $rm_cmd  = join "\n\t", map { "$_" }
                    $self-&gt;split_command('- $(RM_F)',  @files);
    my $rmf_cmd = join "\n\t", map { "$_" }
                    $self-&gt;split_command('- $(RM_RF)', @dirs);

    my $m = sprintf &lt;&lt;'MAKE', $rm_cmd, $rmf_cmd;
# Delete temporary files (via clean) and also delete dist files
realclean purge :: realclean_subdirs
	%s
	%s
MAKE

    $m .= "\t$attribs{POSTOP}\n" if $attribs{POSTOP};

    return $m;
}


=head3 realclean_subdirs_target

  my $make_frag = $MM-&gt;realclean_subdirs_target;

Returns the realclean_subdirs target.  This is used by the realclean
target to call realclean on any subdirectories which contain Makefiles.

=cut

sub realclean_subdirs_target {
    my $self = shift;
    my @m = &lt;&lt;'EOF';
# so clean is forced to complete before realclean_subdirs runs
realclean_subdirs : clean
EOF
    return join '', @m, "\t\$(NOECHO) \$(NOOP)\n" unless @{$self-&gt;{DIR}};
    foreach my $dir (@{$self-&gt;{DIR}}) {
        foreach my $makefile ('$(MAKEFILE_OLD)', '$(FIRST_MAKEFILE)' ) {
            my $subrclean .= $self-&gt;oneliner(_sprintf562 &lt;&lt;'CODE', $dir, $makefile);
chdir '%1$s';  system '$(MAKE) $(USEMAKEFILE) %2$s realclean' if -f '%2$s';
CODE
            push @m, "\t- $subrclean\n";
        }
    }
    return join '', @m;
}


=head3 signature_target

    my $target = $mm-&gt;signature_target;

Generate the signature target.

Writes the file SIGNATURE with "cpansign -s".

=cut

sub signature_target {
    my $self = shift;

    return &lt;&lt;'MAKE_FRAG';
signature :
	cpansign -s
MAKE_FRAG

}


=head3 distsignature_target

    my $make_frag = $mm-&gt;distsignature_target;

Generates the distsignature target to add SIGNATURE to the MANIFEST in the
distdir.

=cut

sub distsignature_target {
    my $self = shift;

    my $add_sign = $self-&gt;oneliner(&lt;&lt;'CODE', ['-MExtUtils::Manifest=maniadd']);
eval { maniadd({q{SIGNATURE} =&gt; q{Public-key signature (added by MakeMaker)}}) }
    or die "Could not add SIGNATURE to MANIFEST: ${'@'}"
CODE

    my $sign_dist        = $self-&gt;cd('$(DISTVNAME)' =&gt; 'cpansign -s');

    # cpansign -s complains if SIGNATURE is in the MANIFEST yet does not
    # exist
    my $touch_sig        = $self-&gt;cd('$(DISTVNAME)' =&gt; '$(TOUCH) SIGNATURE');
    my $add_sign_to_dist = $self-&gt;cd('$(DISTVNAME)' =&gt; $add_sign );

    return sprintf &lt;&lt;'MAKE', $add_sign_to_dist, $touch_sig, $sign_dist
distsignature : distmeta
	$(NOECHO) %s
	$(NOECHO) %s
	%s

MAKE

}


=head3 special_targets

  my $make_frag = $mm-&gt;special_targets

Returns a make fragment containing any targets which have special
meaning to make.  For example, .SUFFIXES and .PHONY.

=cut

sub special_targets {
    my $make_frag = &lt;&lt;'MAKE_FRAG';
.SUFFIXES : .xs .c .C .cpp .i .s .cxx .cc $(OBJ_EXT)

.PHONY: all config static dynamic test linkext manifest blibdirs clean realclean disttest distdir pure_all subdirs clean_subdirs makemakerdflt manifypods realclean_subdirs subdirs_dynamic subdirs_pure_nolink subdirs_static subdirs-test_dynamic subdirs-test_static test_dynamic test_static

MAKE_FRAG

    $make_frag .= &lt;&lt;'MAKE_FRAG' if $ENV{CLEARCASE_ROOT};
.NO_CONFIG_REC: Makefile

MAKE_FRAG

    return $make_frag;
}




=head2 Init methods

Methods which help initialize the MakeMaker object and macros.


=head3 init_ABSTRACT

    $mm-&gt;init_ABSTRACT

=cut

sub init_ABSTRACT {
    my $self = shift;

    if( $self-&gt;{ABSTRACT_FROM} and $self-&gt;{ABSTRACT} ) {
        warn "Both ABSTRACT_FROM and ABSTRACT are set.  ".
             "Ignoring ABSTRACT_FROM.\n";
        return;
    }

    if ($self-&gt;{ABSTRACT_FROM}){
        $self-&gt;{ABSTRACT} = $self-&gt;parse_abstract($self-&gt;{ABSTRACT_FROM}) or
            carp "WARNING: Setting ABSTRACT via file ".
                 "'$self-&gt;{ABSTRACT_FROM}' failed\n";
    }

    if ($self-&gt;{ABSTRACT} &amp;&amp; $self-&gt;{ABSTRACT} =~ m![[:cntrl:]]+!) {
            warn "WARNING: ABSTRACT contains control character(s),".
                 " they will be removed\n";
            $self-&gt;{ABSTRACT} =~ s![[:cntrl:]]+!!g;
            return;
    }
}

=head3 init_INST

    $mm-&gt;init_INST;

Called by init_main.  Sets up all INST_* variables except those related
to XS code.  Those are handled in init_xs.

=cut

sub init_INST {
    my($self) = shift;

    $self-&gt;{INST_ARCHLIB} ||= $self-&gt;catdir($Curdir,"blib","arch");
    $self-&gt;{INST_BIN}     ||= $self-&gt;catdir($Curdir,'blib','bin');

    # INST_LIB typically pre-set if building an extension after
    # perl has been built and installed. Setting INST_LIB allows
    # you to build directly into, say $Config{privlibexp}.
    unless ($self-&gt;{INST_LIB}){
        if ($self-&gt;{PERL_CORE}) {
            $self-&gt;{INST_LIB} = $self-&gt;{INST_ARCHLIB} = $self-&gt;{PERL_LIB};
        } else {
            $self-&gt;{INST_LIB} = $self-&gt;catdir($Curdir,"blib","lib");
        }
    }

    my @parentdir = split(/::/, $self-&gt;{PARENT_NAME});
    $self-&gt;{INST_LIBDIR}      = $self-&gt;catdir('$(INST_LIB)',     @parentdir);
    $self-&gt;{INST_ARCHLIBDIR}  = $self-&gt;catdir('$(INST_ARCHLIB)', @parentdir);
    $self-&gt;{INST_AUTODIR}     = $self-&gt;catdir('$(INST_LIB)', 'auto',
                                              '$(FULLEXT)');
    $self-&gt;{INST_ARCHAUTODIR} = $self-&gt;catdir('$(INST_ARCHLIB)', 'auto',
                                              '$(FULLEXT)');

    $self-&gt;{INST_SCRIPT}  ||= $self-&gt;catdir($Curdir,'blib','script');

    $self-&gt;{INST_MAN1DIR} ||= $self-&gt;catdir($Curdir,'blib','man1');
    $self-&gt;{INST_MAN3DIR} ||= $self-&gt;catdir($Curdir,'blib','man3');

    return 1;
}


=head3 init_INSTALL

    $mm-&gt;init_INSTALL;

Called by init_main.  Sets up all INSTALL_* variables (except
INSTALLDIRS) and *PREFIX.

=cut

sub init_INSTALL {
    my($self) = shift;

    if( $self-&gt;{ARGS}{INSTALL_BASE} and $self-&gt;{ARGS}{PREFIX} ) {
        die "Only one of PREFIX or INSTALL_BASE can be given.  Not both.\n";
    }

    if( $self-&gt;{ARGS}{INSTALL_BASE} ) {
        $self-&gt;init_INSTALL_from_INSTALL_BASE;
    }
    else {
        $self-&gt;init_INSTALL_from_PREFIX;
    }
}


=head3 init_INSTALL_from_PREFIX

  $mm-&gt;init_INSTALL_from_PREFIX;

=cut

sub init_INSTALL_from_PREFIX {
    my $self = shift;

    $self-&gt;init_lib2arch;

    # There are often no Config.pm defaults for these new man variables so
    # we fall back to the old behavior which is to use installman*dir
    foreach my $num (1, 3) {
        my $k = 'installsiteman'.$num.'dir';

        $self-&gt;{uc $k} ||= uc "\$(installman${num}dir)"
          unless $Config{$k};
    }

    foreach my $num (1, 3) {
        my $k = 'installvendorman'.$num.'dir';

        unless( $Config{$k} ) {
            $self-&gt;{uc $k}  ||= $Config{usevendorprefix}
                              ? uc "\$(installman${num}dir)"
                              : '';
        }
    }

    $self-&gt;{INSTALLSITEBIN} ||= '$(INSTALLBIN)'
      unless $Config{installsitebin};
    $self-&gt;{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
      unless $Config{installsitescript};

    unless( $Config{installvendorbin} ) {
        $self-&gt;{INSTALLVENDORBIN} ||= $Config{usevendorprefix}
                                    ? $Config{installbin}
                                    : '';
    }
    unless( $Config{installvendorscript} ) {
        $self-&gt;{INSTALLVENDORSCRIPT} ||= $Config{usevendorprefix}
                                       ? $Config{installscript}
                                       : '';
    }


    my $iprefix = $Config{installprefixexp} || $Config{installprefix} ||
                  $Config{prefixexp}        || $Config{prefix} || '';
    my $vprefix = $Config{usevendorprefix}  ? $Config{vendorprefixexp} : '';
    my $sprefix = $Config{siteprefixexp}    || '';

    # 5.005_03 doesn't have a siteprefix.
    $sprefix = $iprefix unless $sprefix;


    $self-&gt;{PREFIX}       ||= '';

    if( $self-&gt;{PREFIX} ) {
        @{$self}{qw(PERLPREFIX SITEPREFIX VENDORPREFIX)} =
          ('$(PREFIX)') x 3;
    }
    else {
        $self-&gt;{PERLPREFIX}   ||= $iprefix;
        $self-&gt;{SITEPREFIX}   ||= $sprefix;
        $self-&gt;{VENDORPREFIX} ||= $vprefix;

        # Lots of MM extension authors like to use $(PREFIX) so we
        # put something sensible in there no matter what.
        $self-&gt;{PREFIX} = '$('.uc $self-&gt;{INSTALLDIRS}.'PREFIX)';
    }

    my $arch    = $Config{archname};
    my $version = $Config{version};

    # default style
    my $libstyle = $Config{installstyle} || 'lib/perl5';
    my $manstyle = '';

    if( $self-&gt;{LIBSTYLE} ) {
        $libstyle = $self-&gt;{LIBSTYLE};
        $manstyle = $self-&gt;{LIBSTYLE} eq 'lib/perl5' ? 'lib/perl5' : '';
    }

    # Some systems, like VOS, set installman*dir to '' if they can't
    # read man pages.
    for my $num (1, 3) {
        $self-&gt;{'INSTALLMAN'.$num.'DIR'} ||= 'none'
          unless $Config{'installman'.$num.'dir'};
    }

    my %bin_layouts =
    (
        bin         =&gt; { s =&gt; $iprefix,
                         t =&gt; 'perl',
                         d =&gt; 'bin' },
        vendorbin   =&gt; { s =&gt; $vprefix,
                         t =&gt; 'vendor',
                         d =&gt; 'bin' },
        sitebin     =&gt; { s =&gt; $sprefix,
                         t =&gt; 'site',
                         d =&gt; 'bin' },
        script      =&gt; { s =&gt; $iprefix,
                         t =&gt; 'perl',
                         d =&gt; 'bin' },
        vendorscript=&gt; { s =&gt; $vprefix,
                         t =&gt; 'vendor',
                         d =&gt; 'bin' },
        sitescript  =&gt; { s =&gt; $sprefix,
                         t =&gt; 'site',
                         d =&gt; 'bin' },
    );

    my %man_layouts =
    (
        man1dir         =&gt; { s =&gt; $iprefix,
                             t =&gt; 'perl',
                             d =&gt; 'man/man1',
                             style =&gt; $manstyle, },
        siteman1dir     =&gt; { s =&gt; $sprefix,
                             t =&gt; 'site',
                             d =&gt; 'man/man1',
                             style =&gt; $manstyle, },
        vendorman1dir   =&gt; { s =&gt; $vprefix,
                             t =&gt; 'vendor',
                             d =&gt; 'man/man1',
                             style =&gt; $manstyle, },

        man3dir         =&gt; { s =&gt; $iprefix,
                             t =&gt; 'perl',
                             d =&gt; 'man/man3',
                             style =&gt; $manstyle, },
        siteman3dir     =&gt; { s =&gt; $sprefix,
                             t =&gt; 'site',
                             d =&gt; 'man/man3',
                             style =&gt; $manstyle, },
        vendorman3dir   =&gt; { s =&gt; $vprefix,
                             t =&gt; 'vendor',
                             d =&gt; 'man/man3',
                             style =&gt; $manstyle, },
    );

    my %lib_layouts =
    (
        privlib     =&gt; { s =&gt; $iprefix,
                         t =&gt; 'perl',
                         d =&gt; '',
                         style =&gt; $libstyle, },
        vendorlib   =&gt; { s =&gt; $vprefix,
                         t =&gt; 'vendor',
                         d =&gt; '',
                         style =&gt; $libstyle, },
        sitelib     =&gt; { s =&gt; $sprefix,
                         t =&gt; 'site',
                         d =&gt; 'site_perl',
                         style =&gt; $libstyle, },

        archlib     =&gt; { s =&gt; $iprefix,
                         t =&gt; 'perl',
                         d =&gt; "$version/$arch",
                         style =&gt; $libstyle },
        vendorarch  =&gt; { s =&gt; $vprefix,
                         t =&gt; 'vendor',
                         d =&gt; "$version/$arch",
                         style =&gt; $libstyle },
        sitearch    =&gt; { s =&gt; $sprefix,
                         t =&gt; 'site',
                         d =&gt; "site_perl/$version/$arch",
                         style =&gt; $libstyle },
    );


    # Special case for LIB.
    if( $self-&gt;{LIB} ) {
        foreach my $var (keys %lib_layouts) {
            my $Installvar = uc "install$var";

            if( $var =~ /arch/ ) {
                $self-&gt;{$Installvar} ||=
                  $self-&gt;catdir($self-&gt;{LIB}, $Config{archname});
            }
            else {
                $self-&gt;{$Installvar} ||= $self-&gt;{LIB};
            }
        }
    }

    my %type2prefix = ( perl    =&gt; 'PERLPREFIX',
                        site    =&gt; 'SITEPREFIX',
                        vendor  =&gt; 'VENDORPREFIX'
                      );

    my %layouts = (%bin_layouts, %man_layouts, %lib_layouts);
    while( my($var, $layout) = each(%layouts) ) {
        my($s, $t, $d, $style) = @{$layout}{qw(s t d style)};
        my $r = '$('.$type2prefix{$t}.')';

        warn "Prefixing $var\n" if $Verbose &gt;= 2;

        my $installvar = "install$var";
        my $Installvar = uc $installvar;
        next if $self-&gt;{$Installvar};

        $d = "$style/$d" if $style;
        $self-&gt;prefixify($installvar, $s, $r, $d);

        warn "  $Installvar == $self-&gt;{$Installvar}\n"
          if $Verbose &gt;= 2;
    }

    # Generate these if they weren't figured out.
    $self-&gt;{VENDORARCHEXP} ||= $self-&gt;{INSTALLVENDORARCH};
    $self-&gt;{VENDORLIBEXP}  ||= $self-&gt;{INSTALLVENDORLIB};

    return 1;
}


=head3 init_from_INSTALL_BASE

    $mm-&gt;init_from_INSTALL_BASE

=cut

my %map = (
           lib      =&gt; [qw(lib perl5)],
           arch     =&gt; [('lib', 'perl5', $Config{archname})],
           bin      =&gt; [qw(bin)],
           man1dir  =&gt; [qw(man man1)],
           man3dir  =&gt; [qw(man man3)]
          );
$map{script} = $map{bin};

sub init_INSTALL_from_INSTALL_BASE {
    my $self = shift;

    @{$self}{qw(PREFIX VENDORPREFIX SITEPREFIX PERLPREFIX)} =
                                                         '$(INSTALL_BASE)';

    my %install;
    foreach my $thing (keys %map) {
        foreach my $dir (('', 'SITE', 'VENDOR')) {
            my $uc_thing = uc $thing;
            my $key = "INSTALL".$dir.$uc_thing;

            $install{$key} ||=
                ($thing =~ /^man.dir$/ and not $Config{lc $key})
                ? 'none'
                : $self-&gt;catdir('$(INSTALL_BASE)', @{$map{$thing}});
        }
    }

    # Adjust for variable quirks.
    $install{INSTALLARCHLIB} ||= delete $install{INSTALLARCH};
    $install{INSTALLPRIVLIB} ||= delete $install{INSTALLLIB};

    foreach my $key (keys %install) {
        $self-&gt;{$key} ||= $install{$key};
    }

    return 1;
}


=head3 init_VERSION  I&lt;Abstract&gt;

    $mm-&gt;init_VERSION

Initialize macros representing versions of MakeMaker and other tools

MAKEMAKER: path to the MakeMaker module.

MM_VERSION: ExtUtils::MakeMaker Version

MM_REVISION: ExtUtils::MakeMaker version control revision (for backwards
             compat)

VERSION: version of your module

VERSION_MACRO: which macro represents the version (usually 'VERSION')

VERSION_SYM: like version but safe for use as an RCS revision number

DEFINE_VERSION: -D line to set the module version when compiling

XS_VERSION: version in your .xs file.  Defaults to $(VERSION)

XS_VERSION_MACRO: which macro represents the XS version.

XS_DEFINE_VERSION: -D line to set the xs version when compiling.

Called by init_main.

=cut

sub init_VERSION {
    my($self) = shift;

    $self-&gt;{MAKEMAKER}  = $ExtUtils::MakeMaker::Filename;
    $self-&gt;{MM_VERSION} = $ExtUtils::MakeMaker::VERSION;
    $self-&gt;{MM_REVISION}= $ExtUtils::MakeMaker::Revision;
    $self-&gt;{VERSION_FROM} ||= '';

    if ($self-&gt;{VERSION_FROM}){
        $self-&gt;{VERSION} = $self-&gt;parse_version($self-&gt;{VERSION_FROM});
        if( $self-&gt;{VERSION} eq 'undef' ) {
            carp("WARNING: Setting VERSION via file ".
                 "'$self-&gt;{VERSION_FROM}' failed\n");
        }
    }

    if (defined $self-&gt;{VERSION}) {
        if ( $self-&gt;{VERSION} !~ /^\s*v?[\d_\.]+\s*$/ ) {
          require version;
          my $normal = eval { version-&gt;new( $self-&gt;{VERSION} ) };
          $self-&gt;{VERSION} = $normal if defined $normal;
        }
        $self-&gt;{VERSION} =~ s/^\s+//;
        $self-&gt;{VERSION} =~ s/\s+$//;
    }
    else {
        $self-&gt;{VERSION} = '';
    }


    $self-&gt;{VERSION_MACRO}  = 'VERSION';
    ($self-&gt;{VERSION_SYM} = $self-&gt;{VERSION}) =~ s/\W/_/g;
    $self-&gt;{DEFINE_VERSION} = '-D$(VERSION_MACRO)=\"$(VERSION)\"';


    # Graham Barr and Paul Marquess had some ideas how to ensure
    # version compatibility between the *.pm file and the
    # corresponding *.xs file. The bottom line was, that we need an
    # XS_VERSION macro that defaults to VERSION:
    $self-&gt;{XS_VERSION} ||= $self-&gt;{VERSION};

    $self-&gt;{XS_VERSION_MACRO}  = 'XS_VERSION';
    $self-&gt;{XS_DEFINE_VERSION} = '-D$(XS_VERSION_MACRO)=\"$(XS_VERSION)\"';

}


=head3 init_tools

    $MM-&gt;init_tools();

Initializes the simple macro definitions used by tools_other() and
places them in the $MM object.  These use conservative cross platform
versions and should be overridden with platform specific versions for
performance.

Defines at least these macros.

  Macro             Description

  NOOP              Do nothing
  NOECHO            Tell make not to display the command itself

  SHELL             Program used to run shell commands

  ECHO              Print text adding a newline on the end
  RM_F              Remove a file
  RM_RF             Remove a directory
  TOUCH             Update a file's timestamp
  TEST_F            Test for a file's existence
  TEST_S            Test the size of a file
  CP                Copy a file
  CP_NONEMPTY       Copy a file if it is not empty
  MV                Move a file
  CHMOD             Change permissions on a file
  FALSE             Exit with non-zero
  TRUE              Exit with zero

  UMASK_NULL        Nullify umask
  DEV_NULL          Suppress all command output

=cut

sub init_tools {
    my $self = shift;

    $self-&gt;{ECHO}     ||= $self-&gt;oneliner('binmode STDOUT, qq{:raw}; print qq{@ARGV}', ['-l']);
    $self-&gt;{ECHO_N}   ||= $self-&gt;oneliner('print qq{@ARGV}');

    $self-&gt;{TOUCH}    ||= $self-&gt;oneliner('touch', ["-MExtUtils::Command"]);
    $self-&gt;{CHMOD}    ||= $self-&gt;oneliner('chmod', ["-MExtUtils::Command"]);
    $self-&gt;{RM_F}     ||= $self-&gt;oneliner('rm_f',  ["-MExtUtils::Command"]);
    $self-&gt;{RM_RF}    ||= $self-&gt;oneliner('rm_rf', ["-MExtUtils::Command"]);
    $self-&gt;{TEST_F}   ||= $self-&gt;oneliner('test_f', ["-MExtUtils::Command"]);
    $self-&gt;{TEST_S}   ||= $self-&gt;oneliner('test_s', ["-MExtUtils::Command::MM"]);
    $self-&gt;{CP_NONEMPTY} ||= $self-&gt;oneliner('cp_nonempty', ["-MExtUtils::Command::MM"]);
    $self-&gt;{FALSE}    ||= $self-&gt;oneliner('exit 1');
    $self-&gt;{TRUE}     ||= $self-&gt;oneliner('exit 0');

    $self-&gt;{MKPATH}   ||= $self-&gt;oneliner('mkpath', ["-MExtUtils::Command"]);

    $self-&gt;{CP}       ||= $self-&gt;oneliner('cp', ["-MExtUtils::Command"]);
    $self-&gt;{MV}       ||= $self-&gt;oneliner('mv', ["-MExtUtils::Command"]);

    $self-&gt;{MOD_INSTALL} ||=
      $self-&gt;oneliner(&lt;&lt;'CODE', ['-MExtUtils::Install']);
install([ from_to =&gt; {@ARGV}, verbose =&gt; '$(VERBINST)', uninstall_shadows =&gt; '$(UNINST)', dir_mode =&gt; '$(PERM_DIR)' ]);
CODE
    $self-&gt;{DOC_INSTALL} ||= $self-&gt;oneliner('perllocal_install', ["-MExtUtils::Command::MM"]);
    $self-&gt;{UNINSTALL}   ||= $self-&gt;oneliner('uninstall', ["-MExtUtils::Command::MM"]);
    $self-&gt;{WARN_IF_OLD_PACKLIST} ||=
      $self-&gt;oneliner('warn_if_old_packlist', ["-MExtUtils::Command::MM"]);
    $self-&gt;{FIXIN}       ||= $self-&gt;oneliner('MY-&gt;fixin(shift)', ["-MExtUtils::MY"]);
    $self-&gt;{EQUALIZE_TIMESTAMP} ||= $self-&gt;oneliner('eqtime', ["-MExtUtils::Command"]);

    $self-&gt;{UNINST}     ||= 0;
    $self-&gt;{VERBINST}   ||= 0;

    $self-&gt;{SHELL}              ||= $Config{sh};

    # UMASK_NULL is not used by MakeMaker but some CPAN modules
    # make use of it.
    $self-&gt;{UMASK_NULL}         ||= "umask 0";

    # Not the greatest default, but its something.
    $self-&gt;{DEV_NULL}           ||= "&gt; /dev/null 2&gt;&amp;1";

    $self-&gt;{NOOP}               ||= '$(TRUE)';
    $self-&gt;{NOECHO}             = '@' unless defined $self-&gt;{NOECHO};

    $self-&gt;{FIRST_MAKEFILE}     ||= $self-&gt;{MAKEFILE} || 'Makefile';
    $self-&gt;{MAKEFILE}           ||= $self-&gt;{FIRST_MAKEFILE};
    $self-&gt;{MAKEFILE_OLD}       ||= $self-&gt;{MAKEFILE}.'.old';
    $self-&gt;{MAKE_APERL_FILE}    ||= $self-&gt;{MAKEFILE}.'.aperl';

    # Not everybody uses -f to indicate "use this Makefile instead"
    $self-&gt;{USEMAKEFILE}        ||= '-f';

    # Some makes require a wrapper around macros passed in on the command
    # line.
    $self-&gt;{MACROSTART}         ||= '';
    $self-&gt;{MACROEND}           ||= '';

    return;
}


=head3 init_others

    $MM-&gt;init_others();

Initializes the macro definitions having to do with compiling and
linking used by tools_other() and places them in the $MM object.

If there is no description, its the same as the parameter to
WriteMakefile() documented in L&lt;ExtUtils::MakeMaker&gt;.

=cut

sub init_others {
    my $self = shift;

    $self-&gt;{LD_RUN_PATH} = "";

    $self-&gt;{LIBS} = $self-&gt;_fix_libs($self-&gt;{LIBS});

    # Compute EXTRALIBS, BSLOADLIBS and LDLOADLIBS from $self-&gt;{LIBS}
    foreach my $libs ( @{$self-&gt;{LIBS}} ){
        $libs =~ s/^\s*(.*\S)\s*$/$1/; # remove leading and trailing whitespace
        my(@libs) = $self-&gt;extliblist($libs);
        if ($libs[0] or $libs[1] or $libs[2]){
            # LD_RUN_PATH now computed by ExtUtils::Liblist
            ($self-&gt;{EXTRALIBS},  $self-&gt;{BSLOADLIBS},
             $self-&gt;{LDLOADLIBS}, $self-&gt;{LD_RUN_PATH}) = @libs;
            last;
        }
    }

    if ( $self-&gt;{OBJECT} ) {
        $self-&gt;{OBJECT} = join(" ", @{$self-&gt;{OBJECT}}) if ref $self-&gt;{OBJECT};
        $self-&gt;{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
    } elsif ( ($self-&gt;{MAGICXS} || $self-&gt;{XSMULTI}) &amp;&amp; @{$self-&gt;{O_FILES}||[]} ) {
        $self-&gt;{OBJECT} = join(" ", @{$self-&gt;{O_FILES}});
        $self-&gt;{OBJECT} =~ s!\.o(bj)?\b!\$(OBJ_EXT)!g;
    } else {
        # init_dirscan should have found out, if we have C files
        $self-&gt;{OBJECT} = "";
        $self-&gt;{OBJECT} = '$(BASEEXT)$(OBJ_EXT)' if @{$self-&gt;{C}||[]};
    }
    $self-&gt;{OBJECT} =~ s/\n+/ \\\n\t/g;

    $self-&gt;{BOOTDEP}  = (-f "$self-&gt;{BASEEXT}_BS") ? "$self-&gt;{BASEEXT}_BS" : "";
    $self-&gt;{PERLMAINCC} ||= '$(CC)';
    $self-&gt;{LDFROM} = '$(OBJECT)' unless $self-&gt;{LDFROM};

    # Sanity check: don't define LINKTYPE = dynamic if we're skipping
    # the 'dynamic' section of MM.  We don't have this problem with
    # 'static', since we either must use it (%Config says we can't
    # use dynamic loading) or the caller asked for it explicitly.
    if (!$self-&gt;{LINKTYPE}) {
       $self-&gt;{LINKTYPE} = $self-&gt;{SKIPHASH}{'dynamic'}
                        ? 'static'
                        : ($Config{usedl} ? 'dynamic' : 'static');
    }

    return;
}


# Lets look at $self-&gt;{LIBS} carefully: It may be an anon array, a string or
# undefined. In any case we turn it into an anon array
sub _fix_libs {
    my($self, $libs) = @_;

    return !defined $libs       ? ['']          :
           !ref $libs           ? [$libs]       :
           !defined $libs-&gt;[0]  ? ['']          :
                                  $libs         ;
}


=head3 tools_other

    my $make_frag = $MM-&gt;tools_other;

Returns a make fragment containing definitions for the macros init_others()
initializes.

=cut

sub tools_other {
    my($self) = shift;
    my @m;

    # We set PM_FILTER as late as possible so it can see all the earlier
    # on macro-order sensitive makes such as nmake.
    for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH
                      UMASK_NULL DEV_NULL MKPATH EQUALIZE_TIMESTAMP
                      FALSE TRUE
                      ECHO ECHO_N
                      UNINST VERBINST
                      MOD_INSTALL DOC_INSTALL UNINSTALL
                      WARN_IF_OLD_PACKLIST
                      MACROSTART MACROEND
                      USEMAKEFILE
                      PM_FILTER
                      FIXIN
                      CP_NONEMPTY
                    } )
    {
        next unless defined $self-&gt;{$tool};
        push @m, "$tool = $self-&gt;{$tool}\n";
    }

    return join "", @m;
}


=head3 init_DIRFILESEP  I&lt;Abstract&gt;

  $MM-&gt;init_DIRFILESEP;
  my $dirfilesep = $MM-&gt;{DIRFILESEP};

Initializes the DIRFILESEP macro which is the separator between the
directory and filename in a filepath.  ie. / on Unix, \ on Win32 and
nothing on VMS.

For example:

    # instead of $(INST_ARCHAUTODIR)/extralibs.ld
    $(INST_ARCHAUTODIR)$(DIRFILESEP)extralibs.ld

Something of a hack but it prevents a lot of code duplication between
MM_* variants.

Do not use this as a separator between directories.  Some operating
systems use different separators between subdirectories as between
directories and filenames (for example:  VOLUME:[dir1.dir2]file on VMS).

=head3 init_linker  I&lt;Abstract&gt;

    $mm-&gt;init_linker;

Initialize macros which have to do with linking.

PERL_ARCHIVE: path to libperl.a equivalent to be linked to dynamic
extensions.

PERL_ARCHIVE_AFTER: path to a library which should be put on the
linker command line I&lt;after&gt; the external libraries to be linked to
dynamic extensions.  This may be needed if the linker is one-pass, and
Perl includes some overrides for C RTL functions, such as malloc().

EXPORT_LIST: name of a file that is passed to linker to define symbols
to be exported.

Some OSes do not need these in which case leave it blank.


=head3 init_platform

    $mm-&gt;init_platform

Initialize any macros which are for platform specific use only.

A typical one is the version number of your OS specific module.
(ie. MM_Unix_VERSION or MM_VMS_VERSION).

=cut

sub init_platform {
    return '';
}


=head3 init_MAKE

    $mm-&gt;init_MAKE

Initialize MAKE from either a MAKE environment variable or $Config{make}.

=cut

sub init_MAKE {
    my $self = shift;

    $self-&gt;{MAKE} ||= $ENV{MAKE} || $Config{make};
}


=head2 Tools

A grab bag of methods to generate specific macros and commands.



=head3 manifypods

Defines targets and routines to translate the pods into manpages and
put them into the INST_* directories.

=cut

sub manifypods {
    my $self          = shift;

    my $POD2MAN_macro = $self-&gt;POD2MAN_macro();
    my $manifypods_target = $self-&gt;manifypods_target();

    return &lt;&lt;END_OF_TARGET;

$POD2MAN_macro

$manifypods_target

END_OF_TARGET

}


=head3 POD2MAN_macro

  my $pod2man_macro = $self-&gt;POD2MAN_macro

Returns a definition for the POD2MAN macro.  This is a program
which emulates the pod2man utility.  You can add more switches to the
command by simply appending them on the macro.

Typical usage:

    $(POD2MAN) --section=3 --perm_rw=$(PERM_RW) podfile1 man_page1 ...

=cut

sub POD2MAN_macro {
    my $self = shift;

# Need the trailing '--' so perl stops gobbling arguments and - happens
# to be an alternative end of line separator on VMS so we quote it
    return &lt;&lt;'END_OF_DEF';
POD2MAN_EXE = $(PERLRUN) "-MExtUtils::Command::MM" -e pod2man "--"
POD2MAN = $(POD2MAN_EXE)
END_OF_DEF
}


=head3 test_via_harness

  my $command = $mm-&gt;test_via_harness($perl, $tests);

Returns a $command line which runs the given set of $tests with
Test::Harness and the given $perl.

Used on the t/*.t files.

=cut

sub test_via_harness {
    my($self, $perl, $tests) = @_;

    return qq{\t$perl "-MExtUtils::Command::MM" "-MTest::Harness" }.
           qq{"-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests\n};
}

=head3 test_via_script

  my $command = $mm-&gt;test_via_script($perl, $script);

Returns a $command line which just runs a single test without
Test::Harness.  No checks are done on the results, they're just
printed.

Used for test.pl, since they don't always follow Test::Harness
formatting.

=cut

sub test_via_script {
    my($self, $perl, $script) = @_;
    return qq{\t$perl "-I\$(INST_LIB)" "-I\$(INST_ARCHLIB)" $script\n};
}


=head3 tool_autosplit

Defines a simple perl call that runs autosplit. May be deprecated by
pm_to_blib soon.

=cut

sub tool_autosplit {
    my($self, %attribs) = @_;

    my $maxlen = $attribs{MAXLEN} ? '$$AutoSplit::Maxlen=$attribs{MAXLEN};'
                                  : '';

    my $asplit = $self-&gt;oneliner(sprintf &lt;&lt;'PERL_CODE', $maxlen);
use AutoSplit; %s autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1)
PERL_CODE

    return sprintf &lt;&lt;'MAKE_FRAG', $asplit;
# Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
AUTOSPLITFILE = %s

MAKE_FRAG

}


=head3 arch_check

    my $arch_ok = $mm-&gt;arch_check(
        $INC{"Config.pm"},
        File::Spec-&gt;catfile($Config{archlibexp}, "Config.pm")
    );

A sanity check that what Perl thinks the architecture is and what
Config thinks the architecture is are the same.  If they're not it
will return false and show a diagnostic message.

When building Perl it will always return true, as nothing is installed
yet.

The interface is a bit odd because this is the result of a
quick refactoring.  Don't rely on it.

=cut

sub arch_check {
    my $self = shift;
    my($pconfig, $cconfig) = @_;

    return 1 if $self-&gt;{PERL_SRC};

    my($pvol, $pthinks) = $self-&gt;splitpath($pconfig);
    my($cvol, $cthinks) = $self-&gt;splitpath($cconfig);

    $pthinks = $self-&gt;canonpath($pthinks);
    $cthinks = $self-&gt;canonpath($cthinks);

    my $ret = 1;
    if ($pthinks ne $cthinks) {
        print "Have $pthinks\n";
        print "Want $cthinks\n";

        $ret = 0;

        my $arch = (grep length, $self-&gt;splitdir($pthinks))[-1];

        print &lt;&lt;END unless $self-&gt;{UNINSTALLED_PERL};
Your perl and your Config.pm seem to have different ideas about the
architecture they are running on.
Perl thinks: [$arch]
Config says: [$Config{archname}]
This may or may not cause problems. Please check your installation of perl
if you have problems building this extension.
END
    }

    return $ret;
}



=head2 File::Spec wrappers

ExtUtils::MM_Any is a subclass of L&lt;File::Spec&gt;.  The methods noted here
override File::Spec.



=head3 catfile

File::Spec &lt;= 0.83 has a bug where the file part of catfile is not
canonicalized.  This override fixes that bug.

=cut

sub catfile {
    my $self = shift;
    return $self-&gt;canonpath($self-&gt;SUPER::catfile(@_));
}



=head2 Misc

Methods I can't really figure out where they should go yet.


=head3 find_tests

  my $test = $mm-&gt;find_tests;

Returns a string suitable for feeding to the shell to return all
tests in t/*.t.

=cut

sub find_tests {
    my($self) = shift;
    return -d 't' ? 't/*.t' : '';
}

=head3 find_tests_recursive

  my $tests = $mm-&gt;find_tests_recursive;

Returns a string suitable for feeding to the shell to return all
tests in t/ but recursively. Equivalent to

  my $tests = $mm-&gt;find_tests_recursive_in('t');

=cut

sub find_tests_recursive {
    my $self = shift;
    return $self-&gt;find_tests_recursive_in('t');
}

=head3 find_tests_recursive_in

  my $tests = $mm-&gt;find_tests_recursive_in($dir);

Returns a string suitable for feeding to the shell to return all
tests in $dir recursively.

=cut

sub find_tests_recursive_in {
    my($self, $dir) = @_;
    return '' unless -d $dir;

    require File::Find;

    my $base_depth = grep { $_ ne '' } File::Spec-&gt;splitdir( (File::Spec-&gt;splitpath($dir))[1] );
    my %depths;

    my $wanted = sub {
        return unless m!\.t$!;
        my ($volume,$directories,$file) =
            File::Spec-&gt;splitpath( $File::Find::name  );
        my $depth = grep { $_ ne '' } File::Spec-&gt;splitdir( $directories );
        $depth -= $base_depth;
        $depths{ $depth } = 1;
    };

    File::Find::find( $wanted, $dir );

    return join ' ',
        map { $dir . '/*' x $_ . '.t' }
        sort { $a &lt;=&gt; $b }
        keys %depths;
}

=head3 extra_clean_files

    my @files_to_clean = $MM-&gt;extra_clean_files;

Returns a list of OS specific files to be removed in the clean target in
addition to the usual set.

=cut

# An empty method here tickled a perl 5.8.1 bug and would return its object.
sub extra_clean_files {
    return;
}


=head3 installvars

    my @installvars = $mm-&gt;installvars;

A list of all the INSTALL* variables without the INSTALL prefix.  Useful
for iteration or building related variable sets.

=cut

sub installvars {
    return qw(PRIVLIB SITELIB  VENDORLIB
              ARCHLIB SITEARCH VENDORARCH
              BIN     SITEBIN  VENDORBIN
              SCRIPT  SITESCRIPT  VENDORSCRIPT
              MAN1DIR SITEMAN1DIR VENDORMAN1DIR
              MAN3DIR SITEMAN3DIR VENDORMAN3DIR
             );
}


=head3 libscan

  my $wanted = $self-&gt;libscan($path);

Takes a path to a file or dir and returns an empty string if we don't
want to include this file in the library.  Otherwise it returns the
the $path unchanged.

Mainly used to exclude version control administrative directories
and base-level F&lt;README.pod&gt; from installation.

=cut

sub libscan {
    my($self,$path) = @_;

    if ($path =~ m&lt;^README\.pod$&gt;i) {
        warn "WARNING: Older versions of ExtUtils::MakeMaker may errantly install $path as part of this distribution. It is recommended to avoid using this path in CPAN modules.\n";
        return '';
    }

    my($dirs,$file) = ($self-&gt;splitpath($path))[1,2];
    return '' if grep /^(?:RCS|CVS|SCCS|\.svn|_darcs)$/,
                     $self-&gt;splitdir($dirs), $file;

    return $path;
}


=head3 platform_constants

    my $make_frag = $mm-&gt;platform_constants

Returns a make fragment defining all the macros initialized in
init_platform() rather than put them in constants().

=cut

sub platform_constants {
    return '';
}

=head3 post_constants (o)

Returns an empty string per default. Dedicated to overrides from
within Makefile.PL after all constants have been defined.

=cut

sub post_constants {
    "";
}

=head3 post_initialize (o)

Returns an empty string per default. Used in Makefile.PLs to add some
chunk of text to the Makefile after the object is initialized.

=cut

sub post_initialize {
    "";
}

=head3 postamble (o)

Returns an empty string. Can be used in Makefile.PLs to write some
text to the Makefile at the end.

=cut

sub postamble {
    "";
}

=begin private

=head3 _PREREQ_PRINT

    $self-&gt;_PREREQ_PRINT;

Implements PREREQ_PRINT.

Refactored out of MakeMaker-&gt;new().

=end private

=cut

sub _PREREQ_PRINT {
    my $self = shift;

    require Data::Dumper;
    my @what = ('PREREQ_PM');
    push @what, 'MIN_PERL_VERSION' if $self-&gt;{MIN_PERL_VERSION};
    push @what, 'BUILD_REQUIRES'   if $self-&gt;{BUILD_REQUIRES};
    print Data::Dumper-&gt;Dump([@{$self}{@what}], \@what);
    exit 0;
}


=begin private

=head3 _PRINT_PREREQ

  $mm-&gt;_PRINT_PREREQ;

Implements PRINT_PREREQ, a slightly different version of PREREQ_PRINT
added by Redhat to, I think, support generating RPMs from Perl modules.

Should not include BUILD_REQUIRES as RPMs do not include them.

Refactored out of MakeMaker-&gt;new().

=end private

=cut

sub _PRINT_PREREQ {
    my $self = shift;

    my $prereqs= $self-&gt;{PREREQ_PM};
    my @prereq = map { [$_, $prereqs-&gt;{$_}] } keys %$prereqs;

    if ( $self-&gt;{MIN_PERL_VERSION} ) {
        push @prereq, ['perl' =&gt; $self-&gt;{MIN_PERL_VERSION}];
    }

    print join(" ", map { "perl($_-&gt;[0])&gt;=$_-&gt;[1] " }
                 sort { $a-&gt;[0] cmp $b-&gt;[0] } @prereq), "\n";
    exit 0;
}


=begin private

=head3 _perl_header_files

  my $perl_header_files= $self-&gt;_perl_header_files;

returns a sorted list of header files as found in PERL_SRC or $archlibexp/CORE.

Used by perldepend() in MM_Unix and MM_VMS via _perl_header_files_fragment()

=end private

=cut

sub _perl_header_files {
    my $self = shift;

    my $header_dir = $self-&gt;{PERL_SRC} || $ENV{PERL_SRC} || $self-&gt;catdir($Config{archlibexp}, 'CORE');
    opendir my $dh, $header_dir
        or die "Failed to opendir '$header_dir' to find header files: $!";

    # we need to use a temporary here as the sort in scalar context would have undefined results.
    my @perl_headers= sort grep { /\.h\z/ } readdir($dh);

    closedir $dh;

    return @perl_headers;
}

=begin private

=head3 _perl_header_files_fragment ($o, $separator)

  my $perl_header_files_fragment= $self-&gt;_perl_header_files_fragment("/");

return a Makefile fragment which holds the list of perl header files which
XS code depends on $(PERL_INC), and sets up the dependency for the $(OBJECT) file.

The $separator argument defaults to "". MM_VMS will set it to "" and MM_UNIX to "/"
in perldepend(). This reason child subclasses need to control this is that in
VMS the $(PERL_INC) directory will already have delimiters in it, but in
UNIX $(PERL_INC) will need a slash between it an the filename. Hypothetically
win32 could use "\\" (but it doesn't need to).

=end private

=cut

sub _perl_header_files_fragment {
    my ($self, $separator)= @_;
    $separator ||= "";
    return join("\\\n",
                "PERL_HDRS = ",
                map {
                    sprintf( "        \$(PERL_INCDEP)%s%s            ", $separator, $_ )
                } $self-&gt;_perl_header_files()
           ) . "\n\n"
           . "\$(OBJECT) : \$(PERL_HDRS)\n";
}


=head1 AUTHOR

Michael G Schwern &lt;schwern@pobox.com&gt; and the denizens of
makemaker@perl.org with code from ExtUtils::MM_Unix and
ExtUtils::MM_Win32.


=cut

1;
</pre></body></html>