cc-wrapper: add C++-specific paths if -x c++
is passed
This commit is contained in:
parent
d05a3cd763
commit
87607af7a1
@ -15,29 +15,37 @@ fi
|
|||||||
source @out@/nix-support/utils.sh
|
source @out@/nix-support/utils.sh
|
||||||
|
|
||||||
|
|
||||||
# Figure out if linker flags should be passed. GCC prints annoying
|
# Parse command line options and set several variables.
|
||||||
# warnings when they are not needed.
|
# For instance, figure out if linker flags should be passed.
|
||||||
|
# GCC prints annoying warnings when they are not needed.
|
||||||
dontLink=0
|
dontLink=0
|
||||||
getVersion=0
|
getVersion=0
|
||||||
nonFlagArgs=0
|
nonFlagArgs=0
|
||||||
|
[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0
|
||||||
|
|
||||||
for i in "$@"; do
|
params=("$@")
|
||||||
if [ "$i" = -c ]; then
|
n=0
|
||||||
|
while [ $n -lt ${#params[*]} ]; do
|
||||||
|
p=${params[n]}
|
||||||
|
p2=${params[$((n+1))]}
|
||||||
|
if [ "$p" = -c ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -S ]; then
|
elif [ "$p" = -S ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -E ]; then
|
elif [ "$p" = -E ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -E ]; then
|
elif [ "$p" = -E ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -M ]; then
|
elif [ "$p" = -M ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -MM ]; then
|
elif [ "$p" = -MM ]; then
|
||||||
dontLink=1
|
dontLink=1
|
||||||
elif [ "$i" = -x ]; then
|
elif [[ "$p" = -x && "$p2" = *-header ]]; then
|
||||||
# At least for the cases c-header or c++-header we should set dontLink.
|
|
||||||
# I expect no one use -x other than making precompiled headers.
|
|
||||||
dontLink=1
|
dontLink=1
|
||||||
|
elif [[ "$p" = -x && "$p2" = c++* && "$isCpp" = 0 ]]; then
|
||||||
|
isCpp=1
|
||||||
|
elif [ "$p" = -nostdlib ]; then
|
||||||
|
isCpp=-1
|
||||||
elif [ "${i:0:1}" != - ]; then
|
elif [ "${i:0:1}" != - ]; then
|
||||||
nonFlagArgs=1
|
nonFlagArgs=1
|
||||||
elif [ "$i" = -m32 ]; then
|
elif [ "$i" = -m32 ]; then
|
||||||
@ -45,6 +53,7 @@ for i in "$@"; do
|
|||||||
NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
|
NIX_LDFLAGS="$NIX_LDFLAGS -dynamic-linker $(cat @out@/nix-support/dynamic-linker-m32)"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
n=$((n + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
# If we pass a flag like -Wl, then gcc will call the linker unless it
|
# If we pass a flag like -Wl, then gcc will call the linker unless it
|
||||||
@ -58,7 +67,6 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# Optionally filter out paths not refering to the store.
|
# Optionally filter out paths not refering to the store.
|
||||||
params=("$@")
|
|
||||||
if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
|
if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
|
||||||
rest=()
|
rest=()
|
||||||
n=0
|
n=0
|
||||||
@ -83,11 +91,9 @@ if [ "$NIX_ENFORCE_PURITY" = 1 -a -n "$NIX_STORE" ]; then
|
|||||||
params=("${rest[@]}")
|
params=("${rest[@]}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "@prog@" = *++ ]]; then
|
if [[ "$isCpp" = 1 ]]; then
|
||||||
if echo "$@" | grep -qv -- -nostdlib; then
|
NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}"
|
||||||
NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE ${NIX_CXXSTDLIB_COMPILE-@default_cxx_stdlib_compile@}"
|
NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK"
|
||||||
NIX_CFLAGS_LINK="$NIX_CFLAGS_LINK $NIX_CXXSTDLIB_LINK"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Add the flags for the C compiler proper.
|
# Add the flags for the C compiler proper.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user