2014-11-03 15:53:45 +08:00
|
|
|
#!/bin/bash
|
|
|
|
##############################################################################
|
2018-03-25 03:13:52 +08:00
|
|
|
# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
|
2014-11-03 15:53:45 +08:00
|
|
|
# Produced at the Lawrence Livermore National Laboratory.
|
|
|
|
#
|
|
|
|
# This file is part of Spack.
|
2016-05-12 12:22:25 +08:00
|
|
|
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
2014-11-03 15:53:45 +08:00
|
|
|
# LLNL-CODE-647188
|
|
|
|
#
|
2017-11-05 08:08:04 +08:00
|
|
|
# For details, see https://github.com/spack/spack
|
2017-06-25 13:22:55 +08:00
|
|
|
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
|
2014-11-03 15:53:45 +08:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2016-05-12 12:22:25 +08:00
|
|
|
# it under the terms of the GNU Lesser General Public License (as
|
|
|
|
# published by the Free Software Foundation) version 2.1, February 1999.
|
2014-11-03 15:53:45 +08:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
2016-05-12 12:22:25 +08:00
|
|
|
# conditions of the GNU Lesser General Public License for more details.
|
2014-11-03 15:53:45 +08:00
|
|
|
#
|
2016-05-12 12:22:25 +08:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2014-11-03 15:53:45 +08:00
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Spack compiler wrapper script.
|
|
|
|
#
|
|
|
|
# Compiler commands go through this compiler wrapper in Spack builds.
|
|
|
|
# The compiler wrapper is a thin layer around the standard compilers.
|
|
|
|
# It enables several key pieces of functionality:
|
|
|
|
#
|
|
|
|
# 1. It allows Spack to swap compilers into and out of builds easily.
|
|
|
|
# 2. It adds several options to the compile line so that spack
|
|
|
|
# packages can find their dependencies at build time and run time:
|
|
|
|
# -I arguments for dependency /include directories.
|
|
|
|
# -L arguments for dependency /lib directories.
|
|
|
|
# -Wl,-rpath arguments for dependency /lib directories.
|
|
|
|
#
|
|
|
|
|
2016-05-05 23:50:07 +08:00
|
|
|
# This is an array of environment variables that need to be set before
|
2016-04-05 04:00:09 +08:00
|
|
|
# the script runs. They are set by routines in spack.build_environment
|
2014-11-03 15:53:45 +08:00
|
|
|
# as part of spack.package.Package.do_install().
|
2016-05-05 23:50:07 +08:00
|
|
|
parameters=(
|
|
|
|
SPACK_PREFIX
|
|
|
|
SPACK_ENV_PATH
|
|
|
|
SPACK_DEBUG_LOG_DIR
|
2017-11-02 11:11:00 +08:00
|
|
|
SPACK_DEBUG_LOG_ID
|
2016-05-05 23:50:07 +08:00
|
|
|
SPACK_COMPILER_SPEC
|
|
|
|
SPACK_CC_RPATH_ARG
|
|
|
|
SPACK_CXX_RPATH_ARG
|
|
|
|
SPACK_F77_RPATH_ARG
|
|
|
|
SPACK_FC_RPATH_ARG
|
|
|
|
SPACK_SHORT_SPEC
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
SPACK_SYSTEM_DIRS
|
2016-05-05 23:50:07 +08:00
|
|
|
)
|
2014-11-03 15:53:45 +08:00
|
|
|
|
|
|
|
# The compiler input variables are checked for sanity later:
|
|
|
|
# SPACK_CC, SPACK_CXX, SPACK_F77, SPACK_FC
|
2016-05-09 18:37:27 +08:00
|
|
|
# The default compiler flags are passed from these variables:
|
|
|
|
# SPACK_CFLAGS, SPACK_CXXFLAGS, SPACK_FCFLAGS, SPACK_FFLAGS,
|
|
|
|
# SPACK_LDFLAGS, SPACK_LDLIBS
|
2017-03-12 02:52:08 +08:00
|
|
|
# Debug env var is optional; set to "TRUE" for debug logging:
|
2014-11-03 15:53:45 +08:00
|
|
|
# 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.
|
|
|
|
function die {
|
|
|
|
echo "$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2016-05-05 23:50:07 +08:00
|
|
|
for param in ${parameters[@]}; do
|
2016-03-18 09:53:13 +08:00
|
|
|
if [[ -z ${!param} ]]; then
|
2016-04-05 19:42:23 +08:00
|
|
|
die "Spack compiler must be run from Spack! Input '$param' is missing."
|
2014-11-03 15:53:45 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Figure out the type of compiler, the language, and the mode so that
|
|
|
|
# the compiler script knows what to do.
|
|
|
|
#
|
|
|
|
# Possible languages are C, C++, Fortran 77, and Fortran 90.
|
|
|
|
# 'command' is set based on the input command to $SPACK_[CC|CXX|F77|F90]
|
|
|
|
#
|
|
|
|
# 'mode' is set to one of:
|
2016-04-05 04:00:09 +08:00
|
|
|
# vcheck version check
|
2016-03-18 09:53:13 +08:00
|
|
|
# cpp preprocess
|
2014-11-03 15:53:45 +08:00
|
|
|
# cc compile
|
2016-03-18 09:53:13 +08:00
|
|
|
# as assemble
|
2014-11-03 15:53:45 +08:00
|
|
|
# ld link
|
|
|
|
# ccld compile & link
|
2016-03-29 17:58:05 +08:00
|
|
|
|
2014-11-03 15:53:45 +08:00
|
|
|
command=$(basename "$0")
|
2016-05-05 23:50:07 +08:00
|
|
|
comp="CC"
|
2014-11-03 15:53:45 +08:00
|
|
|
case "$command" in
|
2016-04-05 02:33:48 +08:00
|
|
|
cpp)
|
|
|
|
mode=cpp
|
|
|
|
;;
|
2017-01-26 07:26:17 +08:00
|
|
|
cc|c89|c99|gcc|clang|icc|pgcc|xlc|xlc_r)
|
2014-11-03 15:53:45 +08:00
|
|
|
command="$SPACK_CC"
|
|
|
|
language="C"
|
2016-05-05 23:50:07 +08:00
|
|
|
comp="CC"
|
2016-04-28 10:38:51 +08:00
|
|
|
lang_flags=C
|
2014-11-03 15:53:45 +08:00
|
|
|
;;
|
2017-01-26 07:26:17 +08:00
|
|
|
c++|CC|g++|clang++|icpc|pgc++|xlc++|xlc++_r)
|
2014-11-03 15:53:45 +08:00
|
|
|
command="$SPACK_CXX"
|
|
|
|
language="C++"
|
2016-05-05 23:50:07 +08:00
|
|
|
comp="CXX"
|
2016-04-28 10:38:51 +08:00
|
|
|
lang_flags=CXX
|
2014-11-03 15:53:45 +08:00
|
|
|
;;
|
2017-10-11 04:52:10 +08:00
|
|
|
ftn|f90|fc|f95|gfortran|flang|ifort|pgfortran|xlf90|xlf90_r|nagfor)
|
2014-11-03 15:53:45 +08:00
|
|
|
command="$SPACK_FC"
|
|
|
|
language="Fortran 90"
|
2016-05-05 23:50:07 +08:00
|
|
|
comp="FC"
|
2016-05-12 05:56:41 +08:00
|
|
|
lang_flags=F
|
2014-11-03 15:53:45 +08:00
|
|
|
;;
|
2017-10-11 04:52:10 +08:00
|
|
|
f77|gfortran|flang|ifort|pgfortran|xlf|xlf_r|nagfor|ftn)
|
Fix #254: libtool & distutils want certain compiler names.
This changes the compiler wrappers so that they are called by the same
name as the wrapped compiler. Many builds make assumptions about
compiler names, and we need the spack compilers to be recognizable so
that build systems will get their flags right.
This adds per-compiler subdirectories to lib/spack/spack/env directory
that contain symlinks to cc for the C, C++, F77, and F90
compilers. The build now sets CC, CXX, F77, and F90 to point to these
links instead of to the generically named cc, c++, f77, and f90
wrappers.
2015-12-19 18:06:47 +08:00
|
|
|
command="$SPACK_F77"
|
|
|
|
language="Fortran 77"
|
2016-05-05 23:50:07 +08:00
|
|
|
comp="F77"
|
2016-04-28 10:38:51 +08:00
|
|
|
lang_flags=F
|
Fix #254: libtool & distutils want certain compiler names.
This changes the compiler wrappers so that they are called by the same
name as the wrapped compiler. Many builds make assumptions about
compiler names, and we need the spack compilers to be recognizable so
that build systems will get their flags right.
This adds per-compiler subdirectories to lib/spack/spack/env directory
that contain symlinks to cc for the C, C++, F77, and F90
compilers. The build now sets CC, CXX, F77, and F90 to point to these
links instead of to the generically named cc, c++, f77, and f90
wrappers.
2015-12-19 18:06:47 +08:00
|
|
|
;;
|
2014-11-03 15:53:45 +08:00
|
|
|
ld)
|
|
|
|
mode=ld
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
die "Unkown compiler: $command"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2016-04-05 04:00:09 +08:00
|
|
|
# If any of the arguments below are present, then the mode is vcheck.
|
|
|
|
# In vcheck mode, nothing is added in terms of extra search paths or
|
2016-04-05 02:33:48 +08:00
|
|
|
# libraries.
|
2017-05-01 10:08:49 +08:00
|
|
|
if [[ -z $mode ]] || [[ $mode == ld ]]; then
|
2014-11-03 15:53:45 +08:00
|
|
|
for arg in "$@"; do
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $arg == -v || $arg == -V || $arg == --version || $arg == -dumpversion ]]; then
|
2016-02-13 02:05:42 +08:00
|
|
|
mode=vcheck
|
|
|
|
break
|
2016-04-28 10:38:51 +08:00
|
|
|
fi
|
2016-02-23 23:57:19 +08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Finish setting up the mode.
|
2016-04-05 02:33:48 +08:00
|
|
|
if [[ -z $mode ]]; then
|
2016-02-23 23:57:19 +08:00
|
|
|
mode=ccld
|
|
|
|
for arg in "$@"; do
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $arg == -E ]]; then
|
2016-02-13 02:05:42 +08:00
|
|
|
mode=cpp
|
|
|
|
break
|
2016-04-05 03:38:21 +08:00
|
|
|
elif [[ $arg == -S ]]; then
|
2016-03-18 09:53:13 +08:00
|
|
|
mode=as
|
|
|
|
break
|
2016-04-05 03:38:21 +08:00
|
|
|
elif [[ $arg == -c ]]; then
|
2016-02-13 02:05:42 +08:00
|
|
|
mode=cc
|
|
|
|
break
|
|
|
|
fi
|
2014-11-03 15:53:45 +08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2016-05-05 23:50:07 +08:00
|
|
|
# Set up rpath variable according to language.
|
|
|
|
eval rpath=\$SPACK_${comp}_RPATH_ARG
|
|
|
|
|
2016-03-02 05:53:53 +08:00
|
|
|
# Dump the version and exit if we're in testing mode.
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $SPACK_TEST_COMMAND == dump-mode ]]; then
|
2014-11-03 15:53:45 +08:00
|
|
|
echo "$mode"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check that at least one of the real commands was actually selected,
|
|
|
|
# otherwise we don't know what to execute.
|
2016-03-18 09:53:13 +08:00
|
|
|
if [[ -z $command ]]; then
|
2014-11-03 15:53:45 +08:00
|
|
|
die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs."
|
|
|
|
fi
|
|
|
|
|
2016-11-10 00:00:34 +08:00
|
|
|
#
|
|
|
|
# Set paths as defined in the 'environment' section of the compiler config
|
|
|
|
# names are stored in SPACK_ENV_TO_SET
|
|
|
|
# values are stored in SPACK_ENV_SET_<varname>
|
|
|
|
#
|
|
|
|
IFS=':' read -ra env_set_varnames <<< "$SPACK_ENV_TO_SET"
|
|
|
|
for varname in "${env_set_varnames[@]}"; do
|
|
|
|
spack_varname="SPACK_ENV_SET_$varname"
|
|
|
|
export $varname=${!spack_varname}
|
|
|
|
unset $spack_varname
|
|
|
|
done
|
|
|
|
|
2016-05-19 07:50:50 +08:00
|
|
|
#
|
|
|
|
# Filter '.' and Spack environment directories out of PATH so that
|
|
|
|
# this script doesn't just call itself
|
|
|
|
#
|
|
|
|
IFS=':' read -ra env_path <<< "$PATH"
|
|
|
|
IFS=':' read -ra spack_env_dirs <<< "$SPACK_ENV_PATH"
|
|
|
|
spack_env_dirs+=("" ".")
|
|
|
|
PATH=""
|
|
|
|
for dir in "${env_path[@]}"; do
|
|
|
|
addpath=true
|
|
|
|
for env_dir in "${spack_env_dirs[@]}"; do
|
|
|
|
if [[ $dir == $env_dir ]]; then
|
|
|
|
addpath=false
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if $addpath; then
|
|
|
|
PATH="${PATH:+$PATH:}$dir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
export PATH
|
|
|
|
|
2016-04-05 02:33:48 +08:00
|
|
|
if [[ $mode == vcheck ]]; then
|
2016-03-18 09:53:13 +08:00
|
|
|
exec ${command} "$@"
|
|
|
|
fi
|
|
|
|
|
2016-04-05 02:33:48 +08:00
|
|
|
# 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
|
2016-10-08 13:44:37 +08:00
|
|
|
if [[ ($mode == ld || $mode == ccld) && "$SPACK_SHORT_SPEC" =~ "darwin" ]]; then
|
2016-04-05 02:33:48 +08:00
|
|
|
for arg in "$@"; do
|
2017-05-01 10:16:28 +08:00
|
|
|
if [[ ($arg == -r && $mode == ld) || ($arg == -r && $mode == ccld) || ($arg == -Wl,-r && $mode == ccld) ]]; then
|
2016-04-05 02:33:48 +08:00
|
|
|
add_rpaths=false
|
|
|
|
break
|
2016-04-05 03:38:21 +08:00
|
|
|
fi
|
2016-04-05 02:33:48 +08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2014-11-03 15:53:45 +08:00
|
|
|
# Save original command for debug logging
|
|
|
|
input_command="$@"
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
args=()
|
|
|
|
|
|
|
|
#
|
|
|
|
# Parse 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.
|
|
|
|
#
|
|
|
|
# -l arguments are treated as 'other_args' to ensure that they stay in
|
|
|
|
# any groups they are a part of. Dependency library -l statements are
|
|
|
|
# categorized as 'libs'
|
|
|
|
#
|
|
|
|
# The various categories will be recombined with compiler flags into
|
|
|
|
# args variable later.
|
|
|
|
#
|
|
|
|
includes=()
|
|
|
|
libdirs=()
|
|
|
|
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
|
|
|
|
libdirs+=("$arg")
|
|
|
|
;;
|
|
|
|
-l*)
|
|
|
|
arg="${1#-l}"
|
|
|
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
|
|
|
other_args+=("-l$arg")
|
|
|
|
;;
|
|
|
|
-Wl,*)
|
|
|
|
arg="${1#-Wl,}"
|
|
|
|
if [ -z "$arg" ]; then shift; arg="$1"; fi
|
|
|
|
if [[ "$arg" = -rpath=* ]]; then
|
|
|
|
rpaths+=("${arg#-rpath=}")
|
|
|
|
elif [[ "$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
|
|
|
|
;;
|
|
|
|
-Xlinker)
|
|
|
|
if [[ "$2" == "-rpath" ]]; then
|
|
|
|
if [[ "$3" != "-Xlinker" ]]; then
|
|
|
|
die "-Xlinker,-rpath was not followed by -Xlinker,*"
|
|
|
|
fi
|
|
|
|
shift 3;
|
|
|
|
rpaths+=("$1")
|
|
|
|
else
|
|
|
|
other_args+=("$1")
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
other_args+=("$1")
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
2014-11-03 15:53:45 +08:00
|
|
|
|
2016-05-09 18:37:27 +08:00
|
|
|
# Prepend cppflags, cflags, cxxflags, fcflags, fflags, and ldflags
|
|
|
|
|
2016-05-12 05:56:41 +08:00
|
|
|
# Add ldflags
|
2016-04-28 10:38:51 +08:00
|
|
|
case "$mode" in
|
2016-05-12 05:56:41 +08:00
|
|
|
ld|ccld)
|
|
|
|
args=(${SPACK_LDFLAGS[@]} "${args[@]}") ;;
|
2016-04-28 10:38:51 +08:00
|
|
|
esac
|
2016-05-09 18:37:27 +08:00
|
|
|
|
2016-05-12 05:56:41 +08:00
|
|
|
# Add compiler flags.
|
2016-04-28 10:38:51 +08:00
|
|
|
case "$mode" in
|
|
|
|
cc|ccld)
|
2016-05-09 18:37:27 +08:00
|
|
|
# Add c, cxx, fc, and f flags
|
2016-04-28 10:38:51 +08:00
|
|
|
case $lang_flags in
|
|
|
|
C)
|
|
|
|
args=(${SPACK_CFLAGS[@]} "${args[@]}") ;;
|
|
|
|
CXX)
|
|
|
|
args=(${SPACK_CXXFLAGS[@]} "${args[@]}") ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
2016-05-09 18:37:27 +08:00
|
|
|
|
2016-05-12 05:56:41 +08:00
|
|
|
# Add cppflags
|
2016-04-28 10:38:51 +08:00
|
|
|
case "$mode" in
|
2016-05-12 05:56:41 +08:00
|
|
|
cpp|as|cc|ccld)
|
2016-04-28 10:38:51 +08:00
|
|
|
args=(${SPACK_CPPFLAGS[@]} "${args[@]}") ;;
|
|
|
|
esac
|
2014-11-03 15:53:45 +08:00
|
|
|
|
2016-05-12 05:56:41 +08:00
|
|
|
case "$mode" in cc|ccld)
|
|
|
|
# Add fortran flags
|
|
|
|
case $lang_flags in
|
|
|
|
F)
|
|
|
|
args=(${SPACK_FFLAGS[@]} "${args[@]}") ;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
# Include all -L's and prefix/whatever dirs in rpath
|
|
|
|
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib")
|
|
|
|
$add_rpaths && rpaths+=("$SPACK_PREFIX/lib64")
|
|
|
|
|
2014-11-03 15:53:45 +08:00
|
|
|
# Read spack dependencies from the path environment variable
|
|
|
|
IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
|
|
|
|
for dep in "${deps[@]}"; do
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
# Append include directories
|
2016-03-18 09:53:13 +08:00
|
|
|
if [[ -d $dep/include ]]; then
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $mode == cpp || $mode == cc || $mode == as || $mode == ccld ]]; then
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
includes=("${includes[@]}" "$dep/include")
|
2016-03-18 09:53:13 +08:00
|
|
|
fi
|
2014-11-03 15:53:45 +08:00
|
|
|
fi
|
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
# Append lib and RPATH directories
|
2016-03-18 09:53:13 +08:00
|
|
|
if [[ -d $dep/lib ]]; then
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
|
|
|
$add_rpaths && rpaths=("${rpaths[@]}" "$dep/lib")
|
|
|
|
fi
|
|
|
|
if [[ $SPACK_LINK_DEPS == *$dep* ]]; then
|
|
|
|
libdirs=("${libdirs[@]}" "$dep/lib")
|
2015-12-21 23:21:33 +08:00
|
|
|
fi
|
2014-11-03 15:53:45 +08:00
|
|
|
fi
|
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
# Append lib64 and RPATH directories
|
2016-03-18 09:53:13 +08:00
|
|
|
if [[ -d $dep/lib64 ]]; then
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
if [[ $SPACK_RPATH_DEPS == *$dep* ]]; then
|
|
|
|
$add_rpaths && rpaths+=("$dep/lib64")
|
|
|
|
fi
|
|
|
|
if [[ $SPACK_LINK_DEPS == *$dep* ]]; then
|
|
|
|
libdirs+=("$dep/lib64")
|
2015-12-21 23:21:33 +08:00
|
|
|
fi
|
2014-11-03 15:53:45 +08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-11-10 00:00:34 +08:00
|
|
|
# Set extra RPATHs
|
|
|
|
IFS=':' read -ra extra_rpaths <<< "$SPACK_COMPILER_EXTRA_RPATHS"
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
for extra_rpath in "${extra_rpaths[@]}"; do
|
|
|
|
$add_rpaths && rpaths+=("$extra_rpath")
|
|
|
|
libdirs+=("$extra_rpath")
|
2016-11-10 00:00:34 +08:00
|
|
|
done
|
|
|
|
|
2016-04-28 10:38:51 +08:00
|
|
|
# Add SPACK_LDLIBS to args
|
|
|
|
case "$mode" in
|
|
|
|
ld|ccld)
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
for lib in ${SPACK_LDLIBS[@]}; do
|
|
|
|
libs+=("${lib#-l}")
|
|
|
|
done
|
2016-04-28 10:38:51 +08:00
|
|
|
esac
|
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
# Filter system locations to the end of each sublist of args
|
|
|
|
# (includes, library dirs, rpaths)
|
|
|
|
for sd in ${SPACK_SYSTEM_DIRS[@]}; do
|
|
|
|
stripped_includes=`echo $includes | sed "s#\b$sd/\? \b##g"`
|
|
|
|
stripped_libdirs=`echo $libdirs | sed "s#\b$sd/\? \b##g"`
|
|
|
|
stripped_rpaths=`echo $rpaths | sed "s#\b$sd/\? \b##g"`
|
|
|
|
if [[ "$includes" != "$stripped_includes" ]]; then
|
|
|
|
$includes="$stripped_includes $sd"
|
|
|
|
fi
|
|
|
|
if [[ "$libdirs" != "$stripped_libdirs" ]]; then
|
|
|
|
$libdirs="$stripped_libdirs $sd"
|
|
|
|
fi
|
|
|
|
if [[ "$rpaths" != "$stripped_rpaths" ]]; then
|
|
|
|
$rpaths="$stripped_rpaths $sd"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Put the arguments together into one list
|
|
|
|
# Includes come first, then other args, library dirs, and rpaths
|
|
|
|
# rpaths get appropriate flag for ld vs ccld mode
|
|
|
|
for dir in "${includes[@]}"; do args+=("-I$dir"); done
|
|
|
|
args+=("${other_args[@]}")
|
|
|
|
for dir in "${libdirs[@]}"; do args+=("-L$dir"); done
|
|
|
|
for lib in "${libs[@]}"; do args+=("-l$lib"); done
|
|
|
|
if [ "$mode" = ccld ]; then
|
|
|
|
for dir in "${rpaths[@]}"; do
|
|
|
|
args+=("$rpath$dir")
|
|
|
|
done
|
|
|
|
elif [ "$mode" = ld ]; then
|
|
|
|
for dir in "${rpaths[@]}"; do
|
|
|
|
args+=("-rpath" "$dir")
|
|
|
|
done
|
2018-07-10 05:06:10 +08:00
|
|
|
fi
|
2014-11-03 15:53:45 +08:00
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
full_command=("$command")
|
|
|
|
full_command+=("${args[@]}")
|
|
|
|
|
2016-03-28 18:51:41 +08:00
|
|
|
# In test command mode, write out full command for Spack tests.
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $SPACK_TEST_COMMAND == dump-args ]]; then
|
2016-03-28 18:51:41 +08:00
|
|
|
echo "${full_command[@]}"
|
|
|
|
exit
|
|
|
|
elif [[ -n $SPACK_TEST_COMMAND ]]; then
|
|
|
|
die "ERROR: Unknown test command"
|
|
|
|
fi
|
|
|
|
|
2014-11-03 15:53:45 +08:00
|
|
|
#
|
|
|
|
# Write the input and output commands to debug logs if it's asked for.
|
|
|
|
#
|
2016-04-05 03:38:21 +08:00
|
|
|
if [[ $SPACK_DEBUG == TRUE ]]; then
|
2017-11-02 11:11:00 +08:00
|
|
|
input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_DEBUG_LOG_ID.in.log"
|
|
|
|
output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_DEBUG_LOG_ID.out.log"
|
2016-06-09 07:14:01 +08:00
|
|
|
echo "[$mode] $command $input_command" >> "$input_log"
|
|
|
|
echo "[$mode] ${full_command[@]}" >> "$output_log"
|
2014-11-03 15:53:45 +08:00
|
|
|
fi
|
|
|
|
|
Restore cc: package search paths come before dependency paths (#4692)
Spack currently prepends include paths, library paths, and rpaths to the
compile line. This causes problems when a header or library in the package
has the same name as one exported by one of its dependencies. The
*dependency's* header will be preferred over the package's, which is not
what most builds expect. This also breaks some of our production codes.
This restores the original cc behavior (from *very* early Spack) of parsing
compiler arguments out by type (`-L`, `-I`, `-Wl,-rpath`) and reconstituting
the full command at the end.
`<includes> <other_args> <library dirs> <rpaths>`
This differs from the original behavior in one significant way, though: it
*appends* the library arguments so that dependency libraries do not shadow
those in the build.
This is safe because semantics aren't affected by *interleaving* `-I`, `-L`,
and `-Wl,-rpath` arguments with others, only with each other (so the order of
two `-L` args affects the search path, but we search for all libraries on the
command line using the same search path).
We preserve the following:
1. Any system directory in the paths will be listed last.
2. The root package's include/library/RPATH flags come before flags of the
same type for any dependency.
3. Order will be preserved within flags passed by the build (except system
paths, which are moved to be last)
4. Flags for dependencies will appear between the root flags and the system
flags, and the flags for any dependency will come before those for *its*
dependencies (this is for completeness -- we already guarantee this in
`build_environment.py`)
2018-08-05 12:30:17 +08:00
|
|
|
exec "${full_command[@]}"
|