1 package ExtUtils::MM_Win32;
8 ExtUtils::MM_Win32 - methods to override UN*X behaviour in ExtUtils::MakeMaker
12 use ExtUtils::MM_Win32; # Done internally by ExtUtils::MakeMaker if needed
16 See ExtUtils::MM_Unix for a documentation of the methods provided
17 there. This package overrides the implementation of these methods, not
22 use ExtUtils::MakeMaker::Config;
25 use ExtUtils::MakeMaker qw( neatvalue );
27 require ExtUtils::MM_Any;
28 require ExtUtils::MM_Unix;
29 our @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
30 our $VERSION = '6.44';
32 $ENV{EMXSHELL} = 'sh'; # to run `commands`
34 my $BORLAND = $Config{'cc'} =~ /^bcc/i ? 1 : 0;
35 my $GCC = $Config{'cc'} =~ /^gcc/i ? 1 : 0;
38 =head2 Overridden methods
47 my($self,%attribs) = @_;
49 my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
50 my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
51 my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
52 my($imports) = $attribs{IMPORTS} || $self->{IMPORTS} || {};
55 if (not $self->{SKIPHASH}{'dynamic'}) {
57 $self->{BASEEXT}.def: Makefile.PL
59 q! $(PERLRUN) -MExtUtils::Mksymlists \\
60 -e "Mksymlists('NAME'=>\"!, $self->{NAME},
61 q!\", 'DLBASE' => '!,$self->{DLBASE},
62 # The above two lines quoted differently to work around
63 # a bug in the 4DOS/4NT command line interpreter. The visible
64 # result of the bug was files named q('extension_name',) *with the
65 # single quotes and the comma* in the extension build directories.
66 q!', 'DL_FUNCS' => !,neatvalue($funcs),
67 q!, 'FUNCLIST' => !,neatvalue($funclist),
68 q!, 'IMPORTS' => !,neatvalue($imports),
69 q!, 'DL_VARS' => !, neatvalue($vars), q!);"
75 =item replace_manpage_separator
77 Changes the path separator with .
81 sub replace_manpage_separator {
88 =item B<maybe_command>
90 Since Windows has nothing as simple as an executable bit, we check the
93 The PATHEXT env variable will be used to get a list of extensions that
94 might indicate a command, otherwise .com, .exe, .bat and .cmd will be
100 my($self,$file) = @_;
101 my @e = exists($ENV{'PATHEXT'})
102 ? split(/;/, $ENV{PATHEXT})
103 : qw(.com .exe .bat .cmd);
105 for (@e) { $e .= "\Q$_\E|" }
107 # see if file ends in one of the known extensions
108 if ($file =~ /($e)$/i) {
109 return $file if -e $file;
113 return "$file$_" if -e "$file$_";
120 =item B<init_DIRFILESEP>
126 sub init_DIRFILESEP {
129 my $make = $self->make;
131 # The ^ makes sure its not interpreted as an escape in nmake
132 $self->{DIRFILESEP} = $make eq 'nmake' ? '^\\' :
133 $make eq 'dmake' ? '\\\\'
139 Override some of the Unix specific commands with portable
140 ExtUtils::Command ones.
142 Also provide defaults for LD and AR in case the %Config values aren't
145 LDLOADLIBS's default is changed to $Config{libs}.
147 Adjustments are made for Borland's quirks needing -L to come first.
154 # Used in favor of echo because echo won't strip quotes. :(
155 $self->{ECHO} ||= $self->oneliner('print qq{@ARGV}', ['-l']);
156 $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}');
158 $self->{TOUCH} ||= '$(ABSPERLRUN) -MExtUtils::Command -e touch';
159 $self->{CHMOD} ||= '$(ABSPERLRUN) -MExtUtils::Command -e chmod';
160 $self->{CP} ||= '$(ABSPERLRUN) -MExtUtils::Command -e cp';
161 $self->{RM_F} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_f';
162 $self->{RM_RF} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_rf';
163 $self->{MV} ||= '$(ABSPERLRUN) -MExtUtils::Command -e mv';
164 $self->{NOOP} ||= 'rem';
165 $self->{TEST_F} ||= '$(ABSPERLRUN) -MExtUtils::Command -e test_f';
166 $self->{DEV_NULL} ||= '> NUL';
168 $self->{FIXIN} ||= $self->{PERL_CORE} ?
169 "\$(PERLRUN) $self->{PERL_SRC}/win32/bin/pl2bat.pl" :
172 $self->{LD} ||= $Config{ld} || 'link';
173 $self->{AR} ||= $Config{ar} || 'lib';
175 $self->SUPER::init_others;
177 # Setting SHELL from $Config{sh} can break dmake. Its ok without it.
178 delete $self->{SHELL};
180 $self->{LDLOADLIBS} ||= $Config{libs};
181 # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
183 my $libs = $self->{LDLOADLIBS};
185 while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
186 $libpath .= ' ' if length $libpath;
189 $self->{LDLOADLIBS} = $libs;
190 $self->{LDDLFLAGS} ||= $Config{lddlflags};
191 $self->{LDDLFLAGS} .= " $libpath";
200 Add MM_Win32_VERSION.
202 =item platform_constants
209 $self->{MM_Win32_VERSION} = $VERSION;
212 sub platform_constants {
216 foreach my $macro (qw(MM_Win32_VERSION))
218 next unless defined $self->{$macro};
219 $make_frag .= "$macro = $self->{$macro}\n";
226 =item special_targets
228 Add .USESHELL target for dmake.
232 sub special_targets {
235 my $make_frag = $self->SUPER::special_targets;
237 $make_frag .= <<'MAKE_FRAG' if $self->make eq 'dmake';
247 Changes how to run the linker.
249 The rest is duplicate code from MM_Unix. Should move the linker code
256 return '' unless $self->has_link_code;
260 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
264 # If this extension has its own library (eg SDBM_File)
265 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
266 push @m, <<'MAKE_FRAG' if $self->{MYEXTLIB};
271 q{ $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
272 : ($GCC ? '-ru $@ $(OBJECT)'
273 : '-out:$@ $(OBJECT)')).q{
274 $(CHMOD) $(PERM_RWX) $@
275 $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
278 # Old mechanism - still available:
279 push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
280 $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
289 Complicated stuff for Win32 that I don't understand. :(
294 my($self, %attribs) = @_;
295 return '' unless $self->needs_linking(); #might be because of a subdir
297 return '' unless $self->has_link_code;
299 my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
300 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
301 my($ldfrom) = '$(LDFROM)';
304 # one thing for GCC/Mingw32:
305 # we try to overcome non-relocateable-DLL problems by generating
306 # a (hopefully unique) image-base from the dll's name
309 my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT};
310 $dllname =~ /(....)(.{0,4})/;
311 my $baseaddr = unpack("n", $1 ^ $2);
312 $otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $baseaddr);
316 # This section creates the dynamically loadable $(INST_DYNAMIC)
317 # from $(OBJECT) and possibly $(MYEXTLIB).
318 OTHERLDFLAGS = '.$otherldflags.'
319 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
321 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
325 q{ dlltool --def $(EXPORT_LIST) --output-exp dll.exp
326 $(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp
327 dlltool --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
328 $(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp });
331 q{ $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
332 .($self->make eq 'dmake'
333 ? q{$(PERL_ARCHIVE:s,/,\,) $(LDLOADLIBS:s,/,\,) }
334 .q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
335 : q{$(subst /,\,$(PERL_ARCHIVE)) $(subst /,\,$(LDLOADLIBS)) }
336 .q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
340 q{ $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
341 .q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
343 # VS2005 (aka VC 8) or higher, but not for 64-bit compiler from Platform SDK
344 if ($Config{ivsize} == 4 && $Config{cc} eq 'cl' and $Config{ccversion} =~ /^(\d+)/ and $1 >= 14)
348 mt -nologo -manifest $@.manifest -outputresource:$@;2 && del $@.manifest});
352 $(CHMOD) $(PERM_RWX) $@
358 =item extra_clean_files
360 Clean out some extra dll.{base,exp} files which might be generated by
361 gcc. Otherwise, take out all *.pdb files.
365 sub extra_clean_files {
368 return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
378 $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}";
379 $self->{PERL_ARCHIVE_AFTER} = '';
380 $self->{EXPORT_LIST} = '$(BASEEXT).def';
386 Checks for the perl program under several common perl extensions.
391 my($self,$file) = @_;
392 return $file if -r $file && -f _;
393 return "$file.pl" if -r "$file.pl" && -f _;
394 return "$file.plx" if -r "$file.plx" && -f _;
395 return "$file.bat" if -r "$file.bat" && -f _;
402 This target is stubbed out. Not sure why.
413 All we send is -nologo to nmake to prevent it from printing its damned
420 return "PASTHRU = " . ($self->make eq 'nmake' ? "-nologo" : "");
426 These are based on what command.com does on Win98. They may be wrong
427 for other Windows shells, I don't know.
432 my($self, $cmd, $switches) = @_;
433 $switches = [] unless defined $switches;
435 # Strip leading and trailing newlines
439 $cmd = $self->quote_literal($cmd);
440 $cmd = $self->escape_newlines($cmd);
442 $switches = join ' ', @$switches;
444 return qq{\$(ABSPERLRUN) $switches -e $cmd --};
449 my($self, $text) = @_;
451 # I don't know if this is correct, but it seems to work on
452 # Win98's command.com
455 # dmake eats '{' inside double quotes and leaves alone { outside double
456 # quotes; however it transforms {{ into { either inside and outside double
457 # quotes. It also translates }} into }. The escaping below is not
459 if( $self->make eq 'dmake' ) {
468 sub escape_newlines {
469 my($self, $text) = @_;
472 $text =~ s{\n}{\\\n}g;
480 dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
488 NOTE: This only works with simple relative directories. Throw it an absolute dir or something with .. in it and things will go wrong.
493 my($self, $dir, @cmds) = @_;
495 return $self->SUPER::cd($dir, @cmds) unless $self->make eq 'nmake';
497 my $cmd = join "\n\t", map "$_", @cmds;
499 my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir));
501 # No leading tab and no trailing newline makes for easier embedding.
502 my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs;
516 nmake 1.50 limits command length to 2048 characters.
523 return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
540 Defines the PERLDLL symbol if we are configured for static building since all
541 code destined for the perl5xx.dll must be compiled with the PERLDLL symbol
547 my($self,$libperl)=@_;
548 return $self->{CFLAGS} if $self->{CFLAGS};
549 return '' unless $self->needs_linking();
551 my $base = $self->SUPER::cflags($libperl);
552 foreach (split /\n/, $base) {
553 /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2;
555 $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static');
557 return $self->{CFLAGS} = qq{
558 CCFLAGS = $self->{CCFLAGS}
559 OPTIMIZE = $self->{OPTIMIZE}
560 PERLTYPE = $self->{PERLTYPE}