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 = '7.10_01';
32 $ENV{EMXSHELL} = 'sh'; # to run `commands`
34 my ( $BORLAND, $GCC, $DLLTOOL ) = _identify_compiler_environment( \%Config );
36 sub _identify_compiler_environment {
39 my $BORLAND = $config->{cc} =~ /^bcc/i ? 1 : 0;
40 my $GCC = $config->{cc} =~ /\bgcc\b/i ? 1 : 0;
41 my $DLLTOOL = $config->{dlltool} || 'dlltool';
43 return ( $BORLAND, $GCC, $DLLTOOL );
47 =head2 Overridden methods
56 my($self,%attribs) = @_;
58 my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
59 my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
60 my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
61 my($imports) = $attribs{IMPORTS} || $self->{IMPORTS} || {};
64 if (not $self->{SKIPHASH}{'dynamic'}) {
66 $self->{BASEEXT}.def: Makefile.PL
68 q! $(PERLRUN) -MExtUtils::Mksymlists \\
69 -e "Mksymlists('NAME'=>\"!, $self->{NAME},
70 q!\", 'DLBASE' => '!,$self->{DLBASE},
71 # The above two lines quoted differently to work around
72 # a bug in the 4DOS/4NT command line interpreter. The visible
73 # result of the bug was files named q('extension_name',) *with the
74 # single quotes and the comma* in the extension build directories.
75 q!', 'DL_FUNCS' => !,neatvalue($funcs),
76 q!, 'FUNCLIST' => !,neatvalue($funclist),
77 q!, 'IMPORTS' => !,neatvalue($imports),
78 q!, 'DL_VARS' => !, neatvalue($vars), q!);"
84 =item replace_manpage_separator
86 Changes the path separator with .
90 sub replace_manpage_separator {
97 =item B<maybe_command>
99 Since Windows has nothing as simple as an executable bit, we check the
102 The PATHEXT env variable will be used to get a list of extensions that
103 might indicate a command, otherwise .com, .exe, .bat and .cmd will be
109 my($self,$file) = @_;
110 my @e = exists($ENV{'PATHEXT'})
111 ? split(/;/, $ENV{PATHEXT})
112 : qw(.com .exe .bat .cmd);
114 for (@e) { $e .= "\Q$_\E|" }
116 # see if file ends in one of the known extensions
117 if ($file =~ /($e)$/i) {
118 return $file if -e $file;
122 return "$file$_" if -e "$file$_";
129 =item B<init_DIRFILESEP>
131 Using \ for Windows, except for "gmake" where it is /.
135 sub init_DIRFILESEP {
138 # The ^ makes sure its not interpreted as an escape in nmake
139 $self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' :
140 $self->is_make_type('dmake') ? '\\\\' :
141 $self->is_make_type('gmake') ? '/'
147 Override some of the slower, portable commands with Windows specific ones.
154 $self->{NOOP} ||= 'rem';
155 $self->{DEV_NULL} ||= '> NUL';
157 $self->{FIXIN} ||= $self->{PERL_CORE} ?
158 "\$(PERLRUN) $self->{PERL_SRC}\\win32\\bin\\pl2bat.pl" :
161 $self->SUPER::init_tools;
163 # Setting SHELL from $Config{sh} can break dmake. Its ok without it.
164 delete $self->{SHELL};
172 Override the default link and compile tools.
174 LDLOADLIBS's default is changed to $Config{libs}.
176 Adjustments are made for Borland's quirks needing -L to come first.
183 $self->{LD} ||= 'link';
184 $self->{AR} ||= 'lib';
186 $self->SUPER::init_others;
188 $self->{LDLOADLIBS} ||= $Config{libs};
189 # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
191 my $libs = $self->{LDLOADLIBS};
193 while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
194 $libpath .= ' ' if length $libpath;
197 $self->{LDLOADLIBS} = $libs;
198 $self->{LDDLFLAGS} ||= $Config{lddlflags};
199 $self->{LDDLFLAGS} .= " $libpath";
208 Add MM_Win32_VERSION.
210 =item platform_constants
217 $self->{MM_Win32_VERSION} = $VERSION;
222 sub platform_constants {
226 foreach my $macro (qw(MM_Win32_VERSION))
228 next unless defined $self->{$macro};
229 $make_frag .= "$macro = $self->{$macro}\n";
237 Set SHELL to $ENV{COMSPEC} only if make is type 'gmake'.
243 return '' unless $self->is_make_type('gmake');
244 "\nSHELL = $ENV{COMSPEC}\n";
249 Add MAXLINELENGTH for dmake before all the constants are output.
256 my $make_text = $self->SUPER::constants;
257 return $make_text unless $self->is_make_type('dmake');
259 # dmake won't read any single "line" (even those with escaped newlines)
260 # larger than a certain size which can be as small as 8k. PM_TO_BLIB
261 # on large modules like DateTime::TimeZone can create lines over 32k.
262 # So we'll crank it up to a <ironic>WHOPPING</ironic> 64k.
264 # This has to come here before all the constants and not in
265 # platform_constants which is after constants.
266 my $size = $self->{MAXLINELENGTH} || 800000;
268 # Get dmake to read long commands like PM_TO_BLIB
269 MAXLINELENGTH = $size
273 return $prefix . $make_text;
277 =item special_targets
279 Add .USESHELL target for dmake.
283 sub special_targets {
286 my $make_frag = $self->SUPER::special_targets;
288 $make_frag .= <<'MAKE_FRAG' if $self->is_make_type('dmake');
298 Changes how to run the linker.
300 The rest is duplicate code from MM_Unix. Should move the linker code
307 return '' unless $self->has_link_code;
311 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
315 # If this extension has its own library (eg SDBM_File)
316 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
317 push @m, <<'MAKE_FRAG' if $self->{MYEXTLIB};
322 q{ $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
323 : ($GCC ? '-ru $@ $(OBJECT)'
324 : '-out:$@ $(OBJECT)')).q{
325 $(CHMOD) $(PERM_RWX) $@
326 $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
329 # Old mechanism - still available:
330 push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
331 $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
340 Complicated stuff for Win32 that I don't understand. :(
345 my($self, %attribs) = @_;
346 return '' unless $self->needs_linking(); #might be because of a subdir
348 return '' unless $self->has_link_code;
350 my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
351 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
352 my($ldfrom) = '$(LDFROM)';
356 # This section creates the dynamically loadable $(INST_DYNAMIC)
357 # from $(OBJECT) and possibly $(MYEXTLIB).
358 OTHERLDFLAGS = '.$otherldflags.'
359 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
361 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVEDEP) $(INST_DYNAMIC_DEP)
365 q{ }.$DLLTOOL.q{ --def $(EXPORT_LIST) --output-exp dll.exp
366 $(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) dll.exp
367 }.$DLLTOOL.q{ --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
368 $(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) dll.exp });
371 q{ $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
372 .($self->is_make_type('dmake')
373 ? q{"$(PERL_ARCHIVE:s,/,\,)" $(LDLOADLIBS:s,/,\,) }
374 .q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
375 : q{"$(subst /,\,$(PERL_ARCHIVE))" $(subst /,\,$(LDLOADLIBS)) }
376 .q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
380 q{ $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
381 .q{$(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -def:$(EXPORT_LIST)});
383 # Embed the manifest file if it exists
385 if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
386 if exist $@.manifest del $@.manifest});
389 $(CHMOD) $(PERM_RWX) $@
395 =item extra_clean_files
397 Clean out some extra dll.{base,exp} files which might be generated by
398 gcc. Otherwise, take out all *.pdb files.
402 sub extra_clean_files {
405 return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
415 $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}";
416 $self->{PERL_ARCHIVEDEP} = "\$(PERL_INCDEP)\\$Config{libperl}";
417 $self->{PERL_ARCHIVE_AFTER} = '';
418 $self->{EXPORT_LIST} = '$(BASEEXT).def';
424 Checks for the perl program under several common perl extensions.
429 my($self,$file) = @_;
430 return $file if -r $file && -f _;
431 return "$file.pl" if -r "$file.pl" && -f _;
432 return "$file.plx" if -r "$file.plx" && -f _;
433 return "$file.bat" if -r "$file.bat" && -f _;
439 1; # with Win32::GetShortPathName
447 my ($self, $arg) = @_;
448 if ($arg =~ / / and not $self->is_make_type('gmake')) {
450 $arg = Win32::GetShortPathName($arg);
451 die <<EOF if not defined $arg or $arg =~ / /;
452 Tried to use make dependency with space for non-GNU make:
454 Fallback to short pathname failed.
458 return $self->SUPER::quote_dep($arg);
463 This target is stubbed out. Not sure why.
474 All we send is -nologo to nmake to prevent it from printing its damned
481 return "PASTHRU = " . ($self->is_make_type('nmake') ? "-nologo" : "");
485 =item arch_check (override)
487 Normalize all arguments for consistency of comparison.
494 # Win32 is an XS module, minperl won't have it.
495 # arch_check() is not critical, so just fake it.
496 return 1 unless $self->can_load_xs;
497 return $self->SUPER::arch_check( map { $self->_normalize_path_name($_) } @_);
500 sub _normalize_path_name {
505 my $short = Win32::GetShortPathName($file);
506 return defined $short ? lc $short : lc $file;
512 These are based on what command.com does on Win98. They may be wrong
513 for other Windows shells, I don't know.
518 my($self, $cmd, $switches) = @_;
519 $switches = [] unless defined $switches;
521 # Strip leading and trailing newlines
525 $cmd = $self->quote_literal($cmd);
526 $cmd = $self->escape_newlines($cmd);
528 $switches = join ' ', @$switches;
530 return qq{\$(ABSPERLRUN) $switches -e $cmd --};
535 my($self, $text, $opts) = @_;
536 $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
538 # See: http://www.autohotkey.net/~deleyd/parameters/parameters.htm#CPP
540 # Apply the Microsoft C/C++ parsing rules
541 $text =~ s{\\\\"}{\\\\\\\\\\"}g; # \\" -> \\\\\"
542 $text =~ s{(?<!\\)\\"}{\\\\\\"}g; # \" -> \\\"
543 $text =~ s{(?<!\\)"}{\\"}g; # " -> \"
544 $text = qq{"$text"} if $text =~ /[ \t]/;
546 # Apply the Command Prompt parsing rules (cmd.exe)
547 my @text = split /("[^"]*")/, $text;
548 # We should also escape parentheses, but it breaks one-liners containing
549 # $(MACRO)s in makefiles.
550 s{([<>|&^@!])}{^$1}g foreach grep { !/^"[^"]*"$/ } @text;
551 $text = join('', @text);
553 # dmake expands {{ to { and }} to }.
554 if( $self->is_make_type('dmake') ) {
559 $text = $opts->{allow_variables}
560 ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
566 sub escape_newlines {
567 my($self, $text) = @_;
570 $text =~ s{\n}{\\\n}g;
578 dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
589 my($self, $dir, @cmds) = @_;
591 return $self->SUPER::cd($dir, @cmds) unless $self->is_make_type('nmake');
593 my $cmd = join "\n\t", map "$_", @cmds;
595 my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir));
597 # No leading tab and no trailing newline makes for easier embedding.
598 my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs;
612 nmake 1.50 limits command length to 2048 characters.
619 return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
636 Defines the PERLDLL symbol if we are configured for static building since all
637 code destined for the perl5xx.dll must be compiled with the PERLDLL symbol
643 my($self,$libperl)=@_;
644 return $self->{CFLAGS} if $self->{CFLAGS};
645 return '' unless $self->needs_linking();
647 my $base = $self->SUPER::cflags($libperl);
648 foreach (split /\n/, $base) {
649 /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2;
651 $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static');
653 return $self->{CFLAGS} = qq{
654 CCFLAGS = $self->{CCFLAGS}
655 OPTIMIZE = $self->{OPTIMIZE}
656 PERLTYPE = $self->{PERLTYPE}