1ec8f24b7SThomas Gleixner# SPDX-License-Identifier: GPL-2.0-only 2b61442dfSMasahiro Yamadainclude ../../../build/Build.include 3c2390f16SPaolo Bonzini 4783e9e51SPaolo Bonziniall: 5783e9e51SPaolo Bonzini 6cc68765dSAndrew Jonestop_srcdir = ../../../.. 7*baea2ce5SPaolo Bonziniinclude $(top_srcdir)/scripts/subarch.include 8*baea2ce5SPaolo BonziniARCH ?= $(SUBARCH) 966d69e08SShuah Khan 1066d69e08SShuah Khan# For cross-builds to work, UNAME_M has to map to ARCH and arch specific 1166d69e08SShuah Khan# directories and targets in this Makefile. "uname -m" doesn't map to 1266d69e08SShuah Khan# arch specific sub-directory names. 1366d69e08SShuah Khan# 1466d69e08SShuah Khan# UNAME_M variable to used to run the compiles pointing to the right arch 1566d69e08SShuah Khan# directories and build the right targets for these supported architectures. 1666d69e08SShuah Khan# 1766d69e08SShuah Khan# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable. 1866d69e08SShuah Khan# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable. 1966d69e08SShuah Khan# 2066d69e08SShuah Khan# x86_64 targets are named to include x86_64 as a suffix and directories 2166d69e08SShuah Khan# for includes are in x86_64 sub-directory. s390x and aarch64 follow the 2266d69e08SShuah Khan# same convention. "uname -m" doesn't result in the correct mapping for 2366d69e08SShuah Khan# s390x and aarch64. 2466d69e08SShuah Khan# 2566d69e08SShuah Khan# No change necessary for x86_64 26783e9e51SPaolo BonziniUNAME_M := $(shell uname -m) 27783e9e51SPaolo Bonzini 2866d69e08SShuah Khan# Set UNAME_M for arm64 compile/install to work 2966d69e08SShuah Khanifeq ($(ARCH),arm64) 3066d69e08SShuah Khan UNAME_M := aarch64 3166d69e08SShuah Khanendif 3266d69e08SShuah Khan# Set UNAME_M s390x compile/install to work 3366d69e08SShuah Khanifeq ($(ARCH),s390) 3466d69e08SShuah Khan UNAME_M := s390x 3566d69e08SShuah Khanendif 363e06cdf1SAnup Patel# Set UNAME_M riscv compile/install to work 373e06cdf1SAnup Patelifeq ($(ARCH),riscv) 383e06cdf1SAnup Patel UNAME_M := riscv 393e06cdf1SAnup Patelendif 4066d69e08SShuah Khan 41cf97d5e9SDavid MatlackLIBKVM += lib/assert.c 42cf97d5e9SDavid MatlackLIBKVM += lib/elf.c 43cf97d5e9SDavid MatlackLIBKVM += lib/guest_modes.c 44cf97d5e9SDavid MatlackLIBKVM += lib/io.c 45cf97d5e9SDavid MatlackLIBKVM += lib/kvm_util.c 46cf97d5e9SDavid MatlackLIBKVM += lib/perf_test_util.c 47cf97d5e9SDavid MatlackLIBKVM += lib/rbtree.c 48cf97d5e9SDavid MatlackLIBKVM += lib/sparsebit.c 49cf97d5e9SDavid MatlackLIBKVM += lib/test_util.c 50cf97d5e9SDavid Matlack 51cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/apic.c 52cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/handlers.S 5371d48966SDavid MatlackLIBKVM_x86_64 += lib/x86_64/perf_test_util.c 54cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/processor.c 55cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/svm.c 56cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/ucall.c 57cf97d5e9SDavid MatlackLIBKVM_x86_64 += lib/x86_64/vmx.c 58cf97d5e9SDavid Matlack 59cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/gic.c 60cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/gic_v3.c 61cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/handlers.S 62cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/processor.c 63cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/spinlock.c 64cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/ucall.c 65cf97d5e9SDavid MatlackLIBKVM_aarch64 += lib/aarch64/vgic.c 66cf97d5e9SDavid Matlack 67cf97d5e9SDavid MatlackLIBKVM_s390x += lib/s390x/diag318_test_handler.c 68cf97d5e9SDavid MatlackLIBKVM_s390x += lib/s390x/processor.c 69cf97d5e9SDavid MatlackLIBKVM_s390x += lib/s390x/ucall.c 70cf97d5e9SDavid Matlack 71cf97d5e9SDavid MatlackLIBKVM_riscv += lib/riscv/processor.c 72cf97d5e9SDavid MatlackLIBKVM_riscv += lib/riscv/ucall.c 73783e9e51SPaolo Bonzini 748448ec59SBen Gardon# Non-compiled test targets 758448ec59SBen GardonTEST_PROGS_x86_64 += x86_64/nx_huge_pages_test.sh 768448ec59SBen Gardon 778448ec59SBen Gardon# Compiled test targets 789e6d484fSVitaly KuznetsovTEST_GEN_PROGS_x86_64 = x86_64/cpuid_test 799e6d484fSVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/cr4_cpuid_sync_test 8077a3aa26SEmanuele Giuseppe EspositoTEST_GEN_PROGS_x86_64 += x86_64/get_msr_index_features 8118178ff8SVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/evmcs_test 8239bbcc3aSAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/emulator_error_test 836c2fa8b2SOliver UptonTEST_GEN_PROGS_x86_64 += x86_64/fix_hypercall_test 842c7f76b4SVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/hyperv_clock 857edcb734SVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid 86e2e1cc1fSVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/hyperv_features 87e67bd7dfSVitaly KuznetsovTEST_GEN_PROGS_x86_64 += x86_64/hyperv_svm_test 8861fb1c54SOliver UptonTEST_GEN_PROGS_x86_64 += x86_64/kvm_clock_test 89ac4a4d6dSOliver UptonTEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test 909dba988eSAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test 912325d4ddSSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/monitor_mwait_test 9261cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/platform_info_test 93bef9a701SJim MattsonTEST_GEN_PROGS_x86_64 += x86_64/pmu_event_filter_test 943df22524SEmanuele Giuseppe EspositoTEST_GEN_PROGS_x86_64 += x86_64/set_boot_cpu_id 9561cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test 9661cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/smm_test 9761cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/state_test 988d7fbf01SMakarand SonareTEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test 9994c4b76bSAndrew JonesTEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test 1001ad32105SMaxim LevitskyTEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test 101d8969871SMaciej S. SzmigieroTEST_GEN_PROGS_x86_64 += x86_64/svm_nested_soft_inject_test 102e467b0deSDavid WoodhouseTEST_GEN_PROGS_x86_64 += x86_64/tsc_scaling_sync 10361cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test 104eede2065SJue WangTEST_GEN_PROGS_x86_64 += x86_64/ucna_injection_test 10510e7a099SSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/userspace_io_test 1063cea1891SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test 10797a71a54SJim MattsonTEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test 10861cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test 10909444420SPaolo BonziniTEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test 110e337f7e0SSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/vmx_exception_with_invalid_guest_state 111ce30d8b9SSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/vmx_msrs_test 112ab1ef344SSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/vmx_invalid_nested_guest_state 113da1e3071SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test 11461cfcd54SAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test 115efe58549SIlias StamatisTEST_GEN_PROGS_x86_64 += x86_64/vmx_nested_tsc_scaling_test 116678e90a3SPeter ShierTEST_GEN_PROGS_x86_64 += x86_64/xapic_ipi_test 11785c68eb4SSean ChristophersonTEST_GEN_PROGS_x86_64 += x86_64/xapic_state_test 118c90992bfSAaron LewisTEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test 119449aa906SPeter XuTEST_GEN_PROGS_x86_64 += x86_64/debug_regs 1200c899c25SPaolo BonziniTEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test 121825be3b5SYang WeijiangTEST_GEN_PROGS_x86_64 += x86_64/vmx_pmu_caps_test 1228d4e7e80SDavid WoodhouseTEST_GEN_PROGS_x86_64 += x86_64/xen_shinfo_test 12323200b7aSJoao MartinsTEST_GEN_PROGS_x86_64 += x86_64/xen_vmcall_test 1246a581508SPeter GondaTEST_GEN_PROGS_x86_64 += x86_64/sev_migrate_tests 125bf70636dSYang ZhongTEST_GEN_PROGS_x86_64 += x86_64/amx_test 126753dcf7aSZeng GuangTEST_GEN_PROGS_x86_64 += x86_64/max_vcpuid_cap_test 12730267b43SChenyi QiangTEST_GEN_PROGS_x86_64 += x86_64/triple_fault_event_test 128de1956f4SDavid MatlackTEST_GEN_PROGS_x86_64 += access_tracking_perf_test 129025eed7bSBen GardonTEST_GEN_PROGS_x86_64 += demand_paging_test 13094c4b76bSAndrew JonesTEST_GEN_PROGS_x86_64 += dirty_log_test 1314fd94ec7SBen GardonTEST_GEN_PROGS_x86_64 += dirty_log_perf_test 1321838b06bSIgnacio AlvaradoTEST_GEN_PROGS_x86_64 += hardware_disable_test 133fd4198bfSPaolo BonziniTEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus 134b9c2bd50SYanan WangTEST_GEN_PROGS_x86_64 += kvm_page_table_test 135b58c55d5SSean ChristophersonTEST_GEN_PROGS_x86_64 += max_guest_memory_test 136f73a3446SBen GardonTEST_GEN_PROGS_x86_64 += memslot_modification_stress_test 137cad347faSMaciej S. SzmigieroTEST_GEN_PROGS_x86_64 += memslot_perf_test 13861e52f16SSean ChristophersonTEST_GEN_PROGS_x86_64 += rseq_test 1395b4f758fSSean ChristophersonTEST_GEN_PROGS_x86_64 += set_memory_region_test 14094c4b76bSAndrew JonesTEST_GEN_PROGS_x86_64 += steal_time 1410b45d587SJing ZhangTEST_GEN_PROGS_x86_64 += kvm_binary_stats_test 1423f9808caSOliver UptonTEST_GEN_PROGS_x86_64 += system_counter_offset_test 143fff8dcd7SAndrew Jones 1448448ec59SBen Gardon# Compiled outputs used by test targets 1458448ec59SBen GardonTEST_GEN_PROGS_EXTENDED_x86_64 += x86_64/nx_huge_pages_test 1468448ec59SBen Gardon 1474959d865SRaghavendra Rao AnantaTEST_GEN_PROGS_aarch64 += aarch64/arch_timer 1484f05223aSRicardo KollerTEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions 149fd02029aSAndrew JonesTEST_GEN_PROGS_aarch64 += aarch64/get-reg-list 1505ca24697SRaghavendra Rao AnantaTEST_GEN_PROGS_aarch64 += aarch64/hypercalls 151bf08515dSOliver UptonTEST_GEN_PROGS_aarch64 += aarch64/psci_test 1522f5d27e6SReiji WatanabeTEST_GEN_PROGS_aarch64 += aarch64/vcpu_width_config 153dc0e058eSEric AugerTEST_GEN_PROGS_aarch64 += aarch64/vgic_init 15450b020cdSRicardo KollerTEST_GEN_PROGS_aarch64 += aarch64/vgic_irq 155025eed7bSBen GardonTEST_GEN_PROGS_aarch64 += demand_paging_test 15694c4b76bSAndrew JonesTEST_GEN_PROGS_aarch64 += dirty_log_test 15787c5f35eSAndrew JonesTEST_GEN_PROGS_aarch64 += dirty_log_perf_test 15849fe9a5dSThomas HuthTEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus 159b9c2bd50SYanan WangTEST_GEN_PROGS_aarch64 += kvm_page_table_test 160358928fdSRicardo KollerTEST_GEN_PROGS_aarch64 += memslot_modification_stress_test 161358928fdSRicardo KollerTEST_GEN_PROGS_aarch64 += memslot_perf_test 16261e52f16SSean ChristophersonTEST_GEN_PROGS_aarch64 += rseq_test 1635b4f758fSSean ChristophersonTEST_GEN_PROGS_aarch64 += set_memory_region_test 16494c4b76bSAndrew JonesTEST_GEN_PROGS_aarch64 += steal_time 1650b45d587SJing ZhangTEST_GEN_PROGS_aarch64 += kvm_binary_stats_test 166783e9e51SPaolo Bonzini 167be6f55a6SThomas HuthTEST_GEN_PROGS_s390x = s390x/memop 168b25d4cb4SJanosch FrankTEST_GEN_PROGS_s390x += s390x/resets 16994c4b76bSAndrew JonesTEST_GEN_PROGS_s390x += s390x/sync_regs_test 170c7ef9ebbSJanis Schoetterl-GlauschTEST_GEN_PROGS_s390x += s390x/tprot 171025eed7bSBen GardonTEST_GEN_PROGS_s390x += demand_paging_test 17294c4b76bSAndrew JonesTEST_GEN_PROGS_s390x += dirty_log_test 17349fe9a5dSThomas HuthTEST_GEN_PROGS_s390x += kvm_create_max_vcpus 174b9c2bd50SYanan WangTEST_GEN_PROGS_s390x += kvm_page_table_test 17561e52f16SSean ChristophersonTEST_GEN_PROGS_s390x += rseq_test 1765b4f758fSSean ChristophersonTEST_GEN_PROGS_s390x += set_memory_region_test 1770b45d587SJing ZhangTEST_GEN_PROGS_s390x += kvm_binary_stats_test 178783e9e51SPaolo Bonzini 1793e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += demand_paging_test 1803e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += dirty_log_test 1813e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += kvm_create_max_vcpus 1823e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += kvm_page_table_test 1833e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += set_memory_region_test 1843e06cdf1SAnup PatelTEST_GEN_PROGS_riscv += kvm_binary_stats_test 1853e06cdf1SAnup Patel 1868448ec59SBen GardonTEST_PROGS += $(TEST_PROGS_$(UNAME_M)) 187783e9e51SPaolo BonziniTEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) 1888448ec59SBen GardonTEST_GEN_PROGS_EXTENDED += $(TEST_GEN_PROGS_EXTENDED_$(UNAME_M)) 189783e9e51SPaolo BonziniLIBKVM += $(LIBKVM_$(UNAME_M)) 190783e9e51SPaolo Bonzini 191783e9e51SPaolo BonziniINSTALL_HDR_PATH = $(top_srcdir)/usr 192783e9e51SPaolo BonziniLINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ 193cc68765dSAndrew JonesLINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include 194b80db73dSVitaly Kuznetsovifeq ($(ARCH),x86_64) 195b80db73dSVitaly KuznetsovLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include 196b80db73dSVitaly Kuznetsovelse 19766d69e08SShuah KhanLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include 198b80db73dSVitaly Kuznetsovendif 199319f6f97SThomas HuthCFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ 200319f6f97SThomas Huth -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ 201a5543d34SSean Christopherson -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ 2020cc5963bSMuhammad Usama Anjum -I$(<D) -Iinclude/$(UNAME_M) -I.. $(EXTRA_CFLAGS) $(KHDR_INCLUDES) 203c2390f16SPaolo Bonzini 204c2390f16SPaolo Bonzinino-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ 2056e06983dSShuah Khan $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie) 206c2390f16SPaolo Bonzini 2078343ba2dSChristian Borntraeger# On s390, build the testcases KVM-enabled 2088343ba2dSChristian Borntraegerpgste-option = $(call try-run, echo 'int main() { return 0; }' | \ 2098343ba2dSChristian Borntraeger $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste) 2108343ba2dSChristian Borntraeger 2118343ba2dSChristian Borntraeger 2128343ba2dSChristian BorntraegerLDFLAGS += -pthread $(no-pie-option) $(pgste-option) 213783e9e51SPaolo Bonzini 214783e9e51SPaolo Bonzini# After inclusion, $(OUTPUT) is defined and 215783e9e51SPaolo Bonzini# $(TEST_GEN_PROGS) starts with $(OUTPUT)/ 216783e9e51SPaolo Bonziniinclude ../lib.mk 217783e9e51SPaolo Bonzini 21829faeb96SAaron LewisLIBKVM_C := $(filter %.c,$(LIBKVM)) 21929faeb96SAaron LewisLIBKVM_S := $(filter %.S,$(LIBKVM)) 22029faeb96SAaron LewisLIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C)) 22129faeb96SAaron LewisLIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S)) 222cdc979daSDavid MatlackLIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) 223cdc979daSDavid Matlack 224cdc979daSDavid MatlackEXTRA_CLEAN += $(LIBKVM_OBJS) cscope.* 225783e9e51SPaolo Bonzini 22629faeb96SAaron Lewisx := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)))) 22729faeb96SAaron Lewis$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c 228783e9e51SPaolo Bonzini $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ 229783e9e51SPaolo Bonzini 23029faeb96SAaron Lewis$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S 23129faeb96SAaron Lewis $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ 23229faeb96SAaron Lewis 23366d69e08SShuah Khanx := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) 234cdc979daSDavid Matlack$(TEST_GEN_PROGS): $(LIBKVM_OBJS) 2358448ec59SBen Gardon$(TEST_GEN_PROGS_EXTENDED): $(LIBKVM_OBJS) 236eea192bfSAndrew Jones 237eea192bfSAndrew Jonescscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. 238eea192bfSAndrew Jonescscope: 239eea192bfSAndrew Jones $(RM) cscope.* 240eea192bfSAndrew Jones (find $(include_paths) -name '*.h' \ 241eea192bfSAndrew Jones -exec realpath --relative-base=$(PWD) {} \;; \ 242eea192bfSAndrew Jones find . -name '*.c' \ 243eea192bfSAndrew Jones -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files 244eea192bfSAndrew Jones cscope -b 245