aboutsummaryrefslogtreecommitdiff
blob: f720356a3ea7ec805659c3d5fd8b8d9307a48d41 (plain)
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

# @ECLASS: numeric-int64-multilib.eclass
# @MAINTAINER:
# sci team <sci@gentoo.org>
# @AUTHOR:
# Author: Mark Wright <gienah@gentoo.org>
# Author: Justin Lecher <jlec@gentoo.org>
# @BLURB: Build functions for Fortran multilib int64 multibuild packages
# @DESCRIPTION:
# The numeric-int64-multilib.eclass exports USE flags and utility functions
# necessary to build packages for multilib int64 multibuild in a clean
# and uniform manner.

if [[ ! ${_NUMERIC_INT64_MULTILIB_ECLASS} ]]; then

# EAPI=5 is required for meaningful MULTILIB_USEDEP.
case ${EAPI:-0} in
	5)
		inherit multilib ;;
	6|7) ;;
	*) die "EAPI=${EAPI} is not supported" ;;
esac

inherit alternatives-2 eutils fortran-2 multilib-build numeric toolchain-funcs

IUSE="int64"

# @ECLASS-VARIABLE: NUMERIC_INT32_SUFFIX
# @INTERNAL
# @DESCRIPTION:
# MULTIBUILD_ID suffix for int32 build
NUMERIC_INT32_SUFFIX="int32"

# @ECLASS-VARIABLE: NUMERIC_INT64_SUFFIX
# @INTERNAL
# @DESCRIPTION:
# MULTIBUILD_ID suffix for int64 build
NUMERIC_INT64_SUFFIX="int64"

# @ECLASS-VARIABLE: NUMERIC_STATIC_SUFFIX
# @INTERNAL
# @DESCRIPTION:
# MULTIBUILD_ID suffix for static build
NUMERIC_STATIC_SUFFIX="static"

# @FUNCTION: numeric-int64_is_int64_build
# @DESCRIPTION:
# Returns shell true if the current multibuild is a int64 build,
# else returns shell false.
#
# Example:
#
# @CODE
#	$(numeric-int64_is_int64_build) && \
#		openblas_abi_cflags+=" -DOPENBLAS_USE64BITINT"
# @CODE
numeric-int64_is_int64_build() {
	debug-print-function ${FUNCNAME} "${@}"
	if [[ "${MULTIBUILD_ID}" =~ "${NUMERIC_INT64_SUFFIX}" ]]; then
		return 0
	else
		return 1
	fi
}

# @FUNCTION: numeric-int64_is_static_build
# @DESCRIPTION:
# Returns shell true if current multibuild is a static build,
# else returns shell false.
#
# Example:
#
# @CODE
#	if $(numeric-int64_is_static_build); then
#		dolib.a lib*a
#	fi
# @CODE
numeric-int64_is_static_build() {
	debug-print-function ${FUNCNAME} "${@}"
	if [[ "${MULTIBUILD_ID}" =~ "${NUMERIC_STATIC_SUFFIX}" ]]; then
		return 0
	else
		return 1
	fi
}

# @FUNCTION: numeric-int64_get_module_name
# @USAGE: [<module_name>]
# @DESCRIPTION:
# Return the numeric module name, without the .pc extension,
# for the current fortran int64 build.  If the current build is not an int64
# build, and the ebuild does not have dynamic, threads or openmp USE flags or
# they are disabled, then the module_name is ${NUMERIC_MODULE_NAME} or
# <module_name> if <module_name> is specified.
#
# Takes an optional <module_name> parameter.  If no <module_name> is specified,
# uses ${NUMERIC_MODULE_NAME} as the base to calculate the module_name for the
# current build.
#
# Example:
#
# @CODE
#	NUMERIC_MODULE_NAME=blas
#	profname=$(numeric-int64_get_module_name)
#
#	int32 build:
#	-> profname == blas
#
#	int64 build:
#	-> profname == blas-int64
# @CODE
numeric-int64_get_module_name() {
	debug-print-function ${FUNCNAME} "${@}"
	local module_name="${1:-${NUMERIC_MODULE_NAME}}"
	if has dynamic ${IUSE} && use dynamic; then
		module_name+="-dynamic"
	fi
	if $(numeric-int64_is_int64_build); then
		module_name+="-${NUMERIC_INT64_SUFFIX}"
	fi
	# choose posix threads over openmp when the two are set
	# yet to see the need of having the two profiles simultaneously
	if use_if_iuse threads; then
		module_name+="-threads"
	elif use_if_iuse openmp; then
		module_name+="-openmp"
	fi
	echo "${module_name}"
}

# @FUNCTION: _numeric-int64_get_numeric_alternative
# @INTERNAL
_numeric-int64_get_numeric_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	local alternative_name="${1}"
	if $(numeric-int64_is_int64_build); then
		alternative_name+="-${NUMERIC_INT64_SUFFIX}"
	fi
	echo "${alternative_name}"
}

# @FUNCTION: numeric-int64_get_blas_alternative
# @DESCRIPTION:
# Returns the eselect blas alternative for the current
# int build type. Which is blas-int64 if called from an int64 build,
# or blas otherwise.
numeric-int64_get_blas_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	_numeric-int64_get_numeric_alternative blas
}

# @FUNCTION: numeric-int64_get_cblas_alternative
# @DESCRIPTION:
# Returns the eselect cblas alternative for the current
# int build type. Which is cblas-int64 if called from an int64 build,
# or cblas otherwise.
numeric-int64_get_cblas_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	_numeric-int64_get_numeric_alternative cblas
}

# @FUNCTION: numeric-int64_get_xblas_alternative
# @DESCRIPTION:
# Returns the eselect xblas alternative for the current
# int build type. Which is xblas-int64 if called from an int64 build,
# or xblas otherwise.
numeric-int64_get_xblas_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	_numeric-int64_get_numeric_alternative xblas
}

# @FUNCTION: numeric-int64_get_lapack_alternative
# @DESCRIPTION:
# Returns the eselect lapack alternative for the current
# int build type. Which is lapack-int64 if called from an int64 build,
# or lapack otherwise.
numeric-int64_get_lapack_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	_numeric-int64_get_numeric_alternative lapack
}

# @FUNCTION: numeric-int64_get_blas_module_name
# @DESCRIPTION:
# Returns the pkg-config file name, without the .pc extension,
# for the currently selected blas-int64 module if we are performing an int64
# build, or the currently selected blas module otherwise.
numeric-int64_get_blas_module_name() {
	debug-print-function ${FUNCNAME} "${@}"
	local blas_alternative=$(numeric-int64_get_blas_alternative)
	local blas_symlinks=( $(eselect "${blas_alternative}" files) )
	local blas_prof_symlink="$(readlink -f ${blas_symlinks[0]})"
	local blas_prof_file="${blas_prof_symlink##*/}"
	echo "${blas_prof_file%.pc}"
}

# @FUNCTION: numeric-int64_get_xblas_module_name
# @DESCRIPTION:
# Returns the xblas pkg-config file name,
# without the .pc extension, for the current build. Which is xblas-int64 if
# we are performing an int64 build, or xblas otherwise.
numeric-int64_get_xblas_module_name() {
	debug-print-function ${FUNCNAME} "${@}"
	local xblas_provider="xblas"
	if $(numeric-int64_is_int64_build); then
		xblas_provider+="-${INT64_SUFFIX}"
	fi
	echo "${xblas_provider}"
}

# @FUNCTION: numeric-int64_get_fortran_int64_abi_fflags
# @DESCRIPTION:
# Return the Fortran compiler flag to enable 64 bit integers for
# array indices if we are performing an int64 build, or the empty string
# otherwise.
#
# Example:
#
# @CODE
# src_configure() {
#	my_configure() {
#		export FCFLAGS="${FCFLAGS} $(get_abi_CFLAGS) $(numeric-int64_get_fortran_int64_abi_fflags)"
#		econf $(use_enable fortran)
#	}
#	numeric-int64-multibuild_foreach_all_abi_variants run_in_build_dir my_configure
# }
# @CODE
numeric-int64_get_fortran_int64_abi_fflags() {
	debug-print-function ${FUNCNAME} "${@}"
	$(numeric-int64_is_int64_build) && echo "$(fortran_int64_abi_fflags)"
}

# @FUNCTION: numeric-int64_get_multibuild_int_variants
# @DESCRIPTION:
# Returns the array of int64 and int32
# multibuild combinations.
numeric-int64_get_multibuild_int_variants() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=( int32 ) variant

	use_if_iuse int64 && MULTIBUILD_VARIANTS+=( int64 )

	echo "${MULTIBUILD_VARIANTS[@]}"
}

# @FUNCTION: numeric-int64_get_multibuild_variants
# @DESCRIPTION:
# Returns the array of int64, int32 and static
# multibuild combinations.
numeric-int64_get_multibuild_variants() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=$(numeric-int64_get_multibuild_int_variants)
	if use_if_iuse static-libs; then
		for variant in ${MULTIBUILD_VARIANTS[@]}; do
			MULTIBUILD_VARIANTS+=( static_${variant} )
		done
	fi
	echo "${MULTIBUILD_VARIANTS[@]}"
}

# @FUNCTION: numeric-int64_get_all_abi_variants
# @DESCRIPTION:
# Returns the array of int64, int32 and static build combinations
# combined with all multilib ABI variants.
numeric-int64_get_all_abi_variants() {
	debug-print-function ${FUNCNAME} "${@}"
	local abi ret=() variant

	for abi in $(multilib_get_enabled_abi_pairs); do
		for variant in $(numeric-int64_get_multibuild_variants); do
			if [[ ${variant} =~ int64 ]]; then
				[[ ${abi} =~ amd64 ]] && ret+=( ${abi}_${variant} )
			else
				ret+=( ${abi}_${variant} )
			fi
		done
	done
	echo "${ret[@]}"
}

# @FUNCTION: numeric-int64_ensure_blas_int_support
# @DESCRIPTION:
# Check the blas supports the necessary int types in the currently
# selected blas module.
#
# Example:
#
# @CODE
# src_prepare() {
#	numeric-int64_ensure_blas_int_support
#	...
# @CODE
numeric-int64_ensure_blas_int_support() {
	local MULTILIB_INT64_VARIANTS=( $(numeric-int64_get_multibuild_variants) )
	local MULTIBUILD_ID
	for MULTIBUILD_ID in "${MULTILIB_INT64_VARIANTS[@]}"; do
		local blas_module_name=$(numeric-int64_get_blas_module_name)
		$(tc-getPKG_CONFIG) --exists "${blas_module_name}" \
			|| die "${PN} requires the pkgbuild module ${blas_module_name}"
	done
}

# @FUNCTION: numeric-int64-multibuild_install_alternative
# @USAGE: <alternative name> <provider name> [extra files sources] [extra files dest]
# @DESCRIPTION:
# Install alternatives pc file and extra files for all providers for all multilib ABIs.
numeric-int64-multibuild_install_alternative() {
	debug-print-function ${FUNCNAME} "${@}"
	[[ $# -lt 2 ]] && die "${FUNCNAME} needs at least two arguments"
	pc_file()  {
		debug-print-function ${FUNCNAME} "${@}"
		numeric-int64_is_static_build && return
		local alternative=$(_numeric-int64_get_numeric_alternative "$1")
		local module_name=$(numeric-int64_get_module_name)
		printf \
			"/usr/$(get_libdir)/pkgconfig/${alternative}.pc ${module_name}.pc " \
			>> "${T}"/alternative-${alternative}.sh || die
	}
	pc_install() {
		debug-print-function ${FUNCNAME} "${@}"
		numeric-int64_is_static_build && return
		local alternative=$(_numeric-int64_get_numeric_alternative "$1")
		local module_name=$(numeric-int64_get_module_name $2)
		shift 2
		alternatives_for \
			${alternative} ${module_name} 0 \
			$(cat "${T}"/alternative-${alternative}.sh) ${@}
		rm "${T}"/alternative-${alternative}.sh || die
	}
	numeric-int64-multibuild_foreach_all_abi_variants pc_file ${@}
	numeric-int64-multibuild_foreach_int_abi pc_install ${@}
}

# @FUNCTION: numeric-int64-multibuild_multilib_wrapper
# @USAGE: <argv>...
# @DESCRIPTION:
# Initialize the environment for ABI selected for multibuild.
#
# Example:
#
# @CODE
# 	multibuild_foreach_variant run_in_build_dir \
# 		numeric-int64-multibuild_multilib_wrapper my_src_install
# @CODE
numeric-int64-multibuild_multilib_wrapper() {
	debug-print-function ${FUNCNAME} "${@}"

	local v="${MULTIBUILD_VARIANT%_*}"
	# MULTIBUILD_VARIANT could be abi_x86_64.amd64_static_int32
	v=${v%_${NUMERIC_STATIC_SUFFIX}}
	local ABI="${v#*.}"
	# hack: our int64 and int32 ABIs can correspond to the same ABI
	# in multilib, resulting in multiple sed replacements of headers
	# and thus error like "Flag not listed in wrapper template."
	# Using MULTILIB_ABI_FLAG="${ABI}", the corresponding header
	# is ignored.
	local MULTILIB_ABI_FLAG
	case ${MULTIBUILD_VARIANT} in
	*_${NUMERIC_STATIC_SUFFIX}*|*_${NUMERIC_INT64_SUFFIX})
		MULTILIB_ABI_FLAG="${ABI}"
		;;
	*_${NUMERIC_INT32_SUFFIX})
		MULTILIB_ABI_FLAG="${v%.*}"
		;;
	esac

	multilib_toolchain_setup "${ABI}"
	readonly ABI
	"${@}" || die
}

# @FUNCTION: numeric-int64-multibuild_foreach_int_abi
# @USAGE: <argv> ...
# @DESCRIPTION:
# Run command for each enabled numeric variant (e.g. int32, int64)
numeric-int64-multibuild_foreach_int_abi() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=( $(numeric-int64_get_multibuild_int_variants) )
	multibuild_foreach_variant numeric-int64-multibuild_multilib_wrapper "${@}"
}

# @FUNCTION: numeric-int64-multibuild_foreach_variant
# @USAGE: <argv> ...
# @DESCRIPTION:
# Run command for each enabled numeric abi and static-libs (e.g. int32, int64, static)
numeric-int64-multibuild_foreach_variant() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=( $(numeric-int64_get_multibuild_variants) )
	multibuild_foreach_variant numeric-int64-multibuild_multilib_wrapper "${@}"
}

# @FUNCTION: numeric-int64-multibuild_foreach_all_abi_variants
# @USAGE: <argv> ...
# @DESCRIPTION:
# Run command for each enabled numeric variant (e.g. int32, int64, static) _AND_
# enabled multilib ABI
numeric-int64-multibuild_foreach_all_abi_variants() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=( $(numeric-int64_get_all_abi_variants) )
	multibuild_foreach_variant numeric-int64-multibuild_multilib_wrapper "${@}"
}

# @FUNCTION: numeric-int64-multibuild_copy_sources
# @DESCRIPTION:
# Thin wrapper around multibuild_copy_sources()
numeric-int64-multibuild_copy_sources() {
	debug-print-function ${FUNCNAME} "${@}"
	local MULTIBUILD_VARIANTS=( $(numeric-int64_get_all_abi_variants) )
	multibuild_copy_sources
}

_NUMERIC_INT64_MULTILIB_ECLASS=1
fi