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