[RFC v3 3/3] kvm: selftests: Fix header path when built from parent level with O specified

From: Xiaoyao Li
Date: Wed Mar 25 2020 - 23:25:53 EST


When build kvm selftests in tools/testing/selftests directory with

make O=/home/lxy/kselftests TARGETS=kvm

it fails building some kvm test binaries due to lack of header files,
e.g.,

x86_64/vmx_set_nested_state_test.c: In function âset_default_vmx_stateâ:
x86_64/vmx_set_nested_state_test.c:85:7: error: âstruct
kvm_nested_stateâ has no member named âhdrâ
state->hdr.vmx.vmxon_pa = 0x1000;
...

With "O" is specified, it also takes effect on "make headers_install",
which causes no header files generated in "kernel-src/usr".

Fix INSTALL_HDR_PATH with correct path for this case.

Opportunistically fix the case when KBUILD_OUTPUT specified as well,
even though it can work currently.

Signed-off-by: Xiaoyao Li <xiaoyao.li@xxxxxxxxx>
---
tools/testing/selftests/kvm/Makefile | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile
index 6a95878b2ab7..bf8f56488914 100644
--- a/tools/testing/selftests/kvm/Makefile
+++ b/tools/testing/selftests/kvm/Makefile
@@ -50,7 +50,11 @@ ifeq (0,$(MAKELEVEL))
INSTALL_HDR_PATH := $(top_srcdir)/usr
endif
else
+ ifneq ($(O)$(KBUILD_OUTPUT),)
+ INSTALL_HDR_PATH := $(BUILD)/usr
+ else
INSTALL_HDR_PATH := $(top_srcdir)/usr
+ endif
endif
LINUX_HDR_PATH = $(INSTALL_HDR_PATH)/include/
LINUX_TOOL_INCLUDE = $(top_srcdir)/tools/include
--
2.20.1