xref: /DragonOS/kernel/Makefile (revision 886ce28516f9e3e5940840d1ae64ec3e9c8875fa)
1# 导入环境变量
2include ./env.mk
3
4# export ARCH ?= x86_64
5# 如果是x86_64, 则使用x86_64-unknown-none.json作为target
6ifeq ($(ARCH), x86_64)
7	export TARGET_JSON=arch/x86_64/x86_64-unknown-none.json
8else ifeq ($(ARCH), riscv64)
9	export TARGET_JSON=riscv64gc-unknown-none-elf
10endif
11
12export CARGO_ZBUILD=-Z build-std=core,alloc,compiler_builtins -Z build-std-features=compiler-builtins-mem
13
14.PHONY: ECHO
15ECHO:
16	@echo "$@"
17
18all:
19	$(MAKE) -C src all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1)
20
21
22clean:
23	rm -f Cargo.lock
24	$(MAKE) -C src clean ARCH=$(ARCH)
25
26.PHONY: fmt
27fmt:
28	RUSTFLAGS="$(RUSTFLAGS)" cargo fmt --all $(FMT_CHECK)
29ifeq ($(ARCH), x86_64)
30	RUSTFLAGS="$(RUSTFLAGS)" cargo clippy --all-features
31endif
32
33
34.PHONY: check
35check: ECHO
36# @echo "Checking kernel... ARCH=$(ARCH)"
37# @exit 1
38ifeq ($(ARCH), x86_64)
39	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target ./src/$(TARGET_JSON)
40else ifeq ($(ARCH), riscv64)
41	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target $(TARGET_JSON)
42endif
43
44test:
45# 测试内核库
46	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 test --workspace --exclude dragonos_kernel
47
48