summaryrefslogtreecommitdiff
path: root/lib/spack/env/cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/spack/env/cc')
-rwxr-xr-xlib/spack/env/cc105
1 files changed, 80 insertions, 25 deletions
diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 44f8b9316a..45e5e26269 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -101,10 +101,9 @@ setsep() {
esac
}
-# prepend LISTNAME ELEMENT [SEP]
+# prepend LISTNAME ELEMENT
#
-# Prepend ELEMENT to the list stored in the variable LISTNAME,
-# assuming the list is separated by SEP.
+# Prepend ELEMENT to the list stored in the variable LISTNAME.
# Handles empty lists and single-element lists.
prepend() {
varname="$1"
@@ -119,18 +118,39 @@ prepend() {
fi
}
-# append LISTNAME ELEMENT [SEP]
+# contains LISTNAME ELEMENT
#
-# Append ELEMENT to the list stored in the variable LISTNAME,
-# assuming the list is separated by SEP.
+# Test whether LISTNAME contains ELEMENT.
+# Set $? to 1 if LISTNAME does not contain ELEMENT.
+# Set $? to 0 if LISTNAME does not contain ELEMENT.
+contains() {
+ varname="$1"
+ elt="$2"
+
+ setsep "$varname"
+
+ # the list may: 1) only contain the element, 2) start with the element,
+ # 3) contain the element in the middle, or 4) end wtih the element.
+ eval "[ \"\${$varname}\" = \"$elt\" ]" \
+ || eval "[ \"\${$varname#${elt}${sep}}\" != \"\${$varname}\" ]" \
+ || eval "[ \"\${$varname#*${sep}${elt}${sep}}\" != \"\${$varname}\" ]" \
+ || eval "[ \"\${$varname%${sep}${elt}}\" != \"\${$varname}\" ]"
+}
+
+# append LISTNAME ELEMENT [unique]
+#
+# Append ELEMENT to the list stored in the variable LISTNAME.
# Handles empty lists and single-element lists.
+#
+# If the third argument is provided and if it is the string 'unique',
+# this will not append if ELEMENT is already in the list LISTNAME.
append() {
varname="$1"
elt="$2"
if empty "$varname"; then
eval "$varname=\"\${elt}\""
- else
+ elif [ "$3" != "unique" ] || ! contains "$varname" "$elt" ; then
# Get the appropriate separator for the list we're appending to.
setsep "$varname"
eval "$varname=\"\${$varname}${sep}\${elt}\""
@@ -148,10 +168,21 @@ extend() {
if [ "$sep" != " " ]; then
IFS="$sep"
fi
- eval "for elt in \${$2}; do append $1 \"$3\${elt}\"; done"
+ eval "for elt in \${$2}; do append $1 \"$3\${elt}\" ${_append_args}; done"
unset IFS
}
+# extend_unique LISTNAME1 LISTNAME2 [PREFIX]
+#
+# Append the elements stored in the variable LISTNAME2 to the list
+# stored in LISTNAME1, if they are not already present.
+# If PREFIX is provided, prepend it to each element.
+extend_unique() {
+ _append_args="unique"
+ extend "$@"
+ unset _append_args
+}
+
# preextend LISTNAME1 LISTNAME2 [PREFIX]
#
# Prepend the elements stored in the list at LISTNAME2
@@ -682,7 +713,32 @@ categorize_arguments() {
"$dtags_to_strip")
;;
*)
- append return_other_args_list "$1"
+ # if mode is not ld, we can just add to other args
+ if [ "$mode" != "ld" ]; then
+ append return_other_args_list "$1"
+ shift
+ continue
+ fi
+
+ # if we're in linker mode, we need to parse raw RPATH args
+ case "$1" in
+ -rpath=*)
+ arg="${1#-rpath=}"
+ append_path_lists return_rpath_dirs_list "$arg"
+ ;;
+ --rpath=*)
+ arg="${1#--rpath=}"
+ append_path_lists return_rpath_dirs_list "$arg"
+ ;;
+ -rpath|--rpath)
+ shift
+ [ $# -eq 0 ] && break # ignore -rpath without value
+ append_path_lists return_rpath_dirs_list "$1"
+ ;;
+ *)
+ append return_other_args_list "$1"
+ ;;
+ esac
;;
esac
shift
@@ -890,35 +946,34 @@ extend args_list system_spack_flags_lib_dirs_list "-L"
extend args_list system_lib_dirs_list "-L"
# RPATHs arguments
+rpath_prefix=""
case "$mode" in
ccld)
if [ -n "$dtags_to_add" ] ; then
append args_list "$linker_arg$dtags_to_add"
fi
- extend args_list spack_store_spack_flags_rpath_dirs_list "$rpath"
- extend args_list spack_store_rpath_dirs_list "$rpath"
-
- extend args_list spack_flags_rpath_dirs_list "$rpath"
- extend args_list rpath_dirs_list "$rpath"
-
- extend args_list system_spack_flags_rpath_dirs_list "$rpath"
- extend args_list system_rpath_dirs_list "$rpath"
+ rpath_prefix="$rpath"
;;
ld)
if [ -n "$dtags_to_add" ] ; then
append args_list "$dtags_to_add"
fi
- extend args_list spack_store_spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list spack_store_rpath_dirs_list "-rpath${lsep}"
-
- extend args_list spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list rpath_dirs_list "-rpath${lsep}"
-
- extend args_list system_spack_flags_rpath_dirs_list "-rpath${lsep}"
- extend args_list system_rpath_dirs_list "-rpath${lsep}"
+ rpath_prefix="-rpath${lsep}"
;;
esac
+# if mode is ccld or ld, extend RPATH lists with the prefix determined above
+if [ -n "$rpath_prefix" ]; then
+ extend_unique args_list spack_store_spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend_unique args_list spack_store_rpath_dirs_list "$rpath_prefix"
+
+ extend_unique args_list spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend_unique args_list rpath_dirs_list "$rpath_prefix"
+
+ extend_unique args_list system_spack_flags_rpath_dirs_list "$rpath_prefix"
+ extend_unique args_list system_rpath_dirs_list "$rpath_prefix"
+fi
+
# Other arguments from the input command
extend args_list other_args_list
extend args_list spack_flags_other_args_list