Thomas Gleixner | ec8f24b | 2019-05-19 13:07:45 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 2 | include ../../../../scripts/Kbuild.include |
| 3 | |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 4 | all: |
| 5 | |
Andrew Jones | cc68765 | 2018-09-18 19:54:26 +0200 | [diff] [blame] | 6 | top_srcdir = ../../../.. |
Shuah Khan | 211929f | 2018-12-12 20:25:14 -0700 | [diff] [blame] | 7 | KSFT_KHDR_INSTALL := 1 |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 8 | |
| 9 | # For cross-builds to work, UNAME_M has to map to ARCH and arch specific |
| 10 | # directories and targets in this Makefile. "uname -m" doesn't map to |
| 11 | # arch specific sub-directory names. |
| 12 | # |
| 13 | # UNAME_M variable to used to run the compiles pointing to the right arch |
| 14 | # directories and build the right targets for these supported architectures. |
| 15 | # |
| 16 | # TEST_GEN_PROGS and LIBKVM are set using UNAME_M variable. |
| 17 | # LINUX_TOOL_ARCH_INCLUDE is set using ARCH variable. |
| 18 | # |
| 19 | # x86_64 targets are named to include x86_64 as a suffix and directories |
| 20 | # for includes are in x86_64 sub-directory. s390x and aarch64 follow the |
| 21 | # same convention. "uname -m" doesn't result in the correct mapping for |
| 22 | # s390x and aarch64. |
| 23 | # |
| 24 | # No change necessary for x86_64 |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 25 | UNAME_M := $(shell uname -m) |
| 26 | |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 27 | # Set UNAME_M for arm64 compile/install to work |
| 28 | ifeq ($(ARCH),arm64) |
| 29 | UNAME_M := aarch64 |
| 30 | endif |
| 31 | # Set UNAME_M s390x compile/install to work |
| 32 | ifeq ($(ARCH),s390) |
| 33 | UNAME_M := s390x |
| 34 | endif |
| 35 | |
Ben Gardon | af99e1a | 2020-01-23 10:04:30 -0800 | [diff] [blame] | 36 | LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/sparsebit.c lib/test_util.c |
Eric Auger | 20ba262 | 2020-02-06 11:47:09 +0100 | [diff] [blame] | 37 | LIBKVM_x86_64 = lib/x86_64/processor.c lib/x86_64/vmx.c lib/x86_64/svm.c lib/x86_64/ucall.c |
Thomas Huth | 2040f41 | 2019-07-31 17:15:23 +0200 | [diff] [blame] | 38 | LIBKVM_aarch64 = lib/aarch64/processor.c lib/aarch64/ucall.c |
Thomas Huth | f90f57b | 2019-07-31 17:15:24 +0200 | [diff] [blame] | 39 | LIBKVM_s390x = lib/s390x/processor.c lib/s390x/ucall.c |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 40 | |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 41 | TEST_GEN_PROGS_x86_64 = x86_64/cr4_cpuid_sync_test |
Vitaly Kuznetsov | 18178ff | 2018-10-16 18:50:11 +0200 | [diff] [blame] | 42 | TEST_GEN_PROGS_x86_64 += x86_64/evmcs_test |
Vitaly Kuznetsov | 7edcb73 | 2018-12-10 18:21:59 +0100 | [diff] [blame] | 43 | TEST_GEN_PROGS_x86_64 += x86_64/hyperv_cpuid |
Aaron Lewis | 9dba988 | 2019-05-31 14:14:52 +0000 | [diff] [blame] | 44 | TEST_GEN_PROGS_x86_64 += x86_64/mmio_warning_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 45 | TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test |
| 46 | TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test |
| 47 | TEST_GEN_PROGS_x86_64 += x86_64/smm_test |
| 48 | TEST_GEN_PROGS_x86_64 += x86_64/state_test |
Makarand Sonare | 8d7fbf0 | 2020-05-26 14:51:07 -0700 | [diff] [blame] | 49 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 50 | TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 51 | TEST_GEN_PROGS_x86_64 += x86_64/sync_regs_test |
Jim Mattson | 97a71a5 | 2020-10-26 11:09:22 -0700 | [diff] [blame^] | 52 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_apic_access_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 53 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_close_while_nested_test |
Paolo Bonzini | 0944442 | 2019-09-26 15:01:15 +0200 | [diff] [blame] | 54 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_dirty_log_test |
Aaron Lewis | da1e307 | 2019-05-02 11:31:41 -0700 | [diff] [blame] | 55 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_set_nested_state_test |
Aaron Lewis | 61cfcd5 | 2019-05-21 17:13:58 +0000 | [diff] [blame] | 56 | TEST_GEN_PROGS_x86_64 += x86_64/vmx_tsc_adjust_test |
Aaron Lewis | c90992b | 2019-10-21 16:30:28 -0700 | [diff] [blame] | 57 | TEST_GEN_PROGS_x86_64 += x86_64/xss_msr_test |
Peter Xu | 449aa90 | 2020-05-05 16:50:00 -0400 | [diff] [blame] | 58 | TEST_GEN_PROGS_x86_64 += x86_64/debug_regs |
Paolo Bonzini | 0c899c2 | 2020-09-24 14:45:27 +0200 | [diff] [blame] | 59 | TEST_GEN_PROGS_x86_64 += x86_64/tsc_msrs_test |
Alexander Graf | d468706 | 2020-09-25 16:34:22 +0200 | [diff] [blame] | 60 | TEST_GEN_PROGS_x86_64 += x86_64/user_msr_test |
Paolo Bonzini | 2a31b9d | 2018-10-23 02:36:47 +0200 | [diff] [blame] | 61 | TEST_GEN_PROGS_x86_64 += clear_dirty_log_test |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 62 | TEST_GEN_PROGS_x86_64 += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 63 | TEST_GEN_PROGS_x86_64 += dirty_log_test |
Paolo Bonzini | fd4198bf | 2019-07-15 12:50:46 +0200 | [diff] [blame] | 64 | TEST_GEN_PROGS_x86_64 += kvm_create_max_vcpus |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 65 | TEST_GEN_PROGS_x86_64 += set_memory_region_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 66 | TEST_GEN_PROGS_x86_64 += steal_time |
Andrew Jones | fff8dcd | 2018-09-18 19:54:32 +0200 | [diff] [blame] | 67 | |
Paolo Bonzini | 2a31b9d | 2018-10-23 02:36:47 +0200 | [diff] [blame] | 68 | TEST_GEN_PROGS_aarch64 += clear_dirty_log_test |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 69 | TEST_GEN_PROGS_aarch64 += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 70 | TEST_GEN_PROGS_aarch64 += dirty_log_test |
Thomas Huth | 49fe9a5 | 2019-05-23 18:43:09 +0200 | [diff] [blame] | 71 | TEST_GEN_PROGS_aarch64 += kvm_create_max_vcpus |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 72 | TEST_GEN_PROGS_aarch64 += set_memory_region_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 73 | TEST_GEN_PROGS_aarch64 += steal_time |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 74 | |
Thomas Huth | be6f55a | 2019-08-29 15:07:32 +0200 | [diff] [blame] | 75 | TEST_GEN_PROGS_s390x = s390x/memop |
Janosch Frank | b25d4cb | 2020-01-31 05:02:04 -0500 | [diff] [blame] | 76 | TEST_GEN_PROGS_s390x += s390x/resets |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 77 | TEST_GEN_PROGS_s390x += s390x/sync_regs_test |
Ben Gardon | 025eed7 | 2020-01-23 10:04:27 -0800 | [diff] [blame] | 78 | TEST_GEN_PROGS_s390x += demand_paging_test |
Andrew Jones | 94c4b76b | 2020-03-13 16:56:44 +0100 | [diff] [blame] | 79 | TEST_GEN_PROGS_s390x += dirty_log_test |
Thomas Huth | 49fe9a5 | 2019-05-23 18:43:09 +0200 | [diff] [blame] | 80 | TEST_GEN_PROGS_s390x += kvm_create_max_vcpus |
Sean Christopherson | 5b4f758 | 2020-04-10 16:17:06 -0700 | [diff] [blame] | 81 | TEST_GEN_PROGS_s390x += set_memory_region_test |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 82 | |
| 83 | TEST_GEN_PROGS += $(TEST_GEN_PROGS_$(UNAME_M)) |
| 84 | LIBKVM += $(LIBKVM_$(UNAME_M)) |
| 85 | |
| 86 | INSTALL_HDR_PATH = $(top_srcdir)/usr |
| 87 | LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/ |
Andrew Jones | cc68765 | 2018-09-18 19:54:26 +0200 | [diff] [blame] | 88 | LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include |
Vitaly Kuznetsov | b80db73 | 2020-06-05 16:20:28 +0200 | [diff] [blame] | 89 | ifeq ($(ARCH),x86_64) |
| 90 | LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/x86/include |
| 91 | else |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 92 | LINUX_TOOL_ARCH_INCLUDE = $(top_srcdir)/tools/arch/$(ARCH)/include |
Vitaly Kuznetsov | b80db73 | 2020-06-05 16:20:28 +0200 | [diff] [blame] | 93 | endif |
Thomas Huth | 319f6f9 | 2019-05-17 11:04:45 +0200 | [diff] [blame] | 94 | CFLAGS += -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 \ |
| 95 | -fno-stack-protector -fno-PIE -I$(LINUX_TOOL_INCLUDE) \ |
Sean Christopherson | a5543d3 | 2019-12-20 20:44:56 -0800 | [diff] [blame] | 96 | -I$(LINUX_TOOL_ARCH_INCLUDE) -I$(LINUX_HDR_PATH) -Iinclude \ |
| 97 | -I$(<D) -Iinclude/$(UNAME_M) -I.. |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 98 | |
| 99 | no-pie-option := $(call try-run, echo 'int main() { return 0; }' | \ |
Shuah Khan | 6e06983 | 2019-10-02 17:14:30 -0600 | [diff] [blame] | 100 | $(CC) -Werror -no-pie -x c - -o "$$TMP", -no-pie) |
Paolo Bonzini | c2390f1 | 2019-04-11 15:51:19 +0200 | [diff] [blame] | 101 | |
Christian Borntraeger | 8343ba2 | 2019-05-24 12:27:01 +0200 | [diff] [blame] | 102 | # On s390, build the testcases KVM-enabled |
| 103 | pgste-option = $(call try-run, echo 'int main() { return 0; }' | \ |
| 104 | $(CC) -Werror -Wl$(comma)--s390-pgste -x c - -o "$$TMP",-Wl$(comma)--s390-pgste) |
| 105 | |
| 106 | |
| 107 | LDFLAGS += -pthread $(no-pie-option) $(pgste-option) |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 108 | |
| 109 | # After inclusion, $(OUTPUT) is defined and |
| 110 | # $(TEST_GEN_PROGS) starts with $(OUTPUT)/ |
| 111 | include ../lib.mk |
| 112 | |
| 113 | STATIC_LIBS := $(OUTPUT)/libkvm.a |
| 114 | LIBKVM_OBJ := $(patsubst %.c, $(OUTPUT)/%.o, $(LIBKVM)) |
Andrew Jones | eea192b | 2018-09-18 19:54:27 +0200 | [diff] [blame] | 115 | EXTRA_CLEAN += $(LIBKVM_OBJ) $(STATIC_LIBS) cscope.* |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 116 | |
| 117 | x := $(shell mkdir -p $(sort $(dir $(LIBKVM_OBJ)))) |
| 118 | $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c |
| 119 | $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@ |
| 120 | |
| 121 | $(OUTPUT)/libkvm.a: $(LIBKVM_OBJ) |
| 122 | $(AR) crs $@ $^ |
| 123 | |
Shuah Khan | 66d69e0 | 2020-04-27 18:11:07 -0600 | [diff] [blame] | 124 | x := $(shell mkdir -p $(sort $(dir $(TEST_GEN_PROGS)))) |
Anders Roxell | b2d35fa | 2018-09-04 12:47:21 +0200 | [diff] [blame] | 125 | all: $(STATIC_LIBS) |
Paolo Bonzini | 783e9e5 | 2018-03-27 11:49:19 +0200 | [diff] [blame] | 126 | $(TEST_GEN_PROGS): $(STATIC_LIBS) |
Andrew Jones | eea192b | 2018-09-18 19:54:27 +0200 | [diff] [blame] | 127 | |
| 128 | cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. |
| 129 | cscope: |
| 130 | $(RM) cscope.* |
| 131 | (find $(include_paths) -name '*.h' \ |
| 132 | -exec realpath --relative-base=$(PWD) {} \;; \ |
| 133 | find . -name '*.c' \ |
| 134 | -exec realpath --relative-base=$(PWD) {} \;) | sort -u > cscope.files |
| 135 | cscope -b |