/
libparrot.pm
186 lines (153 loc) · 5.29 KB
/
libparrot.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Copyright (C) 2005-2011, Parrot Foundation.
=head1 NAME
config/inter/libparrot.pm - Determines build information for libparrot
=head1 DESCRIPTION
libparrot is the library containing the parrot VM. This configuration
step determines whether it should be build static or shared.
=cut
package inter::libparrot;
use strict;
use warnings;
use base qw(Parrot::Configure::Step);
use File::Spec ();
use Parrot::Configure::Utils ':inter';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Should parrot link against a shared library};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
my $parrot_is_shared = $conf->options->get('parrot_is_shared');
my $disable_rpath = $conf->options->get('disable-rpath');
$parrot_is_shared = integrate(
$conf->data->get('parrot_is_shared'),
$parrot_is_shared
);
$parrot_is_shared = 0 unless $conf->data->get('has_dynamic_linking');
# Parrot can't necessarily handle a pre-existing installed shared
# libparrot.so. At this point, we don't know the actual name
# of the shared parrot library. So we try some candidates.
my @libs = get_libs();
my @libpaths = get_libpaths($conf);
foreach my $f (@libs) {
foreach my $d (@libpaths) {
my $oldversion = File::Spec->catfile($d, $f);
if (-e $oldversion) {
warn("\nWarning: Building a shared parrot library may conflict " .
"with your previously-installed $oldversion\n");
}
}
}
if (
$conf->options->get('ask')
&&
$conf->data->get('has_dynamic_linking')
) {
$parrot_is_shared = prompt(
"\nShould parrot be built using a shared library?",
$parrot_is_shared ? 'y' : 'n'
);
$parrot_is_shared = lc($parrot_is_shared) eq 'y';
}
$conf->data->set(
parrot_is_shared => $parrot_is_shared,
libparrot_for_makefile_only => $parrot_is_shared
? '$(LIBPARROT_SHARED)'
: '$(LIBPARROT_STATIC)',
);
# Set -rpath (or equivalent) for executables to find the
# shared libparrot in the build directory.
$conf->data->set( rpath_blib => ( ! $disable_rpath
&& $parrot_is_shared
&& $conf->data->get('rpath') )
? '"' . $conf->data->get('rpath')
. $conf->data->get('build_dir')
. '/'
. $conf->data->get('blib_dir') . '"'
: ''
);
# Set -rpath (or equivalent) for the installed executables to find the
# installed shared libparrot.
$conf->data->set( rpath_lib => ( ! $disable_rpath
&& $parrot_is_shared
&& $conf->data->get('rpath') )
? $conf->data->get('rpath')
. '"' . $conf->data->get('libdir') . '"'
: ''
);
# When building shared libraries and dynamically loadable
# modules with 'ld', do we need to include -lparrot? If so
# this variable contains the necessary flags. (This is normally
# empty, but may be overridden by various hints files for
# specific platforms.)
# This version works in the build directory.
unless ( defined( $conf->data->get('libparrot_ldflags') ) ) {
$conf->data->set(libparrot_ldflags => '');
}
# This version refers to the installed library.
unless ( defined( $conf->data->get('inst_libparrot_ldflags') ) ) {
$conf->data->set(inst_libparrot_ldflags => '');
}
# When linking an executable to -lparrot, this variable
# contains the necessary flags to find and use -lparrot.
# This version uses the -lparrot in the build directory.
unless ( defined( $conf->data->get('libparrot_linkflags') ) ) {
$conf->data->set(libparrot_linkflags =>
'-L"'
. $conf->data->get('build_dir')
. '/'
. $conf->data->get('blib_dir')
. '" -lparrot'
);
}
# This version uses the installed -lparrot.
unless ( defined( $conf->data->get('inst_libparrot_linkflags') ) ) {
$conf->data->set(inst_libparrot_linkflags =>
'-L'
. $conf->data->get('libdir')
. ' -lparrot'
);
}
$self->set_result( $parrot_is_shared ? 'yes' : 'no' );
return 1;
}
sub get_libs {
my @libs = ('libparrot.so');
if ($^O eq 'MSWin32') {
@libs = ('libparrot.dll', 'libparrot.lib', 'libparrot.dll.a');
}
if ($^O eq 'cygwin') {
@libs = ('libparrot.dll.a');
}
if ($^O eq 'darwin'){
@libs = qw/libparrot.dylib libparrot.a/;
}
return @libs;
}
sub get_libpaths {
my $conf = shift;
my @libpaths = ('/usr/local/lib', '/usr/lib', $conf->data->get('libdir'));
if ($^O eq 'MSWin32') {
push @libpaths, (split /;/, $ENV{PATH});
}
if (defined $ENV{LD_LIBRARY_PATH}) {
push @libpaths, (split /:/, $ENV{LD_LIBRARY_PATH});
}
if (defined $ENV{LD_RUN_PATH}) {
push @libpaths, (split /:/, $ENV{LD_RUN_PATH});
}
if (defined $ENV{DYLD_LIBRARY_PATH}) {
push @libpaths, (split /:/, $ENV{DYLD_LIBRARY_PATH});
}
return @libpaths
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: