diff options
-rwxr-xr-x | lib/spack/env/cc | 119 |
1 files changed, 88 insertions, 31 deletions
diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 4a3e6eddc9..df6795c264 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -152,7 +152,77 @@ fi # Save original command for debug logging input_command="$@" +args=("$@") +<<<<<<< HEAD +# 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. + # + includes=() + libraries=() + libs=() + rpaths=() + other_args=() + + while [ -n "$1" ]; do + case "$1" in + -I*) + arg="${1#-I}" + if [ -z "$arg" ]; then shift; arg="$1"; fi + includes+=("$arg") + ;; + -L*) + arg="${1#-L}" + if [ -z "$arg" ]; then shift; arg="$1"; fi + libraries+=("$arg") + ;; + -l*) + arg="${1#-l}" + if [ -z "$arg" ]; then shift; arg="$1"; fi + libs+=("$arg") + ;; + -Wl,*) + arg="${1#-Wl,}" + if [ -z "$arg" ]; then shift; arg="$1"; fi + if [[ "$arg" = -rpath=* ]]; then + rpaths+=("${arg#-rpath=}") + elif [[ "$arg" = -rpath ]]; then + shift; arg="$1" + if [[ "$arg" != -Wl,* ]]; then + die "-Wl,-rpath was not followed by -Wl,*" + fi + rpaths+=("${arg#-Wl,}") + else + other_args+=("-Wl,$arg") + fi + ;; + -Xlinker,*) + arg="${1#-Xlinker,}" + if [ -z "$arg" ]; then shift; arg="$1"; fi + if [[ "$arg" = -rpath=* ]]; then + rpaths+=("${arg#-rpath=}") + elif [[ "$arg" = -rpath ]]; then + shift; arg="$1" + if [[ "$arg" != -Xlinker,* ]]; then + die "-Xlinker,-rpath was not followed by -Xlinker,*" + fi + rpaths+=("${arg#-Xlinker,}") + else + other_args+=("-Xlinker,$arg") + fi + ;; + *) + other_args+=("$1") + ;; + esac + shift + done +======= if [ "$mode" == vcheck ] ; then exec ${command} "$@" fi @@ -233,9 +303,8 @@ while [ -n "$1" ]; do esac shift done +>>>>>>> develop -# 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[*]}";; @@ -270,44 +339,32 @@ fi IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES" for dep in "${deps[@]}"; do if [ -d "$dep/include" ]; then - includes+=("$dep/include") + args=("-I$dep/include" "${args[@]}") fi if [ -d "$dep/lib" ]; then - libraries+=("$dep/lib") - rpaths+=("$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") + # 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 + args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}") +elif [[ $mode = ld ]]; then + args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}") fi # @@ -323,7 +380,7 @@ 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="" |