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