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