This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Apply NetBSD patch-ae: another gcc sparc64 bug.
[perl5.git] / lib / ExtUtils / MM_Win32.pm
1 package ExtUtils::MM_Win32;
2
3 our $VERSION = '1.00';
4
5 =head1 NAME
6
7 ExtUtils::MM_Win32 - methods to override UN*X behaviour in ExtUtils::MakeMaker
8
9 =head1 SYNOPSIS
10
11  use ExtUtils::MM_Win32; # Done internally by ExtUtils::MakeMaker if needed
12
13 =head1 DESCRIPTION
14
15 See ExtUtils::MM_Unix for a documentation of the methods provided
16 there. This package overrides the implementation of these methods, not
17 the semantics.
18
19 =over 4
20
21 =cut 
22
23 use Config;
24 #use Cwd;
25 use File::Basename;
26 require Exporter;
27
28 require ExtUtils::MakeMaker;
29 ExtUtils::MakeMaker->import(qw( $Verbose &neatvalue));
30
31 $ENV{EMXSHELL} = 'sh'; # to run `commands`
32 unshift @MM::ISA, 'ExtUtils::MM_Win32';
33
34 $BORLAND = 1 if $Config{'cc'} =~ /^bcc/i;
35 $GCC     = 1 if $Config{'cc'} =~ /^gcc/i;
36 $DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
37 $NMAKE = 1 if $Config{'make'} =~ /^nmake/i;
38 $PERLMAKE = 1 if $Config{'make'} =~ /^pmake/i;
39
40 # a few workarounds for command.com (very basic)
41 {
42     package ExtUtils::MM_Win95;
43
44     # the $^O test may be overkill, but we want to be sure Win32::IsWin95()
45     # exists before we try it
46
47     unshift @MM::ISA, 'ExtUtils::MM_Win95'
48         if ($^O =~ /Win32/ && Win32::IsWin95());
49
50     sub xs_c {
51         my($self) = shift;
52         return '' unless $self->needs_linking();
53         '
54 .xs.c:
55         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) \\
56             $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.c
57         '
58     }
59
60     sub xs_cpp {
61         my($self) = shift;
62         return '' unless $self->needs_linking();
63         '
64 .xs.cpp:
65         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) \\
66             $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.cpp
67         ';
68     }
69
70     # many makes are too dumb to use xs_c then c_o
71     sub xs_o {
72         my($self) = shift;
73         return '' unless $self->needs_linking();
74         '
75 .xs$(OBJ_EXT):
76         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) $(XSUBPP) \\
77             $(XSPROTOARG) $(XSUBPPARGS) $*.xs > $*.c
78         $(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) $*.c
79         ';
80     }
81 }       # end of command.com workarounds
82
83 sub dlsyms {
84     my($self,%attribs) = @_;
85
86     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
87     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
88     my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
89     my($imports)  = $attribs{IMPORTS} || $self->{IMPORTS} || {};
90     my(@m);
91     (my $boot = $self->{NAME}) =~ s/:/_/g;
92
93     if (not $self->{SKIPHASH}{'dynamic'}) {
94         push(@m,"
95 $self->{BASEEXT}.def: Makefile.PL
96 ",
97      q! $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Mksymlists \\
98      -e "Mksymlists('NAME'=>\"!, $self->{NAME},
99      q!\", 'DLBASE' => '!,$self->{DLBASE},
100      # The above two lines quoted differently to work around
101      # a bug in the 4DOS/4NT command line interpreter.  The visible
102      # result of the bug was files named q('extension_name',) *with the
103      # single quotes and the comma* in the extension build directories.
104      q!', 'DL_FUNCS' => !,neatvalue($funcs),
105      q!, 'FUNCLIST' => !,neatvalue($funclist),
106      q!, 'IMPORTS' => !,neatvalue($imports),
107      q!, 'DL_VARS' => !, neatvalue($vars), q!);"
108 !);
109     }
110     join('',@m);
111 }
112
113 sub replace_manpage_separator {
114     my($self,$man) = @_;
115     $man =~ s,/+,.,g;
116     $man;
117 }
118
119 sub maybe_command {
120     my($self,$file) = @_;
121     my @e = exists($ENV{'PATHEXT'})
122           ? split(/;/, $ENV{PATHEXT})
123           : qw(.com .exe .bat .cmd);
124     my $e = '';
125     for (@e) { $e .= "\Q$_\E|" }
126     chop $e;
127     # see if file ends in one of the known extensions
128     if ($file =~ /($e)$/i) {
129         return $file if -e $file;
130     }
131     else {
132         for (@e) {
133             return "$file$_" if -e "$file$_";
134         }
135     }
136     return;
137 }
138
139 sub file_name_is_absolute {
140     my($self,$file) = @_;
141     $file =~ m{^([a-z]:)?[\\/]}i ;
142 }
143
144 sub find_perl {
145     my($self, $ver, $names, $dirs, $trace) = @_;
146     my($name, $dir);
147     if ($trace >= 2){
148         print "Looking for perl $ver by these names:
149 @$names
150 in these dirs:
151 @$dirs
152 ";
153     }
154     foreach $dir (@$dirs){
155         next unless defined $dir; # $self->{PERL_SRC} may be undefined
156         foreach $name (@$names){
157             my ($abs, $val);
158             if ($self->file_name_is_absolute($name)) { # /foo/bar
159                 $abs = $name;
160             } elsif ($self->canonpath($name) eq $self->canonpath(basename($name))) { # foo
161                 $abs = $self->catfile($dir, $name);
162             } else { # foo/bar
163                 $abs = $self->canonpath($self->catfile($self->curdir, $name));
164             }
165             print "Checking $abs\n" if ($trace >= 2);
166             next unless $self->maybe_command($abs);
167             print "Executing $abs\n" if ($trace >= 2);
168             $val = `$abs -e "require $ver;" 2>&1`;
169             if ($? == 0) {
170                 print "Using PERL=$abs\n" if $trace;
171                 return $abs;
172             } elsif ($trace >= 2) {
173                 print "Result: `$val'\n";
174             }
175         }
176     }
177     print STDOUT "Unable to find a perl $ver (by these names: @$names, in these dirs: @$dirs)\n";
178     0; # false and not empty
179 }
180
181 sub catdir {
182     my $self = shift;
183     my @args = @_;
184     for (@args) {
185         # append a slash to each argument unless it has one there
186         $_ .= "\\" if $_ eq '' or substr($_,-1) ne "\\";
187     }
188     my $result = $self->canonpath(join('', @args));
189     $result;
190 }
191
192 =item catfile
193
194 Concatenate one or more directory names and a filename to form a
195 complete path ending with a filename
196
197 =cut
198
199 sub catfile {
200     my $self = shift @_;
201     my $file = pop @_;
202     return $file unless @_;
203     my $dir = $self->catdir(@_);
204     $dir =~ s/(\\\.)$//;
205     $dir .= "\\" unless substr($dir,length($dir)-1,1) eq "\\";
206     return $dir.$file;
207 }
208
209 sub init_others
210 {
211  my ($self) = @_;
212  &ExtUtils::MM_Unix::init_others;
213  $self->{'TOUCH'}  = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e touch';
214  $self->{'CHMOD'}  = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e chmod'; 
215  $self->{'CP'}     = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e cp';
216  $self->{'RM_F'}   = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e rm_f';
217  $self->{'RM_RF'}  = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e rm_rf';
218  $self->{'MV'}     = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e mv';
219  $self->{'NOOP'}   = 'rem';
220  $self->{'TEST_F'} = '$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e test_f';
221  $self->{'LD'}     = $Config{'ld'} || 'link';
222  $self->{'AR'}     = $Config{'ar'} || 'lib';
223  $self->{'LDLOADLIBS'} ||= $Config{'libs'};
224  # -Lfoo must come first for Borland, so we put it in LDDLFLAGS
225  if ($BORLAND) {
226      my $libs = $self->{'LDLOADLIBS'};
227      my $libpath = '';
228      while ($libs =~ s/(?:^|\s)(("?)-L.+?\2)(?:\s|$)/ /) {
229          $libpath .= ' ' if length $libpath;
230          $libpath .= $1;
231      }
232      $self->{'LDLOADLIBS'} = $libs;
233      $self->{'LDDLFLAGS'} ||= $Config{'lddlflags'};
234      $self->{'LDDLFLAGS'} .= " $libpath";
235  }
236  $self->{'DEV_NULL'} = '> NUL';
237  # $self->{'NOECHO'} = ''; # till we have it working
238 }
239
240
241 =item constants (o)
242
243 Initializes lots of constants and .SUFFIXES and .PHONY
244
245 =cut
246
247 sub constants {
248     my($self) = @_;
249     my(@m,$tmp);
250
251     for $tmp (qw/
252
253               AR_STATIC_ARGS NAME DISTNAME NAME_SYM VERSION
254               VERSION_SYM XS_VERSION INST_BIN INST_EXE INST_LIB
255               INST_ARCHLIB INST_SCRIPT PREFIX  INSTALLDIRS
256               INSTALLPRIVLIB INSTALLARCHLIB INSTALLSITELIB
257               INSTALLSITEARCH INSTALLBIN INSTALLSCRIPT PERL_LIB
258               PERL_ARCHLIB SITELIBEXP SITEARCHEXP LIBPERL_A MYEXTLIB
259               FIRST_MAKEFILE MAKE_APERL_FILE PERLMAINCC PERL_SRC
260               PERL_INC PERL FULLPERL PERLRUN PERLRUNINST TEST_LIBS 
261               FULL_AR PERL_CORE
262
263               / ) {
264         next unless defined $self->{$tmp};
265         push @m, "$tmp = $self->{$tmp}\n";
266     }
267
268     push @m, qq{
269 VERSION_MACRO = VERSION
270 DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
271 XS_VERSION_MACRO = XS_VERSION
272 XS_DEFINE_VERSION = -D\$(XS_VERSION_MACRO)=\\\"\$(XS_VERSION)\\\"
273 };
274
275     push @m, qq{
276 MAKEMAKER = $INC{'ExtUtils\MakeMaker.pm'}
277 MM_VERSION = $ExtUtils::MakeMaker::VERSION
278 };
279
280     push @m, q{
281 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
282 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
283 # ROOTEXT = Directory part of FULLEXT with leading slash (eg /DBD)  !!! Deprecated from MM 5.32  !!!
284 # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
285 # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
286 };
287
288     for $tmp (qw/
289               FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
290               LDFROM LINKTYPE
291               / ) {
292         next unless defined $self->{$tmp};
293         push @m, "$tmp = $self->{$tmp}\n";
294     }
295
296     push @m, "
297 # Handy lists of source code files:
298 XS_FILES= ".join(" \\\n\t", sort keys %{$self->{XS}})."
299 C_FILES = ".join(" \\\n\t", @{$self->{C}})."
300 O_FILES = ".join(" \\\n\t", @{$self->{O_FILES}})."
301 H_FILES = ".join(" \\\n\t", @{$self->{H}})."
302 HTMLLIBPODS    = ".join(" \\\n\t", sort keys %{$self->{HTMLLIBPODS}})."
303 HTMLSCRIPTPODS = ".join(" \\\n\t", sort keys %{$self->{HTMLSCRIPTPODS}})."
304 MAN1PODS = ".join(" \\\n\t", sort keys %{$self->{MAN1PODS}})."
305 MAN3PODS = ".join(" \\\n\t", sort keys %{$self->{MAN3PODS}})."
306 ";
307
308     for $tmp (qw/
309               INST_HTMLPRIVLIBDIR INSTALLHTMLPRIVLIBDIR
310               INST_HTMLSITELIBDIR INSTALLHTMLSITELIBDIR
311               INST_HTMLSCRIPTDIR  INSTALLHTMLSCRIPTDIR
312               INST_HTMLLIBDIR                    HTMLEXT
313               INST_MAN1DIR        INSTALLMAN1DIR MAN1EXT
314               INST_MAN3DIR        INSTALLMAN3DIR MAN3EXT
315               /) {
316         next unless defined $self->{$tmp};
317         push @m, "$tmp = $self->{$tmp}\n";
318     }
319
320     push @m, qq{
321 .USESHELL :
322 } if $DMAKE;
323
324     push @m, q{
325 .NO_CONFIG_REC: Makefile
326 } if $ENV{CLEARCASE_ROOT};
327
328     # why not q{} ? -- emacs
329     push @m, qq{
330 # work around a famous dec-osf make(1) feature(?):
331 makemakerdflt: all
332
333 .SUFFIXES: .xs .c .C .cpp .cxx .cc \$(OBJ_EXT)
334
335 # Nick wanted to get rid of .PRECIOUS. I don't remember why. I seem to recall, that
336 # some make implementations will delete the Makefile when we rebuild it. Because
337 # we call false(1) when we rebuild it. So make(1) is not completely wrong when it
338 # does so. Our milage may vary.
339 # .PRECIOUS: Makefile    # seems to be not necessary anymore
340
341 .PHONY: all config static dynamic test linkext manifest
342
343 # Where is the Config information that we are using/depend on
344 CONFIGDEP = \$(PERL_ARCHLIB)\\Config.pm \$(PERL_INC)\\config.h
345 };
346
347     my @parentdir = split(/::/, $self->{PARENT_NAME});
348     push @m, q{
349 # Where to put things:
350 INST_LIBDIR      = }. $self->catdir('$(INST_LIB)',@parentdir)        .q{
351 INST_ARCHLIBDIR  = }. $self->catdir('$(INST_ARCHLIB)',@parentdir)    .q{
352
353 INST_AUTODIR     = }. $self->catdir('$(INST_LIB)','auto','$(FULLEXT)')       .q{
354 INST_ARCHAUTODIR = }. $self->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)')   .q{
355 };
356
357     if ($self->has_link_code()) {
358         push @m, '
359 INST_STATIC  = $(INST_ARCHAUTODIR)\$(BASEEXT)$(LIB_EXT)
360 INST_DYNAMIC = $(INST_ARCHAUTODIR)\$(DLBASE).$(DLEXT)
361 INST_BOOT    = $(INST_ARCHAUTODIR)\$(BASEEXT).bs
362 ';
363     } else {
364         push @m, '
365 INST_STATIC  =
366 INST_DYNAMIC =
367 INST_BOOT    =
368 ';
369     }
370
371     $tmp = $self->export_list;
372     push @m, "
373 EXPORT_LIST = $tmp
374 ";
375     $tmp = $self->perl_archive;
376     push @m, "
377 PERL_ARCHIVE = $tmp
378 ";
379
380 #    push @m, q{
381 #INST_PM = }.join(" \\\n\t", sort values %{$self->{PM}}).q{
382 #
383 #PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
384 #};
385
386     push @m, q{
387 TO_INST_PM = }.join(" \\\n\t", sort keys %{$self->{PM}}).q{
388
389 PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
390 };
391
392     join('',@m);
393 }
394
395
396 sub path {
397     my($self) = @_;
398     my $path = $ENV{'PATH'} || $ENV{'Path'} || $ENV{'path'};
399     my @path = split(';',$path);
400     foreach(@path) { $_ = '.' if $_ eq '' }
401     @path;
402 }
403
404 =item static_lib (o)
405
406 Defines how to produce the *.a (or equivalent) files.
407
408 =cut
409
410 sub static_lib {
411     my($self) = @_;
412 # Come to think of it, if there are subdirs with linkcode, we still have no INST_STATIC
413 #    return '' unless $self->needs_linking(); #might be because of a subdir
414
415     return '' unless $self->has_link_code;
416
417     my(@m);
418     push(@m, <<'END');
419 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)\.exists
420         $(RM_RF) $@
421 END
422     # If this extension has its own library (eg SDBM_File)
423     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
424     push(@m, "\t$self->{CP} \$(MYEXTLIB) \$\@\n") if $self->{MYEXTLIB};
425
426     push @m,
427 q{      $(AR) }.($BORLAND ? '$@ $(OBJECT:^"+")'
428                           : ($GCC ? '-ru $@ $(OBJECT)'
429                                   : '-out:$@ $(OBJECT)')).q{
430         }.$self->{NOECHO}.q{echo "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
431         $(CHMOD) 755 $@
432 };
433
434 # Old mechanism - still available:
435
436     push @m, "\t$self->{NOECHO}".q{echo "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs}."\n\n"
437         if $self->{PERL_SRC};
438
439     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
440     join('', "\n",@m);
441 }
442
443 =item dynamic_bs (o)
444
445 Defines targets for bootstrap files.
446
447 =cut
448
449 sub dynamic_bs {
450     my($self, %attribs) = @_;
451     return '
452 BOOTSTRAP =
453 ' unless $self->has_link_code();
454
455     return '
456 BOOTSTRAP = '."$self->{BASEEXT}.bs".'
457
458 # As Mkbootstrap might not write a file (if none is required)
459 # we use touch to prevent make continually trying to remake it.
460 # The DynaLoader only reads a non-empty file.
461 $(BOOTSTRAP): '."$self->{MAKEFILE} $self->{BOOTDEP}".' $(INST_ARCHAUTODIR)\.exists
462         '.$self->{NOECHO}.'echo "Running Mkbootstrap for $(NAME) ($(BSLOADLIBS))"
463         '.$self->{NOECHO}.'$(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" \
464                 -MExtUtils::Mkbootstrap \
465                 -e "Mkbootstrap(\'$(BASEEXT)\',\'$(BSLOADLIBS)\');"
466         '.$self->{NOECHO}.'$(TOUCH) $(BOOTSTRAP)
467         $(CHMOD) 644 $@
468
469 $(INST_BOOT): $(BOOTSTRAP) $(INST_ARCHAUTODIR)\.exists
470         '."$self->{NOECHO}$self->{RM_RF}".' $(INST_BOOT)
471         -'.$self->{CP}.' $(BOOTSTRAP) $(INST_BOOT)
472         $(CHMOD) 644 $@
473 ';
474 }
475
476 =item dynamic_lib (o)
477
478 Defines how to produce the *.so (or equivalent) files.
479
480 =cut
481
482 sub dynamic_lib {
483     my($self, %attribs) = @_;
484     return '' unless $self->needs_linking(); #might be because of a subdir
485
486     return '' unless $self->has_link_code;
487
488     my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
489     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
490     my($ldfrom) = '$(LDFROM)';
491     my(@m);
492
493 # one thing for GCC/Mingw32:
494 # we try to overcome non-relocateable-DLL problems by generating
495 #    a (hopefully unique) image-base from the dll's name
496 # -- BKS, 10-19-1999
497     if ($GCC) { 
498         my $dllname = $self->{BASEEXT} . "." . $self->{DLEXT};
499         $dllname =~ /(....)(.{0,4})/;
500         my $baseaddr = unpack("n", $1 ^ $2);
501         $otherldflags .= sprintf("-Wl,--image-base,0x%x0000 ", $baseaddr);
502     }
503
504     push(@m,'
505 # This section creates the dynamically loadable $(INST_DYNAMIC)
506 # from $(OBJECT) and possibly $(MYEXTLIB).
507 OTHERLDFLAGS = '.$otherldflags.'
508 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
509
510 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)\.exists $(EXPORT_LIST) $(PERL_ARCHIVE) $(INST_DYNAMIC_DEP)
511 ');
512     if ($GCC) {
513       push(@m,  
514        q{       dlltool --def $(EXPORT_LIST) --output-exp dll.exp
515         $(LD) -o $@ -Wl,--base-file -Wl,dll.base $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp
516         dlltool --def $(EXPORT_LIST) --base-file dll.base --output-exp dll.exp
517         $(LD) -o $@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) $(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) dll.exp });
518     } elsif ($BORLAND) {
519       push(@m,
520        q{       $(LD) $(LDDLFLAGS) $(OTHERLDFLAGS) }.$ldfrom.q{,$@,,}
521        .($DMAKE ? q{$(PERL_ARCHIVE:s,/,\,) $(LDLOADLIBS:s,/,\,) }
522                  .q{$(MYEXTLIB:s,/,\,),$(EXPORT_LIST:s,/,\,)}
523                 : q{$(subst /,\,$(PERL_ARCHIVE)) $(subst /,\,$(LDLOADLIBS)) }
524                  .q{$(subst /,\,$(MYEXTLIB)),$(subst /,\,$(EXPORT_LIST))})
525        .q{,$(RESFILES)});
526     } else {    # VC
527       push(@m,
528        q{       $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
529       .q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
530     }
531     push @m, '
532         $(CHMOD) 755 $@
533 ';
534
535     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
536     join('',@m);
537 }
538
539 sub clean
540 {
541     my ($self) = @_;
542     my $s = &ExtUtils::MM_Unix::clean;
543     my $clean = $GCC ? 'dll.base dll.exp' : '*.pdb';
544     $s .= <<END;
545 clean ::
546         -\$(RM_F) $clean
547
548 END
549     return $s;
550 }
551
552
553
554 sub perl_archive
555 {
556     my ($self) = @_;
557     return '$(PERL_INC)\\'.$Config{'libperl'};
558 }
559
560 sub export_list
561 {
562  my ($self) = @_;
563  return "$self->{BASEEXT}.def";
564 }
565
566 =item canonpath
567
568 No physical check on the filesystem, but a logical cleanup of a
569 path. On UNIX eliminated successive slashes and successive "/.".
570
571 =cut
572
573 sub canonpath {
574     my($self,$path) = @_;
575     $path =~ s/^([a-z]:)/\u$1/;
576     $path =~ s|/|\\|g;
577     $path =~ s|(.)\\+|$1\\|g ;                     # xx////xx  -> xx/xx
578     $path =~ s|(\\\.)+\\|\\|g ;                    # xx/././xx -> xx/xx
579     $path =~ s|^(\.\\)+|| unless $path eq ".\\";   # ./xx      -> xx
580     $path =~ s|\\$|| 
581              unless $path =~ m#^([a-z]:)?\\#;      # xx/       -> xx
582     $path .= '.' if $path =~ m#\\$#;
583     $path;
584 }
585
586 =item perl_script
587
588 Takes one argument, a file name, and returns the file name, if the
589 argument is likely to be a perl script. On MM_Unix this is true for
590 any ordinary, readable file.
591
592 =cut
593
594 sub perl_script {
595     my($self,$file) = @_;
596     return $file if -r $file && -f _;
597     return "$file.pl" if -r "$file.pl" && -f _;
598     return "$file.bat" if -r "$file.bat" && -f _;
599     return;
600 }
601
602 =item pm_to_blib
603
604 Defines target that copies all files in the hash PM to their
605 destination and autosplits them. See L<ExtUtils::Install/DESCRIPTION>
606
607 =cut
608
609 sub pm_to_blib {
610     my $self = shift;
611     my($autodir) = $self->catdir('$(INST_LIB)','auto');
612     return q{
613 pm_to_blib: $(TO_INST_PM)
614         }.$self->{NOECHO}.q{$(PERL) "-I$(INST_ARCHLIB)" "-I$(INST_LIB)" \
615         "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MExtUtils::Install \
616         -e "pm_to_blib(}.
617         ($NMAKE ? 'qw[ <<pmfiles.dat ],'
618                 : $DMAKE ? 'qw[ $(mktmp,pmfiles.dat $(PM_TO_BLIB:s,\\,\\\\,)\n) ],'
619                          : '{ qw[$(PM_TO_BLIB)] },'
620          ).q{'}.$autodir.q{','$(PM_FILTER)')"
621         }. ($NMAKE ? q{
622 $(PM_TO_BLIB)
623 <<
624         } : '') . $self->{NOECHO}.q{$(TOUCH) $@
625 };
626 }
627
628 =item test_via_harness (o)
629
630 Helper method to write the test targets
631
632 =cut
633
634 sub test_via_harness {
635     my($self, $perl, $tests) = @_;
636     "\t$perl".q! -Mblib -I$(PERL_ARCHLIB) -I$(PERL_LIB) -e "use Test::Harness qw(&runtests $$verbose); $$verbose=$(TEST_VERBOSE); runtests @ARGV;" !."$tests\n";
637 }
638
639
640 =item tool_autosplit (override)
641
642 Use Win32 quoting on command line.
643
644 =cut
645
646 sub tool_autosplit{
647     my($self, %attribs) = @_;
648     my($asl) = "";
649     $asl = "\$AutoSplit::Maxlen=$attribs{MAXLEN};" if $attribs{MAXLEN};
650     q{
651 # Usage: $(AUTOSPLITFILE) FileToSplit AutoDirToSplitInto
652 AUTOSPLITFILE = $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -MAutoSplit }.$asl.q{ -e "autosplit($$ARGV[0], $$ARGV[1], 0, 1, 1);"
653 };
654 }
655
656 =item tools_other (o)
657
658 Win32 overrides.
659
660 Defines SHELL, LD, TOUCH, CP, MV, RM_F, RM_RF, CHMOD, UMASK_NULL in
661 the Makefile. Also defines the perl programs MKPATH,
662 WARN_IF_OLD_PACKLIST, MOD_INSTALL. DOC_INSTALL, and UNINSTALL.
663
664 =cut
665
666 sub tools_other {
667     my($self) = shift;
668     my @m;
669     my $bin_sh = $Config{sh} || 'cmd /c';
670     push @m, qq{
671 SHELL = $bin_sh
672 } unless $DMAKE;  # dmake determines its own shell 
673
674     for (qw/ CHMOD CP LD MV NOOP RM_F RM_RF TEST_F TOUCH UMASK_NULL DEV_NULL/ ) {
675         push @m, "$_ = $self->{$_}\n";
676     }
677
678     push @m, q{
679 # The following is a portable way to say mkdir -p
680 # To see which directories are created, change the if 0 to if 1
681 MKPATH = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e mkpath
682
683 # This helps us to minimize the effect of the .exists files A yet
684 # better solution would be to have a stable file in the perl
685 # distribution with a timestamp of zero. But this solution doesn't
686 # need any changes to the core distribution and works with older perls
687 EQUALIZE_TIMESTAMP = $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Command -e eqtime
688 };
689
690
691     return join "", @m if $self->{PARENT};
692
693     push @m, q{
694 # Here we warn users that an old packlist file was found somewhere,
695 # and that they should call some uninstall routine
696 WARN_IF_OLD_PACKLIST = $(PERL) -lwe "exit unless -f $$ARGV[0];" \\
697 -e "print 'WARNING: I have found an old package in';" \\
698 -e "print '     ', $$ARGV[0], '.';" \\
699 -e "print 'Please make sure the two installations are not conflicting';"
700
701 UNINST=0
702 VERBINST=1
703
704 MOD_INSTALL = $(PERL) -I$(INST_LIB) -I$(PERL_LIB) -MExtUtils::Install \
705 -e "install({ @ARGV },'$(VERBINST)',0,'$(UNINST)');"
706
707 DOC_INSTALL = $(PERL) -e "$$\=\"\n\n\";" \
708 -e "print '=head2 ', scalar(localtime), ': C<', shift, '>', ' L<', $$arg=shift, '|', $$arg, '>';" \
709 -e "print '=over 4';" \
710 -e "while (defined($$key = shift) and defined($$val = shift)) { print '=item *';print 'C<', \"$$key: $$val\", '>'; }" \
711 -e "print '=back';"
712
713 UNINSTALL =   $(PERL) -MExtUtils::Install \
714 -e "uninstall($$ARGV[0],1,1); print \"\nUninstall is deprecated. Please check the";" \
715 -e "print \" packlist above carefully.\n  There may be errors. Remove the\";" \
716 -e "print \" appropriate files manually.\n  Sorry for the inconveniences.\n\""
717 };
718
719     return join "", @m;
720 }
721
722 =item xs_o (o)
723
724 Defines suffix rules to go from XS to object files directly. This is
725 only intended for broken make implementations.
726
727 =cut
728
729 sub xs_o {      # many makes are too dumb to use xs_c then c_o
730     my($self) = shift;
731     return ''
732 }
733
734 =item top_targets (o)
735
736 Defines the targets all, subdirs, config, and O_FILES
737
738 =cut
739
740 sub top_targets {
741 # --- Target Sections ---
742
743     my($self) = shift;
744     my(@m);
745     push @m, '
746 #all :: config $(INST_PM) subdirs linkext manifypods
747 ';
748
749     push @m, '
750 all :: pure_all htmlifypods manifypods
751         '.$self->{NOECHO}.'$(NOOP)
752
753           unless $self->{SKIPHASH}{'all'};
754     
755     push @m, '
756 pure_all :: config pm_to_blib subdirs linkext
757         '.$self->{NOECHO}.'$(NOOP)
758
759 subdirs :: $(MYEXTLIB)
760         '.$self->{NOECHO}.'$(NOOP)
761
762 config :: '.$self->{MAKEFILE}.' $(INST_LIBDIR)\.exists
763         '.$self->{NOECHO}.'$(NOOP)
764
765 config :: $(INST_ARCHAUTODIR)\.exists
766         '.$self->{NOECHO}.'$(NOOP)
767
768 config :: $(INST_AUTODIR)\.exists
769         '.$self->{NOECHO}.'$(NOOP)
770 ';
771
772     push @m, $self->dir_target(qw[$(INST_AUTODIR) $(INST_LIBDIR) $(INST_ARCHAUTODIR)]);
773
774     if (%{$self->{HTMLLIBPODS}}) {
775         push @m, qq[
776 config :: \$(INST_HTMLLIBDIR)/.exists
777         $self->{NOECHO}\$(NOOP)
778
779 ];
780         push @m, $self->dir_target(qw[$(INST_HTMLLIBDIR)]);
781     }
782
783     if (%{$self->{HTMLSCRIPTPODS}}) {
784         push @m, qq[
785 config :: \$(INST_HTMLSCRIPTDIR)/.exists
786         $self->{NOECHO}\$(NOOP)
787
788 ];
789         push @m, $self->dir_target(qw[$(INST_HTMLSCRIPTDIR)]);
790     }
791
792     if (%{$self->{MAN1PODS}}) {
793         push @m, qq[
794 config :: \$(INST_MAN1DIR)\\.exists
795         $self->{NOECHO}\$(NOOP)
796
797 ];
798         push @m, $self->dir_target(qw[$(INST_MAN1DIR)]);
799     }
800     if (%{$self->{MAN3PODS}}) {
801         push @m, qq[
802 config :: \$(INST_MAN3DIR)\\.exists
803         $self->{NOECHO}\$(NOOP)
804
805 ];
806         push @m, $self->dir_target(qw[$(INST_MAN3DIR)]);
807     }
808
809     push @m, '
810 $(O_FILES): $(H_FILES)
811 ' if @{$self->{O_FILES} || []} && @{$self->{H} || []};
812
813     push @m, q{
814 help:
815         perldoc ExtUtils::MakeMaker
816 };
817
818     push @m, q{
819 Version_check:
820         }.$self->{NOECHO}.q{$(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) \
821                 -MExtUtils::MakeMaker=Version_check \
822                 -e "Version_check('$(MM_VERSION)')"
823 };
824
825     join('',@m);
826 }
827
828 =item htmlifypods (o)
829
830 Defines targets and routines to translate the pods into HTML manpages
831 and put them into the INST_HTMLLIBDIR and INST_HTMLSCRIPTDIR
832 directories.
833
834 Same as MM_Unix version (changes command-line quoting).
835
836 =cut
837
838 sub htmlifypods {
839     my($self, %attribs) = @_;
840     return "\nhtmlifypods : pure_all\n\t$self->{NOECHO}\$(NOOP)\n" unless
841         %{$self->{HTMLLIBPODS}} || %{$self->{HTMLSCRIPTPODS}};
842     my($dist);
843     my($pod2html_exe);
844     if (defined $self->{PERL_SRC}) {
845         $pod2html_exe = $self->catfile($self->{PERL_SRC},'pod','pod2html');
846     } else {
847         $pod2html_exe = $self->catfile($Config{scriptdirexp},'pod2html');
848     }
849     unless ($pod2html_exe = $self->perl_script($pod2html_exe)) {
850         # No pod2html but some HTMLxxxPODS to be installed
851         print <<END;
852
853 Warning: I could not locate your pod2html program. Please make sure,
854          your pod2html program is in your PATH before you execute 'make'
855
856 END
857         $pod2html_exe = "-S pod2html";
858     }
859     my(@m);
860     push @m,
861 qq[POD2HTML_EXE = $pod2html_exe\n],
862 qq[POD2HTML = \$(PERL) -we "use File::Basename; use File::Path qw(mkpath); %m=\@ARGV;for (keys %m){" \\\n],
863 q[-e "next if -e $$m{$$_} && -M $$m{$$_} < -M $$_ && -M $$m{$$_} < -M '],
864  $self->{MAKEFILE}, q[';" \\
865 -e "print qq(Htmlifying $$m{$$_}\n);" \\
866 -e "$$dir = dirname($$m{$$_}); mkpath($$dir) unless -d $$dir;" \\
867 -e "system(qq[$$^X ].q["-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" $(POD2HTML_EXE) ].qq[$$_>$$m{$$_}])==0 or warn qq(Couldn\\047t install $$m{$$_}\n);" \\
868 -e "chmod(oct($(PERM_RW))), $$m{$$_} or warn qq(chmod $(PERM_RW) $$m{$$_}: $$!\n);}"
869 ];
870     push @m, "\nhtmlifypods : pure_all ";
871     push @m, join " \\\n\t", keys %{$self->{HTMLLIBPODS}}, keys %{$self->{HTMLSCRIPTPODS}};
872
873     push(@m,"\n");
874     if (%{$self->{HTMLLIBPODS}} || %{$self->{HTMLSCRIPTPODS}}) {
875         push @m, "\t$self->{NOECHO}\$(POD2HTML) \\\n\t";
876         push @m, join " \\\n\t", %{$self->{HTMLLIBPODS}}, %{$self->{HTMLSCRIPTPODS}};
877     }
878     join('', @m);
879 }
880
881 =item manifypods (o)
882
883 We don't want manpage process.
884
885 =cut
886
887 sub manifypods {
888     my($self) = shift;
889     return "\nmanifypods :\n\t$self->{NOECHO}\$(NOOP)\n";
890 }
891
892 =item dist_ci (o)
893
894 Same as MM_Unix version (changes command-line quoting).
895
896 =cut
897
898 sub dist_ci {
899     my($self) = shift;
900     my @m;
901     push @m, q{
902 ci :
903         $(PERL) -I$(PERL_ARCHLIB) -I$(PERL_LIB) -MExtUtils::Manifest=maniread \\
904                 -e "@all = keys %{ maniread() };" \\
905                 -e "print(\"Executing $(CI) @all\n\"); system(\"$(CI) @all\");" \\
906                 -e "print(\"Executing $(RCS_LABEL) ...\n\"); system(\"$(RCS_LABEL) @all\");"
907 };
908     join "", @m;
909 }
910
911 =item dist_core (o)
912
913 Same as MM_Unix version (changes command-line quoting).
914
915 =cut
916
917 sub dist_core {
918     my($self) = shift;
919     my @m;
920     push @m, q{
921 dist : $(DIST_DEFAULT)
922         }.$self->{NOECHO}.q{$(PERL) -le "print \"Warning: Makefile possibly out of date with $$vf\" if " \
923             -e "-e ($$vf=\"$(VERSION_FROM)\") and -M $$vf < -M \"}.$self->{MAKEFILE}.q{\";"
924
925 tardist : $(DISTVNAME).tar$(SUFFIX)
926
927 zipdist : $(DISTVNAME).zip
928
929 $(DISTVNAME).tar$(SUFFIX) : distdir
930         $(PREOP)
931         $(TO_UNIX)
932         $(TAR) $(TARFLAGS) $(DISTVNAME).tar $(DISTVNAME)
933         $(RM_RF) $(DISTVNAME)
934         $(COMPRESS) $(DISTVNAME).tar
935         $(POSTOP)
936
937 $(DISTVNAME).zip : distdir
938         $(PREOP)
939         $(ZIP) $(ZIPFLAGS) $(DISTVNAME).zip $(DISTVNAME)
940         $(RM_RF) $(DISTVNAME)
941         $(POSTOP)
942
943 uutardist : $(DISTVNAME).tar$(SUFFIX)
944         uuencode $(DISTVNAME).tar$(SUFFIX) \\
945                 $(DISTVNAME).tar$(SUFFIX) > \\
946                 $(DISTVNAME).tar$(SUFFIX)_uu
947
948 shdist : distdir
949         $(PREOP)
950         $(SHAR) $(DISTVNAME) > $(DISTVNAME).shar
951         $(RM_RF) $(DISTVNAME)
952         $(POSTOP)
953 };
954     join "", @m;
955 }
956
957 =item pasthru (o)
958
959 Defines the string that is passed to recursive make calls in
960 subdirectories.
961
962 =cut
963
964 sub pasthru {
965     my($self) = shift;
966     return "PASTHRU = " . ($NMAKE ? "-nologo" : "");
967 }
968
969
970
971 1;
972 __END__
973
974 =back
975
976 =cut 
977
978