You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.8 KiB

#!/bin/bash
# Wrapper around the opensource clang meant to work around various path or library
# issues occurring when one tries to substitute Apple's version of clang with
# a different version.
# The wrapper tries to mitigate version discrepancies in clang's fatal warnings.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CLANG_COMPILER="${SCRIPT_DIR}/../../../facebook-clang-plugins/clang/bin/clang"
if [ "${0%++}" != "$0" ]; then XX="++"; else XX=""; fi
COMMAND=("${CLANG_COMPILER}${XX}")
# Remove command line options not supported by the opensource compiler or the plugins.
PREV=""
for X in "$@"
do
if [ "$X" == "-fapplication-extension" ] \
|| [ "$X" == "-fembed-bitcode-marker" ] \
|| [[ "$X" =~ "-mwatchos-version-min" ]]; then
continue
elif [ "$X" == "-gmodules" ]; then
# gmodules is an alias for "-g -fmodule-format=obj -dwarf-ext-refs"
# but "-fmodule-format" is not available, so skip it for now.
COMMAND+=("-g" "-dwarf-ext-refs")
elif [ "$X" == "armv7k" ] && [ "$PREV" == "-arch" ]; then
# replace armv7k arch with armv7
COMMAND+=("armv7")
else
COMMAND+=("$X")
fi
PREV="$X"
done
# Never error on warnings. Clang is often more strict than Apple's version.
# These arguments are appended to override previous opposite settings.
# How it's done: surpress all the warnings, since there are no warnings,
# compiler can't elevate them to error level.
COMMAND+=("-Wno-everything")
# set _FORTIFY_SOURCE to 0 to prevent it from changing some function prototypes
# https://securityblog.redhat.com/2014/03/26/fortify-and-you/
# We always do it when building models so we should do same thing
# when building any source code
COMMAND+=("-D_FORTIFY_SOURCE=0")
"${COMMAND[@]}"