This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to ExtUtils-MakeMaker-6.47_01
[perl5.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 strict;
22 use ExtUtils::MakeMaker::Config;
23 use File::Basename;
24
25 our $VERSION = '6.47_01';
26
27 require ExtUtils::MM_Win32;
28 our @ISA = qw(ExtUtils::MM_Win32);
29
30 use ExtUtils::MakeMaker qw( &neatvalue );
31
32 $ENV{EMXSHELL} = 'sh'; # to run `commands`
33
34 my $BORLAND  = $Config{'cc'} =~ /^bcc/i;
35 my $GCC      = $Config{'cc'} =~ /^gcc/i;
36
37
38 =item os_flavor
39
40 We're Netware in addition to being Windows.
41
42 =cut
43
44 sub os_flavor {
45     my $self = shift;
46     return ($self->SUPER::os_flavor, 'Netware');
47 }
48
49 =item init_platform
50
51 Add Netware macros.
52
53 LIBPTH, BASE_IMPORT, NLM_VERSION, MPKTOOL, TOOLPATH, BOOT_SYMBOL,
54 NLM_SHORT_NAME, INCLUDE, PATH, MM_NW5_REVISION
55
56
57 =item platform_constants
58
59 Add Netware macros initialized above to the Makefile.
60
61 =cut
62
63 sub init_platform {
64     my($self) = shift;
65
66     # To get Win32's setup.
67     $self->SUPER::init_platform;
68
69     # incpath is copied to makefile var INCLUDE in constants sub, here just 
70     # make it empty
71     my $libpth = $Config{'libpth'};
72     $libpth =~ s( )(;);
73     $self->{'LIBPTH'} = $libpth;
74
75     $self->{'BASE_IMPORT'} = $Config{'base_import'};
76
77     # Additional import file specified from Makefile.pl
78     if($self->{'base_import'}) {
79         $self->{'BASE_IMPORT'} .= ', ' . $self->{'base_import'};
80     }
81  
82     $self->{'NLM_VERSION'} = $Config{'nlm_version'};
83     $self->{'MPKTOOL'}  = $Config{'mpktool'};
84     $self->{'TOOLPATH'} = $Config{'toolpath'};
85
86     (my $boot = $self->{'NAME'}) =~ s/:/_/g;
87     $self->{'BOOT_SYMBOL'}=$boot;
88
89     # If the final binary name is greater than 8 chars,
90     # truncate it here.
91     if(length($self->{'BASEEXT'}) > 8) {
92         $self->{'NLM_SHORT_NAME'} = substr($self->{'BASEEXT'},0,8);
93     }
94
95     # Get the include path and replace the spaces with ;
96     # Copy this to makefile as INCLUDE = d:\...;d:\;
97     ($self->{INCLUDE} = $Config{'incpath'}) =~ s/([ ]*)-I/;/g;
98
99     # Set the path to CodeWarrior binaries which might not have been set in
100     # any other place
101     $self->{PATH} = '$(PATH);$(TOOLPATH)';
102
103     $self->{MM_NW5_VERSION} = $VERSION;
104 }
105
106 sub platform_constants {
107     my($self) = shift;
108     my $make_frag = '';
109
110     # Setup Win32's constants.
111     $make_frag .= $self->SUPER::platform_constants;
112
113     foreach my $macro (qw(LIBPTH BASE_IMPORT NLM_VERSION MPKTOOL 
114                           TOOLPATH BOOT_SYMBOL NLM_SHORT_NAME INCLUDE PATH
115                           MM_NW5_VERSION
116                       ))
117     {
118         next unless defined $self->{$macro};
119         $make_frag .= "$macro = $self->{$macro}\n";
120     }
121
122     return $make_frag;
123 }
124
125
126 =item const_cccmd
127
128 =cut
129
130 sub const_cccmd {
131     my($self,$libperl)=@_;
132     return $self->{CONST_CCCMD} if $self->{CONST_CCCMD};
133     return '' unless $self->needs_linking();
134     return $self->{CONST_CCCMD} = <<'MAKE_FRAG';
135 CCCMD = $(CC) $(CCFLAGS) $(INC) $(OPTIMIZE) \
136         $(PERLTYPE) $(MPOLLUTE) -o $@ \
137         -DVERSION=\"$(VERSION)\" -DXS_VERSION=\"$(XS_VERSION)\"
138 MAKE_FRAG
139
140 }
141
142
143 =item static_lib
144
145 =cut
146
147 sub static_lib {
148     my($self) = @_;
149
150     return '' unless $self->has_link_code;
151
152     my $m = <<'END';
153 $(INST_STATIC): $(OBJECT) $(MYEXTLIB) $(INST_ARCHAUTODIR)$(DFSEP).exists
154         $(RM_RF) $@
155 END
156
157     # If this extension has it's own library (eg SDBM_File)
158     # then copy that to $(INST_STATIC) and add $(OBJECT) into it.
159     $m .= <<'END'  if $self->{MYEXTLIB};
160         $self->{CP} $(MYEXTLIB) $@
161 END
162
163     my $ar_arg;
164     if( $BORLAND ) {
165         $ar_arg = '$@ $(OBJECT:^"+")';
166     }
167     elsif( $GCC ) {
168         $ar_arg = '-ru $@ $(OBJECT)';
169     }
170     else {
171         $ar_arg = '-type library -o $@ $(OBJECT)';
172     }
173
174     $m .= sprintf <<'END', $ar_arg;
175         $(AR) %s
176         $(NOECHO) $(ECHO) "$(EXTRALIBS)" > $(INST_ARCHAUTODIR)\extralibs.ld
177         $(CHMOD) 755 $@
178 END
179
180     $m .= <<'END' if $self->{PERL_SRC};
181         $(NOECHO) $(ECHO) "$(EXTRALIBS)" >> $(PERL_SRC)\ext.libs
182
183
184 END
185     return $m;
186 }
187
188 =item dynamic_lib
189
190 Defines how to produce the *.so (or equivalent) files.
191
192 =cut
193
194 sub dynamic_lib {
195     my($self, %attribs) = @_;
196     return '' unless $self->needs_linking(); #might be because of a subdir
197
198     return '' unless $self->has_link_code;
199
200     my($otherldflags) = $attribs{OTHERLDFLAGS} || ($BORLAND ? 'c0d32.obj': '');
201     my($inst_dynamic_dep) = $attribs{INST_DYNAMIC_DEP} || "";
202     my($ldfrom) = '$(LDFROM)';
203
204     (my $boot = $self->{NAME}) =~ s/:/_/g;
205
206     my $m = <<'MAKE_FRAG';
207 # This section creates the dynamically loadable $(INST_DYNAMIC)
208 # from $(OBJECT) and possibly $(MYEXTLIB).
209 OTHERLDFLAGS = '.$otherldflags.'
210 INST_DYNAMIC_DEP = '.$inst_dynamic_dep.'
211
212 # Create xdc data for an MT safe NLM in case of mpk build
213 $(INST_DYNAMIC): $(OBJECT) $(MYEXTLIB) $(BOOTSTRAP) $(INST_ARCHAUTODIR)$(DFSEP).exists
214         $(NOECHO) $(ECHO) Export boot_$(BOOT_SYMBOL) > $(BASEEXT).def
215         $(NOECHO) $(ECHO) $(BASE_IMPORT) >> $(BASEEXT).def
216         $(NOECHO) $(ECHO) Import @$(PERL_INC)\perl.imp >> $(BASEEXT).def
217 MAKE_FRAG
218
219
220     if ( $self->{CCFLAGS} =~ m/ -DMPK_ON /) {
221         $m .= <<'MAKE_FRAG';
222         $(MPKTOOL) $(XDCFLAGS) $(BASEEXT).xdc
223         $(NOECHO) $(ECHO) xdcdata $(BASEEXT).xdc >> $(BASEEXT).def
224 MAKE_FRAG
225     }
226
227     # Reconstruct the X.Y.Z version.
228     my $version = join '.', map { sprintf "%d", $_ }
229                               $] =~ /(\d)\.(\d{3})(\d{2})/;
230     $m .= sprintf '     $(LD) $(LDFLAGS) $(OBJECT:.obj=.obj) -desc "Perl %s Extension ($(BASEEXT))  XS_VERSION: $(XS_VERSION)" -nlmversion $(NLM_VERSION)', $version;
231
232     # Taking care of long names like FileHandle, ByteLoader, SDBM_File etc
233     if($self->{NLM_SHORT_NAME}) {
234         # In case of nlms with names exceeding 8 chars, build nlm in the 
235         # current dir, rename and move to auto\lib.
236         $m .= q{ -o $(NLM_SHORT_NAME).$(DLEXT)}
237     } else {
238         $m .= q{ -o $(INST_AUTODIR)\\$(BASEEXT).$(DLEXT)}
239     }
240
241     # Add additional lib files if any (SDBM_File)
242     $m .= q{ $(MYEXTLIB) } if $self->{MYEXTLIB};
243
244     $m .= q{ $(PERL_INC)\Main.lib -commandfile $(BASEEXT).def}."\n";
245
246     if($self->{NLM_SHORT_NAME}) {
247         $m .= <<'MAKE_FRAG';
248         if exist $(INST_AUTODIR)\$(NLM_SHORT_NAME).$(DLEXT) del $(INST_AUTODIR)\$(NLM_SHORT_NAME).$(DLEXT) 
249         move $(NLM_SHORT_NAME).$(DLEXT) $(INST_AUTODIR)
250 MAKE_FRAG
251     }
252
253     $m .= <<'MAKE_FRAG';
254
255         $(CHMOD) 755 $@
256 MAKE_FRAG
257
258     return $m;
259 }
260
261
262 1;
263 __END__
264
265 =back
266
267 =cut 
268
269