1 package ExtUtils::CBuilder::Platform::VMS;
4 use ExtUtils::CBuilder::Base;
6 use vars qw($VERSION @ISA);
8 @ISA = qw(ExtUtils::CBuilder::Base);
10 use File::Spec::Functions qw(catfile catdir);
12 # We do prelink, but don't want the parent to redo it.
14 sub need_prelink { 0 }
17 my ($self, %args) = @_;
19 s/"/""/g foreach values %args;
23 # VMS can only have one define qualifier; add the one from config, if any.
24 if ($self->{config}{ccflags} =~ s{/ def[^=]+ =+ \(? ([^\/\)]*) } {}ix) {
25 push @config_defines, $1;
28 return '' unless keys(%args) || @config_defines;
33 map "\"$_" . ( length($args{$_}) ? "=$args{$_}" : '') . "\"",
38 sub arg_include_dirs {
39 my ($self, @dirs) = @_;
41 # VMS can only have one include list, add the one from config.
42 if ($self->{config}{ccflags} =~ s{/inc[^=]+(?:=)+(?:\()?([^\/\)]*)} {}i) {
47 return ('/include=(' . join(',', @dirs) . ')');
51 my ($self, $type, %args) = @_;
53 my $objects = delete $args{objects};
54 $objects = [$objects] unless ref $objects;
58 # prelink will call Mksymlists, which creates the extension-specific
59 # linker options file and populates it with the boot symbol.
61 my @temp_files = $self->prelink(%args, dl_name => $args{module_name});
63 # We now add the rest of what we need to the linker options file. We
64 # should replicate the functionality of C<ExtUtils::MM_VMS::dlsyms>,
65 # but there is as yet no infrastructure for handling object libraries,
66 # so for now we depend on object files being listed individually on the
67 # command line, which should work for simple cases. We do bring in our
68 # own version of C<ExtUtils::Liblist::Kid::ext> so that any additional
69 # libraries (including PERLSHR) can be added to the options file.
71 my @optlibs = $self->_liblist_ext( $args{'libs'} );
73 my $optfile = 'sys$disk:[]' . $temp_files[0];
74 open my $opt_fh, '>>', $optfile
75 or die "_do_link: Unable to open $optfile: $!";
76 for my $lib (@optlibs) {print $opt_fh "$lib\n" if length $lib }
79 $objects->[-1] .= ',';
80 push @$objects, $optfile . '/OPTIONS,';
82 # This one not needed for DEC C, but leave for completeness.
83 push @$objects, $self->perl_inc() . 'perlshr_attr.opt/OPTIONS';
86 return $self->SUPER::_do_link($type, %args, objects => $objects);
89 sub arg_nolink { return; }
92 my ($self, $file) = @_;
97 my ($self, $file) = @_;
98 return ("/exe=$file");
101 sub arg_share_object_file {
102 my ($self, $file) = @_;
103 return ("$self->{config}{lddlflags}=$file");
108 my ($self, $dl_file) = @_;
109 $dl_file =~ s/\.[^.]+$//;
111 $dl_file = $dl_file .= '.' . $self->{config}{dlext};
113 # Need to create with the same name as DynaLoader will load with.
114 if (defined &DynaLoader::mod2fname) {
115 my ($dev,$dir,$file) = File::Spec->splitpath($dl_file);
116 $file = DynaLoader::mod2fname([$file]);
117 $dl_file = File::Spec->catpath($dev,$dir,$file);
122 # The following is reproduced almost verbatim from ExtUtils::Liblist::Kid::_vms_ext.
123 # We can't just call that because it's tied up with the MakeMaker object hierarchy.
126 my($self, $potential_libs,$verbose,$give_libs) = @_;
130 @crtls = ( ($self->{'config'}{'ldflags'} =~ m-/Debug-i ? $self->{'config'}{'dbgprefix'} : '')
132 push(@crtls, grep { not /\(/ } split /\s+/, $self->{'config'}{'perllibs'});
133 push(@crtls, grep { not /\(/ } split /\s+/, $self->{'config'}{'libc'});
134 # In general, we pass through the basic libraries from %Config unchanged.
135 # The one exception is that if we're building in the Perl source tree, and
136 # a library spec could be resolved via a logical name, we go to some trouble
137 # to ensure that the copy in the local tree is used, rather than one to
138 # which a system-wide logical may point.
139 if ($self->perl_src) {
140 my($lib,$locspec,$type);
141 foreach $lib (@crtls) {
142 if (($locspec,$type) = $lib =~ m{^([\w\$-]+)(/\w+)?} and $locspec =~ /perl/i) {
143 if (lc $type eq '/share') { $locspec .= $self->{'config'}{'exe_ext'}; }
144 elsif (lc $type eq '/library') { $locspec .= $self->{'config'}{'lib_ext'}; }
145 else { $locspec .= $self->{'config'}{'obj_ext'}; }
146 $locspec = catfile($self->perl_src, $locspec);
147 $lib = "$locspec$type" if -e $locspec;
151 $crtlstr = @crtls ? join(' ',@crtls) : '';
153 unless ($potential_libs) {
154 warn "Result:\n\tEXTRALIBS: \n\tLDLOADLIBS: $crtlstr\n" if $verbose;
155 return ('', '', $crtlstr, '', ($give_libs ? [] : ()));
158 my(@dirs,@libs,$dir,$lib,%found,@fndlibs,$ldlib);
160 my($so,$lib_ext,$obj_ext) = @{$self->{'config'}}{'so','lib_ext','obj_ext'};
161 # List of common Unix library names and their VMS equivalents
162 # (VMS equivalent of '' indicates that the library is automatically
163 # searched by the linker, and should be skipped here.)
164 my(@flibs, %libs_seen);
165 my %libmap = ( 'm' => '', 'f77' => '', 'F77' => '', 'V77' => '', 'c' => '',
166 'malloc' => '', 'crypt' => '', 'resolv' => '', 'c_s' => '',
167 'socket' => '', 'X11' => 'DECW$XLIBSHR',
168 'Xt' => 'DECW$XTSHR', 'Xm' => 'DECW$XMLIBSHR',
169 'Xmu' => 'DECW$XMULIBSHR');
170 if ($self->{'config'}{'vms_cc_type'} ne 'decc') { $libmap{'curses'} = 'VAXCCURSE'; }
172 warn "Potential libraries are '$potential_libs'\n" if $verbose;
174 # First, sort out directories and library names in the input
175 foreach $lib (split ' ',$potential_libs) {
176 push(@dirs,$1), next if $lib =~ /^-L(.*)/;
177 push(@dirs,$lib), next if $lib =~ /[:>\]]$/;
178 push(@dirs,$lib), next if -d $lib;
179 push(@libs,$1), next if $lib =~ /^-l(.*)/;
182 push(@dirs,split(' ',$self->{'config'}{'libpth'}));
184 # Now make sure we've got VMS-syntax absolute directory specs
185 # (We don't, however, check whether someone's hidden a relative
186 # path in a logical name.)
187 foreach $dir (@dirs) {
189 warn "Skipping nonexistent Directory $dir\n" if $verbose > 1;
193 warn "Resolving directory $dir\n" if $verbose;
194 if (!File::Spec->file_name_is_absolute($dir)) {
195 $dir = catdir($cwd,$dir);
198 @dirs = grep { length($_) } @dirs;
199 unshift(@dirs,''); # Check each $lib without additions first
201 LIB: foreach $lib (@libs) {
202 if (exists $libmap{$lib}) {
203 next unless length $libmap{$lib};
204 $lib = $libmap{$lib};
207 my(@variants,$variant,$cand);
210 # If we don't have a file type, consider it a possibly abbreviated name and
211 # check for common variants. We try these first to grab libraries before
212 # a like-named executable image (e.g. -lperl resolves to perlshr.exe
214 if ($lib !~ /\.[^:>\]]*$/) {
215 push(@variants,"${lib}shr","${lib}rtl","${lib}lib");
216 push(@variants,"lib$lib") if $lib !~ /[:>\]]/;
218 push(@variants,$lib);
219 warn "Looking for $lib\n" if $verbose;
220 foreach $variant (@variants) {
221 my($fullname, $name);
223 foreach $dir (@dirs) {
226 $name = "$dir$variant";
227 warn "\tChecking $name\n" if $verbose > 2;
228 $fullname = VMS::Filespec::rmsexpand($name);
229 if (defined $fullname and -f $fullname) {
230 # It's got its own suffix, so we'll have to figure out the type
231 if ($fullname =~ /(?:$so|exe)$/i) { $type = 'SHR'; }
232 elsif ($fullname =~ /(?:$lib_ext|olb)$/i) { $type = 'OLB'; }
233 elsif ($fullname =~ /(?:$obj_ext|obj)$/i) {
234 warn "Note (probably harmless): "
235 ."Plain object file $fullname found in library list\n";
239 warn "Note (probably harmless): "
240 ."Unknown library type for $fullname; assuming shared\n";
244 elsif (-f ($fullname = VMS::Filespec::rmsexpand($name,$so)) or
245 -f ($fullname = VMS::Filespec::rmsexpand($name,'.exe'))) {
247 $name = $fullname unless $fullname =~ /exe;?\d*$/i;
249 elsif (not length($ctype) and # If we've got a lib already,
251 ( -f ($fullname = VMS::Filespec::rmsexpand($name,$lib_ext)) or
252 -f ($fullname = VMS::Filespec::rmsexpand($name,'.olb')))) {
254 $name = $fullname unless $fullname =~ /olb;?\d*$/i;
256 elsif (not length($ctype) and # If we've got a lib already,
258 ( -f ($fullname = VMS::Filespec::rmsexpand($name,$obj_ext)) or
259 -f ($fullname = VMS::Filespec::rmsexpand($name,'.obj')))) {
260 warn "Note (probably harmless): "
261 ."Plain object file $fullname found in library list\n";
263 $name = $fullname unless $fullname =~ /obj;?\d*$/i;
266 $ctype = $type; $cand = $name;
267 last if $ctype eq 'SHR';
271 # This has to precede any other CRTLs, so just make it first
272 if ($cand eq 'VAXCCURSE') { unshift @{$found{$ctype}}, $cand; }
273 else { push @{$found{$ctype}}, $cand; }
274 warn "\tFound as $cand (really $fullname), type $ctype\n"
276 push @flibs, $name unless $libs_seen{$fullname}++;
280 warn "Note (probably harmless): "
281 ."No library found for $lib\n";
284 push @fndlibs, @{$found{OBJ}} if exists $found{OBJ};
285 push @fndlibs, map { "$_/Library" } @{$found{OLB}} if exists $found{OLB};
286 push @fndlibs, map { "$_/Share" } @{$found{SHR}} if exists $found{SHR};
287 $lib = join(' ',@fndlibs);
289 $ldlib = $crtlstr ? "$lib $crtlstr" : $lib;
290 warn "Result:\n\tEXTRALIBS: $lib\n\tLDLOADLIBS: $ldlib\n" if $verbose;
291 wantarray ? ($lib, '', $ldlib, '', ($give_libs ? \@flibs : ())) : $lib;