Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6341567rwd; Mon, 19 Jun 2023 06:05:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5KPdnI3fqO/vv1RET3w5KOdzUJ5/9B12C0IOJH9sqz5goFuKtHMl3uAp8H1h2qx9OJWF8d X-Received: by 2002:a05:6a20:4289:b0:122:5c71:6c82 with SMTP id o9-20020a056a20428900b001225c716c82mr208302pzj.41.1687179940407; Mon, 19 Jun 2023 06:05:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687179940; cv=none; d=google.com; s=arc-20160816; b=lJ0vu+e4I9ai9kw70sBw1iiIsP1wVcCFRn+QGHUDaqpJ5ECGdYhHdXceXte/NdjEE0 9qqjcFAZUUHAdMDMb4nSJSvAsZvNneoVoKUMCpNYdVjM71tYBgMAb6Yt/11MLxmympij fS+skcTlT4TAtb7OvjqoEzyYK9mT2v4TxsLW5l+sAfvgyT/U/CdNWWKHNrXI5gsGhqRT i9XtKENAAyoDK4Civ1xr3ZOqX/LueB2MJ2JeqU1Ey1lyrbiLEApNcaWyYEIpzABdRr3A mkzyqKdLkfKQVlVLd+h8rqhDeS+7tPUEcJSurxkFw8OxAmEUDsmaZWGx+DRBteg/c7rH IziA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NbfL+w+rA7lalH3U6pETbEV+3wR3qzABcC0yWoTLmeg=; b=wEF3dFEpbnvGwzF53J2p8IOqDOedqJx6otsWCp8xSjuDClm9hGQ8/22x5FLi4KLifc TRH3yC15sQOC8owQFFKkHO/fUMs2/AiGNwREBJuVU6ZxLBXsMi8f16wXzMS6Uutns7kR w+EN1miSYoL0EyYoQGiiODs5Op6i/d3qkah7Uv8Q0qzrOTFwHzzhDQ+HLJxN9czH/OHS 7W84vitMID9eLSug3XA7hLYjoS3a/c6yRm2UA84MLqrGqbnBt3f6HvrnOttTpVFlAeX9 M4YX2UX9JRDruXuaqj6u2tQMy3goiwth4Secn7FL5i0dkYpdYnOMxtt98+q7QhliNRkA 4GFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fjasle.eu Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u197-20020a6379ce000000b00535bf852410si16382246pgc.313.2023.06.19.06.05.16; Mon, 19 Jun 2023 06:05:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=fjasle.eu Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbjFSMvM (ORCPT + 99 others); Mon, 19 Jun 2023 08:51:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231407AbjFSMvA (ORCPT ); Mon, 19 Jun 2023 08:51:00 -0400 Received: from mail.avm.de (mail.avm.de [IPv6:2001:bf0:244:244::94]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51E281731; Mon, 19 Jun 2023 05:50:20 -0700 (PDT) Received: from mail-auth.avm.de (unknown [IPv6:2001:bf0:244:244::71]) by mail.avm.de (Postfix) with ESMTPS; Mon, 19 Jun 2023 14:50:17 +0200 (CEST) Received: from buildd.core.avm.de (buildd-sv-01.avm.de [172.16.0.225]) by mail-auth.avm.de (Postfix) with ESMTPA id 3F9B781FD7; Mon, 19 Jun 2023 14:50:17 +0200 (CEST) Received: by buildd.core.avm.de (Postfix, from userid 1000) id 32B0318207E; Mon, 19 Jun 2023 14:50:17 +0200 (CEST) Date: Mon, 19 Jun 2023 14:50:17 +0200 From: Nicolas Schier To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , David Howells Subject: Re: [PATCH v2 1/2] kbuild: revive "Entering directory" for Make >= 4.4.1 Message-ID: References: <20230616145751.945864-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230616145751.945864-1-masahiroy@kernel.org> X-purgate-ID: 149429::1687179017-A14E50AE-C5C897CC/0/0 X-purgate-type: clean X-purgate-size: 4548 X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 16, 2023 at 11:57:50PM +0900, Masahiro Yamada wrote: > With commit 9da0763bdd82 ("kbuild: Use relative path when building in > a subdir of the source tree"), compiler messages in out-of-tree builds > include relative paths, which are relative to the build directory, not > the directory where make was started. > > To help IDEs/editors find the source files, Kbuild lets GNU Make print > "Entering directory ..." when it changes the working directory. It has > been working fine for a long time, but David reported it is broken with > the latest GNU Make. > > The behavior was changed by GNU Make commit 8f9e7722ff0f ("[SV 63537] > Fix setting -w in makefiles"). Previously, setting --no-print-directory > to MAKEFLAGS only affected child makes, but it is now interpreted in > the current make as soon as it is set. > > [test code] > > $ cat /tmp/Makefile > ifneq ($(SUBMAKE),1) > MAKEFLAGS += --no-print-directory > all: ; $(MAKE) SUBMAKE=1 > else > all: ; : > endif > > [before 8f9e7722ff0f] > > $ make -C /tmp > make: Entering directory '/tmp' > make SUBMAKE=1 > : > make: Leaving directory '/tmp' > > [after 8f9e7722ff0f] > > $ make -C /tmp > make SUBMAKE=1 > : > > Previously, the effect of --no-print-directory was delayed until Kbuild > started the directory descending, but it is no longer true with GNU Make > 4.4.1. > > This commit adds one more recursion to cater to GNU Make >= 4.4.1. > > When Kbuild needs to change the working directory, __submake will be > executed twice. > > __submake without --no-print-directory --> show "Entering directory ..." > __submake with --no-print-directory --> parse the rest of Makefile > > We end up with one more recursion than needed for GNU Make < 4.4.1, but > I do not want to complicate the version check. > > Reported-by: David Howells > Closes: https://lore.kernel.org/all/2427604.1686237298@warthog.procyon.org.uk/ > Signed-off-by: Masahiro Yamada > --- > > Changes in v2: > - Fix the code. V1 did not work. > - Remove the version check to simplify the code Tested-by: Nicolas Schier > > Makefile | 36 ++++++++++++++++++++---------------- > 1 file changed, 20 insertions(+), 16 deletions(-) > > diff --git a/Makefile b/Makefile > index cc3fe09c4dec..916c1a7984b0 100644 > --- a/Makefile > +++ b/Makefile > @@ -189,13 +189,6 @@ else > abs_objtree := $(CURDIR) > endif # ifneq ($(KBUILD_OUTPUT),) > > -ifeq ($(abs_objtree),$(CURDIR)) > -# Suppress "Entering directory ..." unless we are changing the work directory. > -MAKEFLAGS += --no-print-directory > -else > -need-sub-make := 1 > -endif > - > this-makefile := $(lastword $(MAKEFILE_LIST)) > abs_srctree := $(realpath $(dir $(this-makefile))) > > @@ -214,6 +207,23 @@ endif > export abs_srctree abs_objtree > export sub_make_done := 1 > > +endif # sub_make_done > + > +ifeq ($(abs_objtree),$(CURDIR)) > +# Suppress "Entering directory ..." if we are at the final work directory. > +no-print-directory := --no-print-directory > +else > +# Recursion to show "Entering directory ..." > +need-sub-make := 1 > +endif > + > +ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) > +# If --no-print-directory is unset, recurse once again to set it. > +# You may end up with recursing into __sub-make twice. This is due to the > +# behavior change for GNU Make 4.4.1. > +need-sub-make := 1 > +endif > + > ifeq ($(need-sub-make),1) > > PHONY += $(MAKECMDGOALS) __sub-make > @@ -223,18 +233,12 @@ $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make > > # Invoke a second make in the output directory, passing relevant variables > __sub-make: > - $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS) > + $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \ > + -f $(abs_srctree)/Makefile $(MAKECMDGOALS) > > -endif # need-sub-make > -endif # sub_make_done > +else # need-sub-make > > # We process the rest of the Makefile if this is the final invocation of make > -ifeq ($(need-sub-make),) > - > -# Do not print "Entering directory ...", > -# but we want to display it when entering to the output directory > -# so that IDEs/editors are able to understand relative filenames. > -MAKEFLAGS += --no-print-directory > > ifeq ($(abs_srctree),$(abs_objtree)) > # building in the source tree > -- > 2.39.2 >