forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
executable file
·78 lines (63 loc) · 2.38 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
CLANG_VERSION="8.0.0"
BUILD_DIRECTORY=build-leros-llvm
# Make sure current working directory is leros-llvm
cd "${0%/*}"
SOURCE_ROOT=$(pwd)
PARENT_DIR="$(dirname "${SOURCE_ROOT}")"
# Binary folder of the built compiler
BUILD_ROOT="$PARENT_DIR/$BUILD_DIRECTORY"
BUILD_BIN_DIR="$BUILD_ROOT/bin"
BUILD_CLANG_LIB_DIR="$BUILD_ROOT/lib/clang/$CLANG_VERSION"
# Pull all submodules (clang and lld)
git submodule update --init
git submodule update --recursive --remote
# Create build folder next to source
mkdir -p $BUILD_ROOT
cd $BUILD_ROOT
# Set CMake arguments
ARGS="-DLLVM_TOOL_LEROS_CLANG_BUILD=ON"
ARGS="${ARGS} -DLLVM_TOOL_LEROS_LLD_BUILD=ON"
ARGS="${ARGS} -DLLVM_TARGETS_TO_BUILD=''" # Disable all upstream backends (x86, ARM, ...)
ARGS="${ARGS} -DLLVM_DEFAULT_TARGET_TRIPLE='leros32-unknown-elf'" # Unless specified, clang and the other llvm tools should default to building leros 32 binaries
ARGS="${ARGS} -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='Leros'" # Leros is listed as an experimental target, given that it is not upstream
ARGS="${ARGS} -DCMAKE_BUILD_TYPE='Release'"
ARGS="${ARGS} -DCLANG_ANALYZER_ENABLE_Z3_SOLVER=0" # Disable Z3 library (Z3 development headers on some systems are deprecated)
# Run CMake configuration of leros-llvm inside build directory
cmake ${ARGS} $SOURCE_ROOT
# Use all cores when building
if [[ "$OSTYPE" == "linux-gnu" ]]; then
export MAKEFLAGS=-j$(nproc)
elif [[ "$OSTYPE" == "darwin"* ]]; then
export MAKEFLAGS=-j$(sysctl -n hw.ncpu)
fi
# Build
cmake --build .
# ============ leros-lib =================
LEROS_LIB_DIR="$PARENT_DIR/leros-lib"
LEROS_LIB_DIR="$PARENT_DIR/leros-lib"
cd "$PARENT_DIR"
# Check if the leros-lib repo is checked out next to the leros-llvm repository
if [ -d "$LEROS_LIB_DIR" ]; then
# make sure the repository is up-to-date
cd $LEROS_LIB_DIR
git pull
else
# clone the leros-lib repository
git clone https://github.com/leros-dev/leros-lib
cd $LEROS_LIB_DIR
fi
# Build crt0.leros.o
cd runtime
$BUILD_BIN_DIR/clang crt0.leros.c -c -ffreestanding -o crt0.leros.o
mv crt0.leros.o "$BUILD_CLANG_LIB_DIR/crt0.leros.o"
# Build the runtime library
RUNTIME_LIBRARY_NAME="libclang_rt.builtins-leros32.a"
cd ..
/bin/bash build_runtime.sh "$BUILD_BIN_DIR"
cd "build-leros-compiler-rt-builtins"
cd "lib"
cd "linux"
mkdir -p "${BUILD_CLANG_LIB_DIR}/lib"
mv "$RUNTIME_LIBRARY_NAME" "$BUILD_CLANG_LIB_DIR/lib/$RUNTIME_LIBRARY_NAME"