mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-kbuild@vger.kernel.org
Cc: Joe Perches <joe@perches.com>, Tom Rini <trini@konsulko.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Michal Marek <michal.lkml@markovi.net>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible
Date: Thu, 12 Oct 2017 18:56:04 +0900	[thread overview]
Message-ID: <1507802164-31614-3-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1507802164-31614-1-git-send-email-yamada.masahiro@socionext.com>

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 redefine __FILE__ as the relative path from
$(srctree), but doing so causes a compiler warning:
  warning: "__FILE__" redefined [-Wbuiltin-macro-redefined]

The option -Wno-builtin-macro-redefined can suppress it, but it is
only recognized by GCC 4.4 or newer.  Re-define __FILE__ only when
possible.

Please note __FILE__ is always an absolute path for external modules.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 Makefile | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Makefile b/Makefile
index 2c4a238..a3e8931 100644
--- a/Makefile
+++ b/Makefile
@@ -1091,6 +1091,15 @@ ifdef stackp-check
 endif
 	@:
 
+# If possible, redefne __FILE__ as relative path from $(srctree).
+# $$ is needed to expand the following in submake
+ifeq ($(call cc-option-yn,-Wno-builtin-macro-redefined),y)
+KBUILD_CFLAGS   += -Wno-builtin-macro-redefined \
+		   -D__FILE__=$$(call stringify,$$(src)/$$(notdir $$<))
+endif
+# CAUTION: Do not add any reference to KBUILD_CFLAGS below this line.
+# Any call of cc-option, etc. will fail.
+
 # Generate some files
 # ---------------------------------------------------------------------------
 
-- 
2.7.4

  parent reply	other threads:[~2017-10-12  9:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-12  9:56 [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada
2017-10-12  9:56 ` [PATCH 1/2] kbuild: add stringify helper to quote a string passed to C files Masahiro Yamada
2017-10-12  9:56 ` Masahiro Yamada [this message]
2017-10-14 20:15   ` [PATCH 2/2] kbuild: redefine __FILE__ as relative path from $(srctree) if possible kbuild test robot
2017-10-14  3:17 ` [PATCH 0/2] kbuild: use relative path from $(srctree) instead of __FILE__ Masahiro Yamada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507802164-31614-3-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=geert+renesas@glider.be \
    --cc=joe@perches.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.lkml@markovi.net \
    --cc=trini@konsulko.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®