98 lines
3.3 KiB
Bash
Executable File
98 lines
3.3 KiB
Bash
Executable File
#!/bin/sh
|
|
# Build the TMS34010 LLVM compiler.
|
|
#
|
|
# Two modes:
|
|
#
|
|
# upstream + patches (M0, default)
|
|
# ./scripts/build-llvm.sh
|
|
# Clones llvmorg-23.1.5 into build/llvm-clean, applies patches/llvm and
|
|
# builds it. This mode owns its clone and resets it, but refuses to touch
|
|
# a checkout whose origin is not llvm-project.
|
|
#
|
|
# compiler fork (M1 and later)
|
|
# LLVM_SRC=$PWD/build/llvm-clean LLVM_BRANCH=tms34010 \
|
|
# ./scripts/build-llvm.sh
|
|
# LLVM_REPO=gitea@git.wut.ee:opencode.siil.arti.ee/llvm-tms34010.git \
|
|
# LLVM_BRANCH=tms34010 ./scripts/build-llvm.sh
|
|
# Build the fork branch in place. Fork mode never checks out, resets,
|
|
# cleans or patches the source tree; it only configures and builds it.
|
|
#
|
|
# Environment:
|
|
# LLVM_SRC source tree (default build/llvm-clean)
|
|
# LLVM_BUILD build tree (default build/llvm-clean-build)
|
|
# LLVM_REPO git URL to clone when LLVM_SRC does not exist
|
|
# LLVM_BRANCH branch to clone/build; setting this (or LLVM_REPO) selects
|
|
# fork mode
|
|
set -eu
|
|
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
|
cd "$ROOT"
|
|
mkdir -p build
|
|
SRC=${LLVM_SRC:-build/llvm-clean}
|
|
BUILD=${LLVM_BUILD:-build/llvm-clean-build}
|
|
REPO=${LLVM_REPO:-}
|
|
BRANCH=${LLVM_BRANCH:-}
|
|
TAG=llvmorg-23.1.5
|
|
|
|
origin_url() {
|
|
git -C "$1" config --get remote.origin.url 2>/dev/null || true
|
|
}
|
|
|
|
if [ -n "$REPO" ] || [ -n "$BRANCH" ]; then
|
|
echo "== compiler fork mode: $SRC${BRANCH:+ (branch $BRANCH)}"
|
|
if [ ! -e "$SRC/.git" ]; then
|
|
[ -n "$REPO" ] || {
|
|
echo "build-llvm: $SRC is not a git checkout; set LLVM_REPO to clone it" >&2
|
|
exit 1
|
|
}
|
|
if [ -n "$BRANCH" ]; then
|
|
git clone --branch "$BRANCH" "$REPO" "$SRC"
|
|
else
|
|
git clone "$REPO" "$SRC"
|
|
fi
|
|
fi
|
|
if [ -n "$BRANCH" ]; then
|
|
CURRENT=$(git -C "$SRC" rev-parse --abbrev-ref HEAD)
|
|
if [ "$CURRENT" != "$BRANCH" ]; then
|
|
echo "build-llvm: $SRC is on '$CURRENT', not '$BRANCH'" >&2
|
|
echo "build-llvm: check the branch out first; fork mode never" >&2
|
|
echo "build-llvm: modifies the source tree" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
else
|
|
echo "== upstream + patches mode: $SRC (tag $TAG)"
|
|
if [ -e "$SRC/.git" ]; then
|
|
URL=$(origin_url "$SRC")
|
|
case "$URL" in
|
|
*llvm-project*) ;;
|
|
*)
|
|
echo "build-llvm: refusing to reset $SRC: origin is" >&2
|
|
echo "build-llvm: '${URL:-<none>}', not llvm-project." >&2
|
|
echo "build-llvm: use LLVM_REPO/LLVM_BRANCH for a compiler fork" >&2
|
|
echo "build-llvm: checkout (default mode must not reset it)" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
else
|
|
git clone --depth 1 --branch "$TAG" \
|
|
https://github.com/llvm/llvm-project.git "$SRC"
|
|
fi
|
|
git -C "$SRC" checkout --detach "$TAG"
|
|
git -C "$SRC" reset --hard
|
|
git -C "$SRC" clean -fdx
|
|
|
|
PATCHROOT=$(pwd)/patches/llvm
|
|
for p in "$PATCHROOT"/*.patch; do
|
|
[ -e "$p" ] || continue
|
|
git -C "$SRC" apply "$p"
|
|
done
|
|
fi
|
|
|
|
cmake -S "$SRC/llvm" -B "$BUILD" -G Ninja \
|
|
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON \
|
|
-DLLVM_ENABLE_PROJECTS=clang \
|
|
-DLLVM_TARGETS_TO_BUILD="X86;TMS34010" \
|
|
-DLLVM_INCLUDE_TESTS=ON -DLLVM_INCLUDE_EXAMPLES=OFF \
|
|
-DLLVM_INCLUDE_BENCHMARKS=OFF
|
|
ninja -C "$BUILD" clang opt llc llvm-config FileCheck count not
|