Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Trac #29345: replace the function that populates the CVXOPT_* variables.
Browse files Browse the repository at this point in the history
Our existing function, borrowed from Gentoo, to populate the CVXOPT_*
variables from pkg-config was brittle. It didn't handle -lpthread and
-lm the way it was intended to, and didn't always work with a non-bash
shell. The new version (which has also been upstreamed to Gentoo)
should fix both of those problems. It also suppors getting the -L and
-I flags from pkg-config in the future, which will likely be necessary
to support system installations of some cvxopt dependencies.
  • Loading branch information
orlitzky committed May 30, 2020
1 parent e810ad1 commit 93c9921
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions build/pkgs/cvxopt/spkg-install.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,69 @@
cd src

# Stolen from Gentoo
pkg_libs() {
pkg-config --libs-only-l $* | \
sed -e 's:[ ]-l*\(pthread\|m\)\([ ]\|$\)::g' -e 's:[ ]*$::' | \
tr ' ' '\n' | sort -u | sed -e "s:^-l\(.*\):\1:g" | \
tr '\n' ';' | sed -e 's:;$::'
}
# This is a POSIX (non-bash) compatible version of the same function
# in the Gentoo cvxopt package. It's more general than it needs to
# be right now because we may need to use the "L" and "I" modes in
# the future to support system installations of e.g. suitesparse.
#
# The BLAS_LIB and LAPACK_LIB variables (among others) in cvxopt's
# setup.py are passed in as colon-delimited strings. So, for example,
# if your blas "l" flags are "-lblas -lcblas", then cvxopt wants
# "blas;cblas" for BLAS_LIB.
#
# The following function takes a flag type ("l", "L", or "I") as its
# first argument and a list of packages as its remaining arguments. It
# outputs a list of libraries, library paths, or include paths,
# respectively, for the given packages, retrieved using pkg-config and
# deduplicated, in the appropriate format.
#
cvxopt_output() {
FLAGNAME="${1}"
shift
PACKAGES="${@}"

case "${FLAGNAME}" in
l) PKGCONFIG_MODE="--libs-only-l";;
L) PKGCONFIG_MODE="--libs-only-L";;
I) PKGCONFIG_MODE="--cflags-only-I";;
*) echo "invalid flag name: ${FLAGNAME}"; exit 1;;
esac

CVXOPT_OUTPUT=""
for PKGCONFIG_ITEM in $(pkg-config ${PKGCONFIG_MODE} ${PACKAGES}); do
# First strip off the leading "-l", "-L", or "-I", and replace
# it with a semicolon...
PKGCONFIG_ITEM=";${PKGCONFIG_ITEM#-${FLAGNAME}}"

# Now check to see if this element is already present in the
# list, and skip it if it is. This eliminates multiple entries
# from winding up in the list when multiple package arguments are
# passed to this function.
if [ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM}}" ]
then
# It was already the last entry in the list, so skip it.
continue
elif [ "${CVXOPT_OUTPUT}" != "${CVXOPT_OUTPUT%${PKGCONFIG_ITEM};*}" ]
then
# It was an earlier entry in the list. These two cases are
# separate to ensure that we can e.g. find ";m" at the end
# of the list, but that we don't find ";metis" in the process.
continue
fi

# It isn't in the list yet, so append it.
CVXOPT_OUTPUT="${CVXOPT_OUTPUT}${PKGCONFIG_ITEM}"
done

# Strip the leading ";" from ";foo;bar" before output.
echo "${CVXOPT_OUTPUT#;}"
}

# configure cvxopt by variables
# Note that *_INC_DIR variables have to be non-empty.
# Compilers don't like "-I ".
export CVXOPT_BLAS_LIB="$(pkg_libs blas)"
export CVXOPT_BLAS_LIB="$(cvxopt_output l blas)"
export CVXOPT_BLAS_LIB_DIR="$(pkg-config --variable=libdir blas)"
export CVXOPT_LAPACK_LIB="$(pkg_libs lapack)"
export CVXOPT_LAPACK_LIB="$(cvxopt_output l lapack)"

if test "x$SAGE_SUITESPARSE_LOCALINSTALL" != "x"; then
export CVXOPT_SUITESPARSE_LIB_DIR="${SAGE_LOCAL}"
Expand Down

0 comments on commit 93c9921

Please sign in to comment.