set -e
REAL_COMPILER="@REAL_COMPILER@"
if [ ! -x "$REAL_COMPILER" ]; then
echo "Error: Compiler not found or not executable: $REAL_COMPILER" >&2
exit 1
fi
if [ $# -gt 0 ] && [ "$1" = "$REAL_COMPILER" ]; then
shift
fi
has_s_flag=false
has_c_flag=false
for arg in "$@"; do
case "$arg" in
-S) has_s_flag=true ;;
-c) has_c_flag=true ;;
esac
done
filtered=false
if [ "$has_s_flag" = true ] && [ "$has_c_flag" = true ]; then
new_args=""
arg_count=0
for arg in "$@"; do
case "$arg" in
-c)
filtered=true
;;
*)
arg_count=$((arg_count + 1))
eval "arg_$arg_count=\"\$arg\""
;;
esac
done
set --
i=1
while [ $i -le $arg_count ]; do
eval "set -- \"\$@\" \"\$arg_$i\""
i=$((i + 1))
done
fi
if [ -n "$COMPILER_WRAPPER_DEBUG" ]; then
echo "WRAPPER DEBUG: Real compiler: $REAL_COMPILER" >&2
if [ "$filtered" = true ]; then
echo "WRAPPER DEBUG: Filtered out conflicting -c flag (keeping -S)" >&2
fi
echo "WRAPPER DEBUG: Executing: $REAL_COMPILER $*" >&2
fi
exec "$REAL_COMPILER" "$@"