forked from syswonder/ruxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
284 lines (241 loc) · 7.44 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# Available arguments:
# * General options:
# - `ARCH`: Target architecture: x86_64, riscv64, aarch64
# - `PLATFORM`: Target platform in the `platforms` directory
# - `SMP`: Number of CPUs
# - `MODE`: Build mode: release, debug, reldebug
# - `LOG:` Logging level: warn, error, info, debug, trace
# - `V`: Verbose level: (empty), 1, 2
# - `ARGS`: Command-line arguments separated by comma. Only available when feature `alloc` is enabled.
# - `ENVS`: Environment variables, separated by comma between key value pairs. Only available when feature `alloc` is enabled.
# * App options:
# - `A` or `APP`: Path to the application
# - `FEATURES`: Features of Ruxos modules to be enabled.
# - `APP_FEATURES`: Features of (rust) apps to be enabled.
# * QEMU options:
# - `BLK`: Enable storage devices (virtio-blk)
# - `NET`: Enable network devices (virtio-net)
# - `GRAPHIC`: Enable display devices and graphic output (virtio-gpu)
# - `V9P`: Enable virtio-9p devices
# - `BUS`: Device bus type: mmio, pci
# - `DISK_IMG`: Path to the virtual disk image
# - `ACCEL`: Enable hardware acceleration (KVM on linux)
# - `QEMU_LOG`: Enable QEMU logging (log file is "qemu.log")
# - `NET_DUMP`: Enable network packet dump (log file is "netdump.pcap")
# - `NET_DEV`: QEMU netdev backend types: user, tap
# - `START_PORT`: The starting port number for the open ports in QEMU (default is port 5555)
# - `PORT_NUM`: The number of open ports in QEMU (default is 5)
# * 9P options:
# - `V9P_PATH`: Host path for backend of virtio-9p
# - `NET_9P_ADDR`: Server address and port for 9P netdev
# - `ANAME_9P`: Path for root of 9pfs(parameter of TATTACH for root)
# - `PROTOCOL_9P`: Default protocol version selected for 9P
# * Network options:
# - `IP`: Ruxos IPv4 address (default is 10.0.2.15 for QEMU user netdev)
# - `GW`: Gateway IPv4 address (default is 10.0.2.2 for QEMU user netdev)
# * Libc options:
# - `MUSL`: Link C app with musl libc
# General options
ARCH ?= x86_64
PLATFORM ?=
SMP ?= 1
MODE ?= release
LOG ?= warn
V ?=
# App options
A ?= apps/c/helloworld
APP ?= $(A)
FEATURES ?=
APP_FEATURES ?=
# QEMU options
BLK ?= n
NET ?= n
GRAPHIC ?= n
V9P ?= n
BUS ?= mmio
RISCV_BIOS ?= default
DISK_IMG ?= disk.img
QEMU_LOG ?= n
NET_DUMP ?= n
NET_DEV ?= user
V9P_PATH ?= ./
NET_9P_ADDR ?= 127.0.0.1:564
ANAME_9P ?= ./
PROTOCOL_9P ?= 9P2000.L
START_PORT ?= 5555
PORTS_NUM ?= 5
# Network options
IP ?= 10.0.2.15
GW ?= 10.0.2.2
# args and envs
ARGS ?=
ENVS ?=
# Libc options
MUSL ?= n
# App type
ifeq ($(wildcard $(APP)),)
$(error Application path "$(APP)" is not valid)
endif
ifneq ($(wildcard $(APP)/Cargo.toml),)
APP_TYPE := rust
else
APP_TYPE := c
endif
# Architecture, platform and target
ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),)
PLATFORM_NAME :=
else ifneq ($(PLATFORM),)
# `PLATFORM` is specified, override the `ARCH` variables
builtin_platforms := $(patsubst platforms/%.toml,%,$(wildcard platforms/*))
ifneq ($(filter $(PLATFORM),$(builtin_platforms)),)
# builtin platform
PLATFORM_NAME := $(PLATFORM)
_arch := $(word 1,$(subst -, ,$(PLATFORM)))
else ifneq ($(wildcard $(PLATFORM)),)
# custom platform, read the "platform" field from the toml file
PLATFORM_NAME := $(shell cat $(PLATFORM) | sed -n 's/^platform = "\([a-z0-9A-Z_\-]*\)"/\1/p')
_arch := $(shell cat $(PLATFORM) | sed -n 's/^arch = "\([a-z0-9A-Z_\-]*\)"/\1/p')
else
$(error "PLATFORM" must be one of "$(builtin_platforms)" or a valid path to a toml file)
endif
ifeq ($(origin ARCH),command line)
ifneq ($(ARCH),$(_arch))
$(error "ARCH=$(ARCH)" is not compatible with "PLATFORM=$(PLATFORM)")
endif
endif
ARCH := $(_arch)
endif
ifeq ($(ARCH), x86_64)
# Don't enable kvm for WSL/WSL2.
ACCEL ?= $(if $(findstring -microsoft, $(shell uname -r | tr '[:upper:]' '[:lower:]')),n,y)
PLATFORM_NAME ?= x86_64-qemu-q35
TARGET := x86_64-unknown-none
ifeq ($(findstring fp_simd,$(FEATURES)),)
TARGET_CFLAGS := -mno-sse
endif
BUS := pci
else ifeq ($(ARCH), riscv64)
ACCEL ?= n
PLATFORM_NAME ?= riscv64-qemu-virt
TARGET := riscv64gc-unknown-none-elf
ifeq ($(findstring fp_simd,$(FEATURES)),)
TARGET_CFLAGS := -mabi=lp64d
endif
else ifeq ($(ARCH), aarch64)
ACCEL ?= n
PLATFORM_NAME ?= aarch64-qemu-virt
TARGET := aarch64-unknown-none-softfloat
ifeq ($(findstring fp_simd,$(FEATURES)),)
TARGET_CFLAGS := -mgeneral-regs-only
endif
else
$(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64")
endif
export TARGET_CC = $(CC)
export TARGET_CFLAGS
export RUX_ARCH=$(ARCH)
export RUX_PLATFORM=$(PLATFORM_NAME)
export RUX_SMP=$(SMP)
export RUX_MODE=$(MODE)
export RUX_LOG=$(LOG)
export RUX_TARGET=$(TARGET)
export RUX_IP=$(IP)
export RUX_GW=$(GW)
export RUX_9P_ADDR = $(NET_9P_ADDR)
export RUX_ANAME_9P = $(ANAME_9P)
export RUX_PROTOCOL_9P = $(PROTOCOL_9P)
export RUX_MUSL=$(MUSL)
# Binutils
CROSS_COMPILE ?= $(ARCH)-linux-musl-
CC := $(CROSS_COMPILE)gcc
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
LD := rust-lld -flavor gnu
OBJDUMP ?= rust-objdump -d --print-imm-hex --x86-asm-syntax=intel
OBJCOPY ?= rust-objcopy --binary-architecture=$(ARCH)
GDB ?= gdb-multiarch
# Paths
OUT_DIR ?= $(APP)
APP_NAME := $(shell basename $(APP))
LD_SCRIPT := $(CURDIR)/modules/ruxhal/linker_$(PLATFORM_NAME).lds
OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).elf
OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM_NAME).bin
PREBUILD := $(CURDIR)/scripts/prebuild/$(ARCH).mk
all: build
# prebuild option to be overriden in `$(PREBUILD)`
define run_prebuild
endef
# prebuild makefile might override some variables by their own
# so it must be placed before the rest of the makefiles
ifneq ($(wildcard $(PREBUILD)),)
include $(PREBUILD)
endif
include scripts/make/utils.mk
include scripts/make/build.mk
include scripts/make/qemu.mk
include scripts/make/test.mk
ifeq ($(PLATFORM_NAME), aarch64-raspi4)
include scripts/make/raspi4.mk
else ifeq ($(PLATFORM_NAME), aarch64-bsta1000b)
include scripts/make/bsta1000b-fada.mk
endif
_force: ;
# prebuild scripts must track their dependencies by themselves
prebuild: _force
$(call run_prebuild)
$(OUT_DIR): prebuild
$(OUT_BIN): prebuild
build: $(OUT_DIR) $(OUT_BIN)
disasm:
$(OBJDUMP) $(OUT_ELF) | less
run: build
$(call run_qemu)
justrun:
$(call run_qemu)
debug: build
$(call run_qemu_debug) &
sleep 1
$(GDB) $(OUT_ELF) \
-ex 'target remote localhost:1234' \
-ex 'b rust_entry' \
-ex 'continue' \
-ex 'disp /16i $$pc'
debug_no_attach: build
$(call run_qemu_debug)
clippy:
ifeq ($(origin ARCH), command line)
$(call cargo_clippy,--target $(TARGET))
else
$(call cargo_clippy)
endif
doc:
$(call cargo_doc)
doc_check_missing:
$(call cargo_doc)
fmt:
cargo fmt --all
fmt_c:
@clang-format --style=file -i $(shell find ulib/ruxlibc -iname '*.c' -o -iname '*.h')
test:
$(call app_test)
unittest:
$(call unit_test)
unittest_no_fail_fast:
$(call unit_test,--no-fail-fast)
disk_img:
ifneq ($(wildcard $(DISK_IMG)),)
@printf "$(YELLOW_C)warning$(END_C): disk image \"$(DISK_IMG)\" already exists!\n"
else
$(call make_disk_image,fat32,$(DISK_IMG))
endif
clean: clean_c clean_musl
rm -rf $(APP)/*.bin $(APP)/*.elf
cargo clean
clean_c::
rm -rf ulib/ruxlibc/build_*
rm -rf $(app-objs)
clean_musl:
rm -rf ulib/ruxmusl/build_*
rm -rf ulib/ruxmusl/install
.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c\
clean_musl doc disk_image debug_no_attach prebuild _force