[build] Teach config/inter/libparrot.pm about darwin so that people get properly...
[parrot.git] / config / inter / libparrot.pm
blobf32fa8d3157205ead69788dc3cbe30768664d16b
1 # Copyright (C) 2005-2007, Parrot Foundation.
2 # $Id$
4 =head1 NAME
6 config/inter/libparrot.pm - Determines build information for libparrot
8 =head1 DESCRIPTION
10 libparrot is the library containing the parrot VM. This configuration
11 step determines whether it should be build static or shared.
13 =cut
15 package inter::libparrot;
17 use strict;
18 use warnings;
20 use base qw(Parrot::Configure::Step);
22 use File::Spec ();
23 use Parrot::Configure::Utils ':inter';
26 sub _init {
27 my $self = shift;
28 my %data;
29 $data{description} = q{Should parrot link against a shared library};
30 $data{result} = q{};
31 return \%data;
34 sub runstep {
35 my ( $self, $conf ) = @_;
36 my $parrot_is_shared = $conf->options->get('parrot_is_shared');
37 my $disable_rpath = $conf->options->get('disable-rpath');
39 $parrot_is_shared = integrate(
40 $conf->data->get('parrot_is_shared'),
41 $parrot_is_shared
44 $parrot_is_shared = 0 unless $conf->data->get('has_dynamic_linking');
46 # Parrot can't necessarily handle a pre-existing installed shared
47 # libparrot.so. At this point, we don't know the actual name
48 # of the shared parrot library. So we try some candidates.
49 # See RT #52288: the check for old_versions should be improved
50 my @libs = ('libparrot.so');
51 my @libpaths = ('/usr/local/lib', '/usr/lib', $conf->data->get('libdir'));
52 if ($^O eq 'MSWin32') {
53 push @libpaths, (split /;/, $ENV{PATH});
54 @libs = ('libparrot.dll', 'libparrot.lib', 'libparrot.dll.a');
56 if ($^O eq 'cygwin') {
57 @libs = ('libparrot.dll.a');
59 if ($^O eq 'darwin' {
60 @libs = qw/libparrot.dylib libparrot.a/;
62 if (defined $ENV{LD_LIBRARY_PATH}) {
63 push @libpaths, (split /:/, $ENV{LD_LIBRARY_PATH});
65 if (defined $ENV{LD_RUN_PATH}) {
66 push @libpaths, (split /:/, $ENV{LD_RUN_PATH});
68 if (defined $ENV{DYLD_LIBRARY_PATH}) {
69 push @libpaths, (split /:/, $ENV{DYLD_LIBRARY_PATH});
71 foreach my $f (@libs) {
72 foreach my $d (@libpaths) {
73 my $oldversion = File::Spec->catfile($d, $f);
74 if (-e $oldversion) {
75 warn("\nWarning: Building a shared parrot library may conflict " .
76 "with your previously-installed $oldversion\n");
81 if (
82 $conf->options->get('ask')
84 $conf->data->get('has_dynamic_linking')
85 ) {
86 $parrot_is_shared = prompt(
87 "\nShould parrot be built using a shared library?",
88 $parrot_is_shared ? 'y' : 'n'
91 $parrot_is_shared = lc($parrot_is_shared) eq 'y';
94 $conf->data->set(
95 parrot_is_shared => $parrot_is_shared,
97 libparrot_for_makefile_only => $parrot_is_shared
98 ? '$(LIBPARROT_SHARED)'
99 : '$(LIBPARROT_STATIC)',
102 # Set -rpath (or equivalent) for executables to find the
103 # shared libparrot in the build directory.
104 $conf->data->set( rpath_blib => ( ! $disable_rpath
105 && $parrot_is_shared
106 && $conf->data->get('rpath') )
107 ? $conf->data->get('rpath')
108 . $conf->data->get('build_dir')
109 . $conf->data->get('slash')
110 . $conf->data->get('blib_dir')
111 : ''
114 # Set -rpath (or equivalent) for the installed executables to find the
115 # installed shared libparrot.
116 $conf->data->set( rpath_lib => ( ! $disable_rpath
117 && $parrot_is_shared
118 && $conf->data->get('rpath') )
119 ? $conf->data->get('rpath')
120 . $conf->data->get('libdir')
121 : ''
124 # When building shared libraries and dynamically loadable
125 # modules with 'ld', do we need to include -lparrot? If so
126 # this variable contains the necessary flags. (This is normally
127 # empty, but may be overridden by various hints files for
128 # specific platforms.)
130 # This version works in the build directory.
131 unless ( defined( $conf->data->get('libparrot_ldflags') ) ) {
132 $conf->data->set(libparrot_ldflags => '');
135 # This version refers to the installed library.
136 unless ( defined( $conf->data->get('inst_libparrot_ldflags') ) ) {
137 $conf->data->set(inst_libparrot_ldflags => '');
140 # When linking an executable to -lparrot, this variable
141 # contains the necessary flags to find and use -lparrot.
143 # This version uses the -lparrot in the build directory.
144 unless ( defined( $conf->data->get('libparrot_linkflags') ) ) {
145 $conf->data->set(libparrot_linkflags =>
146 '-L'
147 . $conf->data->get('build_dir')
148 . $conf->data->get('slash')
149 . $conf->data->get('blib_dir')
150 . ' -lparrot'
154 # This version uses the installed -lparrot.
155 unless ( defined( $conf->data->get('inst_libparrot_linkflags') ) ) {
156 $conf->data->set(inst_libparrot_linkflags =>
157 '-L'
158 . $conf->data->get('libdir')
159 . ' -lparrot'
163 $self->set_result( $parrot_is_shared ? 'yes' : 'no' );
165 return 1;
170 # Local Variables:
171 # mode: cperl
172 # cperl-indent-level: 4
173 # fill-column: 100
174 # End:
175 # vim: expandtab shiftwidth=4: