forked from bellard/quickjs
/
build.sh
executable file
·240 lines (213 loc) · 4.76 KB
/
build.sh
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env bash
# Build QuickJS for Apache NuttX RTOS
# To force rebuild: rm -r .obj
## TODO: Set RISC-V Toolchain Path
toolchain=$HOME/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin
export PATH="$toolchain/bin:$PATH"
## Uncomment this to build for QEMU 64-bit RISC-V (Kernel Mode)
## We assume that NuttX is at $HOME/riscv/nuttx and $HOME/riscv/apps
target=riscv
target_path=$HOME/$target
target_options=
## Uncomment this to build for Ox64 BL808 RISC-V SBC
## We assume that NuttX is at $HOME/ox64/nuttx and $HOME/ox64/apps
# target=ox64
# target_path=$HOME/$target
# target_options=" \
# -r \
# -e main \
# -T$target_path/nuttx/binfmt/libelf/gnu-elf.ld \
# -r \
# "
set -e # Exit when any command fails
set -x # Echo commands
pushd ..
mkdir -p .obj
## GCC Options for QuickJS
qjs_options=" \
-Wno-array-bounds \
-Wno-format-truncation \
-fwrapv \
-D_GNU_SOURCE \
-DCONFIG_VERSION=\"2024-01-13\" \
-DCONFIG_BIGNUM \
"
## GCC Options for NuttX
## For riscv-none-elf-gcc: "-march=rv64imafdc_zicsr_zifencei"
## For riscv64-unknown-elf-gcc: "-march=rv64imafdc"
nuttx_options=" \
-c \
-fno-common \
-Wall \
-Wstrict-prototypes \
-Wshadow \
-Wundef \
-Wno-attributes \
-Wno-unknown-pragmas \
-Wno-psabi \
-fno-common \
-pipe \
-Os \
-fno-strict-aliasing \
-fomit-frame-pointer \
-ffunction-sections \
-fdata-sections \
-g \
-mcmodel=medany \
-march=rv64imafdc \
-mabi=lp64d \
-isystem $target_path/apps/import/include \
-isystem $target_path/apps/import/include \
-D__NuttX__ \
-I "$target_path/apps/include" \
"
## Compile the NuttX App
## This one is slooooooow
if [ ! -e ".obj/quickjs.o" ]
then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/quickjs.o \
quickjs.c
fi
# if [ ! -e ".obj/stub.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
-o .obj/stub.o \
nuttx/stub.c
# fi
# if [ ! -e ".obj/arch_atomic.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
-o .obj/arch_atomic.o \
nuttx/arch_atomic.c
# fi
# if [ ! -e ".obj/repl.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/repl.o \
nuttx/repl.c
# fi
# if [ ! -e ".obj/qjscalc.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/qjscalc.o \
nuttx/qjscalc.c
# fi
# if [ ! -e ".obj/qjs.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/qjs.o \
qjs.c
# fi
# if [ ! -e ".obj/libregexp.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/libregexp.o \
libregexp.c
# fi
# if [ ! -e ".obj/libunicode.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/libunicode.o \
libunicode.c
# fi
# if [ ! -e ".obj/cutils.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/cutils.o \
cutils.c
# fi
# if [ ! -e ".obj/quickjs-libc.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/quickjs-libc.o \
quickjs-libc.c
# fi
# if [ ! -e ".obj/libbf.o" ]
# then
riscv64-unknown-elf-gcc \
$nuttx_options \
$qjs_options \
-o .obj/libbf.o \
libbf.c
# fi
## Link the NuttX App
## For riscv-none-elf-ld: "rv64imafdc_zicsr/lp64d"
## For riscv64-unknown-elf-ld: "rv64imafdc/lp64d
riscv64-unknown-elf-ld \
--oformat elf64-littleriscv \
$target_options \
-e _start \
-Bstatic \
-T$target_path/apps/import/scripts/gnu-elf.ld \
-L$target_path/apps/import/libs \
-L "$toolchain/lib/gcc/riscv64-unknown-elf/10.2.0/rv64imafdc/lp64d" \
$target_path/apps/import/startup/crt0.o \
.obj/qjs.o \
.obj/repl.o \
.obj/quickjs.o \
.obj/libregexp.o \
.obj/libunicode.o \
.obj/cutils.o \
.obj/quickjs-libc.o \
.obj/libbf.o \
.obj/qjscalc.o \
.obj/arch_atomic.o \
.obj/stub.o \
--start-group \
-lmm \
-lc \
-lproxies \
-lm \
-lgcc \
$target_path/apps/libapps.a \
$toolchain/lib/gcc/riscv64-unknown-elf/10.2.0/rv64imafdc/lp64d/libgcc.a \
--end-group \
-o $target_path/apps/bin/qjs \
-Map nuttx/qjs-$target.map
## Show the size
riscv64-unknown-elf-size $target_path/apps/bin/qjs
## Dump the disassembly
riscv64-unknown-elf-objdump \
-t -S --demangle --line-numbers --wide \
$target_path/apps/bin/qjs \
>nuttx/qjs-$target.S \
2>&1
## Copy the Demo Script
cp nuttx/blink.js $target_path/apps/bin
## Test with QEMU
pushd ../nuttx
../quickjs-nuttx/nuttx/qemu.exp || true
../quickjs-nuttx/nuttx/qemu.exp \
| tr -d "\r" \
>../quickjs-nuttx/nuttx/qemu.log
# (sleep 10 ; pkill qemu) &
# qemu-system-riscv64 \
# -semihosting \
# -M virt,aclint=on \
# -cpu rv64 \
# -smp 8 \
# -bios none \
# -kernel nuttx \
# -nographic
## Return to quickjs-nuttx
popd
popd