Skip to content

Commit 6f0742d

Browse files
Eric WheelerKJ7NLL
Eric Wheeler
authored andcommitted
Added auto-detection of LAPACK/BLAS library names
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 <perl-pdl@z.ewheeler.org>
1 parent 3c32c5b commit 6f0742d

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Makefile.PL

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ my @pkgs = qw(lapack blas);
1010
our $libs0 = (
1111
eval {require PkgConfig; join ' ', map PkgConfig->find($_)->get_ldflags, @pkgs} ||
1212
eval {require ExtUtils::PkgConfig; join ' ', map ExtUtils::PkgConfig->libs($_), @pkgs} ||
13+
find_libs() ||
1314
`pkg-config @pkgs --libs` ||
1415
'-L/usr/lib/atlas -llapack -lblas -latlas'
1516
) . ' ' . ExtUtils::F77->runtime;
@@ -74,3 +75,45 @@ WriteMakefile(
7475
dist => { PREOP=>'$(PERL) -MPDL::Core::Dev -e pdlpp_mkgen $(DISTVNAME)' }, # GENERATED subdir in dist tarball
7576
clean => { FILES => '*~' },
7677
);
78+
79+
80+
sub find_libs
81+
{
82+
return if $^O =~ /MSWin/i;
83+
84+
my @dirs = split /\s+/, `ldconfig -Nv 2>/dev/null | grep : | cut -f1 -d:`;
85+
86+
# in performance order based on libraries I've used
87+
# for xnec2c in Ubuntu, Debian, SuSE, CentOS, etc.
88+
# See comments here for detail:
89+
# https://github.com/KJ7LNW/xnec2c/blob/master/src/mathlib.c#L29
90+
my @libs = qw/
91+
libopenblaso.so.0 libopenblaso.so libopenblas_openmp.so.0
92+
libtatlas.so.3
93+
liblapack_atlas.so.3
94+
libopenblasp.so.0 libopenblasp.so libopenblas_pthreads.so.0
95+
libopenblas.so.0 libopenblas.so libopenblas_serial.so.0
96+
libsatlas.so.3
97+
liblapacke.so.3
98+
libmkl_rt.so/,
99+
;
100+
101+
for my $l (@libs)
102+
{
103+
for my $d (@dirs)
104+
{
105+
if ( -e "$d/$l" )
106+
{
107+
$l =~ s/^lib//;
108+
$l =~ s/\..*$//;
109+
return "-L$d -l$l"
110+
}
111+
}
112+
}
113+
114+
foreach (`pkg-config --libs atlas`,
115+
`pkg-config --libs lapack`)
116+
{
117+
return $_ if $_;
118+
}
119+
}

0 commit comments

Comments
 (0)