-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathconfig_libs.rb
200 lines (177 loc) · 6.5 KB
/
config_libs.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
## --- BEGIN LICENSE BLOCK ---
# Copyright (c) 2009, Mikio L. Braun
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# * Neither the name of the Technische Universitaet Berlin nor the
# names of its contributors may be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
## --- END LICENSE BLOCK ---
######################################################################
#
# Locating the libraries
#
# This is a bit involved since the standard ATLAS compilation produces
# a liblapack.so which only implements a subset of the lapack functions.
# So the basic strategy is to
#
# (a) find the path to the atlas specific library
# (b) find the path to a full lapack library
#
# Pass the lapack libraries and theirs paths first.
#
# Of course, if you want to build a lapack-only path, we only search
# for the full lapack libraries.
require 'config/config'
require 'config/lib_helpers'
require 'config/opts'
require 'config/config_os_arch'
require 'config/config_fortran'
include JblasConfig
ATLAS_REQUIRED_SYMBOLS = [
'dsyev_', # eigenvalue function not yet included in ATLAS/LAPACK
'ATL_dgemm',
'dgemm_', # matrix-matrix multiplication
'daxpy_', # blas-related function
'cblas_daxpy', # atlas itself often uses cblas
'ATL_caxpy'
]
LAPACK_REQUIRED_SYMBOLS = ['dsyev_', 'daxpy_', 'dgemm_']
ATLAS_LIBS = %w(lapack lapack_fortran lapack_atlas f77blas cblas atlas)
PT_ATLAS_LIBS = %w(lapack lapack_fortran lapack_atlas ptf77blas ptcblas atlas)
LAPACK_LIBS = %w(lapack_fortran lapack blas_fortran blas)
OPENBLAS_LIBS = %w(openblas)
OPENBLAS_REQUIRED_SYMBOLS = LAPACK_REQUIRED_SYMBOLS
NVBLAS_LIBS = %w(lapack_fortran lapack blas_fortran blas nvblas)
NVBLAS_REQUIRED_SYMBOLS = LAPACK_REQUIRED_SYMBOLS
configure :libs => 'LOADLIBES'
desc 'determining build type'
configure 'LINKAGE_TYPE' do
if $opts.defined? :dynamic_libs
CONFIG['LINKAGE_TYPE'] = 'dynamic'
CONFIG.add_xml '<property name="linkage" value="dynamic" />'
else
CONFIG['LINKAGE_TYPE'] = 'static'
CONFIG.add_xml '<property name="linkage" value="static" />'
end
ok(CONFIG['LINKAGE_TYPE'])
end
desc 'getting library path...'
configure :libpath => ['OS_NAME', 'OS_ARCH'] do
if $opts.defined? :libpath
CONFIG[:libpath] = $opts[:libpath].split(':')
else
if CONFIG['OS_NAME'] == 'Mac\ OS\ X'
CONFIG[:libpath] = ['/opt/local/lib']
else
#CONFIG[:libpath] = %w(/usr/lib /lib /usr/lib/sse2)
if CONFIG['OS_ARCH'] == 'aarch64'
CONFIG[:libpath] = %w(/usr/lib/aarch64-linux-gnu)
else
CONFIG[:libpath] = %w(/usr/lib/x86_64-linux-gnu)
end
end
end
ok(CONFIG[:libpath].inspect)
end
desc 'determining whether to build for lapack or atlas'
configure 'BUILD_TYPE' do
if $opts.defined? :build_type
CONFIG['BUILD_TYPE'] = $opts[:build_type]
ok(CONFIG['BUILD_TYPE'])
else
if $opts.defined? :lapack_build
CONFIG['BUILD_TYPE'] = 'lapack'
ok('lapack')
else
CONFIG['BUILD_TYPE'] = 'openblas'
ok('openblas')
end
end
end
desc 'looking for libraries...'
configure 'LOADLIBES' => ['LINKAGE_TYPE', :libpath, 'F77', 'BUILD_TYPE', 'OS_ARCH'] do
if $opts.defined? :libs
libs = $opts[:libs].split(',')
syms = LAPACK_REQUIRED_SYMBOLS
else
case CONFIG['BUILD_TYPE']
when 'atlas'
if $opts.defined? :ptatlas
libs = PT_ATLAS_LIBS
else
libs = ATLAS_LIBS
end
syms = ATLAS_REQUIRED_SYMBOLS
when 'lapack'
libs = LAPACK_LIBS
syms = LAPACK_REQUIRED_SYMBOLS
when 'nvblas'
libs = NVBLAS_LIBS
syms = NVBLAS_REQUIRED_SYMBOLS
when 'openblas'
libs = OPENBLAS_LIBS
syms = OPENBLAS_REQUIRED_SYMBOLS
end
end
result = LibHelpers.find_libs(CONFIG[:libpath], libs, syms)
p result
case CONFIG['LINKAGE_TYPE']
when 'dynamic'
CONFIG['LDFLAGS'] += result.values.uniq.map { |s| '-L' + s.escape }
CONFIG['LOADLIBES'] += result.keys.map { |s| '-l' + s.escape }
when 'static'
CONFIG['LOADLIBES'] += ['-Wl,-z,muldefs'] unless CONFIG['OS_NAME'] == 'Mac\ OS\ X' or CONFIG['OS_NAME'] == 'Windows'
# Add the libraries with their full path to the command line.
# We have to sort them in the order as they appear in +libs+, otherwise
# we'll have unresolved symbols, at least under Linux.
CONFIG['LOADLIBES'] += result.keys.
sort { |x, y| libs.index(x) <=> libs.index(y) }.
map { |s| File.join(result[s], LibHelpers.libname(s)).escape }
if CONFIG['F77'] =~ /gfortran$/
if CONFIG['OS_NAME'] == 'Linux' and CONFIG['OS_ARCH'] == 'amd64'
CONFIG['LOADLIBES'] += ['-lgfortran']
elsif CONFIG['OS_NAME'] == 'Mac\ OS\ X'
print "Looking for where libgfortran.a is... "
libgfortran_path = %x(gfortran -print-file-name=libgfortran.a).strip
puts "(#{libgfortran_path})"
CONFIG['LOADLIBES'] += [libgfortran_path]
else
CONFIG['LOADLIBES'] += ['-l:libgfortran.a']
end
end
#if CONFIG['OS_NAME'] == 'Mac\ OS\ X'
# CONFIG['LOADLIBES'] += ['/opt/local/lib/gcc43/libgfortran.a']
#end
end
ok
end
if __FILE__ == $0
$opts = Opts.new(ARGV)
JblasConfig.run :libs
JblasConfig::CONFIG.dump($stdout)
end