xref: /openbsd-src/gnu/usr.bin/perl/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Win32.pm (revision e068048151d29f2562a32185e21a8ba885482260)
1b39c5158Smillertpackage ExtUtils::MM_Win32;
2b39c5158Smillert
3b39c5158Smillertuse strict;
4eac174f2Safresh1use warnings;
5b39c5158Smillert
6b39c5158Smillert=head1 NAME
7b39c5158Smillert
8b39c5158SmillertExtUtils::MM_Win32 - methods to override UN*X behaviour in ExtUtils::MakeMaker
9b39c5158Smillert
10b39c5158Smillert=head1 SYNOPSIS
11b39c5158Smillert
12b39c5158Smillert use ExtUtils::MM_Win32; # Done internally by ExtUtils::MakeMaker if needed
13b39c5158Smillert
14b39c5158Smillert=head1 DESCRIPTION
15b39c5158Smillert
1656d68f1eSafresh1See L<ExtUtils::MM_Unix> for a documentation of the methods provided
17b39c5158Smillertthere. This package overrides the implementation of these methods, not
18b39c5158Smillertthe semantics.
19b39c5158Smillert
20b39c5158Smillert=cut
21b39c5158Smillert
22b39c5158Smillertuse ExtUtils::MakeMaker::Config;
23b39c5158Smillertuse File::Basename;
24b39c5158Smillertuse File::Spec;
259f11ffb7Safresh1use ExtUtils::MakeMaker qw(neatvalue _sprintf562);
26b39c5158Smillert
27b39c5158Smillertrequire ExtUtils::MM_Any;
28b39c5158Smillertrequire ExtUtils::MM_Unix;
29b39c5158Smillertour @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
30*e0680481Safresh1our $VERSION = '7.70';
3156d68f1eSafresh1$VERSION =~ tr/_//d;
32b39c5158Smillert
33b39c5158Smillert$ENV{EMXSHELL} = 'sh'; # to run `commands`
34b39c5158Smillert
359f11ffb7Safresh1my ( $BORLAND, $GCC, $MSVC ) = _identify_compiler_environment( \%Config );
36898184e3Ssthen
37898184e3Ssthensub _identify_compiler_environment {
38898184e3Ssthen	my ( $config ) = @_;
39898184e3Ssthen
409f11ffb7Safresh1	my $BORLAND = $config->{cc} =~ /\bbcc/i ? 1 : 0;
41898184e3Ssthen	my $GCC     = $config->{cc} =~ /\bgcc\b/i ? 1 : 0;
429f11ffb7Safresh1	my $MSVC    = $config->{cc} =~ /\b(?:cl|icl)/i ? 1 : 0; # MSVC can come as clarm.exe, icl=Intel C
43898184e3Ssthen
449f11ffb7Safresh1	return ( $BORLAND, $GCC, $MSVC );
45898184e3Ssthen}
46b39c5158Smillert
47b39c5158Smillert
48b39c5158Smillert=head2 Overridden methods
49b39c5158Smillert
50b39c5158Smillert=over 4
51b39c5158Smillert
52b39c5158Smillert=item B<dlsyms>
53b39c5158Smillert
54b39c5158Smillert=cut
55b39c5158Smillert
56b39c5158Smillertsub dlsyms {
57b39c5158Smillert    my($self,%attribs) = @_;
589f11ffb7Safresh1    return '' if $self->{SKIPHASH}{'dynamic'};
599f11ffb7Safresh1    $self->xs_dlsyms_iterator(\%attribs);
60b39c5158Smillert}
619f11ffb7Safresh1
629f11ffb7Safresh1=item xs_dlsyms_ext
639f11ffb7Safresh1
649f11ffb7Safresh1On Win32, is C<.def>.
659f11ffb7Safresh1
669f11ffb7Safresh1=cut
679f11ffb7Safresh1
689f11ffb7Safresh1sub xs_dlsyms_ext {
699f11ffb7Safresh1    '.def';
70b39c5158Smillert}
71b39c5158Smillert
72b39c5158Smillert=item replace_manpage_separator
73b39c5158Smillert
74b39c5158SmillertChanges the path separator with .
75b39c5158Smillert
76b39c5158Smillert=cut
77b39c5158Smillert
78b39c5158Smillertsub replace_manpage_separator {
79b39c5158Smillert    my($self,$man) = @_;
8056d68f1eSafresh1    $man =~ s,[/\\]+,.,g;
81b39c5158Smillert    $man;
82b39c5158Smillert}
83b39c5158Smillert
84b39c5158Smillert
85b39c5158Smillert=item B<maybe_command>
86b39c5158Smillert
87b39c5158SmillertSince Windows has nothing as simple as an executable bit, we check the
88b39c5158Smillertfile extension.
89b39c5158Smillert
90b39c5158SmillertThe PATHEXT env variable will be used to get a list of extensions that
91b39c5158Smillertmight indicate a command, otherwise .com, .exe, .bat and .cmd will be
92b39c5158Smillertused by default.
93b39c5158Smillert
94b39c5158Smillert=cut
95b39c5158Smillert
96b39c5158Smillertsub maybe_command {
97b39c5158Smillert    my($self,$file) = @_;
98b39c5158Smillert    my @e = exists($ENV{'PATHEXT'})
99b39c5158Smillert          ? split(/;/, $ENV{PATHEXT})
100b39c5158Smillert	  : qw(.com .exe .bat .cmd);
101b39c5158Smillert    my $e = '';
102b39c5158Smillert    for (@e) { $e .= "\Q$_\E|" }
103b39c5158Smillert    chop $e;
104b39c5158Smillert    # see if file ends in one of the known extensions
105b39c5158Smillert    if ($file =~ /($e)$/i) {
106b39c5158Smillert	return $file if -e $file;
107b39c5158Smillert    }
108b39c5158Smillert    else {
109b39c5158Smillert	for (@e) {
110b39c5158Smillert	    return "$file$_" if -e "$file$_";
111b39c5158Smillert	}
112b39c5158Smillert    }
113b39c5158Smillert    return;
114b39c5158Smillert}
115b39c5158Smillert
116b39c5158Smillert
117b39c5158Smillert=item B<init_DIRFILESEP>
118b39c5158Smillert
119b8851fccSafresh1Using \ for Windows, except for "gmake" where it is /.
120b39c5158Smillert
121b39c5158Smillert=cut
122b39c5158Smillert
123b39c5158Smillertsub init_DIRFILESEP {
124b39c5158Smillert    my($self) = shift;
125b39c5158Smillert
126b39c5158Smillert    # The ^ makes sure its not interpreted as an escape in nmake
127b39c5158Smillert    $self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' :
128b8851fccSafresh1                          $self->is_make_type('dmake') ? '\\\\' :
129b8851fccSafresh1                          $self->is_make_type('gmake') ? '/'
130b39c5158Smillert                                                       : '\\';
131b39c5158Smillert}
132b39c5158Smillert
133898184e3Ssthen=item init_tools
134b39c5158Smillert
135898184e3SsthenOverride some of the slower, portable commands with Windows specific ones.
136b39c5158Smillert
137b39c5158Smillert=cut
138b39c5158Smillert
139898184e3Ssthensub init_tools {
140b39c5158Smillert    my ($self) = @_;
141b39c5158Smillert
142b39c5158Smillert    $self->{NOOP}     ||= 'rem';
143b39c5158Smillert    $self->{DEV_NULL} ||= '> NUL';
144b39c5158Smillert
145b39c5158Smillert    $self->{FIXIN}    ||= $self->{PERL_CORE} ?
14656d68f1eSafresh1      "\$(PERLRUN) -I$self->{PERL_SRC}\\cpan\\ExtUtils-PL2Bat\\lib $self->{PERL_SRC}\\win32\\bin\\pl2bat.pl" :
147b39c5158Smillert      'pl2bat.bat';
148b39c5158Smillert
149898184e3Ssthen    $self->SUPER::init_tools;
150898184e3Ssthen
151898184e3Ssthen    # Setting SHELL from $Config{sh} can break dmake.  Its ok without it.
152898184e3Ssthen    delete $self->{SHELL};
153898184e3Ssthen
154898184e3Ssthen    return;
155898184e3Ssthen}
156898184e3Ssthen
157898184e3Ssthen
158898184e3Ssthen=item init_others
159898184e3Ssthen
160898184e3SsthenOverride the default link and compile tools.
161898184e3Ssthen
162898184e3SsthenLDLOADLIBS's default is changed to $Config{libs}.
163898184e3Ssthen
164898184e3SsthenAdjustments are made for Borland's quirks needing -L to come first.
165898184e3Ssthen
166898184e3Ssthen=cut
167898184e3Ssthen
168898184e3Ssthensub init_others {
169898184e3Ssthen    my $self = shift;
170898184e3Ssthen
171b39c5158Smillert    $self->{LD}     ||= 'link';
172b39c5158Smillert    $self->{AR}     ||= 'lib';
173b39c5158Smillert
174b39c5158Smillert    $self->SUPER::init_others;
175b39c5158Smillert
176b39c5158Smillert    $self->{LDLOADLIBS} ||= $Config{libs};
177b39c5158Smillert    # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
178b39c5158Smillert    if ($BORLAND) {
179b39c5158Smillert        my $libs = $self->{LDLOADLIBS};
180b39c5158Smillert        my $libpath = '';
181b39c5158Smillert        while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
182b39c5158Smillert            $libpath .= ' ' if length $libpath;
183b39c5158Smillert            $libpath .= $1;
184b39c5158Smillert        }
185b39c5158Smillert        $self->{LDLOADLIBS} = $libs;
186b39c5158Smillert        $self->{LDDLFLAGS} ||= $Config{lddlflags};
187b39c5158Smillert        $self->{LDDLFLAGS} .= " $libpath";
188b39c5158Smillert    }
189b39c5158Smillert
190898184e3Ssthen    return;
191b39c5158Smillert}
192b39c5158Smillert
193b39c5158Smillert
194b39c5158Smillert=item init_platform
195b39c5158Smillert
196b39c5158SmillertAdd MM_Win32_VERSION.
197b39c5158Smillert
198b39c5158Smillert=item platform_constants
199b39c5158Smillert
200b39c5158Smillert=cut
201b39c5158Smillert
202b39c5158Smillertsub init_platform {
203b39c5158Smillert    my($self) = shift;
204b39c5158Smillert
205b39c5158Smillert    $self->{MM_Win32_VERSION} = $VERSION;
206898184e3Ssthen
207898184e3Ssthen    return;
208b39c5158Smillert}
209b39c5158Smillert
210b39c5158Smillertsub platform_constants {
211b39c5158Smillert    my($self) = shift;
212b39c5158Smillert    my $make_frag = '';
213b39c5158Smillert
214b39c5158Smillert    foreach my $macro (qw(MM_Win32_VERSION))
215b39c5158Smillert    {
216b39c5158Smillert        next unless defined $self->{$macro};
217b39c5158Smillert        $make_frag .= "$macro = $self->{$macro}\n";
218b39c5158Smillert    }
219b39c5158Smillert
220b39c5158Smillert    return $make_frag;
221b39c5158Smillert}
222b39c5158Smillert
223b8851fccSafresh1=item specify_shell
224b8851fccSafresh1
225b8851fccSafresh1Set SHELL to $ENV{COMSPEC} only if make is type 'gmake'.
226b8851fccSafresh1
227b8851fccSafresh1=cut
228b8851fccSafresh1
229b8851fccSafresh1sub specify_shell {
230b8851fccSafresh1    my $self = shift;
231b8851fccSafresh1    return '' unless $self->is_make_type('gmake');
232b8851fccSafresh1    "\nSHELL = $ENV{COMSPEC}\n";
233b8851fccSafresh1}
234b39c5158Smillert
235898184e3Ssthen=item constants
236898184e3Ssthen
237898184e3SsthenAdd MAXLINELENGTH for dmake before all the constants are output.
238898184e3Ssthen
239898184e3Ssthen=cut
240898184e3Ssthen
241898184e3Ssthensub constants {
242898184e3Ssthen    my $self = shift;
243898184e3Ssthen
244898184e3Ssthen    my $make_text = $self->SUPER::constants;
245898184e3Ssthen    return $make_text unless $self->is_make_type('dmake');
246898184e3Ssthen
247898184e3Ssthen    # dmake won't read any single "line" (even those with escaped newlines)
248898184e3Ssthen    # larger than a certain size which can be as small as 8k.  PM_TO_BLIB
249898184e3Ssthen    # on large modules like DateTime::TimeZone can create lines over 32k.
250898184e3Ssthen    # So we'll crank it up to a <ironic>WHOPPING</ironic> 64k.
251898184e3Ssthen    #
252898184e3Ssthen    # This has to come here before all the constants and not in
253898184e3Ssthen    # platform_constants which is after constants.
2546fb12b70Safresh1    my $size = $self->{MAXLINELENGTH} || 800000;
255898184e3Ssthen    my $prefix = qq{
256898184e3Ssthen# Get dmake to read long commands like PM_TO_BLIB
257898184e3SsthenMAXLINELENGTH = $size
258898184e3Ssthen
259898184e3Ssthen};
260898184e3Ssthen
261898184e3Ssthen    return $prefix . $make_text;
262898184e3Ssthen}
263898184e3Ssthen
264898184e3Ssthen
265b39c5158Smillert=item special_targets
266b39c5158Smillert
267b39c5158SmillertAdd .USESHELL target for dmake.
268b39c5158Smillert
269b39c5158Smillert=cut
270b39c5158Smillert
271b39c5158Smillertsub special_targets {
272b39c5158Smillert    my($self) = @_;
273b39c5158Smillert
274b39c5158Smillert    my $make_frag = $self->SUPER::special_targets;
275b39c5158Smillert
276b39c5158Smillert    $make_frag .= <<'MAKE_FRAG' if $self->is_make_type('dmake');
277b39c5158Smillert.USESHELL :
278b39c5158SmillertMAKE_FRAG
279b39c5158Smillert
280b39c5158Smillert    return $make_frag;
281b39c5158Smillert}
282b39c5158Smillert
2839f11ffb7Safresh1=item static_lib_pure_cmd
284b39c5158Smillert
2859f11ffb7Safresh1Defines how to run the archive utility
286b39c5158Smillert
287b39c5158Smillert=cut
288b39c5158Smillert
2899f11ffb7Safresh1sub static_lib_pure_cmd {
2909f11ffb7Safresh1    my ($self, $from) = @_;
2919f11ffb7Safresh1    $from =~ s/(\$\(\w+)(\))/$1:^"+"$2/g if $BORLAND;
2929f11ffb7Safresh1    sprintf qq{\t\$(AR) %s\n}, ($BORLAND ? '$@ ' . $from
2939f11ffb7Safresh1                          : ($GCC ? '-ru $@ ' . $from
2949f11ffb7Safresh1                                  : '-out:$@ ' . $from));
295b39c5158Smillert}
296b39c5158Smillert
297b39c5158Smillert=item dynamic_lib
298b39c5158Smillert
2999f11ffb7Safresh1Methods are overridden here: not dynamic_lib itself, but the utility
3009f11ffb7Safresh1ones that do the OS-specific work.
301b39c5158Smillert
302b39c5158Smillert=cut
303b39c5158Smillert
3049f11ffb7Safresh1sub xs_make_dynamic_lib {
3059f11ffb7Safresh1    my ($self, $attribs, $from, $to, $todir, $ldfrom, $exportlist) = @_;
3069f11ffb7Safresh1    my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(INST_DYNAMIC_DEP)'."\n", $to, $from, $todir, $exportlist;
307b39c5158Smillert    if ($GCC) {
3089f11ffb7Safresh1      # per https://rt.cpan.org/Ticket/Display.html?id=78395 no longer
3099f11ffb7Safresh1      # uses dlltool - relies on post 2002 MinGW
3109f11ffb7Safresh1      #                             1            2
3119f11ffb7Safresh1      push @m, _sprintf562 <<'EOF', $exportlist, $ldfrom;
3129f11ffb7Safresh1	$(LD) %1$s -o $@ $(LDDLFLAGS) %2$s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -Wl,--enable-auto-image-base
3139f11ffb7Safresh1EOF
314b39c5158Smillert    } elsif ($BORLAND) {
3159f11ffb7Safresh1      my $ldargs = $self->is_make_type('dmake')
3169f11ffb7Safresh1          ? q{"$(PERL_ARCHIVE:s,/,\,)" $(LDLOADLIBS:s,/,\,) $(MYEXTLIB:s,/,\,),}
3179f11ffb7Safresh1          : q{"$(subst /,\,$(PERL_ARCHIVE))" $(subst /,\,$(LDLOADLIBS)) $(subst /,\,$(MYEXTLIB)),};
3189f11ffb7Safresh1      my $subbed;
3199f11ffb7Safresh1      if ($exportlist eq '$(EXPORT_LIST)') {
3209f11ffb7Safresh1          $subbed = $self->is_make_type('dmake')
3219f11ffb7Safresh1              ? q{$(EXPORT_LIST:s,/,\,)}
3229f11ffb7Safresh1              : q{$(subst /,\,$(EXPORT_LIST))};
3239f11ffb7Safresh1      } else {
3249f11ffb7Safresh1            # in XSMULTI, exportlist is per-XS, so have to sub in perl not make
3259f11ffb7Safresh1          ($subbed = $exportlist) =~ s#/#\\#g;
3269f11ffb7Safresh1      }
3279f11ffb7Safresh1      push @m, sprintf <<'EOF', $ldfrom, $ldargs . $subbed;
3289f11ffb7Safresh1        $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) %s,$@,,%s,$(RESFILES)
3299f11ffb7Safresh1EOF
330b39c5158Smillert    } else {	# VC
3319f11ffb7Safresh1      push @m, sprintf <<'EOF', $ldfrom, $exportlist;
3329f11ffb7Safresh1	$(LD) -out:$@ $(LDDLFLAGS) %s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -def:%s
3339f11ffb7Safresh1EOF
334b39c5158Smillert      # Embed the manifest file if it exists
3359f11ffb7Safresh1      push(@m, q{	if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
336b39c5158Smillert	if exist $@.manifest del $@.manifest});
337b39c5158Smillert    }
3389f11ffb7Safresh1    push @m, "\n\t\$(CHMOD) \$(PERM_RWX) \$\@\n";
339b39c5158Smillert
3409f11ffb7Safresh1    join '', @m;
3419f11ffb7Safresh1}
3429f11ffb7Safresh1
3439f11ffb7Safresh1sub xs_dynamic_lib_macros {
3449f11ffb7Safresh1    my ($self, $attribs) = @_;
3459f11ffb7Safresh1    my $otherldflags = $attribs->{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
3469f11ffb7Safresh1    my $inst_dynamic_dep = $attribs->{INST_DYNAMIC_DEP} || "";
3479f11ffb7Safresh1    sprintf <<'EOF', $otherldflags, $inst_dynamic_dep;
3489f11ffb7Safresh1# This section creates the dynamically loadable objects from relevant
3499f11ffb7Safresh1# objects and possibly $(MYEXTLIB).
3509f11ffb7Safresh1OTHERLDFLAGS = %s
3519f11ffb7Safresh1INST_DYNAMIC_DEP = %s
3529f11ffb7Safresh1EOF
353b39c5158Smillert}
354b39c5158Smillert
355b39c5158Smillert=item extra_clean_files
356b39c5158Smillert
357b39c5158SmillertClean out some extra dll.{base,exp} files which might be generated by
358b39c5158Smillertgcc.  Otherwise, take out all *.pdb files.
359b39c5158Smillert
360b39c5158Smillert=cut
361b39c5158Smillert
362b39c5158Smillertsub extra_clean_files {
363b39c5158Smillert    my $self = shift;
364b39c5158Smillert
365b39c5158Smillert    return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
366b39c5158Smillert}
367b39c5158Smillert
368b39c5158Smillert=item init_linker
369b39c5158Smillert
370b39c5158Smillert=cut
371b39c5158Smillert
372b39c5158Smillertsub init_linker {
373b39c5158Smillert    my $self = shift;
374b39c5158Smillert
375b39c5158Smillert    $self->{PERL_ARCHIVE}       = "\$(PERL_INC)\\$Config{libperl}";
376b8851fccSafresh1    $self->{PERL_ARCHIVEDEP}    = "\$(PERL_INCDEP)\\$Config{libperl}";
377b39c5158Smillert    $self->{PERL_ARCHIVE_AFTER} = '';
378b39c5158Smillert    $self->{EXPORT_LIST}        = '$(BASEEXT).def';
379b39c5158Smillert}
380b39c5158Smillert
381b39c5158Smillert
382b39c5158Smillert=item perl_script
383b39c5158Smillert
384b39c5158SmillertChecks for the perl program under several common perl extensions.
385b39c5158Smillert
386b39c5158Smillert=cut
387b39c5158Smillert
388b39c5158Smillertsub perl_script {
389b39c5158Smillert    my($self,$file) = @_;
390b39c5158Smillert    return $file if -r $file && -f _;
391b39c5158Smillert    return "$file.pl"  if -r "$file.pl" && -f _;
392b39c5158Smillert    return "$file.plx" if -r "$file.plx" && -f _;
393b39c5158Smillert    return "$file.bat" if -r "$file.bat" && -f _;
394b39c5158Smillert    return;
395b39c5158Smillert}
396b39c5158Smillert
397b8851fccSafresh1sub can_dep_space {
398eac174f2Safresh1    my ($self) = @_;
399eac174f2Safresh1    return 0 unless $self->can_load_xs;
400eac174f2Safresh1    require Win32;
401eac174f2Safresh1    require File::Spec;
402eac174f2Safresh1    my ($vol, $dir) = File::Spec->splitpath($INC{'ExtUtils/MakeMaker.pm'});
403eac174f2Safresh1    # can_dep_space via GetShortPathName, if short paths are supported
404eac174f2Safresh1    my $canary = Win32::GetShortPathName(File::Spec->catpath($vol, $dir, 'MakeMaker.pm'));
405eac174f2Safresh1    (undef, undef, my $file) = File::Spec->splitpath($canary);
406eac174f2Safresh1    return (length $file > 11) ? 0 : 1;
407b8851fccSafresh1}
408b8851fccSafresh1
409b8851fccSafresh1=item quote_dep
410b8851fccSafresh1
411b8851fccSafresh1=cut
412b8851fccSafresh1
413b8851fccSafresh1sub quote_dep {
414b8851fccSafresh1    my ($self, $arg) = @_;
415b8851fccSafresh1    if ($arg =~ / / and not $self->is_make_type('gmake')) {
416b8851fccSafresh1        require Win32;
417b8851fccSafresh1        $arg = Win32::GetShortPathName($arg);
418b8851fccSafresh1        die <<EOF if not defined $arg or $arg =~ / /;
419b8851fccSafresh1Tried to use make dependency with space for non-GNU make:
420b8851fccSafresh1  '$arg'
421b8851fccSafresh1Fallback to short pathname failed.
422b8851fccSafresh1EOF
423b8851fccSafresh1        return $arg;
424b8851fccSafresh1    }
425b8851fccSafresh1    return $self->SUPER::quote_dep($arg);
426b8851fccSafresh1}
427b39c5158Smillert
428b39c5158Smillert
4299f11ffb7Safresh1=item xs_obj_opt
4309f11ffb7Safresh1
4319f11ffb7Safresh1Override to fixup -o flags for MSVC.
432b39c5158Smillert
433b39c5158Smillert=cut
434b39c5158Smillert
4359f11ffb7Safresh1sub xs_obj_opt {
4369f11ffb7Safresh1    my ($self, $output_file) = @_;
4379f11ffb7Safresh1    ($MSVC ? "/Fo" : "-o ") . $output_file;
438b39c5158Smillert}
439b39c5158Smillert
440b39c5158Smillert
441b39c5158Smillert=item pasthru
442b39c5158Smillert
443b39c5158SmillertAll we send is -nologo to nmake to prevent it from printing its damned
444b39c5158Smillertbanner.
445b39c5158Smillert
446b39c5158Smillert=cut
447b39c5158Smillert
448b39c5158Smillertsub pasthru {
449b39c5158Smillert    my($self) = shift;
4509f11ffb7Safresh1    my $old = $self->SUPER::pasthru;
4519f11ffb7Safresh1    return $old unless $self->is_make_type('nmake');
4529f11ffb7Safresh1    $old =~ s/(PASTHRU\s*=\s*)/$1 -nologo /;
4539f11ffb7Safresh1    $old;
454b39c5158Smillert}
455b39c5158Smillert
456b39c5158Smillert
457b39c5158Smillert=item arch_check (override)
458b39c5158Smillert
459b39c5158SmillertNormalize all arguments for consistency of comparison.
460b39c5158Smillert
461b39c5158Smillert=cut
462b39c5158Smillert
463b39c5158Smillertsub arch_check {
464b39c5158Smillert    my $self = shift;
465b39c5158Smillert
466b39c5158Smillert    # Win32 is an XS module, minperl won't have it.
467b39c5158Smillert    # arch_check() is not critical, so just fake it.
468b39c5158Smillert    return 1 unless $self->can_load_xs;
469b39c5158Smillert    return $self->SUPER::arch_check( map { $self->_normalize_path_name($_) } @_);
470b39c5158Smillert}
471b39c5158Smillert
472b39c5158Smillertsub _normalize_path_name {
473b39c5158Smillert    my $self = shift;
474b39c5158Smillert    my $file = shift;
475b39c5158Smillert
476b39c5158Smillert    require Win32;
477b39c5158Smillert    my $short = Win32::GetShortPathName($file);
478b39c5158Smillert    return defined $short ? lc $short : lc $file;
479b39c5158Smillert}
480b39c5158Smillert
481b39c5158Smillert
482b39c5158Smillert=item oneliner
483b39c5158Smillert
484b39c5158SmillertThese are based on what command.com does on Win98.  They may be wrong
485b39c5158Smillertfor other Windows shells, I don't know.
486b39c5158Smillert
487b39c5158Smillert=cut
488b39c5158Smillert
489b39c5158Smillertsub oneliner {
490b39c5158Smillert    my($self, $cmd, $switches) = @_;
491b39c5158Smillert    $switches = [] unless defined $switches;
492b39c5158Smillert
493b39c5158Smillert    # Strip leading and trailing newlines
494b39c5158Smillert    $cmd =~ s{^\n+}{};
495b39c5158Smillert    $cmd =~ s{\n+$}{};
496b39c5158Smillert
497b39c5158Smillert    $cmd = $self->quote_literal($cmd);
498b39c5158Smillert    $cmd = $self->escape_newlines($cmd);
499b39c5158Smillert
500b39c5158Smillert    $switches = join ' ', @$switches;
501b39c5158Smillert
502b39c5158Smillert    return qq{\$(ABSPERLRUN) $switches -e $cmd --};
503b39c5158Smillert}
504b39c5158Smillert
505b39c5158Smillert
506b39c5158Smillertsub quote_literal {
507898184e3Ssthen    my($self, $text, $opts) = @_;
508898184e3Ssthen    $opts->{allow_variables} = 1 unless defined $opts->{allow_variables};
509b39c5158Smillert
510898184e3Ssthen    # See: http://www.autohotkey.net/~deleyd/parameters/parameters.htm#CPP
511b39c5158Smillert
512898184e3Ssthen    # Apply the Microsoft C/C++ parsing rules
513898184e3Ssthen    $text =~ s{\\\\"}{\\\\\\\\\\"}g;  # \\" -> \\\\\"
514898184e3Ssthen    $text =~ s{(?<!\\)\\"}{\\\\\\"}g; # \"  -> \\\"
515898184e3Ssthen    $text =~ s{(?<!\\)"}{\\"}g;       # "   -> \"
51656d68f1eSafresh1    $text = qq{"$text"} if $text =~ /[ \t#]/; # hash because gmake 4.2.1
517898184e3Ssthen
518898184e3Ssthen    # Apply the Command Prompt parsing rules (cmd.exe)
519898184e3Ssthen    my @text = split /("[^"]*")/, $text;
520898184e3Ssthen    # We should also escape parentheses, but it breaks one-liners containing
521898184e3Ssthen    # $(MACRO)s in makefiles.
522898184e3Ssthen    s{([<>|&^@!])}{^$1}g foreach grep { !/^"[^"]*"$/ } @text;
523898184e3Ssthen    $text = join('', @text);
524898184e3Ssthen
525898184e3Ssthen    # dmake expands {{ to { and }} to }.
526b39c5158Smillert    if( $self->is_make_type('dmake') ) {
527b39c5158Smillert        $text =~ s/{/{{/g;
528898184e3Ssthen        $text =~ s/}/}}/g;
529b39c5158Smillert    }
530b39c5158Smillert
531898184e3Ssthen    $text = $opts->{allow_variables}
532898184e3Ssthen      ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text);
533898184e3Ssthen
534898184e3Ssthen    return $text;
535b39c5158Smillert}
536b39c5158Smillert
537b39c5158Smillert
538b39c5158Smillertsub escape_newlines {
539b39c5158Smillert    my($self, $text) = @_;
540b39c5158Smillert
541b39c5158Smillert    # Escape newlines
542b39c5158Smillert    $text =~ s{\n}{\\\n}g;
543b39c5158Smillert
544b39c5158Smillert    return $text;
545b39c5158Smillert}
546b39c5158Smillert
547b39c5158Smillert
548b39c5158Smillert=item cd
549b39c5158Smillert
550b39c5158Smillertdmake can handle Unix style cd'ing but nmake (at least 1.5) cannot.  It
551b39c5158Smillertwants:
552b39c5158Smillert
553b39c5158Smillert    cd dir1\dir2
554b39c5158Smillert    command
555b39c5158Smillert    another_command
556b39c5158Smillert    cd ..\..
557b39c5158Smillert
558b39c5158Smillert=cut
559b39c5158Smillert
560b39c5158Smillertsub cd {
561b39c5158Smillert    my($self, $dir, @cmds) = @_;
562b39c5158Smillert
563b39c5158Smillert    return $self->SUPER::cd($dir, @cmds) unless $self->is_make_type('nmake');
564b39c5158Smillert
565b39c5158Smillert    my $cmd = join "\n\t", map "$_", @cmds;
566b39c5158Smillert
567b39c5158Smillert    my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir));
568b39c5158Smillert
569b39c5158Smillert    # No leading tab and no trailing newline makes for easier embedding.
570b39c5158Smillert    my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs;
571b39c5158Smillertcd %s
572b39c5158Smillert	%s
573b39c5158Smillert	cd %s
574b39c5158SmillertMAKE_FRAG
575b39c5158Smillert
576b39c5158Smillert    chomp $make_frag;
577b39c5158Smillert
578b39c5158Smillert    return $make_frag;
579b39c5158Smillert}
580b39c5158Smillert
581b39c5158Smillert
582b39c5158Smillert=item max_exec_len
583b39c5158Smillert
584b39c5158Smillertnmake 1.50 limits command length to 2048 characters.
585b39c5158Smillert
586b39c5158Smillert=cut
587b39c5158Smillert
588b39c5158Smillertsub max_exec_len {
589b39c5158Smillert    my $self = shift;
590b39c5158Smillert
591b39c5158Smillert    return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
592b39c5158Smillert}
593b39c5158Smillert
594b39c5158Smillert
595b39c5158Smillert=item os_flavor
596b39c5158Smillert
597b39c5158SmillertWindows is Win32.
598b39c5158Smillert
599b39c5158Smillert=cut
600b39c5158Smillert
601b39c5158Smillertsub os_flavor {
602b39c5158Smillert    return('Win32');
603b39c5158Smillert}
604b39c5158Smillert
60556d68f1eSafresh1=item dbgoutflag
60656d68f1eSafresh1
60756d68f1eSafresh1Returns a CC flag that tells the CC to emit a separate debugging symbol file
60856d68f1eSafresh1when compiling an object file.
60956d68f1eSafresh1
61056d68f1eSafresh1=cut
61156d68f1eSafresh1
61256d68f1eSafresh1sub dbgoutflag {
61356d68f1eSafresh1    $MSVC ? '-Fd$(*).pdb' : '';
61456d68f1eSafresh1}
615b39c5158Smillert
616b39c5158Smillert=item cflags
617b39c5158Smillert
618b39c5158SmillertDefines the PERLDLL symbol if we are configured for static building since all
619b39c5158Smillertcode destined for the perl5xx.dll must be compiled with the PERLDLL symbol
620b39c5158Smillertdefined.
621b39c5158Smillert
622b39c5158Smillert=cut
623b39c5158Smillert
624b39c5158Smillertsub cflags {
625b39c5158Smillert    my($self,$libperl)=@_;
626b39c5158Smillert    return $self->{CFLAGS} if $self->{CFLAGS};
627b39c5158Smillert    return '' unless $self->needs_linking();
628b39c5158Smillert
629b39c5158Smillert    my $base = $self->SUPER::cflags($libperl);
630b39c5158Smillert    foreach (split /\n/, $base) {
631b39c5158Smillert        /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2;
632b39c5158Smillert    };
633b39c5158Smillert    $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static');
634b39c5158Smillert
635b39c5158Smillert    return $self->{CFLAGS} = qq{
636b39c5158SmillertCCFLAGS = $self->{CCFLAGS}
637b39c5158SmillertOPTIMIZE = $self->{OPTIMIZE}
638b39c5158SmillertPERLTYPE = $self->{PERLTYPE}
639b39c5158Smillert};
640b39c5158Smillert
641b39c5158Smillert}
642b39c5158Smillert
6439f11ffb7Safresh1=item make_type
6449f11ffb7Safresh1
6459f11ffb7Safresh1Returns a suitable string describing the type of makefile being written.
6469f11ffb7Safresh1
6479f11ffb7Safresh1=cut
6489f11ffb7Safresh1
6499f11ffb7Safresh1sub make_type {
6509f11ffb7Safresh1    my ($self) = @_;
6519f11ffb7Safresh1    my $make = $self->make;
6529f11ffb7Safresh1    $make = +( File::Spec->splitpath( $make ) )[-1];
6539f11ffb7Safresh1    $make =~ s!\.exe$!!i;
6549f11ffb7Safresh1    if ( $make =~ m![^A-Z0-9]!i ) {
6559f11ffb7Safresh1      ($make) = grep { m!make!i } split m![^A-Z0-9]!i, $make;
6569f11ffb7Safresh1    }
6579f11ffb7Safresh1    return "$make-style";
6589f11ffb7Safresh1}
6599f11ffb7Safresh1
660b39c5158Smillert1;
661b39c5158Smillert__END__
662b39c5158Smillert
663b39c5158Smillert=back
664