Merge branch 'correct-cc' of git://github.com/eschnett/spack into eschnett-correct-cc

This commit is contained in:
Todd Gamblin
2016-03-27 13:38:06 -07:00

110
lib/spack/env/cc vendored
View File

@@ -65,7 +65,7 @@ function die {
}
for param in $parameters; do
if [ -z "${!param}" ]; then
if [[ -z ${!param} ]]; then
die "Spack compiler must be run from spack! Input $param was missing!"
fi
done
@@ -78,10 +78,11 @@ done
# 'command' is set based on the input command to $SPACK_[CC|CXX|F77|F90]
#
# 'mode' is set to one of:
# cpp preprocess
# cc compile
# as assemble
# ld link
# ccld compile & link
# cpp preprocessor
# vcheck version check
#
command=$(basename "$0")
@@ -131,6 +132,9 @@ if [ -z "$mode" ]; then
if [ "$arg" = -E ]; then
mode=cpp
break
elif [ "$arg" = -S ]; then
mode=as
break
elif [ "$arg" = -c ]; then
mode=cc
break
@@ -146,21 +150,25 @@ fi
# Check that at least one of the real commands was actually selected,
# otherwise we don't know what to execute.
if [ -z "$command" ]; then
if [[ -z $command ]]; then
die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs."
fi
# Save original command for debug logging
input_command="$@"
if [ "$mode" == vcheck ] ; then
exec ${command} "$@"
fi
# Save original command for debug logging
input_command="$@"
args=("$@")
# Dump parsed values for unit testing if asked for
if [[ -n $SPACK_TEST_COMMAND ]]; then
#
# Now do real parsing of the command line args, trying hard to keep
# non-rpath linker arguments in the proper order w.r.t. other command
# line arguments. This is important for things like groups.
# non-rpath linker arguments in the proper order w.r.t. other command line
# arguments. This is important for things like groups.
#
includes=()
libraries=()
@@ -234,8 +242,6 @@ while [ -n "$1" ]; do
shift
done
# Dump parsed values for unit testing if asked for
if [ -n "$SPACK_TEST_COMMAND" ]; then
IFS=$'\n'
case "$SPACK_TEST_COMMAND" in
dump-includes) echo "${includes[*]}";;
@@ -260,8 +266,8 @@ if [ -n "$SPACK_TEST_COMMAND" ]; then
echo "${other_args[*]}"
;;
*)
echo "ERROR: Unknown test command"
exit 1 ;;
die "ERROR: Unknown test command"
;;
esac
exit
fi
@@ -269,45 +275,46 @@ fi
# Read spack dependencies from the path environment variable
IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
for dep in "${deps[@]}"; do
if [ -d "$dep/include" ]; then
includes+=("$dep/include")
if [[ -d $dep/include ]]; then
if [[ $mode = cpp || $mode = cc || $mode = as || $mode = ccld ]]; then
args=("-I$dep/include" "${args[@]}")
fi
fi
if [ -d "$dep/lib" ]; then
libraries+=("$dep/lib")
rpaths+=("$dep/lib")
if [[ -d $dep/lib ]]; then
# libraries+=("$dep/lib")
if [[ $mode = ccld ]]; then
args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}")
elif [[ $mode = ld ]]; then
args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}")
fi
fi
if [ -d "$dep/lib64" ]; then
libraries+=("$dep/lib64")
rpaths+=("$dep/lib64")
if [[ -d $dep/lib64 ]]; then
# libraries+=("$dep/lib64")
if [[ $mode = ccld ]]; then
args=("-L$dep/lib" "-Wl,-rpath,$dep/lib" "${args[@]}")
elif [[ $mode = ld ]]; then
args=("-L$dep/lib" "-rpath" "$dep/lib" "${args[@]}")
fi
fi
done
# Include all -L's and prefix/whatever dirs in rpath
for dir in "${libraries[@]}"; do
[[ dir = $SPACK_INSTALL* ]] && rpaths+=("$dir")
done
rpaths+=("$SPACK_PREFIX/lib")
rpaths+=("$SPACK_PREFIX/lib64")
# Put the arguments together
args=()
for dir in "${includes[@]}"; do args+=("-I$dir"); done
args+=("${other_args[@]}")
for dir in "${libraries[@]}"; do args+=("-L$dir"); done
for lib in "${libs[@]}"; do args+=("-l$lib"); done
if [ "$mode" = ccld ]; then
for dir in "${rpaths[@]}"; do
args+=("-Wl,-rpath")
args+=("-Wl,$dir");
done
elif [ "$mode" = ld ]; then
for dir in "${rpaths[@]}"; do
args+=("-rpath")
args+=("$dir");
done
if [[ $mode = ccld ]]; then
# for dir in "${libraries[@]}"; do
# if [[ dir = $SPACK_INSTALL* ]]; then
# args=("-Wl,-rpath,$dir" "${args[@]}")
# fi
# done
args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}")
elif [[ $mode = ld ]]; then
# for dir in "${libraries[@]}"; do
# if [[ dir = $SPACK_INSTALL* ]]; then
# args=("-rpath" "$dir" "${args[@]}")
# fi
# done
args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}")
fi
#
@@ -323,30 +330,25 @@ unset DYLD_LIBRARY_PATH
#
IFS=':' read -ra env_path <<< "$PATH"
IFS=':' read -ra spack_env_dirs <<< "$SPACK_ENV_PATH"
spack_env_dirs+=(".")
spack_env_dirs+=("" ".")
PATH=""
for dir in "${env_path[@]}"; do
remove=""
for rm_dir in "${spack_env_dirs[@]}"; do
if [ "$dir" = "$rm_dir" ]; then remove=True; fi
if [[ $dir = $rm_dir ]]; then remove=True; fi
done
if [ -z "$remove" ]; then
if [ -z "$PATH" ]; then
PATH="$dir"
else
PATH="$PATH:$dir"
fi
if [[ -z $remove ]]; then
PATH="${PATH:+$PATH:}$dir"
fi
done
export PATH
full_command=("$command")
full_command+=("${args[@]}")
full_command=("$command" "${args[@]}")
#
# Write the input and output commands to debug logs if it's asked for.
#
if [ "$SPACK_DEBUG" = "TRUE" ]; then
if [[ $SPACK_DEBUG = TRUE ]]; then
input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log"
output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log"
echo "$input_command" >> $input_log