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