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
201
202
203
204
205
206
207
208
209
210
211
|
# $NetBSD: blas.buildlink3.mk,v 1.4 2022/09/26 09:33:01 thor Exp $
#
# This Makefile fragment is meant to be included by packages that use any
# BLAS (Basic Linear Algebra System) implementation instead of one particular
# one.
#
# Since pkgsrc always ships BLAS and LAPACK together (as upstream
# implementations do), this adds both BLAS_LIBS and LAPACK_LIBS to the linker
# flags. Often, they will be identical or at least redundant. LAPACK_LIBS
# does include BLAS_LIBS, in any case.
#
# The C interfaces CBLAS and LAPACKE are also selected
# via BLAS_C_INTERFACE in the package and respective CBLAS_LIBS and
# LAPACKE_LIBS are set. Also, BLAS_INCLUDES is set to preprocessor
# flags to locate/use respective headers.
#
# Note that use of the Accelerate framework is experimental and only
# attempted if user and package explicitly want it.
#
# Keywords: blas lapack netlib atlas openblas mkl
#
# === User-settable variables ===
#
# PKGSRC_BLAS_TYPES
# This value specifies an exhaustive list of BLAS implementations we wish to
# use in this pkgsrc installation, in descending order of preference.
# The implementation selected for a build will be the first one in
# PKGSRC_BLAS_TYPES that also appears in BLAS_ACCEPTED (see below).
# Typically set in mk.conf.
#
# Possible: one or more of netlib, openblas, openblas_pthread,
# openblas_openmp, accelerate.framework
# (Accelerate has differing API and needs special handling, might
# be supported in a few specific packages ony.)
#
# Default: All currently supported implementations (${_BLAS_TYPES})
# except accelerate.framework
#
# === Package-settable variables ===
#
# BLAS_ACCEPTED
# This is a list of blas packages that are compatible with the current
# package. If not set, any BLAS implementation is OK.
# Typically set in package Makefile.
#
# BLAS_C_INTERFACE
# Set to yes if the package requires CBLAS or LAPACKE. This defines
# BLAS_INCLUDES and pulls in additional packages for netlib. Optimized
# implementations include the C interfaces in the main library anyway,
# but you still have the effect on BLAS_INCLUDES.
#
# BLAS_INDEX64
# Set to yes if the package wants to utilize 64 bit indices.
#
# === Variables automatically set here for use in package builds ===
#
# BLAS_TYPE
# This is the BLAS implementation chosen for a particular package build from
# PKGSRC_BLAS_TYPES and BLAS_ACCEPTED. If PKGSRC_BLAS_TYPES and
# BLAS_ACCEPTED have no implementations in common, it defaults to none
# and the build fails.
# BLAS_LIBS
# Linker flags used for linking to BLAS library
# LAPACK_LIBS
# Linker flags used for linking to LAPACK library
# (including BLAS)
# CBLAS_LIBS
# Linker flags used for linking to CBLAS library
# (including BLAS)
# LAPACKE_LIBS
# Linker flags used for linking to LAPACKE library
# (including BLAS and LAPACK)
# BLAS_INCLUDES
# Preprocessor flags to locate/use C interfaces
# (both for CBLAS and LAPACKE)
# BLAS_PC, CBLAS_PC, LAPACK_PC, LAPACKE_PC
# Names of pkg-config modules for the respective API. For optimized BLAS,
# they will usually be identical.
.if !defined(MK_BLAS_BUILDLINK3_MK)
MK_BLAS_BUILDLINK3_MK=
BUILD_DEFS+= PKGSRC_BLAS_TYPES
BUILD_DEFS_EFFECTS+= BLAS_TYPE BLAS_LIBS LAPACK_LIBS \
CBLAS_LIBS LAPACKE_LIBS BLAS_INCLUDES
.include "../../mk/bsd.prefs.mk"
# List of all possible BLAS choices, in order of *DEFAULT* preference.
# netlib is the reference implementation to which all others conform and
# should come first by default for maximum compatibility. It is also the
# slowest and not desirable in many situations. Users can override by setting
# PKGSRC_BLAS_TYPES. (See comment above)
_BLAS_TYPES= netlib openblas openblas_pthread openblas_openmp
# The Accelerate framework is special, as it does not offer BLAS API compatible
# to the others. See liboctave/util/blaswrap.c in octave sources, or
# the wrapper https://github.com/mcg1969/vecLibFort that one might want to
# package.
# We have it as option only if user explicitly set it in PKGSRC_BLAS_TYPES
# and the package accepts it explicitly.
BLAS_ACCEPTED?= ${_BLAS_TYPES}
PKGSRC_BLAS_TYPES?= ${_BLAS_TYPES}
.if !empty(BLAS_INDEX64:Myes)
_BLAS_64= 64
.else
_BLAS_64=
.endif
_BLAS_MATCH=
.for b in ${PKGSRC_BLAS_TYPES}
# Seems like Accelerate does not offer a 64 bit interface (yet?).
# Exclude from list in that case, even if present.
. if ${b} != "accelerate.framework" || ( empty(_BLAS_64) \
&& exists(/System/Library/Frameworks/Accelerate.framework) )
_BLAS_MATCH+= ${BLAS_ACCEPTED:M${b}}
. endif
.endfor
.if !empty(_BLAS_MATCH)
BLAS_TYPE= ${_BLAS_MATCH:[1]}
.else
BLAS_TYPE= none
.endif
.if ${BLAS_TYPE} == "netlib"
_BLAS_PKGPATH= math/lapack${_BLAS_64}
_CBLAS_PKGPATH= math/cblas${_BLAS_64}
_LAPACKE_PKGPATH= math/lapacke${_BLAS_64}
BLAS_LIBS= -lblas${_BLAS_64}
LAPACK_LIBS= -llapack${_BLAS_64} ${BLAS_LIBS}
CBLAS_LIBS= -lcblas${_BLAS_64} ${BLAS_LIBS}
LAPACKE_LIBS= -llapacke${_BLAS_64} ${LAPACK_LIBS}
BLAS_INCLUDES= -I${PREFIX}/include/netlib${_BLAS_64}
BLAS_PC= blas${_BLAS_64}
LAPACK_PC= lapack${_BLAS_64}
CBLAS_PC= cblas${_BLAS_64}
LAPACKE_PC= lapacke${_BLAS_64}
. if ${_BLAS_64} == "64"
BLAS_INCLUDES+= -DWeirdNEC -DHAVE_LAPACK_CONFIG_H -DLAPACK_ILP64
. endif
.elif ${BLAS_TYPE} == "openblas"
_BLAS_PKGPATH= math/openblas${_BLAS_64}
BLAS_LIBS= -lopenblas${_BLAS_64}
LAPACK_LIBS= ${BLAS_LIBS}
CBLAS_LIBS= ${BLAS_LIBS}
LAPACKE_LIBS= ${BLAS_LIBS}
BLAS_INCLUDES= -I${PREFIX}/include/openblas${_BLAS_64}
BLAS_PC= openblas${_BLAS_64}
LAPACK_PC= ${BLAS_PC}
CBLAS_PC= ${BLAS_PC}
LAPACKE_PC= ${BLAS_PC}
.elif ${BLAS_TYPE} == "openblas_pthread"
_BLAS_PKGPATH= math/openblas${_BLAS_64}_pthread
BLAS_LIBS= -lopenblas${_BLAS_64}_pthread
LAPACK_LIBS= ${BLAS_LIBS}
CBLAS_LIBS= ${BLAS_LIBS}
LAPACKE_LIBS= ${BLAS_LIBS}
BLAS_INCLUDES= -I${PREFIX}/include/openblas${_BLAS_64}_pthread
BLAS_PC= openblas${_BLAS_64}_pthread
LAPACK_PC= ${BLAS_PC}
CBLAS_PC= ${BLAS_PC}
LAPACKE_PC= ${BLAS_PC}
.elif ${BLAS_TYPE} == "openblas_openmp"
_BLAS_PKGPATH= math/openblas${_BLAS_64}_openmp
BLAS_LIBS= -lopenblas${_BLAS_64}_openmp
LAPACK_LIBS= ${BLAS_LIBS}
CBLAS_LIBS= ${BLAS_LIBS}
LAPACKE_LIBS= ${BLAS_LIBS}
BLAS_INCLUDES= -I${PREFIX}/include/openblas${_BLAS_64}_openmp
BLAS_PC= openblas${_BLAS_64}_openmp
LAPACK_PC= ${BLAS_PC}
CBLAS_PC= ${BLAS_PC}
LAPACKE_PC= ${BLAS_PC}
.elif ${BLAS_TYPE} == "accelerate.framework"
# No 64 bit variant yet. Excluded above.
# Actually, only CBLAS_LIBS is safe to use. Others have g77/f2c calling
# conventions, not gfortran. This needs custom handling in packages.
BLAS_LIBS= -framework Accelerate
CBLAS_LIBS= ${BLAS_LIBS}
LAPACK_LIBS= ${BLAS_LIBS}
LAPACKE_LIBS= # build a wrapper for that?
BLAS_INCLUDES= # not delivered yet
# Idea for cblas.h including Accelerate/Accelerate.h (would work the same
# for Intel MKL with -DBLASWRAP_MKL for mkl_cblas.h).
#BLAS_INCLUDES= -I${PREFIX}/include/blaswrap -DBLASWRAP_ACCELERATE
# Same idea: Add accelerate_framework.pc in the blaswrap package and then set
#BLAS_PC= accelerate_framework
.else # invalid or unimplemented type
PKG_FAIL_REASON+= \
"There is no acceptable BLAS for ${PKGNAME} in: ${PKGSRC_BLAS_TYPES}."
.endif
.if defined(_BLAS_PKGPATH)
.include "../../${_BLAS_PKGPATH}/buildlink3.mk"
.endif
.if !empty(BLAS_C_INTERFACE:Myes)
. if defined(_CBLAS_PKGPATH)
. include "../../${_CBLAS_PKGPATH}/buildlink3.mk"
. endif
. if defined(_LAPACKE_PKGPATH)
. include "../../${_LAPACKE_PKGPATH}/buildlink3.mk"
. endif
.else
. undef BLAS_INCLUDES
. undef CBLAS_PC
. undef LAPACKE_PC
.endif
.endif # BLAS_BUILDLINK3_MK
|