Skip to content

Commit

Permalink
only link against pthread on openbsd iw perl is linked against it too
Browse files Browse the repository at this point in the history
Since OpenBSD 5.0 we cannot load libpthread. This must be done when perl
boots up, so we have to check that in order to decide whether to link
against that lib or not.
  • Loading branch information
FROGGS committed May 11, 2014
1 parent 671a6e8 commit 2c50e29
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Build.PL
Expand Up @@ -4,7 +4,8 @@ use warnings;
use lib "inc";
use File::Spec::Functions qw(catdir catfile);
use Config;
use My::Utility qw(check_config_script check_prebuilt_binaries check_prereqs_libs check_prereqs_tools $source_packs);
use My::Utility qw(check_config_script check_prebuilt_binaries check_prereqs_libs check_prereqs_tools $source_packs
check_perl_buildlibs);

use Getopt::Long;
my ( $ans, $travis ) = 0;
Expand Down Expand Up @@ -107,6 +108,7 @@ my $build = $package->new(

my $choice;
my %have_libs = ();
my %perl_libs = ();

if (defined $sdl_config) {
# handle --with-sdl-config (without params)
Expand Down Expand Up @@ -173,6 +175,8 @@ else {
}
}

$perl_libs{pthread} = check_perl_buildlibs('pthread') if $have_libs{pthread} && $^O eq 'openbsd';

# prebuilt binaries (windows only)
push @candidates, @{$rv} if $rv = check_prebuilt_binaries($build->os_type);

Expand Down Expand Up @@ -237,6 +241,7 @@ if($choice) {
$build->notes('env_include', $ENV{INCLUDE}) if $ENV{INCLUDE};
$build->notes('env_lib', $ENV{LIB}) if $ENV{LIB};
$build->notes('have_libs', \%have_libs);
$build->notes('perl_libs', \%perl_libs);
$build->create_build_script();

#### clean build_done stamp; force rebuild when running 'Build'
Expand Down
11 changes: 6 additions & 5 deletions inc/My/Builder/Unix.pm
Expand Up @@ -37,7 +37,12 @@ sub get_additional_libs {
}
}
push @list, (keys %rv);
push @list, '-lpthread' if ($^O eq 'openbsd');
if ($^O eq 'openbsd') {
my $osver = `uname -r 2>/dev/null`;
if ($self->notes('perl_libs')->{pthread} || ($osver && $osver < 5.0)) {
push @list, '-lpthread'
}
}
return join(' ', @list);
}

Expand Down Expand Up @@ -161,10 +166,6 @@ sub _get_configure_cmd {
$extra .= ' --disable-audio';
}

if($pack eq 'SDL' && $^O eq 'openbsd') {
$extra_ldflags .= ' -lpthread';
}

if($pack =~ /^SDL_/) {
$extra .= " --with-sdl-prefix=$escaped_prefixdir";
}
Expand Down
23 changes: 22 additions & 1 deletion inc/My/Utility.pm
Expand Up @@ -4,7 +4,7 @@ use warnings;
use base qw(Exporter);

our @EXPORT_OK = qw(check_config_script check_prebuilt_binaries check_prereqs_libs check_prereqs_tools find_SDL_dir find_file check_header
sed_inplace get_dlext $inc_lib_candidates $source_packs);
sed_inplace get_dlext $inc_lib_candidates $source_packs check_perl_buildlibs);
use Config;
use ExtUtils::CBuilder;
use File::Spec::Functions qw(splitdir catdir splitpath catpath rel2abs);
Expand Down Expand Up @@ -418,6 +418,27 @@ sub check_prereqs_libs {
return $ret;
}

sub check_perl_buildlibs {
my @libs = @_;
my $ret = 1;
my $dlext = get_dlext();
my $devnull = File::Spec->devnull();
for my $lib (@libs) {
print "checking if perl is linked against $lib... ";
if($Config{libs} =~ /\Q-l$lib\E\b/
|| $Config{perllibs} =~ /\Q-l$lib\E\b/
|| `ldd $^X 2>$devnull` =~ /[\/\\]lib\Q$lib\E[\-\d\.]*\.($dlext[\d\.]*|so|dll)$/) {
print "yes\n";
$ret &= 1;
}
else {
print "no\n";
$ret = 0;
}
}
return $ret;
}

sub check_prereqs {
my $bp = shift;
my $ret = 1;
Expand Down

0 comments on commit 2c50e29

Please sign in to comment.