-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
80 lines (73 loc) · 3.33 KB
/
Makefile
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
79
80
LLVM_VERSION=18.1.8
LLVM_DOWNLOAD_URL?="https://github.com/llvm/llvm-project/releases/download/llvmorg-$(LLVM_VERSION)/llvm-project-$(LLVM_VERSION).src.tar.xz"
LLVM_BUILD_ARGS?=""
LLVM_SOURCE_ARCHIVE=lib/llvm-$(LLVM_VERSION).src.tar.xz
LLVM_RELEASE_DIR=lib/llvm-$(LLVM_VERSION)
LLVM_INSTALL_DIR=lib/llvm
LLVM_CACHE_BUSTER_DATE=20240803
ZLIB_LIBRARY?=$(shell find /lib /opt /usr/lib /usr -name libz.a | head -n 1)
ZLIB_INCLUDE_DIR?=$(shell find /usr /opt -name zlib.h | head -n 1 | xargs dirname)
PWD?=$(shell pwd)
# By default, use all cores available except one, so things stay responsive.
NUM_THREADS?=$(shell expr `getconf _NPROCESSORS_ONLN 2>/dev/null` - 1)
PHONY:
# Download the LLVM project source code.
#
# This is a prerequisite for all of the targets that build LLVM.
# We keep the version as part of the name so that we can download a different
# version without clobbering the old version we previously downloaded.
$(LLVM_SOURCE_ARCHIVE):
mkdir -p `dirname $@`
curl -L --fail ${LLVM_DOWNLOAD_URL} --output $@
# Extract the LLVM project source code to a folder for a release build.
$(LLVM_RELEASE_DIR): $(LLVM_SOURCE_ARCHIVE)
mkdir -p $@
tar -xvf $(LLVM_SOURCE_ARCHIVE) --strip-components=1 -C $@
touch $@
# Configure CMake for the LLVM release build.
$(LLVM_RELEASE_DIR)/build/CMakeCache.txt: $(LLVM_RELEASE_DIR)
mkdir -p $(LLVM_RELEASE_DIR)/build
cd $(LLVM_RELEASE_DIR)/build && env CC=clang CXX=clang++ cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$(PWD)/$(LLVM_INSTALL_DIR) \
-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \
-DLIBCLANG_BUILD_STATIC=ON \
-DLLVM_ENABLE_BINDINGS=OFF \
-DLLVM_ENABLE_LIBXML2=OFF \
-DLLVM_ENABLE_LTO=OFF \
-DLLVM_ENABLE_OCAMLDOC=OFF \
-DLLVM_ENABLE_PIC=OFF \
-DLLVM_ENABLE_PROJECTS='clang;lld' \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_ENABLE_WARNINGS=OFF \
-DLLVM_ENABLE_Z3_SOLVER=OFF \
-DLLVM_ENABLE_ZLIB=FORCE_ON \
-DLLVM_ENABLE_ZSTD=OFF \
-DZLIB_LIBRARY="$(ZLIB_LIBRARY)" \
-DZLIB_INCLUDE_DIR=$(ZLIB_INCLUDE_DIR) \
-DLLVM_HAVE_LIBXAR=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_TOOL_REMARKS_SHLIB_BUILD=OFF \
$(LLVM_BUILD_ARGS) \
../llvm
# Build an install LLVM to the relative install path, so it's ready to use.
# Then remove all the unnecessary parts we don't need to put in our bundle.
# We remove everything except includes, static libs and the llvm-config binary.
# For convenience of troubleshooting, for now we also include llc and clang.
llvm: $(LLVM_RELEASE_DIR)/build/CMakeCache.txt
mkdir -p $(LLVM_INSTALL_DIR)
make -C $(LLVM_RELEASE_DIR)/build -j$(NUM_THREADS) install
rm -r $(LLVM_INSTALL_DIR)/share/
rm -r $(LLVM_INSTALL_DIR)/lib/clang/
rm -r $(LLVM_INSTALL_DIR)/lib/cmake/
rm -r $(LLVM_INSTALL_DIR)/libexec/
rm `ls -rtd $(LLVM_INSTALL_DIR)/bin/* | grep -v llvm-config | grep -v llc | grep -v clang | grep -v lld`
rm `ls -rtd $(LLVM_INSTALL_DIR)/bin/* | grep clang- | grep -v -E 'clang-[0-9]+'`
# The output of this command is used by Cirrus CI as a cache key,
# so that it can know when to invalidate the cache.
# Currently, we use both the target triple and LLVM version, as well as
# a date number tacked onto the end as an arbitrary cache buster, which we
# can update whenever we change something else about the way we build.
llvm-ci-cache-key: PHONY
@echo "`clang -v 2>&1 | grep Target`, LLVM: $(LLVM_VERSION), Date: $(LLVM_CACHE_BUSTER_DATE)"