diff --git a/build/pkgs/cvxopt/spkg-install.in b/build/pkgs/cvxopt/spkg-install.in index 980eddf1493..bed0f34ceee 100644 --- a/build/pkgs/cvxopt/spkg-install.in +++ b/build/pkgs/cvxopt/spkg-install.in @@ -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}"