Received: by 10.223.176.46 with SMTP id f43csp2132197wra; Thu, 25 Jan 2018 05:30:43 -0800 (PST) X-Google-Smtp-Source: AH8x225gXSib0HAMJS+gWfrYbeShuUG+toHTLRCCHdzK5NfCK3osiDIVMhSZn5TM6FKUEWJfN7Z/ X-Received: by 2002:a17:902:7402:: with SMTP id g2-v6mr11081563pll.206.1516887043443; Thu, 25 Jan 2018 05:30:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516887043; cv=none; d=google.com; s=arc-20160816; b=AsAaPtWQ7Jt87R2BcUGu1uf/vd2tmJ+feHc9YMn3XJq0L4jrB0JgZcZ8OL0Ce+k9UM Zd88C+Exn/k3SLljcfh/ZhbP4pEtO2Ds8yeNadLGDW6oUKP30F5VowTiAc7fX/eSCTaK ooMZnFpLB86auNStfvqLb0ILcnwcTDH7iKPQrzU/PLW/8kleWSSQ1a898mmbvh/vVePU KCT0lLWafARIUEw/WbWnDV75MruX1zEWon/sTErm58pJ60mTHNcDt0017wq7q5isGE2W 1XKNLPLGCwx+XzxSUoWqv9okCu04JYOLndJ7Ogkeo+f0mgZP5DWU94BkHqgdQ51EhLzG Abpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-filter :arc-authentication-results; bh=ox9AqqFavasIjHfXpOnQfEYKtq12O6m3AZXDj9ofmcY=; b=CxzRS5rkdGrH/IZoWSN27fADIZbkQFeb7yjFjiUhoPXzQeHnb95zsGYRmaYtszJhgq Y2/5hRTRhDC5snMoZXhF/m1HKqV17UnvBi4Y6pnnJc+zacD+JQ9EAt7vKHYgY5uLUtPG OZP5rQHvKGhUddKYDUxXO6gEOMxn7mZIBa1CAeQvbwFePeVjBmL1kQDwpU31L+OB2m69 XZObiILhAD7dRmj8dJZEP5LlNRiY0pm+Cnx2zxDrSlKNigrNywIFCXNVnJSC4ja26W8N JynSK9zZX5nq5GAA9NtW+JJO1phNW2yWaRORiCc/2CYGopYWe21SKOzB4Ef1L4ZszoPS OK1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=uHmJqevg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n64si4614403pfb.184.2018.01.25.05.30.25; Thu, 25 Jan 2018 05:30:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=uHmJqevg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751860AbeAYNJZ (ORCPT + 99 others); Thu, 25 Jan 2018 08:09:25 -0500 Received: from conssluserg-05.nifty.com ([210.131.2.90]:42759 "EHLO conssluserg-05.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751391AbeAYNJY (ORCPT ); Thu, 25 Jan 2018 08:09:24 -0500 Received: from mail-ua0-f173.google.com (mail-ua0-f173.google.com [209.85.217.173]) (authenticated) by conssluserg-05.nifty.com with ESMTP id w0PD9FeF032282; Thu, 25 Jan 2018 22:09:16 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-05.nifty.com w0PD9FeF032282 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1516885756; bh=ox9AqqFavasIjHfXpOnQfEYKtq12O6m3AZXDj9ofmcY=; h=In-Reply-To:References:From:Date:Subject:To:Cc:From; b=uHmJqevgdyYQ9lliwVby3QGt2Qud5LUSVnr6qrQfjO6G3B/w4D9XvCggHfM3gNT9y NSIXbECOiJvGAeh4BsX3k531aQUrJP2be4SFyAQc31SUQdTvR8q8ToPIo3qP/KSKTl rR5fBWuu7BzjRH92BJvkoinDIdXxDwtU34FMo9/s+WReYVtXVll8KWTEoWK8vl46VB r6KvPrGsR5ws+Qm4N51BmvPeweDVeRowkNvc5r0kvWslFpRxeyNdQIsZKE653p73RT VMl9yRGO9lblCQInKuzpJOGkrGCkIYGRjreYrSoqL/5oToBm6B0ulOf4NqVtgVZh2K fxcC7drcIIiUQ== X-Nifty-SrcIP: [209.85.217.173] Received: by mail-ua0-f173.google.com with SMTP id e25so2602222uan.5; Thu, 25 Jan 2018 05:09:16 -0800 (PST) X-Gm-Message-State: AKwxytehPrL1Os7nqcZ/1MyekuT/3C80LJHqhOuGR3pILBxhlgw316JE rFeabWoz3TRtYpXgq76GEfnSN+GMBK8t6OW2ano= X-Received: by 10.176.5.70 with SMTP id 64mr7187078uax.87.1516885755136; Thu, 25 Jan 2018 05:09:15 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.49.90 with HTTP; Thu, 25 Jan 2018 05:08:34 -0800 (PST) In-Reply-To: <20180122134607.00d77101@cakuba.netronome.com> References: <20180122134607.00d77101@cakuba.netronome.com> From: Masahiro Yamada Date: Thu, 25 Jan 2018 22:08:34 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Mutli-directory module Makefiles To: Jakub Kicinski Cc: Linux Kbuild mailing list , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-01-23 6:46 GMT+09:00 Jakub Kicinski : > Hi! > > in drivers/net/ethernet/netronome/nfp there is a module which is built > from C sources in 4 directories. What is the best way to handle that? > > Currently we just add all the objects in one Makefile: > > nfp-objs := \ > nfpcore/nfp6000_pcie.o \ > nfpcore/nfp_cppcore.o \ > etc. I recommend you to refactor the Makefile, adding Makefiles into nfpcore, nic, flower, bpf sub-directories. Also, ifeq is ugly, can you rewrite like follows? nfp-$(CONFIG_NFP_APP_FLOWER) += flower/ nfp-$(CONFIG_BPF_SYSCALL) += bpf/ nfp-$(CONFIG_NFP_DEBUG) += nfp_net_debugfs.o > However, this makes it impossible to build a single object in subdirs: > > $ make drivers/net/ethernet/netronome/nfp/nfpcore/nfp_cppcore.o > scripts/Makefile.build:45: drivers/net/ethernet/netronome/nfp/nfpcore/Makefile: No such file or directory > make[2]: *** No rule to make target 'drivers/net/ethernet/netronome/nfp/nfpcore/Makefile'. Stop. > > Documentation/kbuild/modules.txt also contains an unclear remark that > this is not recommended (or is it about the use of $(src)?): > > --- 4.3 Several Subdirectories > ... > To build the module complex.ko, we then need the following > kbuild file: > > --> filename: Kbuild > obj-m := complex.o > complex-y := src/complex_main.o > complex-y += src/hal/hardwareif.o > > ccflags-y := -I$(src)/include > ccflags-y += -I$(src)/src/hal/include > > As you can see, kbuild knows how to handle object files located > in other directories. The trick is to specify the directory > relative to the kbuild file's location. **That being said, this > is NOT recommended practice.** > > Making the include optional would work: > > diff --git a/scripts/Makefile.build b/scripts/Makefile.build > @@ -42,7 +42,7 @@ save-cflags := $(CFLAGS) > # The filename Kbuild has precedence over Makefile > kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) > kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) > -include $(kbuild-file) > +-include $(kbuild-file) > > # If the save-* variables changed error out > ifeq ($(KBUILD_NOPEDANTIC),) > > Or we could create empty Makefiles in subdirectories... Is there a > better way of handling this? Which is preferred? -- Best Regards Masahiro Yamada