xref: /DragonOS/kernel/Makefile (revision 703ce5a77c1e4bebadc5aaa6cbb21595663d4477)
14fda81ceSLoGin# 导入环境变量
27c958c9eSVal213include ./env.mk
34fda81ceSLoGin
47c958c9eSVal213# export ARCH ?= x86_64
54fda81ceSLoGin# 如果是x86_64, 则使用x86_64-unknown-none.json作为target
64fda81ceSLoGinifeq ($(ARCH), x86_64)
74fda81ceSLoGin	export TARGET_JSON=arch/x86_64/x86_64-unknown-none.json
84fda81ceSLoGinelse ifeq ($(ARCH), riscv64)
923ef2b33SLoGin	export TARGET_JSON=riscv64gc-unknown-none-elf
104fda81ceSLoGinendif
114fda81ceSLoGin
124fda81ceSLoGinexport CARGO_ZBUILD=-Z build-std=core,alloc,compiler_builtins -Z build-std-features=compiler-builtins-mem
134fda81ceSLoGin
144fda81ceSLoGin.PHONY: ECHO
154fda81ceSLoGinECHO:
164fda81ceSLoGin	@echo "$@"
17f479f321Sfslongjin
182813126eSloginall:
194fda81ceSLoGin	$(MAKE) -C src all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1)
205df5d799Sfslongjin
21279de4c7Sfslongjin
22f479f321Sfslongjinclean:
232813126eSlogin	rm -f Cargo.lock
244fda81ceSLoGin	$(MAKE) -C src clean ARCH=$(ARCH)
25e92d0228SLoGin
26e92d0228SLoGin.PHONY: fmt
27e92d0228SLoGinfmt:
28*703ce5a7SLoGin	RUSTFLAGS="$(RUSTFLAGS)" cargo fmt --all $(FMT_CHECK)
293660256aSLoGinifeq ($(ARCH), x86_64)
30*703ce5a7SLoGin	RUSTFLAGS="$(RUSTFLAGS)" cargo clippy --all-features
313660256aSLoGinendif
323660256aSLoGin
3370a4e555SLoGin
344fda81ceSLoGin.PHONY: check
354fda81ceSLoGincheck: ECHO
364fda81ceSLoGin# @echo "Checking kernel... ARCH=$(ARCH)"
374fda81ceSLoGin# @exit 1
384fda81ceSLoGinifeq ($(ARCH), x86_64)
39*703ce5a7SLoGin	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target ./src/$(TARGET_JSON)
404fda81ceSLoGinelse ifeq ($(ARCH), riscv64)
41*703ce5a7SLoGin	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 check --workspace $(CARGO_ZBUILD) --message-format=json --target $(TARGET_JSON)
424fda81ceSLoGinendif
4370a4e555SLoGin
4491e9d4abSLoGintest:
4591e9d4abSLoGin# 测试内核库
46*703ce5a7SLoGin	RUSTFLAGS="$(RUSTFLAGS)" cargo +nightly-2024-07-23 test --workspace --exclude dragonos_kernel
4791e9d4abSLoGin
48