-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathMakefile.essentiajs
88 lines (73 loc) · 2.96 KB
/
Makefile.essentiajs
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
ESSENTIAJS_VERSION=0.1.3
## Path to libs for Emscripten
LIB_DIR_ESSENTIA=$(EMSCRIPTEN)/system/local/lib
EIGEN_PATH=/usr/local/include/eigen3
## Pass custom build and dist directories using system environment variables
BUILD_DIR_ES := $(or $(ESSENTIAJS_WASM_BUILDS_DIR),builds)
DIST_DIR_ES := $(or $(ESSENTIAJS_BUILDS_DIR),dist)
## C++ source code for Essentia.js
BINDING_ESSENTIAJS=src/cpp/bindings_essentiajs.cpp
INCLUDE_ESSENTIAJS=src/cpp/includes/essentiajs.cpp
## Define builds
ESSENTIA_JS_WEB=$(BUILD_DIR_ES)/essentia-wasm.web.js
ESSENTIA_JS_WEB_WASM=$(BUILD_DIR_ES)/essentia-wasm.web.wasm
ESSENTIA_JS_MODULE=$(BUILD_DIR_ES)/essentia-wasm.module.js
ESSENTIA_WASM_UMD_MODULE=$(BUILD_DIR_ES)/essentia-wasm.umd.js
ESSENTIA_WASM_ES6_MODULE=$(BUILD_DIR_ES)/essentia-wasm.es.js
## Path to custom --pre-js and --post-js files for Emscripten
PRE_JS_WASM=src/js/wasm.module.pre.js
POST_JS_WEB_WASM=src/js/wasm.webmodule.post.js
POST_JS_ES6_WASM=src/js/wasm.es6module.post.js
POST_JS_UMD_WASM=src/js/wasm.umd.post.js
codegen:
@echo "Generating cpp source code from essentia python bindings ..."
@cd src/python && python configure_bindings.py
build:
@mkdir -p $(BUILD_DIR_ES)
@echo "Compiling the emscripten embind cpp bindings to bitcode ..."
@emcc -I $(EIGEN_PATH) \
--bind -Oz $(BINDING_ESSENTIAJS) $(INCLUDE_ESSENTIAJS) \
-o $(BUILD_DIR_ES)/essentiajs.bc \
-s EXCEPTION_DEBUG \
-s ASSERTIONS=2 \
-s DISABLE_EXCEPTION_CATCHING=2 || exit 1
@echo "Done ..."
@echo "Linking and compiling the bindings with essentia to js, wasm files ..."
@echo "compiling async builds..."
@emcc --bind -Oz $(BUILD_DIR_ES)/essentiajs.bc ${LIB_DIR_ESSENTIA}/essentia.a \
-s WASM=1 \
-o $(ESSENTIA_JS_WEB) \
-s EXCEPTION_DEBUG \
-s ASSERTIONS=2 \
-s ENVIRONMENT=web \
-s MODULARIZE=1 \
-s EXPORT_NAME="EssentiaWASM" \
--post-js $(POST_JS_WEB_WASM) \
-s ALLOW_MEMORY_GROWTH=1 || exit 1
@echo "Done ..."
@echo "compiling sync builds..."
@emcc --bind -Oz $(BUILD_DIR_ES)/essentiajs.bc ${LIB_DIR_ESSENTIA}/essentia.a \
-s WASM=1 \
-o $(ESSENTIA_JS_MODULE) \
-s BINARYEN_ASYNC_COMPILATION=0 \
-s ALLOW_MEMORY_GROWTH=1 \
-s SINGLE_FILE=1 || exit 1
@cat $(PRE_JS_WASM) $(ESSENTIA_JS_WEB) > $$.tmp && mv $$.tmp $(ESSENTIA_JS_WEB)
@cat $(PRE_JS_WASM) $(ESSENTIA_JS_MODULE) > $$.tmp && mv $$.tmp $(ESSENTIA_JS_MODULE)
@cp -f $(ESSENTIA_JS_MODULE) $(ESSENTIA_WASM_ES6_MODULE)
@cat $(POST_JS_ES6_WASM) >> $(ESSENTIA_WASM_ES6_MODULE)
@cp -f $(ESSENTIA_JS_MODULE) $(ESSENTIA_WASM_UMD_MODULE)
@cat $(POST_JS_UMD_WASM) >> $(ESSENTIA_WASM_UMD_MODULE)
@rm -f $(ESSENTIA_JS_MODULE)
@mkdir -p $(DIST_DIR_ES)
@cp -f $(ESSENTIA_JS_WEB) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_JS_WEB_WASM) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_WASM_UMD_MODULE) $(DIST_DIR_ES)/
@cp -f $(ESSENTIA_WASM_ES6_MODULE) $(DIST_DIR_ES)/
@echo "Done ..."
@echo "Removing unnecessary files ..."
@rm $(BUILD_DIR_ES)/essentiajs.bc
@echo "Builds ..."
@ls $(BUILD_DIR_ES)
clean:
@rm -rf $(BUILD_DIR_ES)