76 строки
2.7 KiB
Bash
76 строки
2.7 KiB
Bash
|
|
#!/bin/bash -e
|
||
|
|
#
|
||
|
|
# This script allows CMAKE_CXX_COMPILER to be a standard
|
||
|
|
# C++ compiler and hosttrace sets RULE_LAUNCH_COMPILE and
|
||
|
|
# RULE_LAUNCH_LINK in CMake so that all compiler and link
|
||
|
|
# commands are prefixed with this script followed by the
|
||
|
|
# C++ compiler. Thus if $1 == $2 then we know the command
|
||
|
|
# was intended for the C++ compiler and we discard both
|
||
|
|
# $1 and $2 and redirect the command to linker.
|
||
|
|
# If $1 != $2 then we know that the command was not intended
|
||
|
|
# for the C++ compiler and we just discard $1 and launch
|
||
|
|
# the original command. Examples of when $2 will not equal
|
||
|
|
# $1 are 'ar', 'cmake', etc. during the linking phase
|
||
|
|
#
|
||
|
|
|
||
|
|
# emit a message about the underlying command executed
|
||
|
|
: ${DEBUG:=0}
|
||
|
|
: ${HOSTTRACE_DEBUG_LAUNCH_COMPILER:=${DEBUG}}
|
||
|
|
|
||
|
|
debug-message()
|
||
|
|
{
|
||
|
|
if [ "${HOSTTRACE_DEBUG_LAUNCH_COMPILER}" -ne 0 ]; then
|
||
|
|
echo -e "##### $(basename ${BASH_SOURCE[0]}) executing: \"$@\"... #####"
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
# if hosttrace compiler is not passed, someone is probably trying to invoke it directly
|
||
|
|
if [ -z "${1}" ]; then
|
||
|
|
echo -e "\n${BASH_SOURCE[0]} was invoked without the hosttrace compiler as the first argument."
|
||
|
|
echo "This script is not indended to be directly invoked by any mechanism other"
|
||
|
|
echo -e "than through a RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK property set in CMake.\n"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# if hosttrace compiler is not passed, someone is probably trying to invoke it directly
|
||
|
|
if [ -z "${2}" ]; then
|
||
|
|
echo -e "\n${BASH_SOURCE[0]} was invoked without the C++ compiler as the second argument."
|
||
|
|
echo "This script is not indended to be directly invoked by any mechanism other"
|
||
|
|
echo -e "than through a RULE_LAUNCH_COMPILE or RULE_LAUNCH_LINK property set in CMake.\n"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# if there aren't two args, this isn't necessarily invalid, just a bit strange
|
||
|
|
if [ -z "${3}" ]; then exit 0; fi
|
||
|
|
|
||
|
|
# store the hosttrace compiler
|
||
|
|
HOSTTRACE_COMPILER=${1}
|
||
|
|
|
||
|
|
# remove the hosttrace compiler from the arguments
|
||
|
|
shift
|
||
|
|
|
||
|
|
# store the expected C++ compiler
|
||
|
|
CXX_COMPILER=${1}
|
||
|
|
|
||
|
|
# remove the expected C++ compiler from the arguments
|
||
|
|
shift
|
||
|
|
|
||
|
|
if [[ "${CXX_COMPILER}" != "${1}" ]]; then
|
||
|
|
debug-message $@
|
||
|
|
# the command does not depend on hosttrace so just execute the command w/o re-directing to ${HOSTTRACE_COMPILER}
|
||
|
|
eval $@
|
||
|
|
else
|
||
|
|
# the executable is the C++ compiler, so we need to re-direct to ${HOSTTRACE_COMPILER}
|
||
|
|
if [ ! -f "${HOSTTRACE_COMPILER}" ]; then
|
||
|
|
echo -e "\nError: the compiler redirect for hosttrace was not found at ${HOSTTRACE_COMPILER}\n"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
# discard the compiler from the command
|
||
|
|
shift
|
||
|
|
|
||
|
|
debug-message ${HOSTTRACE_COMPILER} $@
|
||
|
|
# execute ${HOSTTRACE_COMPILER} (again, usually nvcc_wrapper)
|
||
|
|
${HOSTTRACE_COMPILER} $@
|
||
|
|
fi
|