1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-only 2*4882a593Smuzhiyuninclude ../../../../scripts/Kbuild.include 3*4882a593Smuzhiyun 4*4882a593Smuzhiyunall: 5*4882a593Smuzhiyun 6*4882a593Smuzhiyuntop_srcdir = ../../../.. 7*4882a593SmuzhiyunKSFT_KHDR_INSTALL := 1 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun# For cross-builds to work, UNAME_M has to map to ARCH and arch specific 10*4882a593Smuzhiyun# directories and targets in this Makefile. "uname -m" doesn't map to 11*4882a593Smuzhiyun# arch specific sub-directory names. 12*4882a593Smuzhiyun# 13*4882a593Smuzhiyun# UNAME_M variable to used to run the compiles pointing to the right arch 14*4882a593Smuzhiyun# directories and build the right targets for these supported architectures. 15*4882a593Smuzhiyun# 16*4882a593Smuzhiyun# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable. 17*4882a593Smuzhiyun# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable. 18*4882a593Smuzhiyun# 19*4882a593Smuzhiyun# x86_64 targets are named to include x86_64 as a suffix and directories 20*4882a593Smuzhiyun# for includes are in x86_64 sub-directory. s390x and aarch64 follow the 21*4882a593Smuzhiyun# same convention. "uname -m" doesn't result in the correct mapping for 22*4882a593Smuzhiyun# s390x and aarch64. 23*4882a593Smuzhiyun# 24*4882a593Smuzhiyun# No change necessary for x86_64 25*4882a593SmuzhiyunUNAME_M := $(shell uname -m) 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun# Set UNAME_M for arm64 compile/install to work 28*4882a593Smuzhiyunifeq ($(ARCH),arm64) 29*4882a593Smuzhiyun UNAME_M := aarch64 30*4882a593Smuzhiyunendif 31*4882a593Smuzhiyun# Set UNAME_M s390x compile/install to work 32*4882a593Smuzhiyunifeq ($(ARCH),s390) 33*4882a593Smuzhiyun UNAME_M := s390x 34*4882a593Smuzhiyunendif 35*4882a593Smuzhiyun 36*4882a593SmuzhiyunLIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c 37*4882a593SmuzhiyunLIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c lib/x86_64/handlers.S 38*4882a593SmuzhiyunLIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c 39*4882a593SmuzhiyunLIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test 42*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/evmcs_test 43*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid 44*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test 45*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test 46*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/platform_info_test 47*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test 48*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/smm_test 49*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/state_test 50*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test 51*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test 52*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test 53*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test 54*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test 55*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test 56*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test 57*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test 58*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test 59*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/debug_regs 60*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test 61*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += x86_64/user_msr_test 62*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += demand_paging_test 63*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += dirty_log_test 64*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += dirty_log_perf_test 65*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus 66*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += set_memory_region_test 67*4882a593SmuzhiyunTEST_GEN_PROGS_x86_64 += steal_time 68*4882a593Smuzhiyun 69*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += aarch64/get-reg-list 70*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve 71*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += demand_paging_test 72*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += dirty_log_test 73*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus 74*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += set_memory_region_test 75*4882a593SmuzhiyunTEST_GEN_PROGS_aarch64 += steal_time 76*4882a593Smuzhiyun 77*4882a593SmuzhiyunTEST_GEN_PROGS_s390x = s390x/memop 78*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += s390x/resets 79*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += s390x/sync_regs_test 80*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += demand_paging_test 81*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += dirty_log_test 82*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += kvm_create_max_vcpus 83*4882a593SmuzhiyunTEST_GEN_PROGS_s390x += set_memory_region_test 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunTEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) 86*4882a593SmuzhiyunLIBKVM += $(LIBKVM_$(UNAME_M)) 87*4882a593Smuzhiyun 88*4882a593SmuzhiyunINSTALL_HDR_PATH = $(top_srcdir)/usr 89*4882a593SmuzhiyunLINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ 90*4882a593SmuzhiyunLINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include 91*4882a593Smuzhiyunifeq ($(ARCH),x86_64) 92*4882a593SmuzhiyunLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include 93*4882a593Smuzhiyunelse 94*4882a593SmuzhiyunLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include 95*4882a593Smuzhiyunendif 96*4882a593SmuzhiyunCFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ 97*4882a593Smuzhiyun -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ 98*4882a593Smuzhiyun -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ 99*4882a593Smuzhiyun -I$(<D) -Iinclude/$(UNAME_M) -I.. 100*4882a593Smuzhiyun 101*4882a593Smuzhiyunno-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ 102*4882a593Smuzhiyun $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie) 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun# On s390, build the testcases KVM-enabled 105*4882a593Smuzhiyunpgste-option = $(call try-run, echo 'int main() { return 0; }' | \ 106*4882a593Smuzhiyun $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste) 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun 109*4882a593SmuzhiyunLDFLAGS += -pthread $(no-pie-option) $(pgste-option) 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun# After inclusion, $(OUTPUT) is defined and 112*4882a593Smuzhiyun# $(TEST_GEN_PROGS) starts with $(OUTPUT)/ 113*4882a593Smuzhiyuninclude ../lib.mk 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunSTATIC_LIBS := $(OUTPUT)/libkvm.a 116*4882a593SmuzhiyunLIBKVM_C := $(filter %.c,$(LIBKVM)) 117*4882a593SmuzhiyunLIBKVM_S := $(filter %.S,$(LIBKVM)) 118*4882a593SmuzhiyunLIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C)) 119*4882a593SmuzhiyunLIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S)) 120*4882a593SmuzhiyunEXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.* 121*4882a593Smuzhiyun 122*4882a593Smuzhiyunx := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)))) 123*4882a593Smuzhiyun$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c 124*4882a593Smuzhiyun $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S 127*4882a593Smuzhiyun $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ 128*4882a593Smuzhiyun 129*4882a593SmuzhiyunLIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) 130*4882a593Smuzhiyun$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS) 131*4882a593Smuzhiyun $(AR) crs $@ $^ 132*4882a593Smuzhiyun 133*4882a593Smuzhiyunx := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) 134*4882a593Smuzhiyunall: $(STATIC_LIBS) 135*4882a593Smuzhiyun$(TEST_GEN_PROGS): $(STATIC_LIBS) 136*4882a593Smuzhiyun 137*4882a593Smuzhiyuncscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. 138*4882a593Smuzhiyuncscope: 139*4882a593Smuzhiyun $(RM) cscope.* 140*4882a593Smuzhiyun (find $(include_paths) -name '*.h' \ 141*4882a593Smuzhiyun -exec realpath --relative-base=$(PWD) {} \;; \ 142*4882a593Smuzhiyun find . -name '*.c' \ 143*4882a593Smuzhiyun -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files 144*4882a593Smuzhiyun cscope -b 145