18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ciinclude ../../../../scripts/Kbuild.include
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciall:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_citop_srcdir = ../../../..
78c2ecf20Sopenharmony_ciKSFT_KHDR_INSTALL := 1
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci# For cross-builds to work, UNAME_M has to map to ARCH and arch specific
108c2ecf20Sopenharmony_ci# directories and targets in this Makefile. "uname -m" doesn't map to
118c2ecf20Sopenharmony_ci# arch specific sub-directory names.
128c2ecf20Sopenharmony_ci#
138c2ecf20Sopenharmony_ci# UNAME_M variable to used to run the compiles pointing to the right arch
148c2ecf20Sopenharmony_ci# directories and build the right targets for these supported architectures.
158c2ecf20Sopenharmony_ci#
168c2ecf20Sopenharmony_ci# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
178c2ecf20Sopenharmony_ci# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
188c2ecf20Sopenharmony_ci#
198c2ecf20Sopenharmony_ci# x86_64 targets are named to include x86_64 as a suffix and directories
208c2ecf20Sopenharmony_ci# for includes are in x86_64 sub-directory. s390x and aarch64 follow the
218c2ecf20Sopenharmony_ci# same convention. "uname -m" doesn't result in the correct mapping for
228c2ecf20Sopenharmony_ci# s390x and aarch64.
238c2ecf20Sopenharmony_ci#
248c2ecf20Sopenharmony_ci# No change necessary for x86_64
258c2ecf20Sopenharmony_ciUNAME_M := $(shell uname -m)
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci# Set UNAME_M for arm64 compile/install to work
288c2ecf20Sopenharmony_ciifeq ($(ARCH),arm64)
298c2ecf20Sopenharmony_ci	UNAME_M := aarch64
308c2ecf20Sopenharmony_ciendif
318c2ecf20Sopenharmony_ci# Set UNAME_M s390x compile/install to work
328c2ecf20Sopenharmony_ciifeq ($(ARCH),s390)
338c2ecf20Sopenharmony_ci	UNAME_M := s390x
348c2ecf20Sopenharmony_ciendif
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciLIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c
378c2ecf20Sopenharmony_ciLIBKVM_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
388c2ecf20Sopenharmony_ciLIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
398c2ecf20Sopenharmony_ciLIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
428c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
438c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
448c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
458c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
468c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
478c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
488c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/smm_test
498c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/state_test
508c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
518c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
528c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
538c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
548c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
558c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
568c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
578c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
588c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
598c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/debug_regs
608c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
618c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += x86_64/user_msr_test
628c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += demand_paging_test
638c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += dirty_log_test
648c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += dirty_log_perf_test
658c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
668c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += set_memory_region_test
678c2ecf20Sopenharmony_ciTEST_GEN_PROGS_x86_64 += steal_time
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
708c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
718c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += demand_paging_test
728c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += dirty_log_test
738c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
748c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += set_memory_region_test
758c2ecf20Sopenharmony_ciTEST_GEN_PROGS_aarch64 += steal_time
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x = s390x/memop
788c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += s390x/resets
798c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += s390x/sync_regs_test
808c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += demand_paging_test
818c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += dirty_log_test
828c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += kvm_create_max_vcpus
838c2ecf20Sopenharmony_ciTEST_GEN_PROGS_s390x += set_memory_region_test
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ciTEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M))
868c2ecf20Sopenharmony_ciLIBKVM += $(LIBKVM_$(UNAME_M))
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ciINSTALL_HDR_PATH = $(top_srcdir)/usr
898c2ecf20Sopenharmony_ciLINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
908c2ecf20Sopenharmony_ciLINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
918c2ecf20Sopenharmony_ciifeq ($(ARCH),x86_64)
928c2ecf20Sopenharmony_ciLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include
938c2ecf20Sopenharmony_cielse
948c2ecf20Sopenharmony_ciLINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include
958c2ecf20Sopenharmony_ciendif
968c2ecf20Sopenharmony_ciCFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \
978c2ecf20Sopenharmony_ci	-fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \
988c2ecf20Sopenharmony_ci	-I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \
998c2ecf20Sopenharmony_ci	-I$(<D) -Iinclude/$(UNAME_M) -I..
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_cino-pie-option := $(call try-run, echo 'int main() { return 0; }' | \
1028c2ecf20Sopenharmony_ci        $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci# On s390, build the testcases KVM-enabled
1058c2ecf20Sopenharmony_cipgste-option = $(call try-run, echo 'int main() { return 0; }' | \
1068c2ecf20Sopenharmony_ci	$(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste)
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciLDFLAGS += -pthread $(no-pie-option) $(pgste-option)
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci# After inclusion, $(OUTPUT) is defined and
1128c2ecf20Sopenharmony_ci# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
1138c2ecf20Sopenharmony_ciinclude ../lib.mk
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ciSTATIC_LIBS := $(OUTPUT)/libkvm.a
1168c2ecf20Sopenharmony_ciLIBKVM_C := $(filter %.c,$(LIBKVM))
1178c2ecf20Sopenharmony_ciLIBKVM_S := $(filter %.S,$(LIBKVM))
1188c2ecf20Sopenharmony_ciLIBKVM_C_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM_C))
1198c2ecf20Sopenharmony_ciLIBKVM_S_OBJ := $(patsubst %.S, $(OUTPUT)/%.o, $(LIBKVM_S))
1208c2ecf20Sopenharmony_ciEXTRA_CLEAN += $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ) $(STATIC_LIBS) cscope.*
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cix := $(shell mkdir -p $(sort $(dir $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ))))
1238c2ecf20Sopenharmony_ci$(LIBKVM_C_OBJ): $(OUTPUT)/%.o: %.c
1248c2ecf20Sopenharmony_ci	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci$(LIBKVM_S_OBJ): $(OUTPUT)/%.o: %.S
1278c2ecf20Sopenharmony_ci	$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ciLIBKVM_OBJS = $(LIBKVM_C_OBJ) $(LIBKVM_S_OBJ)
1308c2ecf20Sopenharmony_ci$(OUTPUT)/libkvm.a: $(LIBKVM_OBJS)
1318c2ecf20Sopenharmony_ci	$(AR) crs $@ $^
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cix := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS))))
1348c2ecf20Sopenharmony_ciall: $(STATIC_LIBS)
1358c2ecf20Sopenharmony_ci$(TEST_GEN_PROGS): $(STATIC_LIBS)
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cicscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
1388c2ecf20Sopenharmony_cicscope:
1398c2ecf20Sopenharmony_ci	$(RM) cscope.*
1408c2ecf20Sopenharmony_ci	(find $(include_paths) -name '*.h' \
1418c2ecf20Sopenharmony_ci		-exec realpath --relative-base=$(PWD) {} \;; \
1428c2ecf20Sopenharmony_ci	find . -name '*.c' \
1438c2ecf20Sopenharmony_ci		-exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files
1448c2ecf20Sopenharmony_ci	cscope -b
145