From patchwork Fri Apr 21 19:03:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 9693555 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 107926038D for ; Fri, 21 Apr 2017 19:05:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0310128628 for ; Fri, 21 Apr 2017 19:05:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EBAAA2864A; Fri, 21 Apr 2017 19:05:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E250428628 for ; Fri, 21 Apr 2017 19:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BPqZ373NesEBooeugboR6nf1q3LlF8FnyMwWFj0Cr7k=; b=FstXJOJ/zx3rq6331A/NTVod5A ce1DgYMIDmeejQ0v7BrKUV7rdTz2LZdfAE6L2It8zfRwuNwNz573ayW4QEH+KREkgWM7MkQvaBSCj q3BTWXWYqoshBTyopweWLVGxS57AAEG8ct9BNR6fddWwsbx1cec5vwlCHGGjMSqHr9GggfCXKzQt1 c16W6986+mM5sD2x3Q/M+nKn+QBXBn5/eT/BA6QBmGqkz8bspYEl9ag8s6vD3GVV/yXp/xTcaq6PQ baQ10A2I3VlYbuZQIJlBQ4zpfa6ow5S+zMtyClLDJhkUTcvqAQ4BHSgZIy+GMGUPkIMk1WNd0rTar wM7jUvlg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d1dre-0005XU-Fo; Fri, 21 Apr 2017 19:05:06 +0000 Received: from conuserg-09.nifty.com ([210.131.2.76]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d1dra-0004it-JN for linux-arm-kernel@lists.infradead.org; Fri, 21 Apr 2017 19:05:04 +0000 Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-09.nifty.com with ESMTP id v3LJ3vv4021371; Sat, 22 Apr 2017 04:04:04 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v3LJ3vv4021371 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1492801445; bh=UqoPNXOEzt5sAONs+cvzU2zKu8MnC5VA8qWN1sxt+T4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S/S8OyIpPHlzsvIVHaTA9omi3vNhxTfcPvwZ6pv9aBmd5oohL01YpGCAiPFFJFIxl ckm4gIe6EpWtqm9Ub3Coh9Qm6mbTNCpYodhPXUUNi1ntFKjCLqOwGhoDy91FhA/+LX ccUssEFuEXiNAhJyCak6q/9e6OyCytDrVLN6Bor79RZZkn35e0Cx8aa85XESH+uYr9 YfCKVnwQIiHGwkn3qmLqdw3Qf9MtAQiO8cRqigLp83H+3xM8XCmTLv/eP2wrPKD2I4 veSu+JyZ/0Ra68c6d/OR0mfNnCvpvFAWJmYZ/rdFLeo+VTkLcFo7Ob1im5Q2sbgsF2 kjOS20mWEdG1Q== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Subject: [RFC PATCH 1/2] kbuild: add KBUILD_FILE to point relative file path from $(srctree) Date: Sat, 22 Apr 2017 04:03:26 +0900 Message-Id: <1492801407-26823-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492801407-26823-1-git-send-email-yamada.masahiro@socionext.com> References: <1492801407-26823-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170421_120502_935538_2C3B3976 X-CRM114-Status: GOOD ( 12.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Masahiro Yamada , Greg KH , x86@kernel.org, linux-kernel@vger.kernel.org, Linus Torvalds , Michal Marek , Andrew Morton , Sam Ravnborg , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since Kbuild runs in the objtree, __FILE__ can be a very long path depending of $(srctree). Commit 9da0763bdd82 ("kbuild: Use relative path when building in a subdir of the source tree") made the situation better for cases where objtree is a child of srctree. ($(srctree) is "..") For other cases of out-of-tree build, filenames in WARN_ON() etc. are still an absolute path. It also means the kernel image depends on where it was built. Here, the idea is to define a new macro, KBUILD_FILE, to point the relative file path from $(srctree). If we replace __FILE__ with KBUILD_FILE, we can rip off the path to the build directory. I am adding stringify helper because '"..."' wrapping is the same pattern for KBUILD_BASENAME, KBUILD_MODNAME, and KBUILD_FILE. Please note KBUILD_FILE is still an absolute path for external modules. We can strip KBUILD_EXTMOD from the path if we want, but I am not doing that. It would make it difficult to figure out the module in question in case of WARN_ON(). Signed-off-by: Masahiro Yamada --- scripts/Kbuild.include | 4 ++++ scripts/Makefile.lib | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 61f87a9..7fc3841 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -31,6 +31,10 @@ baseprereq = $(basename $(notdir $<)) escsq = $(subst $(squote),'\$(squote)',$1) ### +# Quote a string to pass it to C files. foo => '"foo"' +stringify = $(squote)$(quote)$1$(quote)$(squote) + +### # Easy method for doing a status message kecho := : quiet_kecho := echo diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 9e70196..f8dce56 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -96,10 +96,11 @@ obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) # Note: Files that end up in two or more modules are compiled without the # KBUILD_MODNAME definition. The reason is that any made-up name would # differ in different configs. -name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) +name-fix = $(call stringify,$(subst $(comma),_,$(subst -,_,$1))) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) modname_flags = $(if $(filter 1,$(words $(modname))),\ -DKBUILD_MODNAME=$(call name-fix,$(modname))) +filepath_flags = -DKBUILD_FILE=$(call stringify,$(src)/$(notdir $<)) orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(KBUILD_SUBDIR_CCFLAGS) \ $(ccflags-y) $(CFLAGS_$(basetarget).o) @@ -163,7 +164,7 @@ endif c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(__c_flags) $(modkern_cflags) \ - $(basename_flags) $(modname_flags) + $(basename_flags) $(modname_flags) $(filepath_flags) a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(__a_flags) $(modkern_aflags)