forked from saghul/txiki.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (98 loc) · 2.96 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
BUILD_DIR=build
BUILDTYPE?=Release
JOBS?=$(shell getconf _NPROCESSORS_ONLN)
TJS=$(BUILD_DIR)/tjs
QJSC=$(BUILD_DIR)/tjsc
STDLIB_MODULES=$(wildcard src/js/stdlib/*.js)
ESBUILD?=npx esbuild
ESBUILD_PARAMS_COMMON=--target=es2022 --platform=neutral --format=esm --main-fields=main,module
all: $(TJS)
$(BUILD_DIR):
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILDTYPE)
$(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=$@ \
--minify \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/polyfills.c: $(QJSC) src/bundles/js/core/polyfills.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
-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=$@ \
--minify \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/core.c: $(QJSC) src/bundles/js/core/core.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
-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=$@ \
--minify \
--external:tjs:* \
--log-override:direct-eval=silent \
$(ESBUILD_PARAMS_COMMON)
src/bundles/c/core/run-main.c: $(QJSC) src/bundles/js/core/run-main.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
-o $@ \
-n "run-main.js" \
-p tjs__ \
src/bundles/js/core/run-main.js
core: src/bundles/c/core/polyfills.c src/bundles/c/core/core.c src/bundles/c/core/run-main.c
src/bundles/c/stdlib/%.c: $(QJSC) src/bundles/js/stdlib/%.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
-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_COMMON)
src/bundles/c/stdlib/%.c: $(QJSC) src/bundles/js/stdlib/%.js
@mkdir -p $(basename $(dir $@))
$(QJSC) -m \
-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)