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