-
Notifications
You must be signed in to change notification settings - Fork 20
/
Makefile
233 lines (197 loc) · 6.64 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
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
# arch = {riscv32, riscv64, x86_64, aarch64, mipsel}
# mode = {debug, release}
arch ?= riscv32
mode ?= debug
out_dir ?= build/$(arch)
out_img ?= build/$(arch).img
out_qcow2 ?= build/$(arch).qcow2
out_qcow2_cache := $(out_qcow2).cache
ld_path_file := $(out_dir)/etc/ld-musl-$(arch).path
prebuilt_version ?= 0.1.2
rcore_fs_fuse_revision ?= 7f5eeac
prebuilt_tar := build/$(arch)_v$(prebuilt_version).tar.gz
rust_src_dir := rust/src/bin
rust_bin_path := rust/target/$(arch)-rcore/$(mode)
rust_bins := $(patsubst $(rust_src_dir)/%.rs, $(rust_bin_path)/%, $(wildcard $(rust_src_dir)/*.rs))
ucore_bin_path := ucore/build/$(arch)
biscuit_bin_path := biscuit/build/$(arch)
app_bin_path := app/build/$(arch)
busybox := $(out_dir)/busybox
alpine_version_major := 3.10
alpine_version_full := 3.10.2
alpine_file := alpine-minirootfs-$(alpine_version_full)-$(arch).tar.gz
alpine := alpine/$(alpine_file)
musl-gcc_file := $(arch)-linux-musl-cross.tgz
musl-gcc_version := 6
musl-gcc := musl-gcc/build/$(arch)/musl-gcc
musl-rust_version := 1.42.0
musl-rust_file := rust-$(musl-rust_version)-$(arch)-unknown-linux-musl.tar.gz
musl-rust := musl-rust/$(musl-rust_file)
rust_build_args := --target targets/$(arch)-rcore.json
cmake_build_args := -DARCH=$(arch)
ifeq ($(mode), release)
rust_build_args += --release
cmake_build_args += -DCMAKE_BUILD_TYPE=Release
else ifeq ($(mode), debug)
cmake_build_args += -DCMAKE_BUILD_TYPE=Debug
endif
.PHONY: all clean build rust ucore biscuit app bin busybox nginx redis alpine iperf3 musl-gcc musl-rust pre make localtime cmake libc-test
all: build
rust:
@echo Building rust programs
@cd rust && cargo xbuild $(rust_build_args)
@rm -rf $(out_dir)/rust && mkdir -p $(out_dir)/rust
@cp $(rust_bins) $(out_dir)/rust
ucore:
@echo Building ucore programs
@mkdir -p ucore/build
@cd ucore/build && cmake $(cmake_build_args) .. && make -j
@rm -rf $(out_dir)/ucore && mkdir -p $(out_dir)/ucore
@cp $(ucore_bin_path)/* $(out_dir)/ucore
biscuit:
ifneq ($(shell uname), Darwin)
@echo Building biscuit programs
@mkdir -p biscuit/build
@cd biscuit/build && cmake $(cmake_build_args) .. && make -j
@rm -rf $(out_dir)/biscuit && mkdir -p $(out_dir)/biscuit
@cp $(biscuit_bin_path)/* $(out_dir)/biscuit
endif
app:
ifneq ($(shell uname), Darwin)
@echo Building custom test programs
@mkdir -p app/build
@cd app/build && cmake $(cmake_build_args) .. && make -j
@rm -rf $(out_dir)/app && mkdir -p $(out_dir)/app
@cp $(app_bin_path)/* $(out_dir)/app
endif
$(busybox):
ifeq ($(arch), x86_64)
@wget https://www.busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-x86_64 -O $(busybox)
else ifeq ($(arch), aarch64)
@wget https://raw.githubusercontent.com/docker-library/busybox/a3f79e474f617f7ff008148555df93bc7ae4a9ab/musl/busybox.tar.xz -O busybox.tar.xz
@mkdir -p tmp
@tar -x -C tmp -f busybox.tar.xz
@mv tmp/bin/busybox $(busybox)
@rm -rf tmp && rm busybox.tar.xz
else ifeq ($(arch), mipsel)
@wget https://www.busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/busybox-mipsel -O $(busybox)
else ifeq ($(arch), $(filter $(arch), riscv64 riscv32))
@wget https://github.com/rcore-os/busybox-prebuilts/raw/master/busybox-1.30.1-${arch}/busybox -O $(busybox)
endif
busybox: $(busybox)
nginx:
ifneq ($(shell uname), Darwin)
@echo Building nginx
mkdir -p $(out_dir)/usr/local/nginx/conf
mkdir -p $(out_dir)/usr/local/nginx/logs
@cd nginx && make arch=$(arch) all
@cp nginx/build/$(arch)/nginx $(out_dir)
@cp nginx/nginx.conf $(out_dir)/usr/local/nginx/conf
endif
redis:
ifneq ($(shell uname), Darwin)
@echo Building redis
@mkdir -p $(out_dir)
@cd redis && make arch=$(arch) all
@cp redis/build/$(arch)/redis-server $(out_dir)/redis-server
@cp redis/build/$(arch)/redis-cli $(out_dir)/redis-cli
@cp redis/redis.conf $(out_dir)/redis.conf
endif
iperf3:
ifeq ($(arch), x86_64)
ifneq ($(shell uname), Darwin)
@echo Building iperf3
@mkdir -p $(out_dir)/dev
@dd if=/dev/urandom of=$(out_dir)/dev/urandom count=512
@cd iperf3 && make arch=$(arch) all
@cp iperf3/build/$(arch)/iperf3 $(out_dir)
endif
endif
$(alpine):
-wget "http://dl-cdn.alpinelinux.org/alpine/v$(alpine_version_major)/releases/$(arch)/$(alpine_file)" -O $(alpine)
alpine: $(alpine)
ifeq ($(arch), $(filter $(arch), x86_64 aarch64))
@mkdir -p $(out_dir)/etc
@echo "nameserver 101.6.6.6" > $(out_dir)/etc/resolv.conf
@cd $(out_dir) && tar xf ../../$(alpine)
endif
$(musl-gcc):
ifeq ($(arch), $(filter $(arch), x86_64))
cd musl-gcc && make all arch=$(arch)
endif
libc-test:
# mkdir -p $(out_dir)/dev/shm
@echo Building libc-test
@mkdir -p $(out_dir)/libc-test
cp -r libc-test $(out_dir)
musl-gcc: $(musl-gcc)
ifeq ($(arch), $(filter $(arch), x86_64))
@echo Building musl-gcc
cp -r $(musl-gcc)/* $(out_dir)/usr/
@mkdir -p $(out_dir)/etc
endif
musl-rust:
ifneq ($(shell uname), Darwin)
@mkdir -p $(out_dir)/etc
@echo Building musl-rust
@mkdir -p $(out_dir)
@cd musl-rust && make all
endif
test:
ifeq ($(arch), $(filter $(arch), x86_64 aarch64))
@echo setup test DIR
@mkdir -p $(out_dir)
@cp -r testsuits_alpine $(out_dir)/test
@cp test.sh $(out_dir)
endif
ifeq ($(prebuilt), 1)
build: $(prebuilt_tar)
@tar -xzf $< -C build
else
build: pre alpine rust ucore biscuit app busybox nginx redis iperf3 test musl-gcc make localtime musl-rust libc-test
endif
$(prebuilt_tar):
@mkdir -p build
@wget https://github.com/rcore-os/rcore-user/releases/download/v$(prebuilt_version)/$(arch).tar.gz -O $@
sfsimg:
ifeq ($(wildcard $(out_qcow2_cache)), )
@make $(out_img)
@echo Generating sfsimg
@qemu-img convert -f raw $(out_img) -O qcow2 $(out_qcow2)
@qemu-img resize $(out_qcow2) +1G
cp $(out_qcow2) $(out_qcow2_cache)
else
cp $(out_qcow2_cache) $(out_qcow2)
endif
# pack qcow2 and img without building again
pack:
rcore-fs-fuse $(out_img) $(out_dir) zip
qemu-img convert -f raw $(out_img) -O qcow2 $(out_qcow2)
qemu-img resize $(out_qcow2) +1G
$(out_img): build rcore-fs-fuse
rcore-fs-fuse $@ $(out_dir) zip
make:
@cd make && make make
# TODO: download from somewhere else
localtime:
cp -r /usr/share/zoneinfo $(out_dir)/usr/share/zoneinfo
ln -sf /usr/share/zoneinfo/Asia/Shanghai $(out_dir)/etc/localtime
cmake:
@cd cmake && make all
pre:
@mkdir -p $(out_dir)
@mkdir -p $(out_dir)/etc
cat /dev/null > $(ld_path_file)
@echo "/usr/$(arch)-linux-musl/lib" >> $(ld_path_file)
@echo "/usr/lib" >> $(ld_path_file)
tar: build
@cd pre build && tar -czf $(arch).tar.gz $(arch)
rcore-fs-fuse:
ifneq ($(shell rcore-fs-fuse dir image git-version), $(rcore_fs_fuse_revision))
@echo Installing rcore-fs-fuse
@cargo install rcore-fs-fuse --git https://github.com/rcore-os/rcore-fs --rev $(rcore_fs_fuse_revision) --force
endif
clean:
@cd rust && cargo clean
@rm -rf biscuit/build ucore/build app/build
@rm -rf $(out_dir)