This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Jeffrey's Unicode adventure continues: unify the In/*.pl
[perl5.git] / lib / ExtUtils / MM_OS2.pm
1 package ExtUtils::MM_OS2;
2
3 use strict;
4
5 our $VERSION = '1.00';
6
7 #use Config;
8 #use Cwd;
9 #use File::Basename;
10 require Exporter;
11
12 require ExtUtils::MakeMaker;
13 ExtUtils::MakeMaker->import(qw( $Verbose &neatvalue));
14
15 use File::Spec;
16
17 unshift @MM::ISA, 'ExtUtils::MM_OS2';
18
19 =pod
20
21 =head1 NAME
22
23 ExtUtils::MM_OS2 - methods to override UN*X behaviour in ExtUtils::MakeMaker
24
25 =head1 SYNOPSIS
26
27  use ExtUtils::MM_OS2; # Done internally by ExtUtils::MakeMaker if needed
28
29 =head1 DESCRIPTION
30
31 See ExtUtils::MM_Unix for a documentation of the methods provided
32 there. This package overrides the implementation of these methods, not
33 the semantics.
34
35 =head1 METHODS
36
37 =over 4
38
39 =cut
40
41 sub dlsyms {
42     my($self,%attribs) = @_;
43
44     my($funcs) = $attribs{DL_FUNCS} || $self->{DL_FUNCS} || {};
45     my($vars)  = $attribs{DL_VARS} || $self->{DL_VARS} || [];
46     my($funclist) = $attribs{FUNCLIST} || $self->{FUNCLIST} || [];
47     my($imports)  = $attribs{IMPORTS} || $self->{IMPORTS} || {};
48     my(@m);
49     (my $boot = $self->{NAME}) =~ s/:/_/g;
50
51     if (not $self->{SKIPHASH}{'dynamic'}) {
52         push(@m,"
53 $self->{BASEEXT}.def: Makefile.PL
54 ",
55      '  $(PERL) "-I$(PERL_ARCHLIB)" "-I$(PERL_LIB)" -e \'use ExtUtils::Mksymlists; \\
56      Mksymlists("NAME" => "$(NAME)", "DLBASE" => "$(DLBASE)", ',
57      '"VERSION" => "$(VERSION)", "DISTNAME" => "$(DISTNAME)", ',
58      '"INSTALLDIRS" => "$(INSTALLDIRS)", ',
59      '"DL_FUNCS" => ',neatvalue($funcs),
60      ', "FUNCLIST" => ',neatvalue($funclist),
61      ', "IMPORTS" => ',neatvalue($imports),
62      ', "DL_VARS" => ', neatvalue($vars), ');\'
63 ');
64     }
65     if ($self->{IMPORTS} && %{$self->{IMPORTS}}) {
66         # Make import files (needed for static build)
67         -d 'tmp_imp' or mkdir 'tmp_imp', 0777 or die "Can't mkdir tmp_imp";
68         open IMP, '>tmpimp.imp' or die "Can't open tmpimp.imp";
69         my ($name, $exp);
70         while (($name, $exp)= each %{$self->{IMPORTS}}) {
71             my ($lib, $id) = ($exp =~ /(.*)\.(.*)/) or die "Malformed IMPORT `$exp'";
72             print IMP "$name $lib $id ?\n";
73         }
74         close IMP or die "Can't close tmpimp.imp";
75         # print "emximp -o tmpimp$Config::Config{lib_ext} tmpimp.imp\n";
76         system "emximp -o tmpimp$Config::Config{lib_ext} tmpimp.imp" 
77             and die "Cannot make import library: $!, \$?=$?";
78         unlink <tmp_imp/*>;
79         system "cd tmp_imp; $Config::Config{ar} x ../tmpimp$Config::Config{lib_ext}" 
80             and die "Cannot extract import objects: $!, \$?=$?";      
81     }
82     join('',@m);
83 }
84
85 sub static_lib {
86     my($self) = @_;
87     my $old = $self->ExtUtils::MM_Unix::static_lib();
88     return $old unless $self->{IMPORTS} && %{$self->{IMPORTS}};
89     
90     my @chunks = split /\n{2,}/, $old;
91     shift @chunks unless length $chunks[0]; # Empty lines at the start
92     $chunks[0] .= <<'EOC';
93
94         $(AR) $(AR_STATIC_ARGS) $@ tmp_imp/* && $(RANLIB) $@
95 EOC
96     return join "\n\n". '', @chunks;
97 }
98
99 sub replace_manpage_separator {
100     my($self,$man) = @_;
101     $man =~ s,/+,.,g;
102     $man;
103 }
104
105 sub maybe_command {
106     my($self,$file) = @_;
107     $file =~ s,[/\\]+,/,g;
108     return $file if -x $file && ! -d _;
109     return "$file.exe" if -x "$file.exe" && ! -d _;
110     return "$file.cmd" if -x "$file.cmd" && ! -d _;
111     return;
112 }
113
114 sub file_name_is_absolute {
115     shift;
116     return File::Spec->file_name_is_absolute(@_);
117 }
118
119 sub perl_archive
120 {
121  return "\$(PERL_INC)/libperl\$(LIB_EXT)";
122 }
123
124 =item perl_archive_after
125
126 This is an internal method that returns path to a library which
127 should be put on the linker command line I<after> the external libraries
128 to be linked to dynamic extensions.  This may be needed if the linker
129 is one-pass, and Perl includes some overrides for C RTL functions,
130 such as malloc().
131
132 =cut 
133
134 sub perl_archive_after
135 {
136  return "\$(PERL_INC)/libperl_override\$(LIB_EXT)" unless $OS2::is_aout;
137  return "";
138 }
139
140 sub export_list
141 {
142  my ($self) = @_;
143  return "$self->{BASEEXT}.def";
144 }
145
146 1;
147
148 __END__
149
150 =pod
151
152 =back
153
154 =cut