forked from bellard/mquickjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (135 loc) · 3.74 KB
/
Makefile
File metadata and controls
165 lines (135 loc) · 3.74 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#CONFIG_PROFILE=y
#CONFIG_X86_32=y
#CONFIG_ARM32=y
#CONFIG_WIN32=y
#CONFIG_SOFTFLOAT=y
#CONFIG_ASAN=y
#CONFIG_GPROF=y
CONFIG_SMALL=y
# consider warnings as errors (for development)
#CONFIG_WERROR=y
ifdef CONFIG_ARM32
CROSS_PREFIX=arm-linux-gnu-
endif
ifdef CONFIG_WIN32
ifdef CONFIG_X86_32
CROSS_PREFIX?=i686-w64-mingw32-
else
CROSS_PREFIX?=x86_64-w64-mingw32-
endif
EXE=.exe
else
CROSS_PREFIX?=
EXE=
endif
HOST_CC=gcc
CC=$(CROSS_PREFIX)gcc
CFLAGS=-Wall -g -MMD -D_GNU_SOURCE -fno-math-errno -fno-trapping-math
HOST_CFLAGS=-Wall -g -MMD -D_GNU_SOURCE -fno-math-errno -fno-trapping-math
ifdef CONFIG_WERROR
CFLAGS+=-Werror
HOST_CFLAGS+=-Werror
endif
ifdef CONFIG_ARM32
CFLAGS+=-mthumb
endif
ifdef CONFIG_SMALL
CFLAGS+=-Os
else
CFLAGS+=-O2
endif
#CFLAGS+=-fstack-usage
ifdef CONFIG_SOFTFLOAT
CFLAGS+=-msoft-float
CFLAGS+=-DUSE_SOFTFLOAT
endif # CONFIG_SOFTFLOAT
HOST_CFLAGS+=-O2
LDFLAGS=-g
HOST_LDFLAGS=-g
ifdef CONFIG_GPROF
CFLAGS+=-p
LDFLAGS+=-p
endif
ifdef CONFIG_ASAN
CFLAGS+=-fsanitize=address -fno-omit-frame-pointer
LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer
endif
ifdef CONFIG_X86_32
CFLAGS+=-m32
LDFLAGS+=-m32
endif
ifdef CONFIG_PROFILE
CFLAGS+=-p
LDFLAGS+=-p
endif
# when cross compiling from a 64 bit system to a 32 bit system, force
# a 32 bit output
ifdef CONFIG_X86_32
MQJS_BUILD_FLAGS=-m32
endif
ifdef CONFIG_ARM32
MQJS_BUILD_FLAGS=-m32
endif
PROGS=mqjs$(EXE) example$(EXE)
TEST_PROGS=dtoa_test libm_test
all: $(PROGS)
MQJS_OBJS=mqjs.o mqjs_led.o mqjs_gpio.o readline_tty.o readline.o mquickjs.o dtoa.o libm.o cutils.o
LIBS=-lm
mqjs$(EXE): $(MQJS_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
mquickjs.o: mquickjs_atom.h
# Build the REPL stdlib with LED and GPIO support enabled
mqjs_stdlib.host.o: mqjs_stdlib.c
$(HOST_CC) $(HOST_CFLAGS) -DCONFIG_LED -DCONFIG_GPIO -c -o $@ $<
mqjs_stdlib: mqjs_stdlib.host.o mquickjs_build.host.o
$(HOST_CC) $(HOST_LDFLAGS) -o $@ $^
mquickjs_atom.h: mqjs_stdlib
./mqjs_stdlib -a $(MQJS_BUILD_FLAGS) > $@
mqjs_stdlib.h: mqjs_stdlib
./mqjs_stdlib $(MQJS_BUILD_FLAGS) > $@
mqjs.o: mqjs_stdlib.h
# C API example
example.o: example_stdlib.h
example$(EXE): example.o mquickjs.o dtoa.o libm.o cutils.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
example_stdlib: example_stdlib.host.o mquickjs_build.host.o
$(HOST_CC) $(HOST_LDFLAGS) -o $@ $^
example_stdlib.h: example_stdlib
./example_stdlib $(MQJS_BUILD_FLAGS) > $@
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.host.o: %.c
$(HOST_CC) $(HOST_CFLAGS) -c -o $@ $<
test: mqjs example
./mqjs tests/test_closure.js
./mqjs tests/test_language.js
./mqjs tests/test_loop.js
./mqjs tests/test_builtin.js
# test bytecode generation and loading
./mqjs -o test_builtin.bin tests/test_builtin.js
# @sha256sum -c test_builtin.sha256
./mqjs -b test_builtin.bin
./example tests/test_rect.js
microbench: mqjs
./mqjs tests/microbench.js
octane: mqjs
./mqjs --memory-limit 256M tests/octane/run.js
size: mqjs
size mqjs mqjs.o readline.o cutils.o dtoa.o libm.o mquickjs.o
dtoa_test: tests/dtoa_test.o dtoa.o cutils.o tests/gay-fixed.o tests/gay-precision.o tests/gay-shortest.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
libm_test: tests/libm_test.o libm.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
rempio2_test: tests/rempio2_test.o libm.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
# ESP32 target - generates 32-bit headers required before running idf.py build
esp32: mqjs_stdlib
./mqjs_stdlib -m32 > mqjs_stdlib.h
./mqjs_stdlib -a -m32 > mquickjs_atom.h
@echo ""
@echo "32-bit headers generated. Now run:"
@echo " idf.py set-target esp32s3 # or esp32c6, esp32h2"
@echo " idf.py build"
clean:
rm -f *.o *.d *~ tests/*.o tests/*.d tests/*~ test_builtin.bin mqjs_stdlib mqjs_stdlib.h mquickjs_build_atoms mquickjs_atom.h mqjs_example example_stdlib example_stdlib.h $(PROGS) $(TEST_PROGS)
-include $(wildcard *.d)