forked from WebAssembly/wasi-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
142 lines (127 loc) · 4.96 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
ROOT_DIR=${CURDIR}
LLVM_PROJ_DIR?=$(ROOT_DIR)/src/llvm-project
PREFIX?=/opt/wasi-sdk
CLANG_VERSION=$(shell ./llvm_version.sh $(LLVM_PROJ_DIR))
VERSION:=$(shell ./version.sh)
DEBUG_PREFIX_MAP=-fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION)
default: build
@echo "Use -fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION)"
clean:
rm -rf build $(PREFIX)
build/llvm.BUILT:
mkdir -p build/llvm
cd build/llvm; cmake -G Ninja \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
-DLLVM_TARGETS_TO_BUILD=WebAssembly \
-DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-wasi \
-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=$(LLVM_PROJ_DIR)/clang \
-DLLVM_EXTERNAL_LLD_SOURCE_DIR=$(LLVM_PROJ_DIR)/lld \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
-DDEFAULT_SYSROOT=$(PREFIX)/share/wasi-sysroot \
$(LLVM_PROJ_DIR)/llvm
ninja -v -C build/llvm \
install-clang \
install-lld \
install-llc \
install-llvm-ar \
install-llvm-ranlib \
install-llvm-dwarfdump \
$(if $(patsubst 8.%,,$(CLANG_VERSION)),install-clang-resource-headers,install-clang-headers) \
install-llvm-nm \
install-llvm-size \
llvm-config
touch build/llvm.BUILT
build/wasi-libc.BUILT: build/llvm.BUILT
$(MAKE) -C $(ROOT_DIR)/src/wasi-libc \
WASM_CC=$(PREFIX)/bin/clang \
SYSROOT=$(PREFIX)/share/wasi-sysroot
touch build/wasi-libc.BUILT
build/compiler-rt.BUILT: build/llvm.BUILT
mkdir -p build/compiler-rt
cd build/compiler-rt; cmake -G Ninja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DCOMPILER_RT_BAREMETAL_BUILD=On \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DCOMPILER_RT_HAS_FPIC_FLAG=OFF \
-DCOMPILER_RT_ENABLE_IOS=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \
-DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF \
-DWASI_SDK_PREFIX=$(PREFIX) \
-DCMAKE_C_FLAGS="-O1 $(DEBUG_PREFIX_MAP)" \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCOMPILER_RT_OS_DIR=wasi \
-DCMAKE_INSTALL_PREFIX=$(PREFIX)/lib/clang/$(CLANG_VERSION)/ \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
$(LLVM_PROJ_DIR)/compiler-rt/lib/builtins
ninja -v -C build/compiler-rt install
cp -R $(ROOT_DIR)/build/llvm/lib/clang $(PREFIX)/lib/
touch build/compiler-rt.BUILT
build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUILT
mkdir -p build/libcxx
cd build/libcxx; cmake -G Ninja \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DLIBCXX_HAS_PTHREAD_API:BOOL=ON \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXX_ENABLE_SHARED:BOOL=OFF \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \
-DLIBCXX_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=OFF \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$(LLVM_PROJ_DIR)/libcxxabi/include \
-DLIBCXX_HAS_MUSL_LIBC:BOOL=ON \
-DLIBCXX_ABI_VERSION=2 \
-DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi \
-DWASI_SDK_PREFIX=$(PREFIX) \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \
--debug-trycompile \
$(LLVM_PROJ_DIR)/libcxx
ninja -v -C build/libcxx install
touch build/libcxx.BUILT
build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT
mkdir -p build/libcxxabi
cd build/libcxxabi; cmake -G Ninja \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_C_COMPILER_WORKS=ON \
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXXABI_ENABLE_SHARED:BOOL=OFF \
-DLIBCXXABI_SILENT_TERMINATE:BOOL=ON \
-DLIBCXXABI_HAS_PTHREAD_API:BOOL=ON \
$(if $(patsubst 8.%,,$(CLANG_VERSION)),-DLIBCXXABI_ENABLE_PIC:BOOL=OFF,) \
-DCXX_SUPPORTS_CXX11=ON \
-DLLVM_COMPILER_CHECKED=ON \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXXABI_LIBCXX_PATH=$(LLVM_PROJ_DIR)/libcxx \
-DLIBCXXABI_LIBCXX_INCLUDES=$(PREFIX)/share/wasi-sysroot/include/c++/v1 \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasi-sdk.cmake \
-DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi \
-DWASI_SDK_PREFIX=$(PREFIX) \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) -I$(PREFIX)/share/wasi-sysroot/include" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) -I$(PREFIX)/share/wasi-sysroot/include/c++/v1" \
-DUNIX:BOOL=ON \
--debug-trycompile \
$(LLVM_PROJ_DIR)/libcxxabi
ninja -v -C build/libcxxabi install
touch build/libcxxabi.BUILT
build/config.BUILT:
mkdir -p $(PREFIX)/share/misc
cp src/config/config.sub src/config/config.guess $(PREFIX)/share/misc
touch build/config.BUILT
build: build/llvm.BUILT build/wasi-libc.BUILT build/compiler-rt.BUILT build/libcxxabi.BUILT build/libcxx.BUILT build/config.BUILT
strip: build/llvm.BUILT
cd $(PREFIX)/bin; strip clang-9 llc lld llvm-ar
package: build/package.BUILT
build/package.BUILT: build strip
command -v dpkg-deb >/dev/null && ./deb_from_installation.sh || true
./tar_from_installation.sh
touch build/package.BUILT
.PHONY: default clean build strip package