#*************************************************************************************** # Copyright (c) 2014-2022 Zihao Yu, Nanjing University # # NEMU is licensed under Mulan PSL v2. # You can use this software according to the terms and conditions of the Mulan PSL v2. # You may obtain a copy of Mulan PSL v2 at: # http://license.coscl.org.cn/MulanPSL2 # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. # # See the Mulan PSL v2 for more details. #**************************************************************************************/
# Sanity check # 环境检查 # 条件的检查:ifeq 判断 $(wildcard $(NEMU_HOME)/src/nemu-main.c) 的结果是否为空。空结果表示 nemu-main.c 文件在指定目录下不存在。 ifeq ($(wildcard$(NEMU_HOME)/src/nemu-main.c),) $(error NEMU_HOME=$(NEMU_HOME) is not a NEMU repo) endif
# Include variables and rules generated by menuconfig # 导入一些配置文件(自动生成) -include$(NEMU_HOME)/include/config/auto.conf -include$(NEMU_HOME)/include/config/auto.conf.cmd
# Extract variabls from menuconfig GUEST_ISA ?= $(call remove_quote,$(CONFIG_ISA)) ENGINE ?= $(call remove_quote,$(CONFIG_ENGINE)) NAME = $(GUEST_ISA)-nemu-$(ENGINE)
# Include all filelist.mk to merge file lists FILELIST_MK = $(shell find -L ./src -name "filelist.mk") include$(FILELIST_MK)
# Filter out directories and files in blacklist to obtain the final set of source files DIRS-BLACKLIST-y += $(DIRS-BLACKLIST) SRCS-BLACKLIST-y += $(SRCS-BLACKLIST) $(shell find -L $(DIRS-BLACKLIST-y) -name "*.c") SRCS-y += $(shell find -L $(DIRS-y) -name "*.c") SRCS = $(filter-out $(SRCS-BLACKLIST-y),$(SRCS-y))
# Include rules for menuconfig include$(NEMU_HOME)/scripts/config.mk
ifdef CONFIG_TARGET_AM include$(AM_HOME)/Makefile LINKAGE += $(ARCHIVES) else # Include rules to build NEMU include$(NEMU_HOME)/scripts/native.mk endif
#*************************************************************************************** # Copyright (c) 2014-2022 Zihao Yu, Nanjing University # # NEMU is licensed under Mulan PSL v2. # You can use this software according to the terms and conditions of the Mulan PSL v2. # You may obtain a copy of Mulan PSL v2 at: # http://license.coscl.org.cn/MulanPSL2 # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. # # See the Mulan PSL v2 for more details. #**************************************************************************************/
ifeq ($(wildcard .config),) $(warning$(COLOR_RED)Warning: .config does not exists!$(COLOR_END)) $(warning$(COLOR_RED)To build the project, first run 'make menuconfig'.$(COLOR_END)) endif
# Help text used by make help help: @echo ' menuconfig - Update current config utilising a menu based program' @echo ' savedefconfig - Save current config as configs/defconfig (minimal config)'
#*************************************************************************************** # Copyright (c) 2014-2022 Zihao Yu, Nanjing University # # NEMU is licensed under Mulan PSL v2. # You can use this software according to the terms and conditions of the Mulan PSL v2. # You may obtain a copy of Mulan PSL v2 at: # http://license.coscl.org.cn/MulanPSL2 # # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. # # See the Mulan PSL v2 for more details. #**************************************************************************************/
# Add necessary options if the target is a shared library ifeq ($(SHARE),1) SO = -so CFLAGS += -fPIC -fvisibility=hidden LDFLAGS += -shared -fPIC endif
ifeq ($(wildcard .config),) $(warning$(COLOR_RED)Warning: .config does not exists!$(COLOR_END)) $(warning$(COLOR_RED)To build the project, first run 'make menuconfig'.$(COLOR_END)) endif
make run make[1]: Entering directory '/home/luyoung/ysyx-workbench' make[1]: Leaving directory '/home/luyoung/ysyx-workbench' /home/luyoung/ysyx-workbench/nemu/build/riscv32-nemu-interpreter --log=/home/luyoung/ysyx-workbench/nemu/build/nemu-log.txt over ...
# Makefile for AbstractMachine Kernels and Libraries
### *Get a more readable version of this Makefile* by `make html` (requires python-markdown) html: cat Makefile | sed 's/^\([^#]\)/ \1/g' | markdown_py > Makefile.html .PHONY: html
## 1. Basic Setup and Checks
### Default to create a bare-metal kernel image ifeq ($(MAKECMDGOALS),) MAKECMDGOALS = image .DEFAULT_GOAL = image endif
### Override checks when `make clean/clean-all/html` ifeq ($(findstring$(MAKECMDGOALS),clean|clean-all|html),)
### Print build info message $(info # Building $(NAME)-$(MAKECMDGOALS) [$(ARCH)])
### Check: environment variable `$AM_HOME` looks sane ifeq ($(wildcard$(AM_HOME)/am/include/am.h),) $(error $$AM_HOME must be an AbstractMachine repo) endif
### Check: environment variable `$ARCH` must be in the supported list ARCHS = $(basename $(notdir $(shell ls $(AM_HOME)/scripts/*.mk))) ifeq ($(filter$(ARCHS), $(ARCH)), ) $(error Expected $$ARCH in {$(ARCHS)}, Got "$(ARCH)") endif
### Extract instruction set architecture (`ISA`) and platform from `$ARCH`. Example: `ARCH=x86_64-qemu -> ISA=x86_64; PLATFORM=qemu` ARCH_SPLIT = $(subst -, ,$(ARCH)) ISA = $(word 1,$(ARCH_SPLIT)) PLATFORM = $(word 2,$(ARCH_SPLIT))
### Check if there is something to build ifeq ($(flavor SRCS), undefined) $(error Nothing to build) endif
### Paste in arch-specific configurations (e.g., from `scripts/x86_64-qemu.mk`) -include $(AM_HOME)/scripts/$(ARCH).mk
### Fall back to native gcc/binutils if there is no cross compiler ifeq ($(wildcard $(shell which $(CC))),) $(info # $(CC) not found; fall back to default gcc and binutils) CROSS_COMPILE := endif
## 5. Compilation Rules
### Rule (compile): a single `.c` -> `.o` (gcc) $(DST_DIR)/%.o: %.c @mkdir -p $(dir $@) && echo + CC $< @$(CC) -std=gnu11 $(CFLAGS) -c -o $@ $(realpath $<)