NetWare changeover from Watcom to Codewarrior, from C Aditya.
[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 File::Basename;
23
24 #require Exporter;
25
26 #use ExtUtils::MakeMaker;
27 #Exporter::import('ExtUtils::MakeMaker',
28 #       qw( $Verbose &neatvalue));
29
30 use vars qw(@ISA $VERSION);
31 $VERSION = '2.01_01';
32
33 require ExtUtils::MM_Win32;
34 @ISA = qw(ExtUtils::MM_Win32);
35
36 use ExtUtils::MakeMaker qw( &neatvalue );
37
38 $ENV{EMXSHELL} = 'sh'; # to run `commands`
39 #unshift @MM::ISA, 'ExtUtils::MM_NW5';
40
41 $BORLAND = 1 if $Config{'cc'} =~ /^bcc/i;
42 $GCC     = 1 if $Config{'cc'} =~ /^gcc/i;
43 $DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
44 $NMAKE = 1 if $Config{'make'} =~ /^nmake/i;
45 $PERLMAKE = 1 if $Config{'make'} =~ /^pmake/i;
46
47
48         
49 sub init_others
50 {
51  my ($self) = @_;
52  $self->SUPER::init_others(@_);
53
54  # incpath is copied to makefile var INCLUDE in constants sub, here just make it empty
55  my $libpth = $Config{'libpth'};
56  $libpth =~ s( )(;);
57  $self->{'LIBPTH'} = $libpth;
58  $self->{'BASE_IMPORT'} = $Config{'base_import'};
59  
60  # Additional import file specified from Makefile.pl
61  if($self->{'base_import'}) {
62         $self->{'BASE_IMPORT'} .= ', ' . $self->{'base_import'};
63  }
64  
65  $self->{'NLM_VERSION'} = $Config{'nlm_version'};
66  $self->{'MPKTOOL'}     = $Config{'mpktool'};
67  $self->{'TOOLPATH'}    = $Config{'toolpath'};
68 }
69
70
71 =item constants (o)
72
73 Initializes lots of constants and .SUFFIXES and .PHONY
74
75 =cut
76 # NetWare override
77 sub const_cccmd {
78     my($self,$libperl)=@_;
79     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
80     return '' unless $self->needs_linking();
81     return $self->{CONST_CCCMD} = 
82         q{CCCMD = $(CC) $(CCFLAGS) $(INC) $(OPTIMIZE) \\
83         $(PERLTYPE) $(MPOLLUTE) -o $@ \\
84         -DVERSION=\"$(VERSION)\" -DXS_VERSION=\"$(XS_VERSION)\"};
85 }
86
87 sub constants {
88     my($self) = @_;
89     my(@m,$tmp);
90
91 # Added LIBPTH, BASE_IMPORT, ABSTRACT, NLM_VERSION BOOT_SYMBOL, NLM_SHORT_NAME
92 # for NETWARE
93
94     for $tmp (qw/
95
96               AR_STATIC_ARGS NAME DISTNAME NAME_SYM VERSION
97               VERSION_SYM XS_VERSION INST_BIN INST_LIB
98               INST_ARCHLIB INST_SCRIPT PREFIX  INSTALLDIRS
99               INSTALLPRIVLIB INSTALLARCHLIB INSTALLSITELIB
100               INSTALLSITEARCH INSTALLBIN INSTALLSCRIPT PERL_LIB
101               PERL_ARCHLIB SITELIBEXP SITEARCHEXP LIBPERL_A MYEXTLIB
102               FIRST_MAKEFILE MAKE_APERL_FILE PERLMAINCC PERL_SRC
103               PERL_INC PERL FULLPERL LIBPTH BASE_IMPORT PERLRUN
104                   FULLPERLRUN PERLRUNINST FULL_AR PERL_CORE FULLPERLRUNINST
105                   NLM_VERSION MPKTOOL TOOLPATH
106                   
107               / ) {
108         next unless defined $self->{$tmp};
109         push @m, "$tmp = $self->{$tmp}\n";
110     }
111
112         (my $boot = $self->{'NAME'}) =~ s/:/_/g;
113         $self->{'BOOT_SYMBOL'}=$boot;
114         push @m, "BOOT_SYMBOL = $self->{'BOOT_SYMBOL'}\n";
115
116         # If the final binary name is greater than 8 chars,
117         # truncate it here and rename it after creation
118         # otherwise, Watcom Linker fails
119         
120         if(length($self->{'BASEEXT'}) > 8) {
121                 $self->{'NLM_SHORT_NAME'} = substr($self->{'BASEEXT'},0,8);
122                 push @m, "NLM_SHORT_NAME = $self->{'NLM_SHORT_NAME'}\n";
123         }
124         
125     push @m, qq{
126 VERSION_MACRO = VERSION
127 DEFINE_VERSION = -D\$(VERSION_MACRO)=\\\"\$(VERSION)\\\"
128 XS_VERSION_MACRO = XS_VERSION
129 XS_DEFINE_VERSION = -D\$(XS_VERSION_MACRO)=\\\"\$(XS_VERSION)\\\"
130 };
131
132         # Get the include path and replace the spaces with ;
133         # Copy this to makefile as INCLUDE = d:\...;d:\;
134         (my $inc = $Config{'incpath'}) =~ s/([ ]*)-I/;/g;
135
136 =head
137         # Commented by Ananth since the below code was not adding the DBI path
138         # and compilation was failing due to non-availability of the correct path. 3 Jan 2002
139
140         # Get the additional include path and append to INCLUDE, keep it in
141         # INC will give problems during compilation, hence reset it after getting
142         # the value
143 ##      (my $add_inc = $self->{'INC'}) =~ s/ -I/;/g;
144         $self->{'INC'} = '';
145         push @m, qq{
146 INCLUDE = $inc;$add_inc;
147 };
148 =cut
149
150 push @m, qq{
151 INCLUDE = $inc;
152 };
153         # Set the path to CodeWarrior binaries which might not have been set in
154         # any other place
155         push @m, qq{
156 PATH = \$(PATH);\$(TOOLPATH)
157 };
158
159     push @m, qq{
160 MAKEMAKER = $INC{'ExtUtils/MakeMaker.pm'}
161 MM_VERSION = $ExtUtils::MakeMaker::VERSION
162 };
163
164     push @m, q{
165 # FULLEXT = Pathname for extension directory (eg Foo/Bar/Oracle).
166 # BASEEXT = Basename part of FULLEXT. May be just equal FULLEXT. (eg Oracle)
167 # PARENT_NAME = NAME without BASEEXT and no trailing :: (eg Foo::Bar)
168 # DLBASE  = Basename part of dynamic library. May be just equal BASEEXT.
169 };
170
171     for $tmp (qw/
172               FULLEXT BASEEXT PARENT_NAME DLBASE VERSION_FROM INC DEFINE OBJECT
173               LDFROM LINKTYPE
174               / ) {
175         next unless defined $self->{$tmp};
176         push @m, "$tmp = $self->{$tmp}\n";
177     }
178
179     push @m, "
180 # Handy lists of source code files:
181 XS_FILES= ".join(" \\\n\t", sort keys %{$self->{XS}})."
182 C_FILES = ".join(" \\\n\t", @{$self->{C}})."
183 O_FILES = ".join(" \\\n\t", @{$self->{O_FILES}})."
184 H_FILES = ".join(" \\\n\t", @{$self->{H}})."
185 MAN1PODS = ".join(" \\\n\t", sort keys %{$self->{MAN1PODS}})."
186 MAN3PODS = ".join(" \\\n\t", sort keys %{$self->{MAN3PODS}})."
187 ";
188
189     for $tmp (qw/
190               INST_MAN1DIR        INSTALLMAN1DIR MAN1EXT
191               INST_MAN3DIR        INSTALLMAN3DIR MAN3EXT
192               /) {
193         next unless defined $self->{$tmp};
194         push @m, "$tmp = $self->{$tmp}\n";
195     }
196
197     push @m, qq{
198 .USESHELL :
199 } if $DMAKE;
200
201     push @m, q{
202 .NO_CONFIG_REC: Makefile
203 } if $ENV{CLEARCASE_ROOT};
204
205     # why not q{} ? -- emacs
206     push @m, qq{
207 # work around a famous dec-osf make(1) feature(?):
208 makemakerdflt: all
209
210 .SUFFIXES: .xs .c .C .cpp .cxx .cc \$(OBJ_EXT)
211
212 # Nick wanted to get rid of .PRECIOUS. I don't remember why. I seem to recall, that
213 # some make implementations will delete the Makefile when we rebuild it. Because
214 # we call false(1) when we rebuild it. So make(1) is not completely wrong when it
215 # does so. Our milage may vary.
216 # .PRECIOUS: Makefile    # seems to be not necessary anymore
217
218 .PHONY: all config static dynamic test linkext manifest
219
220 # Where is the Config information that we are using/depend on
221 CONFIGDEP = \$(PERL_ARCHLIB)\\Config.pm \$(PERL_INC)\\config.h
222 };
223
224     my @parentdir = split(/::/, $self->{PARENT_NAME});
225     push @m, q{
226 # Where to put things:
227 INST_LIBDIR      = }. File::Spec->catdir('$(INST_LIB)',@parentdir)        .q{
228 INST_ARCHLIBDIR  = }. File::Spec->catdir('$(INST_ARCHLIB)',@parentdir)    .q{
229
230 INST_AUTODIR     = }. File::Spec->catdir('$(INST_LIB)','auto','$(FULLEXT)')       .q{
231 INST_ARCHAUTODIR = }. File::Spec->catdir('$(INST_ARCHLIB)','auto','$(FULLEXT)')   .q{
232 };
233
234     if ($self->has_link_code()) {
235         push @m, '
236 INST_STATIC  = $(INST_ARCHAUTODIR)\$(BASEEXT)$(LIB_EXT)
237 INST_DYNAMIC = $(INST_ARCHAUTODIR)\$(DLBASE).$(DLEXT)
238 INST_BOOT    = $(INST_ARCHAUTODIR)\$(BASEEXT).bs
239 ';
240     } else {
241         push @m, '
242 INST_STATIC  =
243 INST_DYNAMIC =
244 INST_BOOT    =
245 ';
246     }
247
248     $tmp = $self->export_list;
249     push @m, "
250 EXPORT_LIST = $tmp
251 ";
252     $tmp = $self->perl_archive;
253     push @m, "
254 PERL_ARCHIVE = $tmp
255 ";
256
257 #    push @m, q{
258 #INST_PM = }.join(" \\\n\t", sort values %{$self->{PM}}).q{
259 #
260 #PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
261 #};
262
263     push @m, q{
264 TO_INST_PM = }.join(" \\\n\t", sort keys %{$self->{PM}}).q{
265
266 PM_TO_BLIB = }.join(" \\\n\t", %{$self->{PM}}).q{
267 };
268
269     join('',@m);
270 }
271
272 =item dynamic_lib (o)
273
274 Defines how to produce the *.so (or equivalent) files.
275
276 =cut
277
278 sub dynamic_lib {
279         my($self, %attribs) = @_;
280     return '' unless $self->needs_linking(); #might be because of a subdir
281
282     return '' unless $self->has_link_code;
283
284     my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
285     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
286     my($ldfrom) = '$(LDFROM)';
287     my(@m);
288         (my $boot = $self->{NAME}) =~ s/:/_/g;
289         my ($mpk);
290     push(@m,'
291 # This section creates the dynamically loadable $(INST_DYNAMIC)
292 # from $(OBJECT) and possibly $(MYEXTLIB).
293 OTHERLDFLAGS = '.$otherldflags.'
294 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
295
296 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP)
297 ');
298 #      push(@m,
299 #      q{       $(LD) -out:$@ $(LDDLFLAGS) }.$ldfrom.q{ $(OTHERLDFLAGS) }
300 #      .q{$(MYEXTLIB) $(PERL_ARCHIVE) $(LDLOADLIBS) -def:$(EXPORT_LIST)});
301
302                 # Create xdc data for an MT safe NLM in case of mpk build
303 #       if ( scalar(keys %XS) == 0 ) { return; }
304                 push(@m, 
305                 q{      @echo Export boot_$(BOOT_SYMBOL) > $(BASEEXT).def
306 }); 
307         push(@m, 
308     q{  @echo $(BASE_IMPORT) >> $(BASEEXT).def 
309 });
310         push(@m, 
311     q{  @echo Import @$(PERL_INC)\perl.imp >> $(BASEEXT).def 
312 });  
313
314                 if ( $self->{CCFLAGS} =~ m/ -DMPK_ON /) {
315                         $mpk=1;
316                         push @m, '      $(MPKTOOL) $(XDCFLAGS) $(BASEEXT).xdc
317 ';
318                         push @m, '      @echo xdcdata $(BASEEXT).xdc >> $(BASEEXT).def
319 ';
320                 } else {
321                         $mpk=0;
322                 }
323                 
324                 push(@m,
325                         q{      $(LD) $(LDFLAGS) $(OBJECT:.obj=.obj) } 
326                         );
327
328                 push(@m,
329                         q{      -desc "Perl 5.7.3 Extension ($(BASEEXT))        XS_VERSION: $(XS_VERSION)" -nlmversion $(NLM_VERSION) } 
330                         );
331                         
332                 # Taking care of long names like FileHandle, ByteLoader, SDBM_File etc
333                 if($self->{NLM_SHORT_NAME}) {
334                         # In case of nlms with names exceeding 8 chars, build nlm in the 
335                         # current dir, rename and move to auto\lib.  If we create in auto\lib
336                         # in the first place, we can't rename afterwards.
337                         push(@m,
338                                 q{ -o $(NLM_SHORT_NAME).$(DLEXT)}
339                                 );
340                 } else {
341                         push(@m,
342                                 q{ -o $(INST_AUTODIR)\\$(BASEEXT).$(DLEXT)}
343                                 );
344                 }
345
346                 
347 #               if ($mpk) {
348 #               push (@m, 
349 #               q{ Option XDCDATA=$(BASEEXT).xdc }
350 #               );
351 #               }
352
353                 # Add additional lib files if any (SDBM_File)
354                 if($self->{MYEXTLIB}) {
355                         push(@m,
356                                 q{ $(MYEXTLIB) }
357                                 );
358                 }
359
360 #For now lets comment all the Watcom lib calls
361 #q{ LibPath $(LIBPTH) Library plib3s.lib Library math3s.lib Library clib3s.lib Library emu387.lib Library $(PERL_ARCHIVE) Library $(PERL_INC)\Main.lib}
362         
363        
364                 push(@m,
365                                 q{ $(PERL_INC)\Main.lib}
366                            .q{ -commandfile $(BASEEXT).def }
367                         );
368
369                 # If it is having a short name, rename it 
370                 if($self->{NLM_SHORT_NAME}) {
371                         push @m, '
372  if exist $(INST_AUTODIR)\\$(BASEEXT).$(DLEXT) del $(INST_AUTODIR)\\$(BASEEXT).$(DLEXT)';
373                         push @m, '
374  rename $(NLM_SHORT_NAME).$(DLEXT) $(BASEEXT).$(DLEXT)';
375                         push @m, '
376  move $(BASEEXT).$(DLEXT) $(INST_AUTODIR)';
377                 }
378
379     push @m, '
380         $(CHMOD) 755 $@
381 ';
382
383     push @m, $self->dir_target('$(INST_ARCHAUTODIR)');
384 # }  else {
385 #       push @m, '
386 #       @$(NOOP)
387 #';
388 # }
389     join('',@m);
390 }
391
392
393 1;
394 __END__
395
396 =back
397
398 =cut 
399