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