-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
186 lines (158 loc) · 5.32 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
185
186
# Compiler and Output Settings
CC=emcc
BUILD_DIR=build
OBJ_DIR=obj
DIST_DIR=dist
# Directories
SRC_DIR=src
XS_DIR=moddable/xs
MODULES_DIR=moddable/modules
# Source Files
SOURCES := \
$(SRC_DIR)/xs_sandbox.c \
$(SRC_DIR)/wedge.c \
$(SRC_DIR)/xs_sandbox_platform.c \
$(XS_DIR)/sources/xsAll.c \
$(XS_DIR)/sources/xsAPI.c \
$(XS_DIR)/sources/xsArguments.c \
$(XS_DIR)/sources/xsArray.c \
$(XS_DIR)/sources/xsAtomics.c \
$(XS_DIR)/sources/xsBigInt.c \
$(XS_DIR)/sources/xsBoolean.c \
$(XS_DIR)/sources/xsCode.c \
$(XS_DIR)/sources/xsCommon.c \
$(XS_DIR)/sources/xsDataView.c \
$(XS_DIR)/sources/xsDate.c \
$(XS_DIR)/sources/xsDebug.c \
$(XS_DIR)/sources/xsDefaults.c \
$(XS_DIR)/sources/xsdtoa.c \
$(XS_DIR)/sources/xsError.c \
$(XS_DIR)/sources/xsFunction.c \
$(XS_DIR)/sources/xsGenerator.c \
$(XS_DIR)/sources/xsGlobal.c \
$(XS_DIR)/sources/xsJSON.c \
$(XS_DIR)/sources/xsLexical.c \
$(XS_DIR)/sources/xsLockdown.c \
$(XS_DIR)/sources/xsMapSet.c \
$(XS_DIR)/sources/xsMarshall.c \
$(XS_DIR)/sources/xsMath.c \
$(XS_DIR)/sources/xsmc.c \
$(XS_DIR)/sources/xsMemory.c \
$(XS_DIR)/sources/xsModule.c \
$(XS_DIR)/sources/xsNumber.c \
$(XS_DIR)/sources/xsObject.c \
$(XS_DIR)/sources/xsPlatforms.c \
$(XS_DIR)/sources/xsProfile.c \
$(XS_DIR)/sources/xsPromise.c \
$(XS_DIR)/sources/xsProperty.c \
$(XS_DIR)/sources/xsProxy.c \
$(XS_DIR)/sources/xsre.c \
$(XS_DIR)/sources/xsRegExp.c \
$(XS_DIR)/sources/xsRun.c \
$(XS_DIR)/sources/xsScope.c \
$(XS_DIR)/sources/xsScript.c \
$(XS_DIR)/sources/xsSnapshot.c \
$(XS_DIR)/sources/xsSourceMap.c \
$(XS_DIR)/sources/xsString.c \
$(XS_DIR)/sources/xsSymbol.c \
$(XS_DIR)/sources/xsSyntaxical.c \
$(XS_DIR)/sources/xsTree.c \
$(XS_DIR)/sources/xsType.c
# Object Files
OBJECTS := $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(SOURCES)))
# Compilation Flags
CFLAGS := -fno-common \
-DINCLUDE_XSPLATFORM \
-DXSPLATFORM=\"xs_sandbox_platform.h\" \
-DmxMetering=1 \
-DmxParse=1 \
-DmxRun=1 \
-DmxSloppy=1 \
-DmxSnapshot=1 \
-DmxRegExpUnicodePropertyEscapes=1 \
-DmxStringNormalize=1 \
-DmxMinusZero=1 \
-DmxDebug=1 \
-DmxUnalignedAccess=0 \
-DWASM_BUILD=1 \
-I$(XS_DIR)/includes \
-I$(XS_DIR)/platforms \
-I$(XS_DIR)/sources \
-I$(SRC_DIR) \
-O2
CFLAGS += -DmxNoConsole=1
# CFLAGS += -g3
# CFLAGS += -fdebug-compilation-dir=..
# The bounds checking seems to enable `fxCheckCStack` which doesn't work in WASM
CFLAGS += -DmxBoundsCheck=0
# Linker Flags
LDFLAGS := -sINITIAL_MEMORY=4194304 \
-sSTACK_SIZE=262144 \
-sALLOW_MEMORY_GROWTH \
-sMEMORY_GROWTH_GEOMETRIC_STEP=1.0 \
-sSUPPORT_LONGJMP=1 \
-sMODULARIZE=1 \
-sEXPORT_ES6=1 \
-sEXPORTED_RUNTIME_METHODS=ccall,cwrap \
-sEXPORTED_FUNCTIONS='["_initMachine", "_restoreSnapshot", "_sandboxInput", "_takeSnapshot", "_malloc", "_free", "_getMeteringLimit", "_setMeteringLimit", "_getMeteringInterval", "_setMeteringInterval", "_getActive", "_getMeteringCount"]' \
--js-library=$(SRC_DIR)/lib.js \
--use-preload-cache
# LDFLAGS += -sSINGLE_FILE
LDFLAGS += -sSTACK_OVERFLOW_CHECK=1
LDFLAGS += -sASSERTIONS=2
LDFLAGS += -sSAFE_HEAP=1
LDFLAGS += -sAUTO_JS_LIBRARIES=0
LDFLAGS += -sAUTO_NATIVE_LIBRARIES=0
LDFLAGS += -sALLOW_UNIMPLEMENTED_SYSCALLS=0
LDFLAGS += -sFETCH=0
LDFLAGS += -sWASMFS=0
LDFLAGS += -sPROXY_POSIX_SOCKETS=0
LDFLAGS += -sFILESYSTEM=0
LDFLAGS += -sUSE_SDL=0
LDFLAGS += -sWASM_WORKERS=0
# LDFLAGS += -g3
# LDFLAGS += -fdebug-compilation-dir=..
# LDFLAGS += -sSYSCALL_DEBUG=0
# LDFLAGS += -sRUNTIME_DEBUG=1
# LDFLAGS += -sDETERMINISTIC=1 # Doesn't seem to work
# LDFLAGS += -sDYLINK_DEBUG=1
# LDFLAGS += -sSOCKET_DEBUG=1
# LDFLAGS += -sFS_DEBUG=1
# LDFLAGS += -sWEBSOCKET_DEBUG=1
# LDFLAGS += -sASYNCIFY_DEBUG=2
# LDFLAGS += -sPTHREADS_DEBUG=1
# LDFLAGS += -sFETCH_DEBUG=1
# Makefile Rules
all: $(DIST_DIR)/index.mjs $(DIST_DIR)/index.d.ts
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(XS_DIR)/sources/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(MODULES_DIR)/data/text/decoder/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(MODULES_DIR)/data/text/encoder/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(OBJ_DIR)/%.o: $(MODULES_DIR)/data/base64/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/wasm-wrapper.mjs: $(OBJECTS) $(SRC_DIR)/lib.js | $(BUILD_DIR)
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SRC_DIR)/wasm-wrapper.mjs: $(BUILD_DIR)/wasm-wrapper.mjs
cp $< $@
$(SRC_DIR)/wasm-wrapper.wasm: $(BUILD_DIR)/wasm-wrapper.wasm
cp $< $@
$(DIST_DIR)/wasm-wrapper.wasm: $(BUILD_DIR)/wasm-wrapper.wasm | $(DIST_DIR)
cp $< $@
$(DIST_DIR)/index.mjs $(DIST_DIR)/index.js $(DIST_DIR)/index.d.mts: $(SRC_DIR)/*.mts $(SRC_DIR)/wasm-wrapper.mjs tsconfig.json $(SRC_DIR)/wasm-wrapper.wasm $(DIST_DIR)/wasm-wrapper.wasm | $(DIST_DIR)
npx rollup --config rollup.config.mjs
$(DIST_DIR)/index.d.ts: $(DIST_DIR)/index.d.mts
cp $< $@
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(DIST_DIR):
mkdir -p $(DIST_DIR)
clean:
rm -rf $(OBJ_DIR) $(BUILD_DIR) $(DIST_DIR)
rm -f $(SRC_DIR)/wasm-wrapper.mjs $(SRC_DIR)/wasm-wrapper.wasm
.PHONY: all clean