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 use vars qw(@ISA $VERSION $BORLAND $GCC $DMAKE $NMAKE);
29 require ExtUtils::MM_Any;
30 require ExtUtils::MM_Unix;
31 @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
34 $ENV{EMXSHELL} = 'sh'; # to run `commands`
36 $BORLAND = 1 if $Config{'cc'} =~ /^bcc/i;
37 $GCC = 1 if $Config{'cc'} =~ /^gcc/i;
38 $DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
39 $NMAKE = 1 if $Config{'make'} =~ /^nmake/i;
42 =head2 Overridden methods
51 my($self,%attribs) = @_;
53 my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
54 my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
55 my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
56 my($imports) = $attribs{IMPORTS} || $self->{IMPORTS} || {};
59 if (not $self->{SKIPHASH}{'dynamic'}) {
61 $self->{BASEEXT}.def: Makefile.PL
63 q! $(PERLRUN) -MExtUtils::Mksymlists \\
64 -e "Mksymlists('NAME'=>\"!, $self->{NAME},
65 q!\", 'DLBASE' => '!,$self->{DLBASE},
66 # The above two lines quoted differently to work around
67 # a bug in the 4DOS/4NT command line interpreter. The visible
68 # result of the bug was files named q('extension_name',) *with the
69 # single quotes and the comma* in the extension build directories.
70 q!', 'DL_FUNCS' => !,neatvalue($funcs),
71 q!, 'FUNCLIST' => !,neatvalue($funclist),
72 q!, 'IMPORTS' => !,neatvalue($imports),
73 q!, 'DL_VARS' => !, neatvalue($vars), q!);"
79 =item replace_manpage_separator
81 Changes the path separator with .
85 sub replace_manpage_separator {
92 =item B<maybe_command>
94 Since Windows has nothing as simple as an executable bit, we check the
97 The PATHEXT env variable will be used to get a list of extensions that
98 might indicate a command, otherwise .com, .exe, .bat and .cmd will be
104 my($self,$file) = @_;
105 my @e = exists($ENV{'PATHEXT'})
106 ? split(/;/, $ENV{PATHEXT})
107 : qw(.com .exe .bat .cmd);
109 for (@e) { $e .= "\Q$_\E|" }
111 # see if file ends in one of the known extensions
112 if ($file =~ /($e)$/i) {
113 return $file if -e $file;
117 return "$file$_" if -e "$file$_";
124 =item B<init_DIRFILESEP>
130 sub init_DIRFILESEP {
133 # The ^ makes sure its not interpreted as an escape in nmake
134 $self->{DIRFILESEP} = $NMAKE ? '^\\' :
141 Override some of the Unix specific commands with portable
142 ExtUtils::Command ones.
144 Also provide defaults for LD and AR in case the %Config values aren't
147 LDLOADLIBS's default is changed to $Config{libs}.
149 Adjustments are made for Borland's quirks needing -L to come first.
156 # Used in favor of echo because echo won't strip quotes. :(
157 $self->{ECHO} ||= $self->oneliner('print qq{@ARGV}', ['-l']);
158 $self->{ECHO_N} ||= $self->oneliner('print qq{@ARGV}');
160 $self->{TOUCH} ||= '$(ABSPERLRUN) -MExtUtils::Command -e touch';
161 $self->{CHMOD} ||= '$(ABSPERLRUN) -MExtUtils::Command -e chmod';
162 $self->{CP} ||= '$(ABSPERLRUN) -MExtUtils::Command -e cp';
163 $self->{RM_F} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_f';
164 $self->{RM_RF} ||= '$(ABSPERLRUN) -MExtUtils::Command -e rm_rf';
165 $self->{MV} ||= '$(ABSPERLRUN) -MExtUtils::Command -e mv';
166 $self->{NOOP} ||= 'rem';
167 $self->{TEST_F} ||= '$(ABSPERLRUN) -MExtUtils::Command -e test_f';
168 $self->{DEV_NULL} ||= '> NUL';
170 $self->{FIXIN} ||= $self->{PERL_CORE} ?
171 "\$(PERLRUN) $self->{PERL_SRC}/win32/bin/pl2bat.pl" :
174 $self->{LD} ||= $Config{ld} || 'link';
175 $self->{AR} ||= $Config{ar} || 'lib';
177 $self->SUPER::init_others;
179 # Setting SHELL from $Config{sh} can break dmake. Its ok without it.
180 delete $self->{SHELL};
182 $self->{LDLOADLIBS} ||= $Config{libs};
183 # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
185 my $libs = $self->{LDLOADLIBS};
187 while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
188 $libpath .= ' ' if length $libpath;
191 $self->{LDLOADLIBS} = $libs;
192 $self->{LDDLFLAGS} ||= $Config{lddlflags};
193 $self->{LDDLFLAGS} .= " $libpath";
202 Add MM_Win32_VERSION.
204 =item platform_constants
211 $self->{MM_Win32_VERSION} = $VERSION;
214 sub platform_constants {
218 foreach my $macro (qw(MM_Win32_VERSION))
220 next unless defined $self->{$macro};
221 $make_frag .= "$macro = $self->{$macro}\n";
228 =item special_targets
230 Add .USESHELL target for dmake.
234 sub special_targets {
237 my $make_frag = $self->SUPER::special_targets;
239 $make_frag .= <<'MAKE_FRAG' if $DMAKE;
249 Changes how to run the linker.
251 The rest is duplicate code from MM_Unix. Should move the linker code
258 return '' unless $self->has_link_code;
262 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
266 # If this extension has its own library (eg SDBM_File)
267 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
268 push @m, <<'MAKE_FRAG' if $self->{MYEXTLIB};
273 q{ $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
274 : ($GCC ? '-ru $@ $(OBJECT)'
275 : '-out:$@ $(OBJECT)')).q{
276 $(CHMOD) $(PERM_RWX) $@
277 $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
280 # Old mechanism - still available:
281 push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
282 $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
291 Complicated stuff for Win32 that I don't understand. :(
296 my($self, %attribs) = @_;
297 return '' unless $self->needs_linking(); #might be because of a subdir
299 return '' unless $self->has_link_code;
301 my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
302 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
303 my($ldfrom) = '$(LDFROM)';
306 # one thing for GCC/Mingw32:
307 # we try to overcome non-relocateable-DLL problems by generating
308 # a (hopefully unique) image-base from the dll's name
311 my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT};
312 $dllname =~ /(....)(.{0,4})/;
313 my $baseaddr = unpack("n", $1 ^ $2);
314 $otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $baseaddr);
318 # This section creates the dynamically loadable $(INST_DYNAMIC)
319 # from $(OBJECT) and possibly $(MYEXTLIB).
320 OTHERLDFLAGS = '.$otherldflags.'
321 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
323 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
327 q{ dlltool --def $(EXPORT_LIST) --output-exp dll.exp
328 $(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp
329 dlltool --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
330 $(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp });
333 q{ $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
334 .($DMAKE ? q{$(PERL_ARCHIVE:s,/,\,) $(LDLOADLIBS:s,/,\,) }
335 .q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
336 : q{$(subst /,\,$(PERL_ARCHIVE)) $(subst /,\,$(LDLOADLIBS)) }
337 .q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
341 q{ $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
342 .q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
345 $(CHMOD) $(PERM_RWX) $@
351 =item extra_clean_files
353 Clean out some extra dll.{base,exp} files which might be generated by
354 gcc. Otherwise, take out all *.pdb files.
358 sub extra_clean_files {
361 return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
371 $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}";
372 $self->{PERL_ARCHIVE_AFTER} = '';
373 $self->{EXPORT_LIST} = '$(BASEEXT).def';
379 Checks for the perl program under several common perl extensions.
384 my($self,$file) = @_;
385 return $file if -r $file && -f _;
386 return "$file.pl" if -r "$file.pl" && -f _;
387 return "$file.plx" if -r "$file.plx" && -f _;
388 return "$file.bat" if -r "$file.bat" && -f _;
395 This target is stubbed out. Not sure why.
406 All we send is -nologo to nmake to prevent it from printing its damned
413 return "PASTHRU = " . ($NMAKE ? "-nologo" : "");
419 These are based on what command.com does on Win98. They may be wrong
420 for other Windows shells, I don't know.
425 my($self, $cmd, $switches) = @_;
426 $switches = [] unless defined $switches;
428 # Strip leading and trailing newlines
432 $cmd = $self->quote_literal($cmd);
433 $cmd = $self->escape_newlines($cmd);
435 $switches = join ' ', @$switches;
437 return qq{\$(ABSPERLRUN) $switches -e $cmd};
442 my($self, $text) = @_;
444 # I don't know if this is correct, but it seems to work on
445 # Win98's command.com
448 # dmake eats '{' inside double quotes and leaves alone { outside double
449 # quotes; however it transforms {{ into { either inside and outside double
450 # quotes. It also translates }} into }. The escaping below is not
461 sub escape_newlines {
462 my($self, $text) = @_;
465 $text =~ s{\n}{\\\n}g;
473 dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
481 B<NOTE> This cd can only go one level down. So far this sufficient for
482 what MakeMaker needs.
487 my($self, $dir, @cmds) = @_;
489 return $self->SUPER::cd($dir, @cmds) unless $NMAKE;
491 my $cmd = join "\n\t", map "$_", @cmds;
493 # No leading tab and no trailing newline makes for easier embedding.
494 my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd;
508 nmake 1.50 limits command length to 2048 characters.
515 return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;