Skip to content

Commit

Permalink
Added auto-detection of LAPACK/BLAS library names
Browse files Browse the repository at this point in the history
Added find_libs() to the root Makefile.PL to find libraries in
Debian, Ubuntu, CentOS 7/8, SUSE.

See PDLPorters#15

Signed-off-by: Eric Wheeler <[email protected]>
  • Loading branch information
Eric Wheeler authored and KJ7NLL committed Jul 16, 2022
1 parent 3c32c5b commit 6f0742d
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ my @pkgs = qw(lapack blas);
our $libs0 = (
eval {require PkgConfig; join ' ', map PkgConfig->find($_)->get_ldflags, @pkgs} ||
eval {require ExtUtils::PkgConfig; join ' ', map ExtUtils::PkgConfig->libs($_), @pkgs} ||
find_libs() ||
`pkg-config @pkgs --libs` ||
'-L/usr/lib/atlas -llapack -lblas -latlas'
) . ' ' . ExtUtils::F77->runtime;
Expand Down Expand Up @@ -74,3 +75,45 @@ WriteMakefile(
dist => { PREOP=>'$(PERL) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' }, # GENERATED subdir in dist tarball
clean => { FILES => '*~' },
);
sub find_libs
{
return if $^O =~ /MSWin/i;
my @dirs = split /\s+/, `ldconfig -Nv 2>/dev/null | grep : | cut -f1 -d:`;
# in performance order based on libraries I've used
# for xnec2c in Ubuntu, Debian, SuSE, CentOS, etc.
# See comments here for detail:
# https://github.com/KJ7LNW/xnec2c/blob/master/src/mathlib.c#L29
my @libs = qw/
libopenblaso.so.0 libopenblaso.so libopenblas_openmp.so.0
libtatlas.so.3
liblapack_atlas.so.3
libopenblasp.so.0 libopenblasp.so libopenblas_pthreads.so.0
libopenblas.so.0 libopenblas.so libopenblas_serial.so.0
libsatlas.so.3
liblapacke.so.3
libmkl_rt.so/,
;
for my $l (@libs)
{
for my $d (@dirs)
{
if ( -e "$d/$l" )
{
$l =~ s/^lib//;
$l =~ s/\..*$//;
return "-L$d -l$l"
}
}
}
foreach (`pkg-config --libs atlas`,
`pkg-config --libs lapack`)
{
return $_ if $_;
}
}

0 comments on commit 6f0742d

Please sign in to comment.