Clean up cc script

This commit is contained in:
Erik Schnetter
2016-04-04 14:33:48 -04:00
parent a7e13b1963
commit 7bc28cc334

65
lib/spack/env/cc vendored
View File

@@ -84,13 +84,12 @@ done
# ld link # ld link
# ccld compile & link # ccld compile & link
# vcheck version check # vcheck version check
#
# Depending on the mode, we may or may not add extra rpaths.
# This variable controls whether they are added.
add_rpaths=true
command=$(basename "$0") command=$(basename "$0")
case "$command" in case "$command" in
cpp)
mode=cpp
;;
cc|c89|c99|gcc|clang|icc|pgcc|xlc) cc|c89|c99|gcc|clang|icc|pgcc|xlc)
command="$SPACK_CC" command="$SPACK_CC"
language="C" language="C"
@@ -107,22 +106,8 @@ case "$command" in
command="$SPACK_F77" command="$SPACK_F77"
language="Fortran 77" language="Fortran 77"
;; ;;
cpp)
mode=cpp
;;
ld) ld)
mode=ld mode=ld
# Darwin's linker has a -r argument that merges object files
# together. It doesn't work with -rpath.
if [[ $OSTYPE = darwin* ]]; then
for arg in "$@"; do
if [ "$arg" = -r ]; then
add_rpaths=false
break
fi
done
fi
;; ;;
*) *)
die "Unkown compiler: $command" die "Unkown compiler: $command"
@@ -130,11 +115,11 @@ case "$command" in
esac esac
# If any of the arguments below is present then the mode is vcheck. In # If any of the arguments below is present then the mode is vcheck. In
# vcheck mode nothing is added in terms of extra search paths or # vcheck mode, nothing is added in terms of extra search paths or
# libraries # libraries.
if [ -z "$mode" ]; then if [[ -z $mode ]]; then
for arg in "$@"; do for arg in "$@"; do
if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then if [[ $arg = -v || $arg = -V || $arg = --version || $arg = -dumpversion ]]; then
mode=vcheck mode=vcheck
break break
fi fi
@@ -142,16 +127,16 @@ if [ -z "$mode" ]; then
fi fi
# Finish setting up the mode. # Finish setting up the mode.
if [ -z "$mode" ]; then if [[ -z $mode ]]; then
mode=ccld mode=ccld
for arg in "$@"; do for arg in "$@"; do
if [ "$arg" = -E ]; then if [[ $arg = -E ]]; then
mode=cpp mode=cpp
break break
elif [ "$arg" = -S ]; then elif [[ $arg = -S ]]; then
mode=as mode=as
break break
elif [ "$arg" = -c ]; then elif [[ $arg = -c ]]; then
mode=cc mode=cc
break break
fi fi
@@ -159,7 +144,7 @@ if [ -z "$mode" ]; then
fi fi
# Dump the version and exit if we're in testing mode. # Dump the version and exit if we're in testing mode.
if [ "$SPACK_TEST_COMMAND" = "dump-mode" ]; then if [[ $SPACK_TEST_COMMAND = dump-mode ]]; then
echo "$mode" echo "$mode"
exit exit
fi fi
@@ -170,10 +155,23 @@ if [[ -z $command ]]; then
die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs." die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs."
fi fi
if [ "$mode" == vcheck ] ; then if [[ $mode == vcheck ]]; then
exec ${command} "$@" exec ${command} "$@"
fi fi
# Darwin's linker has a -r argument that merges object files together.
# It doesn't work with -rpath.
# This variable controls whether they are added.
add_rpaths=true
if [[ mode = ld && $OSTYPE = darwin* ]]; then
for arg in "$@"; do
if [[ $arg = -r ]]; then
add_rpaths=false
break
fi
done
fi
# Save original command for debug logging # Save original command for debug logging
input_command="$@" input_command="$@"
args=("$@") args=("$@")
@@ -234,11 +232,14 @@ IFS=':' read -ra spack_env_dirs <<< "$SPACK_ENV_PATH"
spack_env_dirs+=("" ".") spack_env_dirs+=("" ".")
PATH="" PATH=""
for dir in "${env_path[@]}"; do for dir in "${env_path[@]}"; do
remove="" addpath=true
for rm_dir in "${spack_env_dirs[@]}"; do for env_dir in "${spack_env_dirs[@]}"; do
if [[ $dir = $rm_dir ]]; then remove=True; fi if [[ $dir = $env_dir ]]; then
addpath=false
break
fi
done done
if [[ -z $remove ]]; then if $addpath; then
PATH="${PATH:+$PATH:}$dir" PATH="${PATH:+$PATH:}$dir"
fi fi
done done