package ExtUtils
::MM_Win32
;
ExtUtils::MM_Win32 - methods to override UN*X behaviour in ExtUtils::MakeMaker
use ExtUtils::MM_Win32; # Done internally by ExtUtils::MakeMaker if needed
See ExtUtils::MM_Unix for a documentation of the methods provided
there. This package overrides the implementation of these methods, not
use ExtUtils
::MakeMaker
::Config
;
use ExtUtils
::MakeMaker
qw( neatvalue );
use vars
qw(@ISA $VERSION $BORLAND $GCC $DMAKE $NMAKE);
require ExtUtils::MM_Any;
require ExtUtils::MM_Unix;
@ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
$ENV{EMXSHELL
} = 'sh'; # to run `commands`
$BORLAND = 1 if $Config{'cc'} =~ /^bcc/i;
$GCC = 1 if $Config{'cc'} =~ /^gcc/i;
$DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
$NMAKE = 1 if $Config{'make'} =~ /^nmake/i;
=head2 Overridden methods
my($funcs) = $attribs{DL_FUNCS
} || $self->{DL_FUNCS
} || {};
my($vars) = $attribs{DL_VARS
} || $self->{DL_VARS
} || [];
my($funclist) = $attribs{FUNCLIST
} || $self->{FUNCLIST
} || [];
my($imports) = $attribs{IMPORTS
} || $self->{IMPORTS
} || {};
if (not $self->{SKIPHASH
}{'dynamic'}) {
$self->{BASEEXT}.def: Makefile.PL
q
! $(PERLRUN
) -MExtUtils
::Mksymlists
\\
-e
"Mksymlists('NAME'=>\"!, $self->{NAME},
q!\", 'DLBASE' => '!,$self->{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' => !,neatvalue($funcs),
q!, 'FUNCLIST' => !,neatvalue($funclist),
q!, 'IMPORTS' => !,neatvalue($imports),
q!, 'DL_VARS' => !, neatvalue($vars), q!);"
=item replace_manpage_separator
Changes the path separator with .
sub replace_manpage_separator
{
Since Windows has nothing as simple as an executable bit, we check the
The PATHEXT env variable will be used to get a list of extensions that
might indicate a command, otherwise .com, .exe, .bat and .cmd will be
my @e = exists($ENV{'PATHEXT'})
?
split(/;/, $ENV{PATHEXT
})
: qw(.com .exe .bat .cmd);
for (@e) { $e .= "\Q$_\E|" }
# see if file ends in one of the known extensions
return $file if -e
$file;
return "$file$_" if -e
"$file$_";
# The ^ makes sure its not interpreted as an escape in nmake
$self->{DIRFILESEP
} = $NMAKE ?
'^\\' :
Override some of the Unix specific commands with portable
Also provide defaults for LD and AR in case the %Config values aren't
LDLOADLIBS's default is changed to $Config{libs}.
Adjustments are made for Borland's quirks needing -L to come first.
# Used in favor of echo because echo won't strip quotes. :(
$self->{ECHO
} ||= $self->oneliner('print qq{@ARGV}', ['-l']);
$self->{ECHO_N
} ||= $self->oneliner('print qq{@ARGV}');
$self->{TOUCH
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e touch';
$self->{CHMOD
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e chmod';
$self->{CP
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e cp';
$self->{RM_F
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_f';
$self->{RM_RF
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_rf';
$self->{MV
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e mv';
$self->{TEST_F
} ||= '$(ABSPERLRUN) -MExtUtils::Command -e test_f';
$self->{DEV_NULL
} ||= '> NUL';
$self->{FIXIN
} ||= $self->{PERL_CORE
} ?
"\$(PERLRUN) $self->{PERL_SRC}/win32/bin/pl2bat.pl" :
$self->{LD
} ||= $Config{ld
} || 'link';
$self->{AR
} ||= $Config{ar
} || 'lib';
$self->SUPER::init_others
;
# Setting SHELL from $Config{sh} can break dmake. Its ok without it.
$self->{LDLOADLIBS
} ||= $Config{libs
};
# -Lfoo must come first for Borland, so we put it in LDDLFLAGS
my $libs = $self->{LDLOADLIBS
};
while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
$libpath .= ' ' if length $libpath;
$self->{LDLOADLIBS
} = $libs;
$self->{LDDLFLAGS
} ||= $Config{lddlflags
};
$self->{LDDLFLAGS
} .= " $libpath";
$self->{MM_Win32_VERSION
} = $VERSION;
foreach my $macro (qw(MM_Win32_VERSION))
next unless defined $self->{$macro};
$make_frag .= "$macro = $self->{$macro}\n";
Add .USESHELL target for dmake.
my $make_frag = $self->SUPER::special_targets
;
$make_frag .= <<'MAKE_FRAG' if $DMAKE;
Changes how to run the linker.
The rest is duplicate code from MM_Unix. Should move the linker code
return '' unless $self->has_link_code;
$(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
# If this extension has its own library (eg SDBM_File)
# then copy that to $(INST_STATIC) and add $(OBJECT) into it.
push @m, <<'MAKE_FRAG' if $self->{MYEXTLIB};
q{ $(AR) }.($BORLAND ?
'$@ $(OBJECT:^"+")'
: ($GCC ?
'-ru $@ $(OBJECT)'
: '-out:$@ $(OBJECT)')).q{
$(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
# Old mechanism - still available:
push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
$(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
Complicated stuff for Win32 that I don't understand. :(
my($self, %attribs) = @_;
return '' unless $self->needs_linking(); #might be because of a subdir
return '' unless $self->has_link_code;
my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
my($ldfrom) = '$(LDFROM)';
# one thing for GCC/Mingw32:
# we try to overcome non-relocateable-DLL problems by generating
# a (hopefully unique) image-base from the dll's name
my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT};
$dllname =~ /(....)(.{0,4})/;
my $baseaddr = unpack("n", $1 ^ $2);
$otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $baseaddr);
# This section creates the dynamically loadable $(INST_DYNAMIC)
# from $(OBJECT) and possibly $(MYEXTLIB).
OTHERLDFLAGS = '.$otherldflags.'
INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
q{ dlltool --def $(EXPORT_LIST) --output-exp dll.exp
$(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp
dlltool --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
$(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp });
q{ $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
.($DMAKE ?
q{$(PERL_ARCHIVE:s,/,\,) $(LDLOADLIBS:s,/,\,) }
.q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
: q{$(subst /,\,$(PERL_ARCHIVE)) $(subst /,\,$(LDLOADLIBS)) }
.q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
q{ $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
.q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
Clean out some extra dll.{base,exp} files which might be generated by
gcc. Otherwise, take out all *.pdb files.
return $GCC ?
(qw(dll.base dll.exp)) : ('*.pdb');
$self->{PERL_ARCHIVE
} = "\$(PERL_INC)\\$Config{libperl}";
$self->{PERL_ARCHIVE_AFTER
} = '';
$self->{EXPORT_LIST
} = '$(BASEEXT).def';
Checks for the perl program under several common perl extensions.
return $file if -r
$file && -f _
;
return "$file.pl" if -r
"$file.pl" && -f _
;
return "$file.plx" if -r
"$file.plx" && -f _
;
return "$file.bat" if -r
"$file.bat" && -f _
;
This target is stubbed out. Not sure why.
All we send is -nologo to nmake to prevent it from printing its damned
return "PASTHRU = " . ($NMAKE ?
"-nologo" : "");
These are based on what command.com does on Win98. They may be wrong
for other Windows shells, I don't know.
my($self, $cmd, $switches) = @_;
$switches = [] unless defined $switches;
# Strip leading and trailing newlines
$cmd = $self->quote_literal($cmd);
$cmd = $self->escape_newlines($cmd);
$switches = join ' ', @
$switches;
return qq{\
$(ABSPERLRUN
) $switches -e
$cmd};
# I don't know if this is correct, but it seems to work on
# dmake eats '{' inside double quotes and leaves alone { outside double
# quotes; however it transforms {{ into { either inside and outside double
# quotes. It also translates }} into }. The escaping below is not
dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
B<NOTE> This cd can only go one level down. So far this sufficient for
my($self, $dir, @cmds) = @_;
return $self->SUPER::cd
($dir, @cmds) unless $NMAKE;
my $cmd = join "\n\t", map "$_", @cmds;
# No leading tab and no trailing newline makes for easier embedding.
my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd;
nmake 1.50 limits command length to 2048 characters.
return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;