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 L<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 _sprintf562);
27 require ExtUtils::MM_Any;
28 require ExtUtils::MM_Unix;
29 our @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
30 our $VERSION = '7.42';
33 $ENV{EMXSHELL} = 'sh'; # to run `commands`
35 my ( $BORLAND, $GCC, $MSVC ) = _identify_compiler_environment( \%Config );
37 sub _identify_compiler_environment {
40 my $BORLAND = $config->{cc} =~ /\bbcc/i ? 1 : 0;
41 my $GCC = $config->{cc} =~ /\bgcc\b/i ? 1 : 0;
42 my $MSVC = $config->{cc} =~ /\b(?:cl|icl)/i ? 1 : 0; # MSVC can come as clarm.exe, icl=Intel C
44 return ( $BORLAND, $GCC, $MSVC );
48 =head2 Overridden methods
57 my($self,%attribs) = @_;
58 return '' if $self->{SKIPHASH}{'dynamic'};
59 $self->xs_dlsyms_iterator(\%attribs);
72 =item replace_manpage_separator
74 Changes the path separator with .
78 sub replace_manpage_separator {
85 =item B<maybe_command>
87 Since Windows has nothing as simple as an executable bit, we check the
90 The PATHEXT env variable will be used to get a list of extensions that
91 might indicate a command, otherwise .com, .exe, .bat and .cmd will be
98 my @e = exists($ENV{'PATHEXT'})
99 ? split(/;/, $ENV{PATHEXT})
100 : qw(.com .exe .bat .cmd);
102 for (@e) { $e .= "\Q$_\E|" }
104 # see if file ends in one of the known extensions
105 if ($file =~ /($e)$/i) {
106 return $file if -e $file;
110 return "$file$_" if -e "$file$_";
117 =item B<init_DIRFILESEP>
119 Using \ for Windows, except for "gmake" where it is /.
123 sub init_DIRFILESEP {
126 # The ^ makes sure its not interpreted as an escape in nmake
127 $self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' :
128 $self->is_make_type('dmake') ? '\\\\' :
129 $self->is_make_type('gmake') ? '/'
135 Override some of the slower, portable commands with Windows specific ones.
142 $self->{NOOP} ||= 'rem';
143 $self->{DEV_NULL} ||= '> NUL';
145 $self->{FIXIN} ||= $self->{PERL_CORE} ?
146 "\$(PERLRUN) -I$self->{PERL_SRC}\\cpan\\ExtUtils-PL2Bat\\lib $self->{PERL_SRC}\\win32\\bin\\pl2bat.pl" :
149 $self->SUPER::init_tools;
151 # Setting SHELL from $Config{sh} can break dmake. Its ok without it.
152 delete $self->{SHELL};
160 Override the default link and compile tools.
162 LDLOADLIBS's default is changed to $Config{libs}.
164 Adjustments are made for Borland's quirks needing -L to come first.
171 $self->{LD} ||= 'link';
172 $self->{AR} ||= 'lib';
174 $self->SUPER::init_others;
176 $self->{LDLOADLIBS} ||= $Config{libs};
177 # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
179 my $libs = $self->{LDLOADLIBS};
181 while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
182 $libpath .= ' ' if length $libpath;
185 $self->{LDLOADLIBS} = $libs;
186 $self->{LDDLFLAGS} ||= $Config{lddlflags};
187 $self->{LDDLFLAGS} .= " $libpath";
196 Add MM_Win32_VERSION.
198 =item platform_constants
205 $self->{MM_Win32_VERSION} = $VERSION;
210 sub platform_constants {
214 foreach my $macro (qw(MM_Win32_VERSION))
216 next unless defined $self->{$macro};
217 $make_frag .= "$macro = $self->{$macro}\n";
225 Set SHELL to $ENV{COMSPEC} only if make is type 'gmake'.
231 return '' unless $self->is_make_type('gmake');
232 "\nSHELL = $ENV{COMSPEC}\n";
237 Add MAXLINELENGTH for dmake before all the constants are output.
244 my $make_text = $self->SUPER::constants;
245 return $make_text unless $self->is_make_type('dmake');
247 # dmake won't read any single "line" (even those with escaped newlines)
248 # larger than a certain size which can be as small as 8k. PM_TO_BLIB
249 # on large modules like DateTime::TimeZone can create lines over 32k.
250 # So we'll crank it up to a <ironic>WHOPPING</ironic> 64k.
252 # This has to come here before all the constants and not in
253 # platform_constants which is after constants.
254 my $size = $self->{MAXLINELENGTH} || 800000;
256 # Get dmake to read long commands like PM_TO_BLIB
257 MAXLINELENGTH = $size
261 return $prefix . $make_text;
265 =item special_targets
267 Add .USESHELL target for dmake.
271 sub special_targets {
274 my $make_frag = $self->SUPER::special_targets;
276 $make_frag .= <<'MAKE_FRAG' if $self->is_make_type('dmake');
283 =item static_lib_pure_cmd
285 Defines how to run the archive utility
289 sub static_lib_pure_cmd {
290 my ($self, $from) = @_;
291 $from =~ s/(\$\(\w+)(\))/$1:^"+"$2/g if $BORLAND;
292 sprintf qq{\t\$(AR) %s\n}, ($BORLAND ? '$@ ' . $from
293 : ($GCC ? '-ru $@ ' . $from
294 : '-out:$@ ' . $from));
299 Methods are overridden here: not dynamic_lib itself, but the utility
300 ones that do the OS-specific work.
304 sub xs_make_dynamic_lib {
305 my ($self, $attribs, $from, $to, $todir, $ldfrom, $exportlist) = @_;
306 my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(INST_DYNAMIC_DEP)'."\n", $to, $from, $todir, $exportlist;
308 # per https://rt.cpan.org/Ticket/Display.html?id=78395 no longer
309 # uses dlltool - relies on post 2002 MinGW
311 push @m, _sprintf562 <<'EOF', $exportlist, $ldfrom;
312 $(LD) %1$s -o $@ $(LDDLFLAGS) %2$s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -Wl,--enable-auto-image-base
315 my $ldargs = $self->is_make_type('dmake')
316 ? q{"$(PERL_ARCHIVE:s,/,\,)" $(LDLOADLIBS:s,/,\,) $(MYEXTLIB:s,/,\,),}
317 : q{"$(subst /,\,$(PERL_ARCHIVE))" $(subst /,\,$(LDLOADLIBS)) $(subst /,\,$(MYEXTLIB)),};
319 if ($exportlist eq '$(EXPORT_LIST)') {
320 $subbed = $self->is_make_type('dmake')
321 ? q{$(EXPORT_LIST:s,/,\,)}
322 : q{$(subst /,\,$(EXPORT_LIST))};
324 # in XSMULTI, exportlist is per-XS, so have to sub in perl not make
325 ($subbed = $exportlist) =~ s#/#\\#g;
327 push @m, sprintf <<'EOF', $ldfrom, $ldargs . $subbed;
328 $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) %s,$@,,%s,$(RESFILES)
331 push @m, sprintf <<'EOF', $ldfrom, $exportlist;
332 $(LD) -out:$@ $(LDDLFLAGS) %s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -def:%s
334 # Embed the manifest file if it exists
335 push(@m, q{ if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
336 if exist $@.manifest del $@.manifest});
338 push @m, "\n\t\$(CHMOD) \$(PERM_RWX) \$\@\n";
343 sub xs_dynamic_lib_macros {
344 my ($self, $attribs) = @_;
345 my $otherldflags = $attribs->{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
346 my $inst_dynamic_dep = $attribs->{INST_DYNAMIC_DEP} || "";
347 sprintf <<'EOF', $otherldflags, $inst_dynamic_dep;
348 # This section creates the dynamically loadable objects from relevant
349 # objects and possibly $(MYEXTLIB).
351 INST_DYNAMIC_DEP = %s
355 =item extra_clean_files
357 Clean out some extra dll.{base,exp} files which might be generated by
358 gcc. Otherwise, take out all *.pdb files.
362 sub extra_clean_files {
365 return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
375 $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}";
376 $self->{PERL_ARCHIVEDEP} = "\$(PERL_INCDEP)\\$Config{libperl}";
377 $self->{PERL_ARCHIVE_AFTER} = '';
378 $self->{EXPORT_LIST} = '$(BASEEXT).def';
384 Checks for the perl program under several common perl extensions.
389 my($self,$file) = @_;
390 return $file if -r $file && -f _;
391 return "$file.pl" if -r "$file.pl" && -f _;
392 return "$file.plx" if -r "$file.plx" && -f _;
393 return "$file.bat" if -r "$file.bat" && -f _;
399 1; # with Win32::GetShortPathName
407 my ($self, $arg) = @_;
408 if ($arg =~ / / and not $self->is_make_type('gmake')) {
410 $arg = Win32::GetShortPathName($arg);
411 die <<EOF if not defined $arg or $arg =~ / /;
412 Tried to use make dependency with space for non-GNU make:
414 Fallback to short pathname failed.
418 return $self->SUPER::quote_dep($arg);
424 Override to fixup -o flags for MSVC.
429 my ($self, $output_file) = @_;
430 ($MSVC ? "/Fo" : "-o ") . $output_file;
436 All we send is -nologo to nmake to prevent it from printing its damned
443 my $old = $self->SUPER::pasthru;
444 return $old unless $self->is_make_type('nmake');
445 $old =~ s/(PASTHRU\s*=\s*)/$1 -nologo /;
450 =item arch_check (override)
452 Normalize all arguments for consistency of comparison.
459 # Win32 is an XS module, minperl won't have it.
460 # arch_check() is not critical, so just fake it.
461 return 1 unless $self->can_load_xs;
462 return $self->SUPER::arch_check( map { $self->_normalize_path_name($_) } @_);
465 sub _normalize_path_name {
470 my $short = Win32::GetShortPathName($file);
471 return defined $short ? lc $short : lc $file;
477 These are based on what command.com does on Win98. They may be wrong
478 for other Windows shells, I don't know.
483 my($self, $cmd, $switches) = @_;
484 $switches = [] unless defined $switches;
486 # Strip leading and trailing newlines
490 $cmd = $self->quote_literal($cmd);
491 $cmd = $self->escape_newlines($cmd);
493 $switches = join ' ', @$switches;
495 return qq{\$(ABSPERLRUN) $switches -e $cmd --};
500 my($self, $text, $opts) = @_;
501 $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
503 # See: http://www.autohotkey.net/~deleyd/parameters/parameters.htm#CPP
505 # Apply the Microsoft C/C++ parsing rules
506 $text =~ s{\\\\"}{\\\\\\\\\\"}g; # \\" -> \\\\\"
507 $text =~ s{(?<!\\)\\"}{\\\\\\"}g; # \" -> \\\"
508 $text =~ s{(?<!\\)"}{\\"}g; # " -> \"
509 $text = qq{"$text"} if $text =~ /[ \t#]/; # hash because gmake 4.2.1
511 # Apply the Command Prompt parsing rules (cmd.exe)
512 my @text = split /("[^"]*")/, $text;
513 # We should also escape parentheses, but it breaks one-liners containing
514 # $(MACRO)s in makefiles.
515 s{([<>|&^@!])}{^$1}g foreach grep { !/^"[^"]*"$/ } @text;
516 $text = join('', @text);
518 # dmake expands {{ to { and }} to }.
519 if( $self->is_make_type('dmake') ) {
524 $text = $opts->{allow_variables}
525 ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
531 sub escape_newlines {
532 my($self, $text) = @_;
535 $text =~ s{\n}{\\\n}g;
543 dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
554 my($self, $dir, @cmds) = @_;
556 return $self->SUPER::cd($dir, @cmds) unless $self->is_make_type('nmake');
558 my $cmd = join "\n\t", map "$_", @cmds;
560 my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir));
562 # No leading tab and no trailing newline makes for easier embedding.
563 my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs;
577 nmake 1.50 limits command length to 2048 characters.
584 return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
600 Returns a CC flag that tells the CC to emit a separate debugging symbol file
601 when compiling an object file.
606 $MSVC ? '-Fd$(*).pdb' : '';
611 Defines the PERLDLL symbol if we are configured for static building since all
612 code destined for the perl5xx.dll must be compiled with the PERLDLL symbol
618 my($self,$libperl)=@_;
619 return $self->{CFLAGS} if $self->{CFLAGS};
620 return '' unless $self->needs_linking();
622 my $base = $self->SUPER::cflags($libperl);
623 foreach (split /\n/, $base) {
624 /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2;
626 $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static');
628 return $self->{CFLAGS} = qq{
629 CCFLAGS = $self->{CCFLAGS}
630 OPTIMIZE = $self->{OPTIMIZE}
631 PERLTYPE = $self->{PERLTYPE}
638 Returns a suitable string describing the type of makefile being written.
644 my $make = $self->make;
645 $make = +( File::Spec->splitpath( $make ) )[-1];
646 $make =~ s!\.exe$!!i;
647 if ( $make =~ m![^A-Z0-9]!i ) {
648 ($make) = grep { m!make!i } split m![^A-Z0-9]!i, $make;
650 return "$make-style";