1 # -*-eselect-*- vim: ft=eselect
2 # Copyright 2019 Gentoo Foundation
3 # Distributed under the terms of the GNU GPL version 2 or later
5 inherit config tests multilib skel
9 DESCRIPTION="Manage installed alternatives of $MODULE shared objects"
10 MAINTAINER="lumin@debian.org"
13 ### helper utility to find all available BLAS/CBLAS implementations
15 [[ $# -eq 1 ]] || die -q "in which libdir?"
18 for cand in ${EROOT}/etc/env.d/blas/$1/*; do
19 [[ "config" = $(basename ${cand}) ]] && continue
20 [[ -r ${cand} ]] && basename ${cand}
24 ### helper utility to validate a BLAS/CBLAS library directory
25 validate_blaslibdir() {
26 [[ -d $1 ]] || return 2 # dir doesn't exist
27 [[ -r "${1}/libblas.so.3" ]] && [[ -r "${1}/libblas.so" ]] \
28 && [[ -r "${1}/libcblas.so.3" ]] && [[ -r "${1}/libcblas.so" ]] \
34 # do_show -- show both lib64 and lib32 selection
35 # do_show libxx -- show libxx selection
36 local libdir cur libdirs=( $(list_libdirs) )
38 # if manually specified libdirs
39 if [[ ! $# -eq 0 ]]; then
41 has $libdir ${libdirs[@]} || die -q "invalid libdir '$libdir'!"
46 for libdir in ${libdirs[@]}; do
47 [[ ! -d ${EROOT}/usr/$libdir ]] && continue
48 [[ ! -r ${EROOT}/etc/env.d/blas/${libdir}/config ]] && continue
49 cur=$(load_config ${EROOT}/etc/env.d/blas/${libdir}/config CURRENT)
57 local libdir libdirs=( $(list_libdirs) )
59 # if manually specified libdirs
60 if [[ ! $# -eq 0 ]]; then
62 has $libdir ${libdirs[@]} || die -q "invalid libdir '$libdir'!"
67 for libdir in ${libdirs[@]}; do
68 [[ ! -d ${EROOT}/usr/$libdir ]] || [[ -L ${EROOT}/usr/$libdir ]] && continue
69 targets=( $(find_targets_in $libdir) )
70 cur=$(load_config ${EROOT}/etc/env.d/blas/${libdir}/config CURRENT)
72 write_list_start "Available BLAS/CBLAS ($libdir) candidates:"
73 for (( i = 0; i < ${#targets[@]}; i++ )); do
74 [[ ${targets[i]} = $cur ]] \
75 && targets[i]=$(highlight_marker "${targets[i]}")
77 write_numbered_list -m "(none found)" "${targets[@]}"
83 echo "validate candidates and remove invalid ones"
87 local i ldpath targets target candidate
88 local libdir libdirs=( $(list_libdirs) )
89 for libdir in ${libdirs[@]}; do
90 [[ ! -d ${EROOT}/usr/$libdir ]] || [[ -L ${EROOT}/usr/$libdir ]] && continue
91 targets=( $(find_targets_in $libdir) )
92 for target in ${targets[@]}; do
93 candidate=${EROOT}/etc/env.d/blas/${libdir}/${target}
94 ldpath=$(load_config $candidate LDPATH)
95 if ! validate_blaslibdir $ldpath; then
96 echo "Removing invalid BLAS/CBLAS candidate ($candidate) ..."
106 echo "Activate one of the installed $MODULE implementations"
109 describe_set_parameters() {
110 echo "[<libdir>] <implementation>"
113 describe_set_options() {
114 echo "libdir: lib64 or lib32. Will use the native one when omitted."
115 echo "implementation : implementation name or number (from 'list' action)"
119 local libdirs=( $(list_libdirs) )
120 local targets libdir ldconf libpath impl
122 # check argument existence
123 [[ $# -eq 1 ]] || [[ $# -eq 2 ]] || \
124 die -q "Please specify [<libdir>] <impl> to activate!"
126 if [[ $# -eq 2 ]]; then libdir="$1"; else libdir="$(get_libdir)"; fi
127 if [[ $# -eq 2 ]]; then impl="$2"; else impl="$1"; fi
129 has "$libdir" "${libdirs[@]}" || die -q "Invalid libdir ($libdir) !"
130 targets=( $(find_targets_in $libdir) )
131 if ! has "$impl" "${targets[@]}"; then
132 if [[ ${impl} -gt 0 ]] && [[ ${impl} -le ${#targets[@]} ]]; then
133 impl=${targets[(${impl} - 1)]}
135 die -q "Invalid impl ($impl) !"
138 # store the configuration to env.d
139 store_config ${EROOT}/etc/env.d/blas/${libdir}/config CURRENT "${impl}"
140 # generate ld.so.conf file
141 ldconf="${EROOT}/etc/ld.so.conf.d/81-blas-${libdir}.conf"
142 libpath=$(load_config ${EROOT}/etc/env.d/blas/${libdir}/${impl} LDPATH)
144 echo "# Auto-generated by eselect::blas. DON'T EDIT." >> $ldconf
145 echo "$libpath" >> $ldconf
147 # refresh cache. env-update will call ldconfig (see
148 # portage::env_update.py) so we don't need to call it explicitly.
153 describe_add_parameters() {
154 echo "<libdir> <dir> <impl>"
157 describe_add_options() {
158 echo "libdir : library directory where $MODULE implementation is installed (lib, lib64, etc.)"
159 echo "dir : directory containing lib{,c}blas.so{.3}"
160 echo "impl : name of the $MODULE implementation"
165 || die -q "Please specify <libdir> <dir> <impl> to activate!"
166 validate_blaslibdir $2 || die -q "invalid blas libdir!"
167 store_config ${EROOT}/etc/env.d/blas/$1/$3 LDPATH $2