| 1 | package ExtUtils::MM_Win32; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | ExtUtils::MM_Win32 - methods to override UN*X behaviour in ExtUtils::MakeMaker | ||
| 9 | |||
| 10 | =head1 SYNOPSIS | ||
| 11 | |||
| 12 | use ExtUtils::MM_Win32; # Done internally by ExtUtils::MakeMaker if needed | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | See ExtUtils::MM_Unix for a documentation of the methods provided | ||
| 17 | there. This package overrides the implementation of these methods, not | ||
| 18 | the semantics. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | use ExtUtils::MakeMaker::Config; | ||
| 23 | use File::Basename; | ||
| 24 | use File::Spec; | ||
| 25 | use ExtUtils::MakeMaker qw(neatvalue _sprintf562); | ||
| 26 | |||
| 27 | require ExtUtils::MM_Any; | ||
| 28 | require ExtUtils::MM_Unix; | ||
| 29 | our @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix ); | ||
| 30 | our $VERSION = '7.13_01'; | ||
| 31 | $VERSION = eval $VERSION; | ||
| 32 | |||
| 33 | $ENV{EMXSHELL} = 'sh'; # to run `commands` | ||
| 34 | |||
| 35 | my ( $BORLAND, $GCC, $MSVC, $DLLTOOL ) = _identify_compiler_environment( \%Config ); | ||
| 36 | |||
| 37 | sub _identify_compiler_environment { | ||
| 38 | my ( $config ) = @_; | ||
| 39 | |||
| 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 | ||
| 43 | my $DLLTOOL = $config->{dlltool} || 'dlltool'; | ||
| 44 | |||
| 45 | return ( $BORLAND, $GCC, $MSVC, $DLLTOOL ); | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | =head2 Overridden methods | ||
| 50 | |||
| 51 | =over 4 | ||
| 52 | |||
| 53 | =item B<dlsyms> | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub dlsyms { | ||
| 58 | my($self,%attribs) = @_; | ||
| 59 | return '' if $self->{SKIPHASH}{'dynamic'}; | ||
| 60 | $self->xs_dlsyms_iterator(\%attribs); | ||
| 61 | } | ||
| 62 | |||
| 63 | =item xs_dlsyms_ext | ||
| 64 | |||
| 65 | On Win32, is C<.def>. | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | sub xs_dlsyms_ext { | ||
| 70 | '.def'; | ||
| 71 | } | ||
| 72 | |||
| 73 | =item replace_manpage_separator | ||
| 74 | |||
| 75 | Changes the path separator with . | ||
| 76 | |||
| 77 | =cut | ||
| 78 | |||
| 79 | sub replace_manpage_separator { | ||
| 80 | my($self,$man) = @_; | ||
| 81 | $man =~ s,/+,.,g; | ||
| 82 | $man; | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | =item B<maybe_command> | ||
| 87 | |||
| 88 | Since Windows has nothing as simple as an executable bit, we check the | ||
| 89 | file extension. | ||
| 90 | |||
| 91 | The PATHEXT env variable will be used to get a list of extensions that | ||
| 92 | might indicate a command, otherwise .com, .exe, .bat and .cmd will be | ||
| 93 | used by default. | ||
| 94 | |||
| 95 | =cut | ||
| 96 | |||
| 97 | sub maybe_command { | ||
| 98 | my($self,$file) = @_; | ||
| 99 | my @e = exists($ENV{'PATHEXT'}) | ||
| 100 | ? split(/;/, $ENV{PATHEXT}) | ||
| 101 | : qw(.com .exe .bat .cmd); | ||
| 102 | my $e = ''; | ||
| 103 | for (@e) { $e .= "\Q$_\E|" } | ||
| 104 | chop $e; | ||
| 105 | # see if file ends in one of the known extensions | ||
| 106 | if ($file =~ /($e)$/i) { | ||
| 107 | return $file if -e $file; | ||
| 108 | } | ||
| 109 | else { | ||
| 110 | for (@e) { | ||
| 111 | return "$file$_" if -e "$file$_"; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | return; | ||
| 115 | } | ||
| 116 | |||
| 117 | |||
| 118 | =item B<init_DIRFILESEP> | ||
| 119 | |||
| 120 | Using \ for Windows, except for "gmake" where it is /. | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | sub init_DIRFILESEP { | ||
| 125 | my($self) = shift; | ||
| 126 | |||
| 127 | # The ^ makes sure its not interpreted as an escape in nmake | ||
| 128 | $self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' : | ||
| 129 | $self->is_make_type('dmake') ? '\\\\' : | ||
| 130 | $self->is_make_type('gmake') ? '/' | ||
| 131 | : '\\'; | ||
| 132 | } | ||
| 133 | |||
| 134 | =item init_tools | ||
| 135 | |||
| 136 | Override some of the slower, portable commands with Windows specific ones. | ||
| 137 | |||
| 138 | =cut | ||
| 139 | |||
| 140 | sub init_tools { | ||
| 141 | my ($self) = @_; | ||
| 142 | |||
| 143 | $self->{NOOP} ||= 'rem'; | ||
| 144 | $self->{DEV_NULL} ||= '> NUL'; | ||
| 145 | |||
| 146 | $self->{FIXIN} ||= $self->{PERL_CORE} ? | ||
| 147 | "\$(PERLRUN) $self->{PERL_SRC}\\win32\\bin\\pl2bat.pl" : | ||
| 148 | 'pl2bat.bat'; | ||
| 149 | |||
| 150 | $self->SUPER::init_tools; | ||
| 151 | |||
| 152 | # Setting SHELL from $Config{sh} can break dmake. Its ok without it. | ||
| 153 | delete $self->{SHELL}; | ||
| 154 | |||
| 155 | return; | ||
| 156 | } | ||
| 157 | |||
| 158 | |||
| 159 | =item init_others | ||
| 160 | |||
| 161 | Override the default link and compile tools. | ||
| 162 | |||
| 163 | LDLOADLIBS's default is changed to $Config{libs}. | ||
| 164 | |||
| 165 | Adjustments are made for Borland's quirks needing -L to come first. | ||
| 166 | |||
| 167 | =cut | ||
| 168 | |||
| 169 | sub init_others { | ||
| 170 | my $self = shift; | ||
| 171 | |||
| 172 | $self->{LD} ||= 'link'; | ||
| 173 | $self->{AR} ||= 'lib'; | ||
| 174 | |||
| 175 | $self->SUPER::init_others; | ||
| 176 | |||
| 177 | $self->{LDLOADLIBS} ||= $Config{libs}; | ||
| 178 | # -Lfoo must come first for Borland, so we put it in LDDLFLAGS | ||
| 179 | if ($BORLAND) { | ||
| 180 | my $libs = $self->{LDLOADLIBS}; | ||
| 181 | my $libpath = ''; | ||
| 182 | while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) { | ||
| 183 | $libpath .= ' ' if length $libpath; | ||
| 184 | $libpath .= $1; | ||
| 185 | } | ||
| 186 | $self->{LDLOADLIBS} = $libs; | ||
| 187 | $self->{LDDLFLAGS} ||= $Config{lddlflags}; | ||
| 188 | $self->{LDDLFLAGS} .= " $libpath"; | ||
| 189 | } | ||
| 190 | |||
| 191 | return; | ||
| 192 | } | ||
| 193 | |||
| 194 | |||
| 195 | =item init_platform | ||
| 196 | |||
| 197 | Add MM_Win32_VERSION. | ||
| 198 | |||
| 199 | =item platform_constants | ||
| 200 | |||
| 201 | =cut | ||
| 202 | |||
| 203 | sub init_platform { | ||
| 204 | my($self) = shift; | ||
| 205 | |||
| 206 | $self->{MM_Win32_VERSION} = $VERSION; | ||
| 207 | |||
| 208 | return; | ||
| 209 | } | ||
| 210 | |||
| 211 | sub platform_constants { | ||
| 212 | my($self) = shift; | ||
| 213 | my $make_frag = ''; | ||
| 214 | |||
| 215 | foreach my $macro (qw(MM_Win32_VERSION)) | ||
| 216 | { | ||
| 217 | next unless defined $self->{$macro}; | ||
| 218 | $make_frag .= "$macro = $self->{$macro}\n"; | ||
| 219 | } | ||
| 220 | |||
| 221 | return $make_frag; | ||
| 222 | } | ||
| 223 | |||
| 224 | =item specify_shell | ||
| 225 | |||
| 226 | Set SHELL to $ENV{COMSPEC} only if make is type 'gmake'. | ||
| 227 | |||
| 228 | =cut | ||
| 229 | |||
| 230 | sub specify_shell { | ||
| 231 | my $self = shift; | ||
| 232 | return '' unless $self->is_make_type('gmake'); | ||
| 233 | "\nSHELL = $ENV{COMSPEC}\n"; | ||
| 234 | } | ||
| 235 | |||
| 236 | =item constants | ||
| 237 | |||
| 238 | Add MAXLINELENGTH for dmake before all the constants are output. | ||
| 239 | |||
| 240 | =cut | ||
| 241 | |||
| 242 | sub constants { | ||
| 243 | my $self = shift; | ||
| 244 | |||
| 245 | my $make_text = $self->SUPER::constants; | ||
| 246 | return $make_text unless $self->is_make_type('dmake'); | ||
| 247 | |||
| 248 | # dmake won't read any single "line" (even those with escaped newlines) | ||
| 249 | # larger than a certain size which can be as small as 8k. PM_TO_BLIB | ||
| 250 | # on large modules like DateTime::TimeZone can create lines over 32k. | ||
| 251 | # So we'll crank it up to a <ironic>WHOPPING</ironic> 64k. | ||
| 252 | # | ||
| 253 | # This has to come here before all the constants and not in | ||
| 254 | # platform_constants which is after constants. | ||
| 255 | my $size = $self->{MAXLINELENGTH} || 800000; | ||
| 256 | my $prefix = qq{ | ||
| 257 | # Get dmake to read long commands like PM_TO_BLIB | ||
| 258 | MAXLINELENGTH = $size | ||
| 259 | |||
| 260 | }; | ||
| 261 | |||
| 262 | return $prefix . $make_text; | ||
| 263 | } | ||
| 264 | |||
| 265 | |||
| 266 | =item special_targets | ||
| 267 | |||
| 268 | Add .USESHELL target for dmake. | ||
| 269 | |||
| 270 | =cut | ||
| 271 | |||
| 272 | sub special_targets { | ||
| 273 | my($self) = @_; | ||
| 274 | |||
| 275 | my $make_frag = $self->SUPER::special_targets; | ||
| 276 | |||
| 277 | $make_frag .= <<'MAKE_FRAG' if $self->is_make_type('dmake'); | ||
| 278 | .USESHELL : | ||
| 279 | MAKE_FRAG | ||
| 280 | |||
| 281 | return $make_frag; | ||
| 282 | } | ||
| 283 | |||
| 284 | =item static_lib_pure_cmd | ||
| 285 | |||
| 286 | Defines how to run the archive utility | ||
| 287 | |||
| 288 | =cut | ||
| 289 | |||
| 290 | sub static_lib_pure_cmd { | ||
| 291 | my ($self, $from) = @_; | ||
| 292 | $from =~ s/(\$\(\w+)(\))/$1:^"+"$2/g if $BORLAND; | ||
| 293 | sprintf qq{\t\$(AR) %s\n}, ($BORLAND ? '$@ ' . $from | ||
| 294 | : ($GCC ? '-ru $@ ' . $from | ||
| 295 | : '-out:$@ ' . $from)); | ||
| 296 | } | ||
| 297 | |||
| 298 | =item dynamic_lib | ||
| 299 | |||
| 300 | Methods are overridden here: not dynamic_lib itself, but the utility | ||
| 301 | ones that do the OS-specific work. | ||
| 302 | |||
| 303 | =cut | ||
| 304 | |||
| 305 | sub xs_make_dynamic_lib { | ||
| 306 | my ($self, $attribs, $from, $to, $todir, $ldfrom, $exportlist) = @_; | ||
| 307 | my @m = sprintf '%s : %s $(MYEXTLIB) %s$(DFSEP).exists %s $(PERL_ARCHIVEDEP) $(INST_DYNAMIC_DEP)'."\n", $to, $from, $todir, $exportlist; | ||
| 308 | if ($GCC) { | ||
| 309 | # per https://rt.cpan.org/Ticket/Display.html?id=78395 no longer | ||
| 310 | # uses dlltool - relies on post 2002 MinGW | ||
| 311 | # 1 2 | ||
| 312 | push @m, _sprintf562 <<'EOF', $exportlist, $ldfrom; | ||
| 313 | $(LD) %1$s -o $@ $(LDDLFLAGS) %2$s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -Wl,--enable-auto-image-base | ||
| 314 | EOF | ||
| 315 | } elsif ($BORLAND) { | ||
| 316 | my $ldargs = $self->is_make_type('dmake') | ||
| 317 | ? q{"$(PERL_ARCHIVE:s,/,\,)" $(LDLOADLIBS:s,/,\,) $(MYEXTLIB:s,/,\,),} | ||
| 318 | : q{"$(subst /,\,$(PERL_ARCHIVE))" $(subst /,\,$(LDLOADLIBS)) $(subst /,\,$(MYEXTLIB)),}; | ||
| 319 | my $subbed; | ||
| 320 | if ($exportlist eq '$(EXPORT_LIST)') { | ||
| 321 | $subbed = $self->is_make_type('dmake') | ||
| 322 | ? q{$(EXPORT_LIST:s,/,\,)} | ||
| 323 | : q{$(subst /,\,$(EXPORT_LIST))}; | ||
| 324 | } else { | ||
| 325 | # in XSMULTI, exportlist is per-XS, so have to sub in perl not make | ||
| 326 | ($subbed = $exportlist) =~ s#/#\\#g; | ||
| 327 | } | ||
| 328 | push @m, sprintf <<'EOF', $ldfrom, $ldargs . $subbed; | ||
| 329 | $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) %s,$@,,%s,$(RESFILES) | ||
| 330 | EOF | ||
| 331 | } else { # VC | ||
| 332 | push @m, sprintf <<'EOF', $ldfrom, $exportlist; | ||
| 333 | $(LD) -out:$@ $(LDDLFLAGS) %s $(OTHERLDFLAGS) $(MYEXTLIB) "$(PERL_ARCHIVE)" $(LDLOADLIBS) -def:%s | ||
| 334 | EOF | ||
| 335 | # Embed the manifest file if it exists | ||
| 336 | push(@m, q{ if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2 | ||
| 337 | if exist $@.manifest del $@.manifest}); | ||
| 338 | } | ||
| 339 | push @m, "\n\t\$(CHMOD) \$(PERM_RWX) \$\@\n"; | ||
| 340 | |||
| 341 | join '', @m; | ||
| 342 | } | ||
| 343 | |||
| 344 | sub xs_dynamic_lib_macros { | ||
| 345 | my ($self, $attribs) = @_; | ||
| 346 | my $otherldflags = $attribs->{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': ''); | ||
| 347 | my $inst_dynamic_dep = $attribs->{INST_DYNAMIC_DEP} || ""; | ||
| 348 | sprintf <<'EOF', $otherldflags, $inst_dynamic_dep; | ||
| 349 | # This section creates the dynamically loadable objects from relevant | ||
| 350 | # objects and possibly $(MYEXTLIB). | ||
| 351 | OTHERLDFLAGS = %s | ||
| 352 | INST_DYNAMIC_DEP = %s | ||
| 353 | EOF | ||
| 354 | } | ||
| 355 | |||
| 356 | =item extra_clean_files | ||
| 357 | |||
| 358 | Clean out some extra dll.{base,exp} files which might be generated by | ||
| 359 | gcc. Otherwise, take out all *.pdb files. | ||
| 360 | |||
| 361 | =cut | ||
| 362 | |||
| 363 | sub extra_clean_files { | ||
| 364 | my $self = shift; | ||
| 365 | |||
| 366 | return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb'); | ||
| 367 | } | ||
| 368 | |||
| 369 | =item init_linker | ||
| 370 | |||
| 371 | =cut | ||
| 372 | |||
| 373 | sub init_linker { | ||
| 374 | my $self = shift; | ||
| 375 | |||
| 376 | $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}"; | ||
| 377 | $self->{PERL_ARCHIVEDEP} = "\$(PERL_INCDEP)\\$Config{libperl}"; | ||
| 378 | $self->{PERL_ARCHIVE_AFTER} = ''; | ||
| 379 | $self->{EXPORT_LIST} = '$(BASEEXT).def'; | ||
| 380 | } | ||
| 381 | |||
| 382 | |||
| 383 | =item perl_script | ||
| 384 | |||
| 385 | Checks for the perl program under several common perl extensions. | ||
| 386 | |||
| 387 | =cut | ||
| 388 | |||
| 389 | sub perl_script { | ||
| 390 | my($self,$file) = @_; | ||
| 391 | return $file if -r $file && -f _; | ||
| 392 | return "$file.pl" if -r "$file.pl" && -f _; | ||
| 393 | return "$file.plx" if -r "$file.plx" && -f _; | ||
| 394 | return "$file.bat" if -r "$file.bat" && -f _; | ||
| 395 | return; | ||
| 396 | } | ||
| 397 | |||
| 398 | sub can_dep_space { | ||
| 399 | my $self = shift; | ||
| 400 | 1; # with Win32::GetShortPathName | ||
| 401 | } | ||
| 402 | |||
| 403 | =item quote_dep | ||
| 404 | |||
| 405 | =cut | ||
| 406 | |||
| 407 | sub quote_dep { | ||
| 408 | my ($self, $arg) = @_; | ||
| 409 | if ($arg =~ / / and not $self->is_make_type('gmake')) { | ||
| 410 | require Win32; | ||
| 411 | $arg = Win32::GetShortPathName($arg); | ||
| 412 | die <<EOF if not defined $arg or $arg =~ / /; | ||
| 413 | Tried to use make dependency with space for non-GNU make: | ||
| 414 | '$arg' | ||
| 415 | Fallback to short pathname failed. | ||
| 416 | EOF | ||
| 417 | return $arg; | ||
| 418 | } | ||
| 419 | return $self->SUPER::quote_dep($arg); | ||
| 420 | } | ||
| 421 | |||
| 422 | |||
| 423 | =item xs_obj_opt | ||
| 424 | |||
| 425 | Override to fixup -o flags for MSVC. | ||
| 426 | |||
| 427 | =cut | ||
| 428 | |||
| 429 | sub xs_obj_opt { | ||
| 430 | my ($self, $output_file) = @_; | ||
| 431 | ($MSVC ? "/Fo" : "-o ") . $output_file; | ||
| 432 | } | ||
| 433 | |||
| 434 | |||
| 435 | =item pasthru | ||
| 436 | |||
| 437 | All we send is -nologo to nmake to prevent it from printing its damned | ||
| 438 | banner. | ||
| 439 | |||
| 440 | =cut | ||
| 441 | |||
| 442 | sub pasthru { | ||
| 443 | my($self) = shift; | ||
| 444 | my $old = $self->SUPER::pasthru; | ||
| 445 | return $old unless $self->is_make_type('nmake'); | ||
| 446 | $old =~ s/(PASTHRU\s*=\s*)/$1 -nologo /; | ||
| 447 | $old; | ||
| 448 | } | ||
| 449 | |||
| 450 | |||
| 451 | =item arch_check (override) | ||
| 452 | |||
| 453 | Normalize all arguments for consistency of comparison. | ||
| 454 | |||
| 455 | =cut | ||
| 456 | |||
| 457 | sub arch_check { | ||
| 458 | my $self = shift; | ||
| 459 | |||
| 460 | # Win32 is an XS module, minperl won't have it. | ||
| 461 | # arch_check() is not critical, so just fake it. | ||
| 462 | return 1 unless $self->can_load_xs; | ||
| 463 | return $self->SUPER::arch_check( map { $self->_normalize_path_name($_) } @_); | ||
| 464 | } | ||
| 465 | |||
| 466 | sub _normalize_path_name { | ||
| 467 | my $self = shift; | ||
| 468 | my $file = shift; | ||
| 469 | |||
| 470 | require Win32; | ||
| 471 | my $short = Win32::GetShortPathName($file); | ||
| 472 | return defined $short ? lc $short : lc $file; | ||
| 473 | } | ||
| 474 | |||
| 475 | |||
| 476 | =item oneliner | ||
| 477 | |||
| 478 | These are based on what command.com does on Win98. They may be wrong | ||
| 479 | for other Windows shells, I don't know. | ||
| 480 | |||
| 481 | =cut | ||
| 482 | |||
| 483 | sub oneliner { | ||
| 484 | my($self, $cmd, $switches) = @_; | ||
| 485 | $switches = [] unless defined $switches; | ||
| 486 | |||
| 487 | # Strip leading and trailing newlines | ||
| 488 | $cmd =~ s{^\n+}{}; | ||
| 489 | $cmd =~ s{\n+$}{}; | ||
| 490 | |||
| 491 | $cmd = $self->quote_literal($cmd); | ||
| 492 | $cmd = $self->escape_newlines($cmd); | ||
| 493 | |||
| 494 | $switches = join ' ', @$switches; | ||
| 495 | |||
| 496 | return qq{\$(ABSPERLRUN) $switches -e $cmd --}; | ||
| 497 | } | ||
| 498 | |||
| 499 | |||
| 500 | sub quote_literal { | ||
| 501 | my($self, $text, $opts) = @_; | ||
| 502 | $opts->{allow_variables} = 1 unless defined $opts->{allow_variables}; | ||
| 503 | |||
| 504 | # See: http://www.autohotkey.net/~deleyd/parameters/parameters.htm#CPP | ||
| 505 | |||
| 506 | # Apply the Microsoft C/C++ parsing rules | ||
| 507 | $text =~ s{\\\\"}{\\\\\\\\\\"}g; # \\" -> \\\\\" | ||
| 508 | $text =~ s{(?<!\\)\\"}{\\\\\\"}g; # \" -> \\\" | ||
| 509 | $text =~ s{(?<!\\)"}{\\"}g; # " -> \" | ||
| 510 | $text = qq{"$text"} if $text =~ /[ \t]/; | ||
| 511 | |||
| 512 | # Apply the Command Prompt parsing rules (cmd.exe) | ||
| 513 | my @text = split /("[^"]*")/, $text; | ||
| 514 | # We should also escape parentheses, but it breaks one-liners containing | ||
| 515 | # $(MACRO)s in makefiles. | ||
| 516 | s{([<>|&^@!])}{^$1}g foreach grep { !/^"[^"]*"$/ } @text; | ||
| 517 | $text = join('', @text); | ||
| 518 | |||
| 519 | # dmake expands {{ to { and }} to }. | ||
| 520 | if( $self->is_make_type('dmake') ) { | ||
| 521 | $text =~ s/{/{{/g; | ||
| 522 | $text =~ s/}/}}/g; | ||
| 523 | } | ||
| 524 | |||
| 525 | $text = $opts->{allow_variables} | ||
| 526 | ? $self->escape_dollarsigns($text) : $self->escape_all_dollarsigns($text); | ||
| 527 | |||
| 528 | return $text; | ||
| 529 | } | ||
| 530 | |||
| 531 | |||
| 532 | sub escape_newlines { | ||
| 533 | my($self, $text) = @_; | ||
| 534 | |||
| 535 | # Escape newlines | ||
| 536 | $text =~ s{\n}{\\\n}g; | ||
| 537 | |||
| 538 | return $text; | ||
| 539 | } | ||
| 540 | |||
| 541 | |||
| 542 | =item cd | ||
| 543 | |||
| 544 | dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It | ||
| 545 | wants: | ||
| 546 | |||
| 547 | cd dir1\dir2 | ||
| 548 | command | ||
| 549 | another_command | ||
| 550 | cd ..\.. | ||
| 551 | |||
| 552 | =cut | ||
| 553 | |||
| 554 | sub cd { | ||
| 555 | my($self, $dir, @cmds) = @_; | ||
| 556 | |||
| 557 | return $self->SUPER::cd($dir, @cmds) unless $self->is_make_type('nmake'); | ||
| 558 | |||
| 559 | my $cmd = join "\n\t", map "$_", @cmds; | ||
| 560 | |||
| 561 | my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir)); | ||
| 562 | |||
| 563 | # No leading tab and no trailing newline makes for easier embedding. | ||
| 564 | my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs; | ||
| 565 | cd %s | ||
| 566 | %s | ||
| 567 | cd %s | ||
| 568 | MAKE_FRAG | ||
| 569 | |||
| 570 | chomp $make_frag; | ||
| 571 | |||
| 572 | return $make_frag; | ||
| 573 | } | ||
| 574 | |||
| 575 | |||
| 576 | =item max_exec_len | ||
| 577 | |||
| 578 | nmake 1.50 limits command length to 2048 characters. | ||
| 579 | |||
| 580 | =cut | ||
| 581 | |||
| 582 | sub max_exec_len { | ||
| 583 | my $self = shift; | ||
| 584 | |||
| 585 | return $self->{_MAX_EXEC_LEN} ||= 2 * 1024; | ||
| 586 | } | ||
| 587 | |||
| 588 | |||
| 589 | =item os_flavor | ||
| 590 | |||
| 591 | Windows is Win32. | ||
| 592 | |||
| 593 | =cut | ||
| 594 | |||
| 595 | sub os_flavor { | ||
| 596 | return('Win32'); | ||
| 597 | } | ||
| 598 | |||
| 599 | |||
| 600 | =item cflags | ||
| 601 | |||
| 602 | Defines the PERLDLL symbol if we are configured for static building since all | ||
| 603 | code destined for the perl5xx.dll must be compiled with the PERLDLL symbol | ||
| 604 | defined. | ||
| 605 | |||
| 606 | =cut | ||
| 607 | |||
| 608 | sub cflags { | ||
| 609 | my($self,$libperl)=@_; | ||
| 610 | return $self->{CFLAGS} if $self->{CFLAGS}; | ||
| 611 | return '' unless $self->needs_linking(); | ||
| 612 | |||
| 613 | my $base = $self->SUPER::cflags($libperl); | ||
| 614 | foreach (split /\n/, $base) { | ||
| 615 | /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2; | ||
| 616 | }; | ||
| 617 | $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static'); | ||
| 618 | |||
| 619 | return $self->{CFLAGS} = qq{ | ||
| 620 | CCFLAGS = $self->{CCFLAGS} | ||
| 621 | OPTIMIZE = $self->{OPTIMIZE} | ||
| 622 | PERLTYPE = $self->{PERLTYPE} | ||
| 623 | }; | ||
| 624 | |||
| 625 | } | ||
| 626 | |||
| 627 | =item make_type | ||
| 628 | |||
| 629 | Returns a suitable string describing the type of makefile being written. | ||
| 630 | |||
| 631 | =cut | ||
| 632 | |||
| 633 | sub make_type { | ||
| 634 | my ($self) = @_; | ||
| 635 | my $make = $self->make; | ||
| 636 | $make = +( File::Spec->splitpath( $make ) )[-1]; | ||
| 637 | $make =~ s!\.exe$!!i; | ||
| 638 | if ( $make =~ m![^A-Z0-9]!i ) { | ||
| 639 | ($make) = grep { m!make!i } split m![^A-Z0-9]!i, $make; | ||
| 640 | } | ||
| 641 | return "$make-style"; | ||
| 642 | } | ||
| 643 | |||
| 644 | 1; | ||
| 645 | __END__ |