forked from arceos-org/arceos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (97 loc) · 2.31 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
# Arguments
ARCH ?= riscv64
SMP ?= 1
MODE ?= release
LOG ?= warn
A ?= apps/helloworld
APP ?= $(A)
APP_FEATURES ?=
DISK_IMG ?= disk.img
FS ?= n
NET ?= n
GRAPHIC ?= n
ifeq ($(wildcard $(APP)),)
$(error Application path "$(APP)" is not valid)
endif
ifneq ($(wildcard $(APP)/Cargo.toml),)
APP_LANG ?= rust
else
APP_LANG ?= c
endif
# Platform
ifeq ($(ARCH), riscv64)
PLATFORM ?= qemu-virt-riscv
TARGET := riscv64gc-unknown-none-elf
else ifeq ($(ARCH), aarch64)
PLATFORM ?= qemu-virt-aarch64
TARGET := aarch64-unknown-none-softfloat
else
$(error "ARCH" must be "riscv64" or "aarch64")
endif
export ARCH
export PLATFORM
export SMP
export MODE
export LOG
# Binutils
ifeq ($(APP_LANG), c)
CROSS_COMPILE ?= $(ARCH)-linux-musl-
CC := $(CROSS_COMPILE)gcc
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
RANLIB := $(CROSS_COMPILE)ranlib
endif
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/axhal/linker_$(ARCH).lds
OUT_ELF := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM).elf
OUT_BIN := $(OUT_DIR)/$(APP_NAME)_$(PLATFORM).bin
all: build
include scripts/make/utils.mk
include scripts/make/cargo.mk
include scripts/make/qemu.mk
include scripts/make/build.mk
include scripts/make/test.mk
build: $(OUT_DIR) $(OUT_BIN)
disasm:
$(OBJDUMP) $(OUT_ELF) | less
run: build justrun
justrun:
$(call run_qemu)
debug: build
$(call run_qemu,-s -S) &
sleep 1
$(GDB) $(OUT_ELF) -ex 'target remote localhost:1234'
clippy:
$(call cargo_clippy)
doc:
$(call cargo_doc)
doc_check_missing:
$(call cargo_doc,-D missing-docs)
fmt:
cargo fmt --all
fmt_c:
@clang-format --style=file -i $(shell find ulib/c_libax -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)),)
@echo -e "$(YELLOW_C)warning$(END_C): disk image \"$(DISK_IMG)\" already exists!"
else
$(call make_disk_image,fat32,$(DISK_IMG))
endif
clean: clean_c
rm -rf $(APP)/*.bin $(APP)/*.elf
cargo clean
clean_c:
rm -rf ulib/c_libax/build_*
rm -rf $(APP)/*.o
.PHONY: all build disasm run justrun debug clippy fmt fmt_c test test_no_fail_fast clean clean_c doc disk_image