-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·182 lines (144 loc) · 4.82 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
ifeq ($(wildcard $(NEMU_HOME)/src/nemu-main.c),)
$(error NEMU_HOME=$(NEMU_HOME) is not a NEMU repo)
endif
CPU_ARCH :=
STEP_RESTORE :=
STEP_GETCP :=
CFLAGS = $(STEP3)
-include $(NEMU_HOME)/include/config/auto.conf
-include $(NEMU_HOME)/include/config/auto.conf.cmd
DIRS-y = src/cpu src/monitor src/utils
DIRS-$(CONFIG_MODE_SYSTEM) += src/memory
remove_quote = $(patsubst "%",%,$(1))
#ISA ?= $(if $(CONFIG_ISA),$(call remove_quote,$(CONFIG_ISA)),x86)
ISA := riscv64
CFLAGS += -D__ISA__=$(ISA)
# CFLAGS += -g
INC_DIR += $(NEMU_HOME)/src/isa/$(ISA)/include
DIRS-y += src/isa/$(ISA)
ENGINE ?= $(call remove_quote,$(CONFIG_ENGINE))
INC_DIR += $(NEMU_HOME)/src/engine/$(ENGINE)
DIRS-y += src/engine/$(ENGINE)
DIRS-$(CONFIG_MODE_USER) += src/user
SRCS-y += src/nemu-main.c
DIRS-$(CONFIG_DEVICE) += src/device/io
SRCS-$(CONFIG_DEVICE) += src/device/device.c src/device/alarm.c src/device/intr.c
SRCS-$(CONFIG_HAS_SERIAL) += src/device/serial.c
SRCS-$(CONFIG_HAS_UARTLITE) += src/device/uartlite.c
SRCS-$(CONFIG_HAS_TIMER) += src/device/timer.c
SRCS-$(CONFIG_HAS_KEYBOARD) += src/device/keyboard.c
SRCS-$(CONFIG_HAS_VGA) += src/device/vga.c
SRCS-$(CONFIG_HAS_AUDIO) += src/device/audio.c
SRCS-$(CONFIG_HAS_DISK) += src/device/disk.c
SRCS-$(CONFIG_HAS_SDCARD) += src/device/sdcard.c
SRCS-$(CONFIG_HAS_FLASH) += src/device/flash.c
SRCS-y += $(shell find $(DIRS-y) -name "*.c")
SRCS = $(SRCS-y)
DIRS-cpp = src/checkpoint src/base src/iostream3 src/profiling
DIRS-y += src/profiling src/checkpoint # profiling.c and cpt_env.c
XSRCS = $(shell find $(DIRS-cpp) -name "*.cpp")
ifeq (${CPU_ARCH}, NEMU_SIM)
CFLAGS += -DNEMU_SIM=1
endif
CC = $(call remove_quote,$(CONFIG_CC))
CXX = $(call remove_quote,$(CONFIG_CXX))
CFLAGS_BUILD += $(call remove_quote,$(CONFIG_CC_OPT))
CFLAGS_BUILD += $(if $(CONFIG_CC_LTO),-flto,)
CFLAGS_BUILD += $(if $(CONFIG_CC_DEBUG),-ggdb3,)
CFLAGS_BUILD += $(if $(CONFIG_CC_ASAN),-fsanitize=address,)
CFLAGS += $(CFLAGS_BUILD)
LDFLAGS += $(CFLAGS_BUILD)
NAME = nemu-$(ENGINE)
LDFLAGS += -lz -lprotobuf
ifndef CONFIG_SHARE
LDFLAGS += -lreadline -ldl -pie
else
SHARE = 1
endif
ifdef CONFIG_DEVICE
LDFLAGS += -lSDL2
endif
ifdef CONFIG_FPU_SOFT
SOFTFLOAT = resource/softfloat/build/softfloat.a
ifeq ($(ISA),riscv64)
SPECIALIZE_TYPE = RISCV
else
SPECIALIZE_TYPE = 8086-SSE
endif
ifdef CONFIG_SHARE
SOFTFLOAT_OPTS_DEFAULT = -DINLINE_LEVEL=5 \
-DSOFTFLOAT_FAST_DIV32TO16 -DSOFTFLOAT_FAST_DIV64TO32
SOFTFLOAT_OPTS_OVERRIDE = SOFTFLOAT_OPTS="$(SOFTFLOAT_OPTS_DEFAULT) -fPIC"
endif
SOFTFLOAT_REPO_PATH = resource/softfloat/repo
ifeq ($(wildcard $(SOFTFLOAT_REPO_PATH)/COPYING.txt),)
$(shell git clone --depth=1 https://github.com/ucb-bar/berkeley-softfloat-3 $(SOFTFLOAT_REPO_PATH))
endif
SOFTFLOAT_BUILD_PATH = $(abspath $(SOFTFLOAT_REPO_PATH)/build/Linux-x86_64-GCC)
INC_DIR += $(SOFTFLOAT_REPO_PATH)/source/include
INC_DIR += $(SOFTFLOAT_REPO_PATH)/source/$(SPECIALIZE_TYPE)
LIBS += $(SOFTFLOAT)
$(SOFTFLOAT):
SPECIALIZE_TYPE=$(SPECIALIZE_TYPE) $(SOFTFLOAT_OPTS_OVERRIDE) $(MAKE) -s -C $(SOFTFLOAT_BUILD_PATH) all
mkdir -p $(@D)
ln -sf $(SOFTFLOAT_BUILD_PATH)/softfloat.a $@
clean-softfloat:
$(MAKE) -s -C $(SOFTFLOAT_BUILD_PATH) clean
clean-all: clean-softfloat
.PHONY: $(SOFTFLOAT) clean-softfloat
else ifdef CONFIG_FPU_HOST
LDFLAGS += -lm
endif
LZ4 = resource/lz4/lib/liblz4.a
LZ4_REPO_PATH = resource/lz4
INC_DIR += $(LZ4_REPO_PATH)/lib
LIBS += $(LZ4)
$(LZ4):
$(MAKE) -s -C $(LZ4_REPO_PATH)
ZSTD = resource/zstd/lib/libzstd.a
ZSTD_REPO_PATH = resource/zstd
INC_DIR += $(ZSTD_REPO_PATH)/lib
LIBS += $(ZSTD)
$(ZSTD):
$(MAKE) -s -C $(ZSTD_REPO_PATH)
ROARING = resource/CRoaring/libroaring.a
ROARING_REPO_PATH = resource/CRoaring
INC_DIR += $(ROARING_REPO_PATH)/include
LIBS += $(ROARING)
include $(NEMU_HOME)/scripts/git.mk
include $(NEMU_HOME)/scripts/config.mk
include $(NEMU_HOME)/scripts/isa.mk
include $(NEMU_HOME)/scripts/build.mk
ifdef CONFIG_DIFFTEST
DIFF_REF_PATH = $(NEMU_HOME)/$(call remove_quote,$(CONFIG_DIFFTEST_REF_PATH))
DIFF_REF_SO = $(DIFF_REF_PATH)/build/$(ISA)-$(call remove_quote,$(CONFIG_DIFFTEST_REF_NAME))-so
MKFLAGS = ISA=$(ISA) SHARE=1 ENGINE=interpreter
ARGS_DIFF = --diff=$(DIFF_REF_SO)
ifndef CONFIG_DIFFTEST_REF_NEMU
$(DIFF_REF_SO):
$(MAKE) -s -C $(DIFF_REF_PATH) $(MKFLAGS)
endif
.PHONY: $(DIFF_REF_SO)
endif
compile_git:
$(call git_commit, "compile")
$(BINARY): compile_git
# Some convenient rules
override ARGS ?= --log=$(BUILD_DIR)/nemu-log.txt
override ARGS += $(ARGS_DIFF)
# Command to execute NEMU
IMG ?=
NEMU_EXEC := $(BINARY) $(ARGS) $(IMG)
run-env: $(BINARY) $(DIFF_REF_SO)
run: run-env
$(call git_commit, "run")
$(NEMU_EXEC)
gdb: run-env
$(call git_commit, "gdb")
gdb -s $(BINARY) --args $(NEMU_EXEC)
clean-tools = $(dir $(shell find ./tools -name "Makefile"))
$(clean-tools):
-@$(MAKE) -s -C $@ clean
clean-tools: $(clean-tools)
clean-all: clean distclean clean-tools
.PHONY: run gdb run-env clean-tools clean-all $(clean-tools)