-
Notifications
You must be signed in to change notification settings - Fork 171
/
Makefile
183 lines (152 loc) · 4.4 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
BUILD_DIR=build
BUILDTYPE?=Release
JOBS?=$(shell getconf _NPROCESSORS_ONLN)
ifeq ($(JOBS),)
JOBS := $(shell sysctl -n hw.ncpu)
endif
ifeq ($(JOBS),)
JOBS := $(shell nproc)
endif
ifeq ($(JOBS),)
JOBS := 4
endif
TJS=$(BUILD_DIR)/tjs
QJSC=$(BUILD_DIR)/tjsc
STDLIB_MODULES=$(wildcard src/js/stdlib/*.js)
ESBUILD?=npx esbuild
ESBUILD_PARAMS_COMMON=--target=es2023 --platform=neutral --format=esm --main-fields=main,module
ESBUILD_PARAMS_MINIFY=--minify --keep-names
QJSC_PARAMS_STIP=-s
JS_NO_STRIP?=0
BUILD_MACOS_MULTIARCH?=0
EXTRA_CMAKE_PARAMS=
ifeq ($(JS_NO_STRIP),1)
ESBUILD_PARAMS_MINIFY=
QJSC_PARAMS_STIP=
endif
ifeq ($(BUILD_MACOS_MULTIARCH),1)
EXTRA_CMAKE_PARAMS=-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
endif
all: $(TJS)
$(BUILD_DIR):
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILDTYPE) $(EXTRA_CMAKE_PARAMS)
$(TJS): $(BUILD_DIR)
cmake --build $(BUILD_DIR) -j $(JOBS)
$(QJSC): $(BUILD_DIR)
cmake --build $(BUILD_DIR) --target tjsc -j $(JOBS)
src/bundles/js/core/polyfills.js: src/js/polyfills/*.js
$(ESBUILD) src/js/polyfills/index.js \
--bundle \
--outfile=$@ \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/polyfills.c: $(QJSC) src/bundles/js/core/polyfills.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "polyfills.js" \
-p tjs__ \
src/bundles/js/core/polyfills.js
src/bundles/js/core/core.js: src/js/core/*.js
$(ESBUILD) src/js/core/index.js \
--bundle \
--outfile=$@ \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/core.c: $(QJSC) src/bundles/js/core/core.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "core.js" \
-p tjs__ \
src/bundles/js/core/core.js
src/bundles/js/core/run-main.js: src/js/run-main/*.js
$(ESBUILD) src/js/run-main/index.js \
--bundle \
--outfile=$@ \
--external:tjs:* \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/run-main.c: $(QJSC) src/bundles/js/core/run-main.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "run-main.js" \
-p tjs__ \
src/bundles/js/core/run-main.js
src/bundles/js/core/run-repl.js: src/js/run-repl/*.js
$(ESBUILD) src/js/run-repl/index.js \
--bundle \
--outfile=$@ \
--external:tjs:* \
--log-override:direct-eval=silent \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/run-repl.c: $(QJSC) src/bundles/js/core/run-repl.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "run-repl.js" \
-p tjs__ \
src/bundles/js/core/run-repl.js
src/bundles/c/core/worker-bootstrap.c: $(QJSC) src/js/worker/worker-bootstrap.js
@mkdir -p $(basename $(dir $@))
$(QJSC) \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "worker-bootstrap.js" \
-p tjs__ \
src/js/worker/worker-bootstrap.js
core: src/bundles/c/core/polyfills.c src/bundles/c/core/core.c src/bundles/c/core/run-main.c src/bundles/c/core/run-repl.c src/bundles/c/core/worker-bootstrap.c
src/bundles/c/stdlib/%.c: $(QJSC) src/bundles/js/stdlib/%.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "tjs:$(basename $(notdir $@))" \
-p tjs__ \
src/bundles/js/stdlib/$(basename $(notdir $@)).js
src/bundles/js/stdlib/%.js: src/js/stdlib/*.js src/js/stdlib/ffi/*.js
$(ESBUILD) src/js/stdlib/$(notdir $@) \
--bundle \
--outfile=$@ \
--external:buffer \
--external:crypto \
$(ESBUILD_PARAMS_MINIFY) \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/stdlib/%.c: $(QJSC) src/bundles/js/stdlib/%.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
$(QJSC_PARAMS_STIP) \
-o $@ \
-n "tjs:$(basename $(notdir $@))" \
-p tjs__ \
src/bundles/js/stdlib/$(basename $(notdir $@)).js
stdlib: $(addprefix src/bundles/c/stdlib/, $(patsubst %.js, %.c, $(notdir $(STDLIB_MODULES))))
js: core stdlib
install: $(TJS)
cmake --build $(BUILD_DIR) --target install
clean: $(BUILD_DIR)
cmake --build $(BUILD_DIR) --target clean
debug:
BUILDTYPE=Debug $(MAKE)
distclean:
@rm -rf $(BUILD_DIR)
@rm -rf src/bundles/js/
format:
clang-format -i src/*.{c,h}
test:
./$(BUILD_DIR)/tjs test tests/
test-advanced:
cd tests/advanced && npm install
./$(BUILD_DIR)/tjs test tests/advanced/
.PRECIOUS: src/bundles/js/core/%.js src/bundles/js/stdlib/%.js
.PHONY: all js debug install clean distclean format test test-advanced core stdlib $(TJS)