-
Notifications
You must be signed in to change notification settings - Fork 302
/
Copy pathMakefile
215 lines (180 loc) · 5.19 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
# 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
# - `LOG:` Logging level: warn, error, info, debug, trace
# - `V`: Verbose level: (empty), 1, 2
# - `TARGET_DIR`: Artifact output directory (cargo target directory)
# - `EXTRA_CONFIG`: Extra config specification file
# - `OUT_CONFIG`: Final config file that takes effect
# * App options:
# - `A` or `APP`: Path to the application
# - `FEATURES`: Features os ArceOS 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)
# - `BUS`: Device bus type: mmio, pci
# - `MEM`: Memory size (default is 128M)
# - `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, bridge
# - `VFIO_PCI`: PCI device address in the format "bus:dev.func" to passthrough
# - `VHOST`: Enable vhost-net for tap backend (only for `NET_DEV=tap`)
# * Network options:
# - `IP`: ArceOS 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)
# General options
ARCH ?= x86_64
PLATFORM ?=
SMP ?= 1
MODE ?= release
LOG ?= warn
V ?=
TARGET_DIR ?= $(PWD)/target
EXTRA_CONFIG ?=
OUT_CONFIG ?= $(PWD)/.axconfig.toml
# App options
A ?= examples/helloworld
APP ?= $(A)
FEATURES ?=
APP_FEATURES ?=
# QEMU options
BLK ?= n
NET ?= n
GRAPHIC ?= n
BUS ?= pci
MEM ?= 128M
ACCEL ?=
DISK_IMG ?= disk.img
QEMU_LOG ?= n
NET_DUMP ?= n
NET_DEV ?= user
VFIO_PCI ?=
VHOST ?= n
# Network options
IP ?= 10.0.2.15
GW ?= 10.0.2.2
# 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
# Feature parsing
include scripts/make/features.mk
# Platform resolving
include scripts/make/platform.mk
# Target
ifeq ($(ARCH), x86_64)
TARGET := x86_64-unknown-none
else ifeq ($(ARCH), aarch64)
ifeq ($(findstring fp_simd,$(FEATURES)),)
TARGET := aarch64-unknown-none-softfloat
else
TARGET := aarch64-unknown-none
endif
else ifeq ($(ARCH), riscv64)
TARGET := riscv64gc-unknown-none-elf
else
$(error "ARCH" must be one of "x86_64", "riscv64", or "aarch64")
endif
export AX_ARCH=$(ARCH)
export AX_PLATFORM=$(PLAT_NAME)
export AX_SMP=$(SMP)
export AX_MODE=$(MODE)
export AX_LOG=$(LOG)
export AX_TARGET=$(TARGET)
export AX_IP=$(IP)
export AX_GW=$(GW)
ifneq ($(filter $(MAKECMDGOALS),unittest unittest_no_fail_fast),)
# When running unit tests, set `AX_CONFIG_PATH` to empty for dummy config
unexport AX_CONFIG_PATH
else
export AX_CONFIG_PATH=$(OUT_CONFIG)
endif
# 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 := $(TARGET_DIR)/$(TARGET)/$(MODE)/linker_$(PLAT_NAME).lds
OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLAT_NAME).elf
OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLAT_NAME).bin
all: build
include scripts/make/utils.mk
include scripts/make/config.mk
include scripts/make/build.mk
include scripts/make/qemu.mk
ifeq ($(PLAT_NAME), aarch64-raspi4)
include scripts/make/raspi4.mk
else ifeq ($(PLAT_NAME), aarch64-bsta1000b)
include scripts/make/bsta1000b-fada.mk
endif
defconfig: _axconfig-gen
$(call defconfig)
oldconfig: _axconfig-gen
$(call oldconfig)
build: $(OUT_DIR) $(OUT_BIN)
disasm:
$(OBJDUMP) $(OUT_ELF) | less
run: build justrun
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'
clippy: oldconfig
ifeq ($(origin ARCH), command line)
$(call cargo_clippy,--target $(TARGET))
else
$(call cargo_clippy)
endif
doc: oldconfig
$(call cargo_doc)
doc_check_missing: oldconfig
$(call cargo_doc)
fmt:
cargo fmt --all
fmt_c:
@clang-format --style=file -i $(shell find ulib/axlibc -iname '*.c' -o -iname '*.h')
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
rm -rf $(APP)/*.bin $(APP)/*.elf $(OUT_CONFIG)
cargo clean
clean_c::
rm -rf ulib/axlibc/build_*
rm -rf $(app-objs)
.PHONY: all defconfig oldconfig \
build disasm run justrun debug \
clippy doc doc_check_missing fmt fmt_c unittest unittest_no_fail_fast \
disk_img clean clean_c