From patchwork Thu Nov 16 07:46:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 10060825 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 B0233601AE for ; Thu, 16 Nov 2017 07:49:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2DBE2A837 for ; Thu, 16 Nov 2017 07:49:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 972302A852; Thu, 16 Nov 2017 07:49:00 +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 47E512A84E for ; Thu, 16 Nov 2017 07:49:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933552AbdKPHse (ORCPT ); Thu, 16 Nov 2017 02:48:34 -0500 Received: from conuserg-10.nifty.com ([210.131.2.77]:37479 "EHLO conuserg-10.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933477AbdKPHsa (ORCPT ); Thu, 16 Nov 2017 02:48:30 -0500 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 vAG7kgbr014686; Thu, 16 Nov 2017 16:46:43 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com vAG7kgbr014686 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1510818403; bh=946oera2CwSCjMd06g9WkzN6GxdWzyddIv9Hht8c13s=; h=From:To:Cc:Subject:Date:From; b=2TsOuB/3ARxw+VaTwAGcHxN9gvb8DL/gztSkOEfZsgT1pMEQVZVWCY+RzXEQy4gsD yXqCoqdfGY83DoE8OuBxq9V9vSLFvEC7DA2tksZ5sNkAbKIUpD65FArPL76mKDO1Z6 fRy+33IJGwaC4+awje7bGxGOY67dZDXEJJBLMnuYI9QwGsrjJRh6rtprZUEumJGgqZ i1DhYJNZP8wn2C2S7ABsr2nH6XcSErvXpIYeldBnmXrCcFN4YhEXk1+YhlmdzYbDmr fMv2wj7eWBzSg7ZuEEkQEx13jXnq8qvz63BGa62zhBFqLl8tEGvvyDVTBy6I9leL3F GuZMU1ebnfI/w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Sam Ravnborg , Michal Marek , Cao jin , Masahiro Yamada , Michal Marek , linux-kernel@vger.kernel.org Subject: [PATCH] kbuild: define KBUILD_MODNAME even if multiple modules share objects Date: Thu, 16 Nov 2017 16:46:36 +0900 Message-Id: <1510818396-17443-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 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 Currently, KBUILD_MODNAME is defined only when $(modname) contains just one word. If an object is shared between multiple modules, undefined KBUILD_MODNAME causes a build error. A simple test case is as follows: obj-m += foo.o obj-m += bar.o foo-objs := foo-bar-common.o foo-main.o bar-objs := foo-bar-common.o bar-main.o In this case, we do not know what to define for KBUILD_MODNAME when compiling foo-bar-common.o ("foo" or "bar" ?), so one reasonable solution is let it fall back to $(basetarget) (= "foo-bar-common"). It would be better to avoid such a design where possible, but we already have such a case, for example, drivers/net/ethernet/cavium/liquidio/Makefile I slightly refactored implementation; we can check $(word 2, $(modname)) instead of $(filter 1,$(words $(modname))). Signed-off-by: Masahiro Yamada Tested-by: Cao jin Reviewed-by: Cao jin --- scripts/Makefile.lib | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 5fbc46d..9f9a7df 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -86,8 +86,7 @@ subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) # differ in different configs. name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) -modname_flags = $(if $(filter 1,$(words $(modname))),\ - -DKBUILD_MODNAME=$(call name-fix,$(modname))) +modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(if $(word 2,$(modname)),$(basetarget),$(modname))) orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \ $(ccflags-y) $(CFLAGS_$(basetarget).o)