osxcross/build_clang.sh

175 lines
3.4 KiB
Bash
Raw Normal View History

2014-11-10 20:43:14 +01:00
#!/usr/bin/env bash
#
# Build and install Clang/LLVM, using `gcc`.
#
# You only need to run this if your distribution does not provide
# clang - or if you want to build your own version from a recent
# source tree.
#
2014-11-10 20:43:14 +01:00
pushd "${0%/*}" &>/dev/null
DESC=clang
USESYSTEMCOMPILER=1
source tools/tools.sh
2015-05-09 17:30:41 +02:00
mkdir -p $BUILD_DIR
2014-11-10 20:43:14 +01:00
source $BASE_DIR/tools/trap_exit.sh
if [ -z "$CLANG_VERSION" ]; then
CLANG_VERSION=10.0.1
2014-11-10 20:43:14 +01:00
fi
if [ -z "$INSTALLPREFIX" ]; then
INSTALLPREFIX="/usr/local"
fi
require cmake
2014-11-10 20:43:14 +01:00
2020-08-27 13:51:17 +02:00
LLVM_PKG=""
CLANG_PKG=""
function set_package_link()
{
pushd $BUILD_DIR &>/dev/null
DOWNLOAD_PAGE=llvmorg-$CLANG_VERSION
download https://github.com/llvm/llvm-project/releases/tag/$DOWNLOAD_PAGE &>/dev/null
if [[ $(file $DOWNLOAD_PAGE) == *gzip* ]]; then
mv $DOWNLOAD_PAGE $DOWNLOAD_PAGE.gz
2020-08-27 13:51:17 +02:00
require gzip
gzip -d $DOWNLOAD_PAGE.gz
2020-08-27 13:51:17 +02:00
fi
links=$(cat $DOWNLOAD_PAGE | grep -Po '(?<=href=")[^"]*' | grep -v "\.sig")
rm -f $DOWNLOAD_PAGE
2020-08-27 13:51:17 +02:00
LLVM_PKG=$(echo "$links" | grep "llvm-$CLANG_VERSION.src" | head -n 1 || true)
CLANG_PKG=$(echo "$links" | grep -E "(clang|cfe)-$CLANG_VERSION.src" | head -n 1 || true)
if [ -n "$LLVM_PKG" ] && [[ $LLVM_PKG != https* ]]; then
LLVM_PKG="https://github.com/$LLVM_PKG"
CLANG_PKG="https://github.com/$CLANG_PKG"
2020-08-27 13:51:17 +02:00
fi
popd &>/dev/null
}
set_package_link
if [ -z "$LLVM_PKG" ] || [ -z "$CLANG_PKG" ]; then
echo "Release $CLANG_VERSION not found!" 1>&2
exit 1
fi
2014-11-10 20:43:14 +01:00
function warn_if_installed()
{
set +e
2020-10-14 09:24:50 +02:00
command -v $1 &>/dev/null && \
2014-11-10 20:43:14 +01:00
{
echo ""
echo "It is highly recommended to uninstall previous $2 versions first:"
2020-10-14 09:24:50 +02:00
echo "-> $(command -v $1 2>/dev/null)"
2014-11-10 20:43:14 +01:00
echo ""
}
set -e
2014-11-10 20:43:14 +01:00
}
if [ $PLATFORM != "Darwin" -a $PLATFORM != "FreeBSD" ]; then
2014-11-10 20:43:14 +01:00
warn_if_installed clang clang
warn_if_installed llvm-config llvm
fi
2020-08-27 13:51:17 +02:00
2014-11-10 20:43:14 +01:00
echo "Building Clang/LLVM $CLANG_VERSION may take a long time."
echo "Installation Prefix: $INSTALLPREFIX"
if [ -z "$UNATTENDED" ]; then
echo ""
read -p "Press enter to start building."
echo ""
fi
2014-11-10 20:43:14 +01:00
pushd $TARBALL_DIR &>/dev/null
2014-11-10 20:43:14 +01:00
download $LLVM_PKG
download $CLANG_PKG
2014-11-10 20:43:14 +01:00
popd &>/dev/null
2020-08-27 13:51:17 +02:00
pushd $BUILD_DIR &>/dev/null
2014-11-10 20:43:14 +01:00
echo "cleaning up ..."
rm -rf llvm* 2>/dev/null
2019-06-04 18:34:11 +02:00
extract "$TARBALL_DIR/$(basename $LLVM_PKG)"
2014-11-10 20:43:14 +01:00
pushd llvm* &>/dev/null
pushd tools &>/dev/null
2019-06-04 18:34:11 +02:00
extract "$TARBALL_DIR/$(basename $CLANG_PKG)"
echo ""
2014-11-10 20:43:14 +01:00
[ -e clang* ] && mv clang* clang
[ -e cfe* ] && mv cfe* clang
popd &>/dev/null
2020-08-27 13:51:17 +02:00
2014-11-10 20:43:14 +01:00
function build()
{
stage=$1
mkdir -p $stage
pushd $stage &>/dev/null
cmake .. \
2019-06-03 18:35:37 +02:00
-DCMAKE_INSTALL_PREFIX=$INSTALLPREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=OFF \
-DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=1
2014-11-10 20:43:14 +01:00
$MAKE $2 -j $JOBS VERBOSE=1
popd &>/dev/null
}
if [ -n "$DISABLE_BOOTSTRAP" ]; then
build build
else
build build_stage1 clang
2014-11-10 20:43:14 +01:00
export CC=$PWD/build_stage1/bin/clang
export CXX=$PWD/build_stage1/bin/clang++
2014-11-10 20:43:14 +01:00
if [ -z "$PORTABLE" ]; then
export CFLAGS="-march=native"
export CXXFLAGS="-march=native"
fi
build build_stage2
if [ -n "$ENABLE_FULL_BOOTSTRAP" ]; then
CC=$PWD/build_stage2/bin/clang \
CXX=$PWD/build_stage2/bin/clang++ \
2014-11-10 20:43:14 +01:00
build build_stage3
fi
fi
if [ -z "$ENABLE_CLANG_INSTALL" ]; then
echo ""
echo "Done!"
echo ""
echo -n "cd into '$PWD/$stage' and type 'make install' to install "
echo "clang/llvm to '$INSTALLPREFIX'"
echo ""
else
pushd $stage &>/dev/null
$MAKE install -j $JOBS VERBOSE=1
popd &>/dev/null
echo ""
echo "Done!"
echo ""
fi
2014-11-10 20:43:14 +01:00
popd &>/dev/null # llvm
popd &>/dev/null