Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions scripts/build_clang.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
#!/bin/sh

BUILD_DIR=${BUILD_DIR:-build}

args() {
for flag in "$@"; do
case "$flag" in
--no-update)
NOUPDATE=1
;;
--use-libc++)
LIBCPP=1
;;
*)
echo Unknown parameter $flag
exit 1
esac
shift
done
}
args "$@"

LIBCPP_CXX_FLAGS="-std=c++11 -stdlib=libc++"
CXXFLAGS="${CXXFLAGS} ${LIBCPP:+$LIBCPP_CXX_FLAGS}"

# Default to Clang.
if [ "$CC" == "gcc" ]; then
CXX=g++
else
CC=clang
CXX=clang++
CFLAGS="${CFLAGS} -fcolor-diagnostics"
CXXFLAGS="${CXXFLAGS} -fcolor-diagnostics"
fi

# Use the 'ninja' build tool by default, but allow 'make' for the non-ninja.
if [ "$MAKE" == "make" ]; then
GENERATOR="-G 'Unix Makefiles'"
GENERATOR="Unix Makefiles"
else
MAKE="ninja"
GENERATOR="-G Ninja"
GENERATOR="Ninja"
fi

# If we don't have an LLVM directory, go get one. If we do, update it.
Expand All @@ -22,7 +47,7 @@ if [ ! -d llvm ]; then
cd llvm/tools
git clone http://github.com/CTSRD-TESLA/clang
cd ../../
elif [ "$1" != "--no-update" ]; then
elif [ -z "$NOUPDATE" ]; then
cd llvm
git pull
cd tools/clang
Expand All @@ -31,16 +56,17 @@ elif [ "$1" != "--no-update" ]; then
fi

# Build out of tree.
mkdir -p build
cd build
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"

if [ -f CMakeCache.txt ]; then
# CMake has already been run. No need to explicitly run it again: its
# previously-generated makefiles will take care of that if needed.
:
else
cmake $GENERATOR \
cmake -G "$GENERATOR" \
-D CMAKE_C_COMPILER=${CC} -D CMAKE_CXX_COMPILER=${CXX} \
-D CMAKE_C_FLAGS="${CFLAGS}" -D CMAKE_CXX_FLAGS="${CXXFLAGS}" \
../llvm
fi

Expand Down