forked from abalabahaha/opusscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (115 loc) · 3.42 KB
/
Makefile
File metadata and controls
142 lines (115 loc) · 3.42 KB
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
LIBOPUS=./opus-native
BUILD = ./build
SRC = ./src
DIST = ./dist
TARGET=js # html asm
CC = em++
INCLUDES = -I $(LIBOPUS)/include/
# Set Flags as proposed by:
# https://developers.google.com/web/updates/2019/01/emscripten-npm
FLAGS=\
-Wall \
-O3 \
--bind \
-flto \
--closure 1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s FILESYSTEM=0 \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORTED_RUNTIME_METHODS="['setValue', 'getValue']" \
-s EXPORTED_FUNCTIONS="['_malloc', '_opus_strerror']" \
define UNUSED_FLAGS
-s STRICT=1 \
endef
CONFIGURATIONS=\
--disable-extra-programs\
--disable-doc\
--disable-intrinsics\
--disable-stack-protector # https://github.com/xiph/opus/issues/138
.PHONY: init build clean
all: init build
############################################################
# make init: Compiling libopus to WebAssembly
#
# 1. To configure the libopus build system, use:
# make config
#
# 2. To compile libopus with those configurations, use:
# make libopus
#
############################################################
.PHONY: config libopus cleantemps
init: config libopus cleantemps
# configure Makefile for libopus
config: $(LIBOPUS)/Makefile # .PHONY target
$(LIBOPUS)/Makefile:
cd $(LIBOPUS); \
./autogen.sh; \
emconfigure ./configure $(CONFIGURATIONS)
# compile libopus to shared object file (wasm bitcode)
libopus: ${LIBOPUS}/.libs/libopus.so # PHONY target
${LIBOPUS}/.libs/libopus.so: $(LIBOPUS)/Makefile
cd $(LIBOPUS); \
emmake make
cleantemps:
rm -rf $(LIBOPUS)/a.out $(LIBOPUS)/a.out.js $(LIBOPUS)/a.out.wasm
############################################################
# make build: Compiling the libopus wrapper to JavaScript
#
# 1. To compile the wrapper, use:
# make wrapper
#
# 2. To link wrapper and library, use:
# make link
#
############################################################
.PHONY: wrapper link
build: wrapper link
# create build directory
$(BUILD)/:
mkdir -p $@
# compile the wrapper to bitcode object file (wasm bitcode)
wrapper: $(BUILD)/ $(BUILD)/opusscript.o # PHONY target
$(BUILD)/opusscript.o: $(SRC)/opusscript.cpp
$(CC) ${FLAGS} $(INCLUDES) -c -o $@ $^
# statically link wrapper and libopus (wasm bitcode)
link: $(BUILD)/ $(BUILD)/opusscript.$(TARGET) # PHONY target
$(BUILD)/opusscript.$(TARGET): ${LIBOPUS}/.libs/libopus.so $(BUILD)/opusscript.o
$(CC) $(FLAGS) $(INCLUDES) -o $@ $^
############################################################
# make clean: Cleanup Compilation Steps
#
# 1. To cleanup results of 'make build', use:
# make cleanbuild
#
# 2. To cleanup results of 'make libopus', use:
# make cleanlibopus
#
# 3. To cleanup results of 'make config', use:
# make cleanconfig
#
############################################################
.PHONY: cleanbuild cleanlibopus cleanconfig
clean: cleanbuild cleanlibopus cleanconfig
cleanbuild:
rm -rf $(BUILD)
cleanlibopus: cleantemps
emmake make -C $(LIBOPUS) clean
cleanconfig:
make -C $(LIBOPUS) distclean
############################################################
# make install: Install Required Files into DIST Directory
#
############################################################
.PHONY: copy_licence copy_opusscript
install: cleanbuild copy_licence copy_opusscript
# create distribution directory
$(DIST)/:
mkdir -p $(DIST)/
copy_licence: $(DIST)/
cp -f opus-native/COPYING $(DIST)/COPYING.libopus;
copy_opusscript: $(DIST)/ init build
cp -f build/opusscript.wasm dist/
cp -f build/opusscript.js dist/
cp -f build/opusscript.html dist/