From patchwork Tue Jan 18 11:29:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 12716205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25A51C433FE for ; Tue, 18 Jan 2022 11:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239790AbiARLat (ORCPT ); Tue, 18 Jan 2022 06:30:49 -0500 Received: from bhuna.collabora.co.uk ([46.235.227.227]:35718 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234162AbiARLas (ORCPT ); Tue, 18 Jan 2022 06:30:48 -0500 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: usama.anjum) with ESMTPSA id E62571F43E07 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1642505447; bh=gjVHu+jWyShCzwYH7u0I9MtX/la4ZTeWCA5VgFyOCk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H5Ez+RSqJ5X1uYdxMk4VSBSDHzgIj98jIrxhiayB5u+Bf/1+/fLT/K6COMerWQlfS VW/rkRju533nMAx2e090k8UIETKYz3QclugU8+pCks9IHB6IuQkWpSVjAh3OWdhso6 S5B9q/6noRCvHIWKgKph20ScEZj9ooGTIbEJemqnlrOsL3wsaJKfHZDYy43YkMJSaV bj+xXPckZj58v9uoUepZW9qEdbVxU5zVD5AV5ZElwlFEezpdkD052I5P7QjG6cniH5 Js/2yfMPqi9CvG9YUju7950Nip/slm5k1tvquYSS3ciIb/FcqCCs4Ac7L6DObu+l78 e2bEsfyep0R6A== From: Muhammad Usama Anjum To: Shuah Khan , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?utf-8?q?Andr=C3=A9_Almeida?= , Paolo Bonzini , =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , "David S. Miller" , Jakub Kicinski , Mat Martineau , Matthieu Baerts , Andrew Morton , chiminghao , linux-kselftest@vger.kernel.org (open list:KERNEL SELFTEST FRAMEWORK), linux-kernel@vger.kernel.org (open list), kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-security-module@vger.kernel.org (open list:LANDLOCK SECURITY MODULE), netdev@vger.kernel.org (open list:NETWORKING [GENERAL]), mptcp@lists.linux.dev (open list:NETWORKING [MPTCP]), linux-mm@kvack.org (open list:MEMORY MANAGEMENT) Cc: Muhammad Usama Anjum , kernel@collabora.com Subject: [PATCH 01/10] selftests: set the BUILD variable to absolute path Date: Tue, 18 Jan 2022 16:29:00 +0500 Message-Id: <20220118112909.1885705-2-usama.anjum@collabora.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220118112909.1885705-1-usama.anjum@collabora.com> References: <20220118112909.1885705-1-usama.anjum@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org The build of kselftests fails if relative path is specified through KBUILD_OUTPUT or O= method. BUILD variable is used to determine the path of the output objects. When make is run from other directories with relative paths, the exact path of the build objects is ambiguous and build fails. make[1]: Entering directory '/home/usama/repos/kernel/linux_mainline2/tools/testing/selftests/alsa' gcc mixer-test.c -L/usr/lib/x86_64-linux-gnu -lasound -o build/kselftest/alsa/mixer-test /usr/bin/ld: cannot open output file build/kselftest/alsa/mixer-test Set the BUILD variable to the absolute path of the output directory. Make the logic readable and easy to follow. Use spaces instead of tabs for indentation as if with tab indentation is considered recipe in make. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/Makefile | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index d08fe4cfe811..a7b63860b7bc 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -114,19 +114,27 @@ ifdef building_out_of_srctree override LDFLAGS = endif -ifneq ($(O),) - BUILD := $(O)/kselftest +top_srcdir ?= ../../.. + +ifeq ("$(origin O)", "command line") + KBUILD_OUTPUT := $(O) +endif + +ifneq ($(KBUILD_OUTPUT),) + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot + # expand a shell special character '~'. We use a somewhat tedious way here. + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) + $(if $(abs_objtree),, \ + $(error failed to create output directory "$(KBUILD_OUTPUT)")) + # $(realpath ...) resolves symlinks + abs_objtree := $(realpath $(abs_objtree)) + BUILD := $(abs_objtree)/kselftest else - ifneq ($(KBUILD_OUTPUT),) - BUILD := $(KBUILD_OUTPUT)/kselftest - else - BUILD := $(shell pwd) - DEFAULT_INSTALL_HDR_PATH := 1 - endif + BUILD := $(CURDIR) + DEFAULT_INSTALL_HDR_PATH := 1 endif # Prepare for headers install -top_srcdir ?= ../../.. include $(top_srcdir)/scripts/subarch.include ARCH ?= $(SUBARCH) export KSFT_KHDR_INSTALL_DONE := 1