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