-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
166 lines (121 loc) · 3.81 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
# dependencies
SQLITE_AMALGAMATION = sqlite-amalgamation-3330000
SQLITE_AMALGAMATION_ZIP_URL = https://www.sqlite.org/2020/sqlite-amalgamation-3330000.zip
SQLITE_AMALGAMATION_ZIP_SHA1 = 5b0a95fc6090499c0cdf7f15fcec9c132f8e021e
EXTENSION_FUNCTIONS = extension-functions.c
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f
# source files
EXPORTED_FUNCTIONS_JSON = src/exported_functions.json
# build options
EMCC ?= emcc
TSC ?= node_modules/typescript/bin/tsc
EXTENSIONS = ext/extension-functions.wasm
CFLAGS = \
-fPIC \
-D_HAVE_SQLITE_CONFIG_H \
-Isrc/c -I'deps/$(SQLITE_AMALGAMATION)'
EMFLAGS = \
-s ALLOW_MEMORY_GROWTH=1 \
-s RESERVED_FUNCTION_POINTERS=64 \
-s WASM=1
EMFLAGS_EXTENSION = \
-s INLINING_LIMIT=50 \
-Os
EMFLAGS_DEBUG = \
-s INLINING_LIMIT=10 \
-O1
EMFLAGS_DIST = \
-s INLINING_LIMIT=50 \
-Os
EMFLAG_INTERFACES = \
-s MAIN_MODULE=1 \
-s EXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS_JSON) \
-s EXTRA_EXPORTED_RUNTIME_METHODS=[$(shell \
grep -Po '(?<=declare function )\w+' src/ts/module.ts | sed -e 's/\(.*\)/"\1"/;' | paste -s -d,)] \
--post-js temp/api.js
# directories
.PHONY: all
all: dist
.PHONY: clean
clean:
rm -rf dist debug ext temp
.PHONY: clean-all
clean-all:
rm -rf dist debug ext temp deps cache
## cache
.PHONY: clean-cache
clean-cache:
rm -rf cache
cache/$(SQLITE_AMALGAMATION).zip:
mkdir -p cache
curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@
cache/$(EXTENSION_FUNCTIONS):
mkdir -p cache
curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@
## deps
.PHONY: clean-deps
clean-deps:
rm -rf deps
.PHONY: deps
deps: deps/$(SQLITE_AMALGAMATION) deps/$(EXTENSION_FUNCTIONS) deps/$(EXPORTED_FUNCTIONS)
deps/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip
mkdir -p deps
echo '$(SQLITE_AMALGAMATION_ZIP_SHA1)' 'cache/$(SQLITE_AMALGAMATION).zip' | sha1sum -c
rm -rf $@
unzip 'cache/$(SQLITE_AMALGAMATION).zip' -d deps/
touch $@
deps/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
mkdir -p deps
echo '$(EXTENSION_FUNCTIONS_SHA1)' 'cache/$(EXTENSION_FUNCTIONS)' | sha1sum -c
cp 'cache/$(EXTENSION_FUNCTIONS)' $@
## temp
.PHONY: clean-temp
clean-temp:
rm -rf temp
temp/bc/shell.bc: deps/$(SQLITE_AMALGAMATION) src/c/config.h
mkdir -p temp/bc
$(EMCC) $(CFLAGS) 'deps/$(SQLITE_AMALGAMATION)/shell.c' -c -o $@
temp/bc/sqlite3.bc: deps/$(SQLITE_AMALGAMATION) src/c/config.h
mkdir -p temp/bc
$(EMCC) $(CFLAGS) -s LINKABLE=1 'deps/$(SQLITE_AMALGAMATION)/sqlite3.c' -c -o $@
temp/bc/glue.bc: src/c/glue.c
mkdir -p temp/bc
$(EMCC) $(CFLAGS) -s LINKABLE=1 src/c/glue.c -c -o $@
temp/bc/extension-functions.bc: deps/$(EXTENSION_FUNCTIONS)
mkdir -p temp/bc
$(EMCC) $(CFLAGS) -s LINKABLE=1 'deps/$(EXTENSION_FUNCTIONS)' -c -o $@
temp/api.js: $(wildcard src/ts/*)
$(TSC)
## extensions
.PHONY: clean-ext
clean-ext:
rm -rf ext
.PHONY: ext
ext: $(EXTENSIONS)
ext/extension-functions.wasm: temp/bc/extension-functions.bc
mkdir -p ext
$(EMCC) $(EMFLAGS) -s SIDE_MODULE=1 -s EXPORTED_FUNCTIONS='["_sqlite3_extension_init"]' $(EMFLAGS_EXTENSION) \
temp/bc/extension-functions.bc -o $@
## debug
.PHONY: clean-debug
clean-debug:
rm -rf debug
.PHONY: debug
debug: debug/sqlite3.html
debug/sqlite3.html: temp/bc/sqlite3.bc temp/bc/glue.bc $(EXTENSIONS) $(EXPORTED_FUNCTIONS_JSON) temp/api.js
mkdir -p debug
$(EMCC) $(EMFLAGS) $(EMFLAG_INTERFACES) $(EMFLAGS_DEBUG) \
--no-heap-copy --embed-file ext \
temp/bc/sqlite3.bc temp/bc/glue.bc -o $@
## dist
.PHONY: clean-dist
clean-dist:
rm -rf dist
.PHONY: dist
dist: dist/sqlite3.html
dist/sqlite3.html: temp/bc/sqlite3.bc temp/bc/glue.bc $(EXTENSIONS) $(EXPORTED_FUNCTIONS_JSON) temp/api.js
mkdir -p dist
$(EMCC) $(EMFLAGS) $(EMFLAG_INTERFACES) $(EMFLAGS_DIST) \
--no-heap-copy --embed-file ext \
temp/bc/sqlite3.bc temp/bc/glue.bc -o $@