2019-05-19 15:07:45 +03:00
# SPDX-License-Identifier: GPL-2.0-only
2019-04-11 16:51:19 +03:00
i n c l u d e . . / . . / . . / . . / s c r i p t s / K b u i l d . i n c l u d e
2018-03-27 12:49:19 +03:00
all :
2018-09-18 20:54:26 +03:00
top_srcdir = ../../../..
2018-12-13 06:25:14 +03:00
KSFT_KHDR_INSTALL := 1
2020-04-28 03:11:07 +03:00
# For cross-builds to work, UNAME_M has to map to ARCH and arch specific
# directories and targets in this Makefile. "uname -m" doesn't map to
# arch specific sub-directory names.
#
# UNAME_M variable to used to run the compiles pointing to the right arch
# directories and build the right targets for these supported architectures.
#
# TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable.
# LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable.
#
# x86_64 targets are named to include x86_64 as a suffix and directories
# for includes are in x86_64 sub-directory. s390x and aarch64 follow the
# same convention. "uname -m" doesn't result in the correct mapping for
# s390x and aarch64.
#
# No change necessary for x86_64
2018-03-27 12:49:19 +03:00
UNAME_M := $( shell uname -m)
2020-04-28 03:11:07 +03:00
# Set UNAME_M for arm64 compile/install to work
i f e q ( $( ARCH ) , a r m 6 4 )
UNAME_M := aarch64
e n d i f
# Set UNAME_M s390x compile/install to work
i f e q ( $( ARCH ) , s 3 9 0 )
UNAME_M := s390x
e n d i f
2020-12-18 17:17:34 +03:00
LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c lib/guest_modes.c lib/perf_test_util.c
2020-10-12 22:47:15 +03:00
LIBKVM_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
2019-07-31 18:15:23 +03:00
LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c
2020-12-07 18:41:25 +03:00
LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c lib/s390x/diag318_test_handler.c
2018-03-27 12:49:19 +03:00
2019-05-21 20:13:58 +03:00
TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test
2018-10-16 19:50:11 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test
2018-12-10 20:21:59 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid
2020-10-28 02:10:44 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test
2019-05-31 17:14:52 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test
2019-05-21 20:13:58 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test
TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test
TEST_GEN_PROGS_x86_64 += x86_64/smm_test
TEST_GEN_PROGS_x86_64 += x86_64/state_test
2020-05-27 00:51:07 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test
2019-05-21 20:13:58 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test
2020-10-12 22:47:16 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/userspace_msr_exit_test
2020-10-26 21:09:22 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test
2019-05-21 20:13:58 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test
2019-09-26 16:01:15 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test
2019-05-02 21:31:41 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test
2019-05-21 20:13:58 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test
2019-10-22 02:30:28 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test
2020-05-05 23:50:00 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/debug_regs
2020-09-24 15:45:27 +03:00
TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test
2020-01-23 21:04:27 +03:00
TEST_GEN_PROGS_x86_64 += demand_paging_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_x86_64 += dirty_log_test
2020-10-28 02:37:33 +03:00
TEST_GEN_PROGS_x86_64 += dirty_log_perf_test
2019-07-15 13:50:46 +03:00
TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus
2020-04-11 02:17:06 +03:00
TEST_GEN_PROGS_x86_64 += set_memory_region_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_x86_64 += steal_time
2018-09-18 20:54:32 +03:00
2020-10-29 23:17:01 +03:00
TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
2020-10-29 23:17:03 +03:00
TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list-sve
2020-01-23 21:04:27 +03:00
TEST_GEN_PROGS_aarch64 += demand_paging_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_aarch64 += dirty_log_test
2020-11-11 15:26:34 +03:00
TEST_GEN_PROGS_aarch64 += dirty_log_perf_test
2019-05-23 19:43:09 +03:00
TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus
2020-04-11 02:17:06 +03:00
TEST_GEN_PROGS_aarch64 += set_memory_region_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_aarch64 += steal_time
2018-03-27 12:49:19 +03:00
2019-08-29 16:07:32 +03:00
TEST_GEN_PROGS_s390x = s390x/memop
2020-01-31 13:02:04 +03:00
TEST_GEN_PROGS_s390x += s390x/resets
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_s390x += s390x/sync_regs_test
2020-01-23 21:04:27 +03:00
TEST_GEN_PROGS_s390x += demand_paging_test
2020-03-13 18:56:44 +03:00
TEST_GEN_PROGS_s390x += dirty_log_test
2019-05-23 19:43:09 +03:00
TEST_GEN_PROGS_s390x += kvm_create_max_vcpus
2020-04-11 02:17:06 +03:00
TEST_GEN_PROGS_s390x += set_memory_region_test
2018-03-27 12:49:19 +03:00
TEST_GEN_PROGS += $( TEST_GEN_PROGS_$( UNAME_M) )
LIBKVM += $( LIBKVM_$( UNAME_M) )
INSTALL_HDR_PATH = $( top_srcdir) /usr
LINUX_HDR_PATH = $( INSTALL_HDR_PATH) /include/
2018-09-18 20:54:26 +03:00
LINUX_TOOL_INCLUDE = $( top_srcdir) /tools/include
2020-06-05 17:20:28 +03:00
i f e q ( $( ARCH ) , x 8 6 _ 6 4 )
LINUX_TOOL_ARCH_INCLUDE = $( top_srcdir) /tools/arch/x86/include
e l s e
2020-04-28 03:11:07 +03:00
LINUX_TOOL_ARCH_INCLUDE = $( top_srcdir) /tools/arch/$( ARCH) /include
2020-06-05 17:20:28 +03:00
e n d i f
2019-05-17 12:04:45 +03:00
CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std= gnu99 \
-fno-stack-protector -fno-PIE -I$( LINUX_TOOL_INCLUDE) \
2019-12-21 07:44:56 +03:00
-I$( LINUX_TOOL_ARCH_INCLUDE) -I$( LINUX_HDR_PATH) -Iinclude \
-I$( <D) -Iinclude/$( UNAME_M) -I..
2019-04-11 16:51:19 +03:00
no-pie-option := $( call try-run, echo 'int main() { return 0; }' | \
2019-10-03 02:14:30 +03:00
$( CC) -Werror -no-pie -x c - -o " $$ TMP " , -no-pie)
2019-04-11 16:51:19 +03:00
2019-05-24 13:27:01 +03:00
# On s390, build the testcases KVM-enabled
pgste-option = $( call try-run, echo 'int main() { return 0; }' | \
$( CC) -Werror -Wl$( comma) --s390-pgste -x c - -o " $$ TMP " ,-Wl$( comma) --s390-pgste)
LDFLAGS += -pthread $( no-pie-option) $( pgste-option)
2018-03-27 12:49:19 +03:00
# After inclusion, $(OUTPUT) is defined and
# $(TEST_GEN_PROGS) starts with $(OUTPUT)/
i n c l u d e . . / l i b . m k
STATIC_LIBS := $( OUTPUT) /libkvm.a
2020-10-12 22:47:15 +03:00
LIBKVM_C := $( filter %.c,$( LIBKVM) )
LIBKVM_S := $( filter %.S,$( LIBKVM) )
LIBKVM_C_OBJ := $( patsubst %.c, $( OUTPUT) /%.o, $( LIBKVM_C) )
LIBKVM_S_OBJ := $( patsubst %.S, $( OUTPUT) /%.o, $( LIBKVM_S) )
EXTRA_CLEAN += $( LIBKVM_C_OBJ) $( LIBKVM_S_OBJ) $( STATIC_LIBS) cscope.*
x := $( shell mkdir -p $( sort $( dir $( LIBKVM_C_OBJ) $( LIBKVM_S_OBJ) ) ) )
$(LIBKVM_C_OBJ) : $( OUTPUT ) /%.o : %.c
$( CC) $( CFLAGS) $( CPPFLAGS) $( TARGET_ARCH) -c $< -o $@
2018-03-27 12:49:19 +03:00
2020-10-12 22:47:15 +03:00
$(LIBKVM_S_OBJ) : $( OUTPUT ) /%.o : %.S
2018-03-27 12:49:19 +03:00
$( CC) $( CFLAGS) $( CPPFLAGS) $( TARGET_ARCH) -c $< -o $@
2020-10-12 22:47:15 +03:00
LIBKVM_OBJS = $( LIBKVM_C_OBJ) $( LIBKVM_S_OBJ)
$(OUTPUT)/libkvm.a : $( LIBKVM_OBJS )
2018-03-27 12:49:19 +03:00
$( AR) crs $@ $^
2020-04-28 03:11:07 +03:00
x := $( shell mkdir -p $( sort $( dir $( TEST_GEN_PROGS) ) ) )
2018-09-04 13:47:21 +03:00
all : $( STATIC_LIBS )
2018-03-27 12:49:19 +03:00
$(TEST_GEN_PROGS) : $( STATIC_LIBS )
2018-09-18 20:54:27 +03:00
cscope : include_paths = $( LINUX_TOOL_INCLUDE ) $( LINUX_HDR_PATH ) include lib ..
cscope :
$( RM) cscope.*
( find $( include_paths) -name '*.h' \
-exec realpath --relative-base= $( PWD) { } \; ; \
find . -name '*.c' \
-exec realpath --relative-base= $( PWD) { } \; ) | sort -u > cscope.files
cscope -b