diff --git a/Makefile b/Makefile index a9ae723fa..ad65867f0 100644 --- a/Makefile +++ b/Makefile @@ -20,22 +20,22 @@ endif -include $(NEMU_HOME)/include/config/auto.conf -include $(NEMU_HOME)/include/config/auto.conf.cmd +include $(NEMU_HOME)/scripts/utils.mk -DIRS-y = src/cpu src/monitor src/utils -DIRS-$(CONFIG_MODE_SYSTEM) += src/memory +ENGINE ?= $(call remove_quote,$(CONFIG_ENGINE)) +INC_DIR += $(NEMU_HOME)/src/engine/$(ENGINE) +DIRS-y = src/engine/$(ENGINE) +NAME = nemu-$(ENGINE) -remove_quote = $(patsubst "%",%,$(1)) +include $(NEMU_HOME)/scripts/isa.mk + +DIRS-y += src/cpu src/monitor src/utils +DIRS-$(CONFIG_MODE_SYSTEM) += src/memory -ISA ?= $(if $(CONFIG_ISA),$(call remove_quote,$(CONFIG_ISA)),x86) -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 @@ -83,8 +83,6 @@ CFLAGS_BUILD += $(if $(CONFIG_CC_ASAN),-fsanitize=address,) CFLAGS += $(CFLAGS_BUILD) LDFLAGS += $(CFLAGS_BUILD) -NAME = nemu-$(ENGINE) - ifndef CONFIG_SHARE ifdef CONFIG_CC_NATIVE_ARCH CFLAGS += -march=native @@ -142,7 +140,6 @@ endif 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 --git a/scripts/isa.mk b/scripts/isa.mk index f8d669f93..6334f261b 100644 --- a/scripts/isa.mk +++ b/scripts/isa.mk @@ -13,10 +13,13 @@ # See the Mulan PSL v2 for more details. #**************************************************************************************/ -ISA ?= x86 -ISAS = $(shell ls $(NEMU_HOME)/src/isa/) +ISA = $(if $(CONFIG_ISA),$(call remove_quote,$(CONFIG_ISA)),x86) +ISAS = $(shell ls $(NEMU_HOME)/src/isa/) + ifeq ($(filter $(ISAS), $(ISA)), ) # ISA must be valid $(error Invalid ISA=$(ISA). Supported: $(ISAS)) endif -NAME := $(ISA)-$(NAME) +CFLAGS += -D__ISA__=$(ISA) CFLAGS += -D__ISA_$(ISA)__=1 + +NAME := $(ISA)-$(NAME) diff --git a/scripts/utils.mk b/scripts/utils.mk new file mode 100644 index 000000000..ec5c9bc65 --- /dev/null +++ b/scripts/utils.mk @@ -0,0 +1,19 @@ +#*************************************************************************************** +# Copyright (c) 2014-2021 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. +#**************************************************************************************/ + +print-%: + @echo $*=$($*) + +remove_quote = $(patsubst "%",%,$(1)) diff --git a/tools/kvm-diff/Makefile b/tools/kvm-diff/Makefile index f11d8a675..7613f6045 100644 --- a/tools/kvm-diff/Makefile +++ b/tools/kvm-diff/Makefile @@ -17,8 +17,12 @@ NAME = kvm SRCS = $(shell find src/ -name "*.c") SHARE = 1 -INC_DIR += $(NEMU_HOME)/include $(NEMU_HOME)/src/isa/x86/include -ISA = x86 +include $(NEMU_HOME)/include/config/auto.conf +include $(NEMU_HOME)/include/config/auto.conf.cmd +include $(NEMU_HOME)/scripts/utils.mk include $(NEMU_HOME)/scripts/isa.mk + +INC_DIR += $(NEMU_HOME)/include $(NEMU_HOME)/src/isa/$(ISA)/include + include $(NEMU_HOME)/scripts/build.mk diff --git a/tools/qemu-dl-diff/Makefile b/tools/qemu-dl-diff/Makefile index aac201f1f..b9aa9262e 100644 --- a/tools/qemu-dl-diff/Makefile +++ b/tools/qemu-dl-diff/Makefile @@ -1,9 +1,14 @@ NAME = qemu + +include $(NEMU_HOME)/include/config/auto.conf +include $(NEMU_HOME)/include/config/auto.conf.cmd +include $(NEMU_HOME)/scripts/utils.mk +include $(NEMU_HOME)/scripts/isa.mk + SRCS = $(shell find src/ -name "*.c" | grep -v "isa") SRCS += $(shell find src/isa/$(ISA) -name "*.c") SHARE = 1 CFLAGS += -DNEMU_HOME=$(NEMU_HOME) -include $(NEMU_HOME)/scripts/isa.mk include $(NEMU_HOME)/scripts/build.mk diff --git a/tools/qemu-socket-diff/Makefile b/tools/qemu-socket-diff/Makefile index 1e763bac2..45c10d18a 100644 --- a/tools/qemu-socket-diff/Makefile +++ b/tools/qemu-socket-diff/Makefile @@ -12,13 +12,18 @@ # # See the Mulan PSL v2 for more details. #**************************************************************************************/ - NAME = qemu + + +include $(NEMU_HOME)/include/config/auto.conf +include $(NEMU_HOME)/include/config/auto.conf.cmd +include $(NEMU_HOME)/scripts/utils.mk +include $(NEMU_HOME)/scripts/isa.mk + SRCS = $(shell find src/ -name "*.c" | grep -v "isa") SRCS += $(shell find src/isa/$(ISA) -name "*.c") SHARE = 1 CFLAGS += -DNEMU_HOME=$(NEMU_HOME) -D_ISA_H_=\"isa/$(ISA).h\" -include $(NEMU_HOME)/scripts/isa.mk include $(NEMU_HOME)/scripts/build.mk