This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
bump ExtUtils-CBuilder version for blead change
[perl5.git] / dist / ExtUtils-CBuilder / lib / ExtUtils / CBuilder / Platform / os2.pm
CommitLineData
6b09c160
YST
1package ExtUtils::CBuilder::Platform::os2;
2
3use strict;
4use ExtUtils::CBuilder::Platform::Unix;
5
6use vars qw($VERSION @ISA);
ed6b886e 7$VERSION = '0.280201';
6b09c160
YST
8@ISA = qw(ExtUtils::CBuilder::Platform::Unix);
9
10sub need_prelink { 1 }
11
d1cf867f
SP
12sub prelink {
13 # Generate import libraries (XXXX currently near .DEF; should be near DLL!)
14 my $self = shift;
3fa7b0d2
RGS
15 my %args = @_;
16
17 my @res = $self->SUPER::prelink(%args);
d1cf867f
SP
18 die "Unexpected number of DEF files" unless @res == 1;
19 die "Can't find DEF file in the output"
3fa7b0d2
RGS
20 unless $res[0] =~ m,^(.*)\.def$,si;
21 my $libname = "$1$self->{config}{lib_ext}"; # Put .LIB file near .DEF file
d1cf867f
SP
22 $self->do_system('emximp', '-o', $libname, $res[0]) or die "emxexp: res=$?";
23 return (@res, $libname);
24}
25
26sub _do_link {
3fa7b0d2
RGS
27 my $self = shift;
28 my ($how, %args) = @_;
29 if ($how eq 'lib_file'
30 and (defined $args{module_name} and length $args{module_name})) {
31
32 # DynaLoader::mod2fname() is a builtin func
33 my $lib = DynaLoader::mod2fname([split /::/, $args{module_name}]);
34
35 # Now know the basename, find directory parts via lib_file, or objects
36 my $objs = ( (ref $args{objects}) ? $args{objects} : [$args{objects}] );
37 my $near_obj = $self->lib_file(@$objs);
38 my $ref_file = ( defined $args{lib_file} ? $args{lib_file} : $near_obj );
39 my $lib_dir = ($ref_file =~ m,(.*)[/\\],s ? "$1/" : '' );
40 my $exp_dir = ($near_obj =~ m,(.*)[/\\],s ? "$1/" : '' );
41
42 $args{dl_file} = $1 if $near_obj =~ m,(.*)\.,s; # put ExportList near OBJ
43 $args{lib_file} = "$lib_dir$lib.$self->{config}{dlext}"; # DLL file
44
45 # XXX _do_link does not have place to put libraries?
46 push @$objs, $self->perl_inc() . "/libperl$self->{config}{lib_ext}";
47 $args{objects} = $objs;
48 }
d1cf867f
SP
49 # Some 'env' do exec(), thus return too early when run from ksh;
50 # To avoid 'env', remove (useless) shrpenv
d1cf867f 51 local $self->{config}{shrpenv} = '';
3fa7b0d2 52 return $self->SUPER::_do_link($how, %args);
d1cf867f
SP
53}
54
3fa7b0d2
RGS
55sub extra_link_args_after_prelink {
56 # Add .DEF file to the link line
d1cf867f 57 my ($self, %args) = @_;
3fa7b0d2
RGS
58
59 my @DEF = grep /\.def$/i, @{$args{prelink_res}};
60 die "More than one .def files created by `prelink' stage" if @DEF > 1;
61 # XXXX No "$how" argument here, so how to test for dynamic link?
62 die "No .def file created by `prelink' stage"
63 unless @DEF or not @{$args{prelink_res}};
64
65 my @after_libs = ($OS2::is_aout ? ()
66 : $self->perl_inc() . "/libperl_override$self->{config}{lib_ext}");
67 # , "-L", "-lperl"
68 (@after_libs, @DEF);
d1cf867f
SP
69}
70
71sub link_executable {
72 # ldflags is not expecting .exe extension given on command line; remove -Zexe
73 my $self = shift;
74 local $self->{config}{ldflags} = $self->{config}{ldflags};
75 $self->{config}{ldflags} =~ s/(?<!\S)-Zexe(?!\S)//;
76 return $self->SUPER::link_executable(@_);
77}
78
79
6b09c160 801;