This repository has been archived by the owner on Apr 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
184 lines (163 loc) · 6.54 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
ROOT_DIR=${CURDIR}
LLVM_PROJECT_URL=https://github.com/llvm/llvm-project.git
MUSL_PROJECT_URL=https://github.com/jfbastien/musl.git
#LLVM_PROJECT_BRANCH=release/8.x
LLVM_PROJECT_SHA=2ed0e79bb8efc3d642e3d8212e17a160f5ebb499
MUSL_SHA=16d3d3825b4bd125244e43826fb0f0da79a1a4ad
VERSION=0.2
DEBUG_PREFIX_MAP=-fdebug-prefix-map=$(ROOT_DIR)=wasmception://v$(VERSION)
WASM_TRIPLE=wasm32-unknown-unknown-wasm
LLVM_VERSION=9
#DEFAULT_SYSROOT_CFG=-DDEFAULT_SYSROOT=$(ROOT_DIR)/sysroot
default: build
ifdef DEFAULT_SYSROOT_CFG
echo "Use $(DEBUG_PREFIX_MAP)"
else
echo "Use --sysroot=$(ROOT_DIR)/sysroot $(DEBUG_PREFIX_MAP)"
endif
clean:
rm -rf build src dist sysroot wasmception-*-bin.tar.gz
src/llvm-project.CLONED:
mkdir -p src/
cd src/; git clone $(LLVM_PROJECT_URL)
ifdef LLVM_PROJECT_BRANCH
cd src/llvm-project; git checkout $(LLVM_PROJECT_BRANCH)
else
ifdef LLVM_PROJECT_SHA
cd src/llvm-project; git checkout $(LLVM_PROJECT_SHA)
endif
endif
touch src/llvm-project.CLONED
src/musl.CLONED:
mkdir -p src/
cd src/; git clone $(MUSL_PROJECT_URL)
ifdef MUSL_SHA
cd src/musl; git checkout $(MUSL_SHA)
endif
cd src/musl; patch -p 1 < $(ROOT_DIR)/patches/musl.1.patch
touch src/musl.CLONED
build/llvm.BUILT: src/llvm-project.CLONED
mkdir -p build/llvm
cd build/llvm; cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=MinSizeRel \
-DCMAKE_INSTALL_PREFIX=$(ROOT_DIR)/dist \
-DLLVM_TARGETS_TO_BUILD=WebAssembly \
-DLLVM_DEFAULT_TARGET_TRIPLE=$(WASM_TRIPLE) \
$(DEFAULT_SYSROOT_CFG) \
-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=$(ROOT_DIR)/src/llvm-project/clang \
-DLLVM_EXTERNAL_LLD_SOURCE_DIR=$(ROOT_DIR)/src/llvm-project/lld \
-DLLVM_ENABLE_PROJECTS="lld;clang" \
$(ROOT_DIR)/src/llvm-project/llvm
cd build/llvm; $(MAKE) -j 8 \
install-clang \
install-lld \
install-llc \
install-llvm-ar \
install-llvm-ranlib \
install-llvm-dwarfdump \
install-clang-headers \
install-llvm-nm \
install-llvm-size \
llvm-config
touch build/llvm.BUILT
build/musl.BUILT: src/musl.CLONED build/llvm.BUILT
mkdir -p build/musl
cd build/musl; $(ROOT_DIR)/src/musl/configure \
CC=$(ROOT_DIR)/dist/bin/clang \
CFLAGS="-O3 $(DEBUG_PREFIX_MAP)" \
--prefix=$(ROOT_DIR)/sysroot \
--enable-debug \
wasm32
make -C build/musl -j 8 install CROSS_COMPILE=$(ROOT_DIR)/dist/bin/llvm-
cp src/musl/arch/wasm32/libc.imports sysroot/lib/
touch build/musl.BUILT
build/compiler-rt.BUILT: src/llvm-project.CLONED build/llvm.BUILT
mkdir -p build/compiler-rt
cd build/compiler-rt; cmake -G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasm_standalone.cmake \
-DCOMPILER_RT_BAREMETAL_BUILD=On \
-DCOMPILER_RT_BUILD_XRAY=OFF \
-DCOMPILER_RT_INCLUDE_TESTS=OFF \
-DCOMPILER_RT_ENABLE_IOS=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=On \
-DCMAKE_C_FLAGS="-O1 $(DEBUG_PREFIX_MAP)" \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCOMPILER_RT_OS_DIR=. \
-DCMAKE_INSTALL_PREFIX=$(ROOT_DIR)/dist/lib/clang/$(LLVM_VERSION).0.0/ \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
$(ROOT_DIR)/src/llvm-project/compiler-rt/lib/builtins
cd build/compiler-rt; make -j 8 install
cp -R $(ROOT_DIR)/build/llvm/lib/clang $(ROOT_DIR)/dist/lib/
touch build/compiler-rt.BUILT
build/libcxx.BUILT: src/llvm-project.CLONED build/llvm.BUILT build/compiler-rt.BUILT build/musl.BUILT
mkdir -p build/libcxx
cd build/libcxx; cmake -G "Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasm_standalone.cmake \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DLIBCXX_ENABLE_THREADS:BOOL=OFF \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXX_ENABLE_SHARED:BOOL=OFF \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \
-DLIBCXX_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$(ROOT_DIR)/src/llvm-project/libcxxabi/include \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) -D_LIBCPP_HAS_MUSL_LIBC" \
--debug-trycompile \
$(ROOT_DIR)/src/llvm-project/libcxx
cd build/libcxx; make -j 8 install
touch build/libcxx.BUILT
build/libcxxabi.BUILT: src/llvm-project.CLONED build/libcxx.BUILT build/llvm.BUILT
mkdir -p build/libcxxabi
cd build/libcxxabi; cmake -G "Unix Makefiles" \
-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_ENABLE_THREADS:BOOL=OFF \
-DCXX_SUPPORTS_CXX11=ON \
-DLLVM_COMPILER_CHECKED=ON \
-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DLIBCXXABI_LIBCXX_PATH=$(ROOT_DIR)/src/llvm-project/libcxx \
-DLIBCXXABI_LIBCXX_INCLUDES=$(ROOT_DIR)/sysroot/include/c++/v1 \
-DLLVM_CONFIG_PATH=$(ROOT_DIR)/build/llvm/bin/llvm-config \
-DCMAKE_TOOLCHAIN_FILE=$(ROOT_DIR)/wasm_standalone.cmake \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) -D_LIBCPP_HAS_MUSL_LIBC" \
-DUNIX:BOOL=ON \
--debug-trycompile \
$(ROOT_DIR)/src/llvm-project/libcxxabi
cd build/libcxxabi; make -j 8 install
touch build/libcxxabi.BUILT
BASICS=sysroot/include/wasmception.h sysroot/lib/wasmception.wasm
sysroot/include/wasmception.h: basics/wasmception.h
cp basics/wasmception.h sysroot/include/
sysroot/lib/wasmception.wasm: build/llvm.BUILT basics/wasmception.c
dist/bin/clang \
--sysroot=./sysroot basics/wasmception.c \
-c -O3 -g $(DEBUG_PREFIX_MAP) \
-o sysroot/lib/wasmception.wasm
build: build/llvm.BUILT build/musl.BUILT build/compiler-rt.BUILT build/libcxxabi.BUILT build/libcxx.BUILT $(BASICS)
strip: build/llvm.BUILT
cd dist/bin; strip clang-$(LLVM_VERSION) llc lld llvm-ar
collect-sources:
-rm -rf build/sources build/sources.txt
{ find sysroot -name "*.o"; find sysroot -name "*.wasm"; find dist/lib sysroot -name "lib*.a"; } | \
xargs ./list_debug_sources.py | sort > build/sources.txt
echo "sysroot/include" >> build/sources.txt
for f in $$(cat build/sources.txt); \
do mkdir -p `dirname build/sources/$$f`; cp -R $$f `dirname build/sources/$$f`; done;
cd build/sources && { git init; git checkout --orphan v$(VERSION); git add -A .; git commit -m "Sources"; }
echo "cd build/sources && git push -f [email protected]:yurydelendik/wasmception.git v$(VERSION)"
revisions:
cd src/llvm-project; echo "LLVM_PROJECT_SHA=`git log -1 --format="%H"`"
cd src/musl; echo "MUSL_SHA=`git log -1 --format="%H"`"
OS_NAME=$(shell uname -s | tr '[:upper:]' '[:lower:]')
pack:
tar czf wasmception-${OS_NAME}-bin.tar.gz dist sysroot
.PHONY: default clean build strip revisions pack collect-sources