Dynamic library/include paths (#8136)

Fixes #7855
Closes #8070
Closes #2645

When searching for library directories (e.g. to add "-L" arguments to
the compiler wrapper) Spack was only trying the "lib/" and "lib64/"
directories for each dependency install prefix; this missed cases
where packages would install libraries to subdirectories and also was
not customizable. This PR makes use of the ".headers" and ".libs"
properties for more-advanced location of header/library directories.
Since packages can override the default behavior of ".headers" and
".libs", it also allows package writers to customize.

The following environment variables which used to be set by Spack
for a package build have been removed:

* Remove SPACK_PREFIX and SPACK_DEPENDENCIES environment variables as
  they are no-longer used
* Remove SPACK_INSTALL environment variable: it was not used before
  this PR
This commit is contained in:
Peter Scheibel
2019-02-13 17:38:14 -06:00
committed by GitHub
parent 1bf86292e1
commit 8ca384875e
9 changed files with 261 additions and 252 deletions

69
lib/spack/env/cc vendored
View File

@@ -24,7 +24,6 @@
# the script runs. They are set by routines in spack.build_environment
# as part of spack.package.Package.do_install().
parameters=(
SPACK_PREFIX
SPACK_ENV_PATH
SPACK_DEBUG_LOG_DIR
SPACK_DEBUG_LOG_ID
@@ -46,8 +45,6 @@ parameters=(
# SPACK_DEBUG
# Test command is used to unit test the compiler script.
# SPACK_TEST_COMMAND
# Dependencies can be empty for pkgs with no deps:
# SPACK_DEPENDENCIES
# die()
# Prints a message and exits with error 1.
@@ -385,52 +382,30 @@ case "$mode" in
flags=("${flags[@]}" "${SPACK_LDFLAGS[@]}") ;;
esac
# Prepend include directories
IFS=':' read -ra include_dirs <<< "$SPACK_INCLUDE_DIRS"
if [[ $mode == cpp || $mode == cc || $mode == as || $mode == ccld ]]; then
for include_dir in "${include_dirs[@]}"; do
includes=("${includes[@]}" "$include_dir")
done
fi
# Include the package's prefix/lib[64] dirs in rpath. We don't know until
# *after* installation which one's correct, so we include both lib and
# lib64, assuming that only one will be present.
case "$mode" in
ld|ccld)
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib")
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib64")
;;
esac
IFS=':' read -ra rpath_dirs <<< "$SPACK_RPATH_DIRS"
if [[ $mode == ccld || $mode == ld ]]; then
for rpath_dir in "${rpath_dirs[@]}"; do
# Append RPATH directories. Note that in the case of the
# top-level package these directories may not exist yet. For dependencies
# it is assumed that paths have already been confirmed.
$add_rpaths && rpaths=("${rpaths[@]}" "$rpath_dir")
done
fi
# Read spack dependencies from the environment. This is a list of prefixes.
IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
for dep in "${deps[@]}"; do
# Append include directories in any compilation mode
case "$mode" in
cpp|cc|as|ccld)
if [[ -d $dep/include ]]; then
includes=("${includes[@]}" "$dep/include")
fi
;;
esac
# Append lib/lib64 and RPATH directories, but only if we're linking
case "$mode" in
ld|ccld)
if [[ -d $dep/lib ]]; then
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
$add_rpaths && rpaths=("${rpaths[@]}" "$dep/lib")
fi
if [[ $SPACK_LINK_DEPS == *$dep* ]]; then
libdirs=("${libdirs[@]}" "$dep/lib")
fi
fi
if [[ -d $dep/lib64 ]]; then
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
$add_rpaths && rpaths+=("$dep/lib64")
fi
if [[ $SPACK_LINK_DEPS == *$dep* ]]; then
libdirs+=("$dep/lib64")
fi
fi
;;
esac
done
IFS=':' read -ra link_dirs <<< "$SPACK_LINK_DIRS"
if [[ $mode == ccld || $mode == ld ]]; then
for link_dir in "${link_dirs[@]}"; do
libdirs=("${libdirs[@]}" "$link_dir")
done
fi
# add RPATHs if we're in in any linking mode
case "$mode" in