Integrate version.pm-0.77 into bleadperl
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / MM_Win32.pm
CommitLineData
68dc0745 1package ExtUtils::MM_Win32;
2
479d2113 3use strict;
4
b75c8c73 5
68dc0745 6=head1 NAME
7
8ExtUtils::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
16See ExtUtils::MM_Unix for a documentation of the methods provided
17there. This package overrides the implementation of these methods, not
18the semantics.
19
68dc0745 20=cut
21
7292dc67 22use ExtUtils::MakeMaker::Config;
68dc0745 23use File::Basename;
ecf68df6 24use File::Spec;
f6d6199c 25use ExtUtils::MakeMaker qw( neatvalue );
68dc0745 26
f6d6199c 27require ExtUtils::MM_Any;
28require ExtUtils::MM_Unix;
a592ba15 29our @ISA = qw( ExtUtils::MM_Any ExtUtils::MM_Unix );
c0956255 30our $VERSION = '6.53_02';
68dc0745 31
32$ENV{EMXSHELL} = 'sh'; # to run `commands`
68dc0745 33
a592ba15 34my $BORLAND = $Config{'cc'} =~ /^bcc/i ? 1 : 0;
35my $GCC = $Config{'cc'} =~ /^gcc/i ? 1 : 0;
479d2113 36
37
38=head2 Overridden methods
39
40=over 4
41
42=item B<dlsyms>
43
44=cut
3e3baf6d 45
68dc0745 46sub dlsyms {
47 my($self,%attribs) = @_;
48
49 my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
50 my($vars) = $attribs{DL_VARS} || $self->{DL_VARS} || [];
762efda7 51 my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
68dc0745 52 my($imports) = $attribs{IMPORTS} || $self->{IMPORTS} || {};
53 my(@m);
68dc0745 54
55 if (not $self->{SKIPHASH}{'dynamic'}) {
56 push(@m,"
57$self->{BASEEXT}.def: Makefile.PL
58",
f6d6199c 59 q! $(PERLRUN) -MExtUtils::Mksymlists \\
5e687e55 60 -e "Mksymlists('NAME'=>\"!, $self->{NAME},
61 q!\", 'DLBASE' => '!,$self->{DLBASE},
62 # The above two lines quoted differently to work around
63 # a bug in the 4DOS/4NT command line interpreter. The visible
64 # result of the bug was files named q('extension_name',) *with the
65 # single quotes and the comma* in the extension build directories.
68dc0745 66 q!', 'DL_FUNCS' => !,neatvalue($funcs),
762efda7 67 q!, 'FUNCLIST' => !,neatvalue($funclist),
68dc0745 68 q!, 'IMPORTS' => !,neatvalue($imports),
69 q!, 'DL_VARS' => !, neatvalue($vars), q!);"
70!);
71 }
72 join('',@m);
73}
74
479d2113 75=item replace_manpage_separator
76
77Changes the path separator with .
78
79=cut
80
68dc0745 81sub replace_manpage_separator {
82 my($self,$man) = @_;
83 $man =~ s,/+,.,g;
84 $man;
85}
86
479d2113 87
88=item B<maybe_command>
89
90Since Windows has nothing as simple as an executable bit, we check the
91file extension.
92
93The PATHEXT env variable will be used to get a list of extensions that
94might indicate a command, otherwise .com, .exe, .bat and .cmd will be
95used by default.
96
97=cut
98
68dc0745 99sub maybe_command {
100 my($self,$file) = @_;
846f184a 101 my @e = exists($ENV{'PATHEXT'})
102 ? split(/;/, $ENV{PATHEXT})
103 : qw(.com .exe .bat .cmd);
104 my $e = '';
105 for (@e) { $e .= "\Q$_\E|" }
106 chop $e;
107 # see if file ends in one of the known extensions
2b2708c8 108 if ($file =~ /($e)$/i) {
846f184a 109 return $file if -e $file;
110 }
111 else {
112 for (@e) {
113 return "$file$_" if -e "$file$_";
114 }
115 }
68dc0745 116 return;
117}
118
68dc0745 119
479d2113 120=item B<init_DIRFILESEP>
121
122Using \ for Windows.
123
124=cut
125
126sub init_DIRFILESEP {
127 my($self) = shift;
128
dedf98bc 129 # The ^ makes sure its not interpreted as an escape in nmake
2e65e370 130 $self->{DIRFILESEP} = $self->is_make_type('nmake') ? '^\\' :
131 $self->is_make_type('dmake') ? '\\\\'
132 : '\\';
68dc0745 133}
134
479d2113 135=item B<init_others>
136
137Override some of the Unix specific commands with portable
138ExtUtils::Command ones.
139
60537fc0 140Also provide defaults for LD and AR in case the %Config values aren't
141set.
3e3baf6d 142
479d2113 143LDLOADLIBS's default is changed to $Config{libs}.
3e3baf6d 144
479d2113 145Adjustments are made for Borland's quirks needing -L to come first.
3e3baf6d 146
147=cut
148
479d2113 149sub init_others {
150 my ($self) = @_;
151
479d2113 152 $self->{NOOP} ||= 'rem';
479d2113 153 $self->{DEV_NULL} ||= '> NUL';
154
7292dc67 155 $self->{FIXIN} ||= $self->{PERL_CORE} ?
6383bd23 156 "\$(PERLRUN) $self->{PERL_SRC}/win32/bin/pl2bat.pl" :
7292dc67 157 'pl2bat.bat';
158
5bdf71cc 159 $self->{LD} ||= 'link';
160 $self->{AR} ||= 'lib';
479d2113 161
162 $self->SUPER::init_others;
163
dedf98bc 164 # Setting SHELL from $Config{sh} can break dmake. Its ok without it.
165 delete $self->{SHELL};
166
479d2113 167 $self->{LDLOADLIBS} ||= $Config{libs};
168 # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
169 if ($BORLAND) {
170 my $libs = $self->{LDLOADLIBS};
171 my $libpath = '';
172 while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
173 $libpath .= ' ' if length $libpath;
174 $libpath .= $1;
175 }
176 $self->{LDLOADLIBS} = $libs;
177 $self->{LDDLFLAGS} ||= $Config{lddlflags};
178 $self->{LDDLFLAGS} .= " $libpath";
3e3baf6d 179 }
180
479d2113 181 return 1;
182}
3e3baf6d 183
3e3baf6d 184
7292dc67 185=item init_platform
3e3baf6d 186
479d2113 187Add MM_Win32_VERSION.
3e3baf6d 188
7292dc67 189=item platform_constants
3e3baf6d 190
479d2113 191=cut
3e3baf6d 192
479d2113 193sub init_platform {
194 my($self) = shift;
3e3baf6d 195
479d2113 196 $self->{MM_Win32_VERSION} = $VERSION;
197}
3e3baf6d 198
479d2113 199sub platform_constants {
200 my($self) = shift;
201 my $make_frag = '';
3e3baf6d 202
479d2113 203 foreach my $macro (qw(MM_Win32_VERSION))
204 {
205 next unless defined $self->{$macro};
206 $make_frag .= "$macro = $self->{$macro}\n";
207 }
3e3baf6d 208
479d2113 209 return $make_frag;
210}
3e3baf6d 211
3e3baf6d 212
7292dc67 213=item special_targets
3e3baf6d 214
479d2113 215Add .USESHELL target for dmake.
3e3baf6d 216
479d2113 217=cut
3e3baf6d 218
479d2113 219sub special_targets {
220 my($self) = @_;
3e3baf6d 221
479d2113 222 my $make_frag = $self->SUPER::special_targets;
3e3baf6d 223
2e65e370 224 $make_frag .= <<'MAKE_FRAG' if $self->is_make_type('dmake');
479d2113 225.USESHELL :
226MAKE_FRAG
3e3baf6d 227
479d2113 228 return $make_frag;
3e3baf6d 229}
230
231
7292dc67 232=item static_lib
68dc0745 233
479d2113 234Changes how to run the linker.
235
236The rest is duplicate code from MM_Unix. Should move the linker code
237to its own method.
68dc0745 238
239=cut
240
241sub static_lib {
242 my($self) = @_;
68dc0745 243 return '' unless $self->has_link_code;
244
245 my(@m);
246 push(@m, <<'END');
7292dc67 247$(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
68dc0745 248 $(RM_RF) $@
249END
479d2113 250
022735b4 251 # If this extension has its own library (eg SDBM_File)
68dc0745 252 # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
479d2113 253 push @m, <<'MAKE_FRAG' if $self->{MYEXTLIB};
254 $(CP) $(MYEXTLIB) $@
255MAKE_FRAG
68dc0745 256
257 push @m,
910dfcc8 258q{ $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
259 : ($GCC ? '-ru $@ $(OBJECT)'
260 : '-out:$@ $(OBJECT)')).q{
479d2113 261 $(CHMOD) $(PERM_RWX) $@
262 $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
68dc0745 263};
264
479d2113 265 # Old mechanism - still available:
266 push @m, <<'MAKE_FRAG' if $self->{PERL_SRC} && $self->{EXTRALIBS};
267 $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
268MAKE_FRAG
68dc0745 269
479d2113 270 join('', @m);
68dc0745 271}
272
68dc0745 273
7292dc67 274=item dynamic_lib
68dc0745 275
479d2113 276Complicated stuff for Win32 that I don't understand. :(
68dc0745 277
278=cut
279
280sub dynamic_lib {
281 my($self, %attribs) = @_;
282 return '' unless $self->needs_linking(); #might be because of a subdir
283
284 return '' unless $self->has_link_code;
285
3e3baf6d 286 my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
68dc0745 287 my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
288 my($ldfrom) = '$(LDFROM)';
289 my(@m);
7a958ec3 290
5db10396 291# one thing for GCC/Mingw32:
292# we try to overcome non-relocateable-DLL problems by generating
7a958ec3 293# a (hopefully unique) image-base from the dll's name
294# -- BKS, 10-19-1999
295 if ($GCC) {
7a958ec3 296 my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT};
297 $dllname =~ /(....)(.{0,4})/;
298 my $baseaddr = unpack("n", $1 ^ $2);
299 $otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $baseaddr);
300 }
301
68dc0745 302 push(@m,'
303# This section creates the dynamically loadable $(INST_DYNAMIC)
304# from $(OBJECT) and possibly $(MYEXTLIB).
305OTHERLDFLAGS = '.$otherldflags.'
306INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
307
7292dc67 308$(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
68dc0745 309');
5b0d9cbe 310 if ($GCC) {
311 push(@m,
910dfcc8 312 q{ dlltool --def $(EXPORT_LIST) --output-exp dll.exp
313 $(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp
5b0d9cbe 314 dlltool --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
315 $(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp });
dc0d354b 316 } elsif ($BORLAND) {
317 push(@m,
318 q{ $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
2e65e370 319 .($self->is_make_type('dmake')
2977d345 320 ? q{$(PERL_ARCHIVE:s,/,\,) $(LDLOADLIBS:s,/,\,) }
dc0d354b 321 .q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
322 : q{$(subst /,\,$(PERL_ARCHIVE)) $(subst /,\,$(LDLOADLIBS)) }
323 .q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
324 .q{,$(RESFILES)});
325 } else { # VC
326 push(@m,
327 q{ $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
328 .q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
277189c8 329
2f30d0d0 330 # Embed the manifest file if it exists
331 push(@m, q{
5bdf71cc 332 if exist $@.manifest mt -nologo -manifest $@.manifest -outputresource:$@;2
333 if exist $@.manifest del $@.manifest});
5b0d9cbe 334 }
68dc0745 335 push @m, '
479d2113 336 $(CHMOD) $(PERM_RWX) $@
68dc0745 337';
338
68dc0745 339 join('',@m);
340}
341
7292dc67 342=item extra_clean_files
479d2113 343
344Clean out some extra dll.{base,exp} files which might be generated by
345gcc. Otherwise, take out all *.pdb files.
346
347=cut
348
7292dc67 349sub extra_clean_files {
350 my $self = shift;
562c1c19 351
7292dc67 352 return $GCC ? (qw(dll.base dll.exp)) : ('*.pdb');
562c1c19 353}
354
479d2113 355=item init_linker
562c1c19 356
479d2113 357=cut
562c1c19 358
479d2113 359sub init_linker {
360 my $self = shift;
68dc0745 361
479d2113 362 $self->{PERL_ARCHIVE} = "\$(PERL_INC)\\$Config{libperl}";
363 $self->{PERL_ARCHIVE_AFTER} = '';
364 $self->{EXPORT_LIST} = '$(BASEEXT).def';
68dc0745 365}
366
45bc4d3a 367
68dc0745 368=item perl_script
369
479d2113 370Checks for the perl program under several common perl extensions.
68dc0745 371
372=cut
373
374sub perl_script {
375 my($self,$file) = @_;
cae6c631 376 return $file if -r $file && -f _;
479d2113 377 return "$file.pl" if -r "$file.pl" && -f _;
378 return "$file.plx" if -r "$file.plx" && -f _;
cae6c631 379 return "$file.bat" if -r "$file.bat" && -f _;
68dc0745 380 return;
381}
382
3e3baf6d 383
7292dc67 384=item xs_o
68dc0745 385
479d2113 386This target is stubbed out. Not sure why.
68dc0745 387
388=cut
389
479d2113 390sub xs_o {
391 return ''
68dc0745 392}
393
68dc0745 394
7292dc67 395=item pasthru
68dc0745 396
479d2113 397All we send is -nologo to nmake to prevent it from printing its damned
398banner.
68dc0745 399
400=cut
401
479d2113 402sub pasthru {
68dc0745 403 my($self) = shift;
2e65e370 404 return "PASTHRU = " . ($self->is_make_type('nmake') ? "-nologo" : "");
071e6b84 405}
68dc0745 406
3e3baf6d 407
5bdf71cc 408=item arch_check (override)
409
410Normalize all arguments for consistency of comparison.
411
412=cut
413
414sub arch_check {
415 my $self = shift;
416
c0956255 417 # Win32 is an XS module, minperl won't have it.
418 # arch_check() is not critical, so just fake it.
419 return 1 unless $self->can_load_xs;
420
5bdf71cc 421 require Win32;
422 return $self->SUPER::arch_check( map { lc Win32::GetShortPathName($_) } @_);
423}
424
425
7292dc67 426=item oneliner
3e3baf6d 427
479d2113 428These are based on what command.com does on Win98. They may be wrong
429for other Windows shells, I don't know.
3e3baf6d 430
431=cut
432
479d2113 433sub oneliner {
434 my($self, $cmd, $switches) = @_;
435 $switches = [] unless defined $switches;
3e3baf6d 436
479d2113 437 # Strip leading and trailing newlines
438 $cmd =~ s{^\n+}{};
439 $cmd =~ s{\n+$}{};
3e3baf6d 440
479d2113 441 $cmd = $self->quote_literal($cmd);
442 $cmd = $self->escape_newlines($cmd);
3e3baf6d 443
479d2113 444 $switches = join ' ', @$switches;
3e3baf6d 445
2977d345 446 return qq{\$(ABSPERLRUN) $switches -e $cmd --};
3e3baf6d 447}
448
68dc0745 449
479d2113 450sub quote_literal {
451 my($self, $text) = @_;
68dc0745 452
479d2113 453 # I don't know if this is correct, but it seems to work on
454 # Win98's command.com
455 $text =~ s{"}{\\"}g;
68dc0745 456
dedf98bc 457 # dmake eats '{' inside double quotes and leaves alone { outside double
458 # quotes; however it transforms {{ into { either inside and outside double
459 # quotes. It also translates }} into }. The escaping below is not
460 # 100% correct.
2e65e370 461 if( $self->is_make_type('dmake') ) {
dedf98bc 462 $text =~ s/{/{{/g;
463 $text =~ s/}}/}}}/g;
464 }
465
479d2113 466 return qq{"$text"};
68dc0745 467}
468
68dc0745 469
479d2113 470sub escape_newlines {
471 my($self, $text) = @_;
68dc0745 472
479d2113 473 # Escape newlines
474 $text =~ s{\n}{\\\n}g;
68dc0745 475
479d2113 476 return $text;
68dc0745 477}
478
68dc0745 479
7292dc67 480=item cd
481
482dmake can handle Unix style cd'ing but nmake (at least 1.5) cannot. It
483wants:
484
5bdf71cc 485 cd dir1\dir2
7292dc67 486 command
487 another_command
5bdf71cc 488 cd ..\..
7292dc67 489
490=cut
491
492sub cd {
493 my($self, $dir, @cmds) = @_;
494
2e65e370 495 return $self->SUPER::cd($dir, @cmds) unless $self->is_make_type('nmake');
7292dc67 496
497 my $cmd = join "\n\t", map "$_", @cmds;
498
277189c8 499 my $updirs = $self->catdir(map { $self->updir } $self->splitdir($dir));
500
7292dc67 501 # No leading tab and no trailing newline makes for easier embedding.
277189c8 502 my $make_frag = sprintf <<'MAKE_FRAG', $dir, $cmd, $updirs;
7292dc67 503cd %s
504 %s
277189c8 505 cd %s
7292dc67 506MAKE_FRAG
507
508 chomp $make_frag;
509
510 return $make_frag;
511}
512
513
479d2113 514=item max_exec_len
68dc0745 515
2c91f887 516nmake 1.50 limits command length to 2048 characters.
68dc0745 517
518=cut
519
479d2113 520sub max_exec_len {
521 my $self = shift;
522
2c91f887 523 return $self->{_MAX_EXEC_LEN} ||= 2 * 1024;
68dc0745 524}
525
526
dedf98bc 527=item os_flavor
528
529Windows is Win32.
530
531=cut
532
533sub os_flavor {
534 return('Win32');
535}
536
537
8b503b1a 538=item cflags
539
540Defines the PERLDLL symbol if we are configured for static building since all
541code destined for the perl5xx.dll must be compiled with the PERLDLL symbol
542defined.
543
544=cut
545
546sub cflags {
547 my($self,$libperl)=@_;
548 return $self->{CFLAGS} if $self->{CFLAGS};
549 return '' unless $self->needs_linking();
550
551 my $base = $self->SUPER::cflags($libperl);
552 foreach (split /\n/, $base) {
553 /^(\S*)\s*=\s*(\S*)$/ and $self->{$1} = $2;
554 };
555 $self->{CCFLAGS} .= " -DPERLDLL" if ($self->{LINKTYPE} eq 'static');
556
557 return $self->{CFLAGS} = qq{
558CCFLAGS = $self->{CCFLAGS}
559OPTIMIZE = $self->{OPTIMIZE}
560PERLTYPE = $self->{PERLTYPE}
561};
562
563}
564
2e65e370 565sub is_make_type {
566 my($self, $type) = @_;
567 return !! ($self->make =~ /\b$type(?:\.exe)?$/);
568}
569
68dc0745 5701;
571__END__
572
573=back
574
575=cut
576
5b0d9cbe 577