-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
70 lines (60 loc) · 2.12 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
SRC=$(wildcard src/*.cc src/**/*.cc !(src/wasm_api.cc))
EMCC_SRC=$(wildcard src/*.cc src/**/*.cc !(src/wasmdec.cc))
OBJS=$(SRC:.cc=.o)
OUT=wasmdec
CC=g++
CCOPTS=-std=c++14 -Iexternal/binaryen/src -Iexternal/cxxopts/include -c -Wall -g
RELEASE_CCOPTS=-std=c++14 -Iexternal/binaryen/src -c -Wall -O3
LDOPTS=-Lexternal/binaryen/lib -lbinaryen -lpthread
default: $(SRC) $(OUT)
$(OUT): $(OBJS)
@echo -n "Link "
@echo $@
$(CC) $(OBJS) $(LDOPTS) -o $@
.cc.o:
@echo -n "Build source "
@echo $<
$(CC) $(CCOPTS) $< -o $@
wasm:
# make wasmBinaryen
mkdir -p emcc_out
EMCC_DEBUG=1 em++ external/binaryen/lib/libbinaryen.so $(EMCC_SRC) \
-std=c++14 -Iexternal/binaryen/src -Iexternal/cxxopts/include -Wall -O3 \
-Wall -o emcc_out/wasmdec.js \
-s EXPORTED_FUNCTIONS='["_wasmdec_create_decompiler", "_wasmdec_decompile", "_wasmdec_get_decompiled_code", "_wasmdec_destroy_decompiler"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap", "addOnPostRun"]' -s ASSERTIONS=1 -s SAFE_HEAP=1
cp emcc_out/wasmdec.wasm wasmdec.js/
echo "(function(){" > wasmdec.js/wasmdec.wasm.js
cat emcc_out/wasmdec.js >> wasmdec.js/wasmdec.wasm.js
sed -i -e 's/rrides={};/rrides={};window\.Wasmdec\.Module=Module;/g' wasmdec.js/wasmdec.wasm.js
echo "})();" >> wasmdec.js/wasmdec.wasm.js
clean:
rm -f *.o wasmdec
rm -f src/*.o
rm -f src/**/*.o
# To build binaryen
binaryen:
cd external/binaryen && cmake . && make
# To build binaryen as a webassembly library
wasmBinaryen:
cd external/binaryen && EMCC_DEBUG=1 em++ src/*.cpp src/**/*.cpp -I/home/p/wasmdec/external/binaryen/src -std=c++11 -o lib/libinaryen.bc
# To install binaryen
installBinaryen:
make installBinaryen`(uname -s)`
installBinaryenLinux:
if [ -d "/usr/lib64" ]; then cp external/binaryen/lib/libbinaryen.so /usr/lib64/; else cp external/binaryen/lib/libbinaryen.so /usr/lib/; fi
installBinaryenDarwin:
cp external/binaryen/lib/libbinaryen.dylib /usr/local/lib/
# To install wasmdec
install:
make install`(uname -s)`
installLinux:
cp ./wasmdec /usr/bin
installDarwin:
cp ./wasmdec /usr/local/bin
# To build and install everything
all:
make binaryen
make installBinaryen
make default
make install