From patchwork Thu Oct 12 09:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 10001409 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 E72C7602BF for ; Thu, 12 Oct 2017 09:56:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7C8228D54 for ; Thu, 12 Oct 2017 09:56:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9FBD28D58; Thu, 12 Oct 2017 09:56:59 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A91F28D54 for ; Thu, 12 Oct 2017 09:56:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750867AbdJLJ46 (ORCPT ); Thu, 12 Oct 2017 05:56:58 -0400 Received: from conuserg-10.nifty.com ([210.131.2.77]:25465 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750722AbdJLJ46 (ORCPT ); Thu, 12 Oct 2017 05:56:58 -0400 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id v9C9uHcn005959; Thu, 12 Oct 2017 18:56:21 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com v9C9uHcn005959 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1507802181; bh=Elzl/KgUZIx0gBuTNrqP4PegHU8/5dYlHpA274IafWQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yjal8HIhF0aoJRKFlLp980ZLwRKtf8zn8beaP8MGXs56hvYTFXTiyuoa6ubmhsDk4 //NtQTx7pQAPfd8cmrh9vGQ+y69l1yc/3bwMupb2pM5L6pnKC3bi/ujrkQZM8wlWRp JPOnGz+bIGyRO9vzgiv9GEuJGeKmP5a1AziI9tJtICRJeg9/vQA8W8yaJLma/VFLDV R0wxcVARWxoFhAAuAGIDgKAvpNezdbk1eLkxTXbURdBiv7i2jkT4+UiLZQMsYyeCQC PZTcGR7i4o5Bhq4cb59T5quQf6VBdn+ifiYp2avq55keVhwAULm7G7ppbzybRPYzV4 dnE/yxnWlwoXw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Joe Perches , Tom Rini , Geert Uytterhoeven , Masahiro Yamada , Michal Marek , 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 Message-Id: <1507802164-31614-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507802164-31614-1-git-send-email-yamada.masahiro@socionext.com> References: <1507802164-31614-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.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 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 --- 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 # ---------------------------------------------------------------------------