xref: /DragonBoot/Makefile (revision 0ec3a34a58ffc0a9c51a23a7ee5e7d803a0060cd)
1*0ec3a34aSLoGin.PHONY: all clean fmt clippy qemu run
2abdb84b8SLoGin
3abdb84b8SLoGin# 检查是否需要进行fmt --check
4abdb84b8SLoGin# 解析命令行参数
5abdb84b8SLoGinFMT_CHECK?=0
6abdb84b8SLoGin
7abdb84b8SLoGinifeq ($(FMT_CHECK), 1)
8abdb84b8SLoGin	FMT_CHECK=--check
9abdb84b8SLoGinelse
10abdb84b8SLoGin	FMT_CHECK=
11abdb84b8SLoGinendif
12abdb84b8SLoGin
13abdb84b8SLoGinexport ARCH ?= riscv64
14abdb84b8SLoGin
15*0ec3a34aSLoGinifeq ($(ARCH), riscv64)
16*0ec3a34aSLoGin	RUST_TARGET=riscv64imac-unknown-none-elf
17*0ec3a34aSLoGinelse
18*0ec3a34aSLoGin	@echo "ARCH=$(ARCH) is not supported"
19*0ec3a34aSLoGin	@exit 1
20*0ec3a34aSLoGinendif
21*0ec3a34aSLoGin
22*0ec3a34aSLoGinEFI_OUTPUT_DIR?=output
23*0ec3a34aSLoGin
24*0ec3a34aSLoGinOBJCOPY_FLAGS=
25*0ec3a34aSLoGin
26*0ec3a34aSLoGin# OBJCOPY_FLAGS+=-j .header -j .text -j .plt -j .sdata -j .data -j .dynamic -j .dynstr -j .dynsym -j .rel -j .rel.*  -j .rela* -j .reloc -j .reloc* -j .sbss
27*0ec3a34aSLoGin
28*0ec3a34aSLoGin
29*0ec3a34aSLoGinOBJCOPY_FLAGS+= --output-target=binary
30*0ec3a34aSLoGin
31*0ec3a34aSLoGinexport RUSTFLAGS=-Crelocation-model=pic
32*0ec3a34aSLoGin
33*0ec3a34aSLoGinifeq ($(ARCH), riscv64)
34*0ec3a34aSLoGin	OBJCOPY_FLAGS+= --binary-architecture=riscv
35*0ec3a34aSLoGinelse
36*0ec3a34aSLoGin	@echo "ARCH=$(ARCH) is not supported"
37*0ec3a34aSLoGin	@exit 1
38*0ec3a34aSLoGinendif
39*0ec3a34aSLoGin
40abdb84b8SLoGinall:
41*0ec3a34aSLoGin	@mkdir -p $(EFI_OUTPUT_DIR)
42abdb84b8SLoGinifeq ($(ARCH), riscv64)
43abdb84b8SLoGin	$(MAKE) riscv64imac
44abdb84b8SLoGinelse
45abdb84b8SLoGin	@echo "ARCH=$(ARCH) is not supported"
46abdb84b8SLoGin	@exit 1
47abdb84b8SLoGinendif
48abdb84b8SLoGin
49abdb84b8SLoGinriscv64imac:
50*0ec3a34aSLoGin	RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target riscv64imac-unknown-none-elf
51*0ec3a34aSLoGin	rust-objcopy $(OBJCOPY_FLAGS) target/$(RUST_TARGET)/release/dragon_boot $(EFI_OUTPUT_DIR)/dragon_boot-riscv64imac.efi
52*0ec3a34aSLoGin
53*0ec3a34aSLoGinrun:
54*0ec3a34aSLoGin	@$(MAKE) all || exit 1
55*0ec3a34aSLoGin	@$(MAKE) qemu
56abdb84b8SLoGin
57abdb84b8SLoGinclean:
58abdb84b8SLoGin	@cargo clean
59abdb84b8SLoGin
60abdb84b8SLoGin
61abdb84b8SLoGinfmt:
62abdb84b8SLoGin	@cargo fmt --all $(FMT_CHECK)
63*0ec3a34aSLoGin
64*0ec3a34aSLoGinclippy:
65*0ec3a34aSLoGin	@cargo clippy --all --target $(RUST_TARGET) --all-features
66*0ec3a34aSLoGin
67*0ec3a34aSLoGin
68*0ec3a34aSLoGinqemu:
69*0ec3a34aSLoGin	cd tools && ./run-qemu.sh && cd ..
70