From patchwork Fri Jun 16 14:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 109197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1423219vqr; Fri, 16 Jun 2023 08:25:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mxEQMGQVIY9bHi2eYvVSLHnCMbtRqyqbNAm+EGYVnp54sgJMnYM3lpaVZxMVQD37BHonI X-Received: by 2002:a17:902:e884:b0:1b5:16f2:a4e3 with SMTP id w4-20020a170902e88400b001b516f2a4e3mr2306620plg.30.1686929116337; Fri, 16 Jun 2023 08:25:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686929116; cv=none; d=google.com; s=arc-20160816; b=RV0NUplX4GQyMZF2eNq/kz5L1b9MrVD77qAn+ra6pwKmJ+0SM3iiooPoJ0yXWRGGa3 POuYVL/1WpfcgHlnZr6s7orj3cASgUkZHNSWIDz5/lbTCrhZ6phxaeeVaud2DR0N21NW 2f7UMgX3fSBisBiAgPoRATlTbppmep7gHV+Mw3E2RhDuYXFx8DNba5pmNluGLQpJExlK f8GnKMZOJFHl7yrjbA874XhwokhW4Qkg9pQq3KvXgLkpXuM+kpNmgG5vrhnobPKhJnMz mv3xMZGCLzkwHdEmS6RsYAsq6IWOWEDpi3uU4LgrA/iOL8aCVozAYRV4UOCtCAYa/W5e LhIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=4DuBr1l6qspiSk2F5R6fDKZ0yiGlo/P37Yflz//CFwg=; b=lLaJLd5xl3s7gCjvRUGxnHlqeUS3UYNSCfM341GAb8LhYuwk5uJreVBcwF3g4jJ7FZ VO+pkmUAQIVDM38TemMu9a+6EifWF72e6GLBPDNpVXmNXAgBt19ebb15YVHikq/uNHyV 4wV4Asui1kO2pvDDr+kmN6ES28fLdMnX3r6iU7nSjNlF0BuPgKME/Jo17vs7lNBGdr/4 pbfRpZQOvR2Sp5cshmKYsL3yUl4Jg+nOboZCVHdl1UbRxbRDJf95K+mcxycaFveMyyjG u6BCOH4NcJ7GpTAUomf67sztWWCbS17CGAPiHABtDInCLpdS06IsOqK1jugQPUcYG0w+ hX2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cin4XiA8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a170902e5c500b001b046acc841si16160379plf.266.2023.06.16.08.24.56; Fri, 16 Jun 2023 08:25:16 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cin4XiA8; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231265AbjFPO6B (ORCPT + 99 others); Fri, 16 Jun 2023 10:58:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjFPO57 (ORCPT ); Fri, 16 Jun 2023 10:57:59 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CEB830C5; Fri, 16 Jun 2023 07:57:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AE4376336C; Fri, 16 Jun 2023 14:57:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 356D7C433C0; Fri, 16 Jun 2023 14:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686927476; bh=MPjQQ3JtAC+4df4LxJ4VAYqSVq149IdkIDQqJgcx6ms=; h=From:To:Cc:Subject:Date:From; b=cin4XiA8F5ZrvkEgAT9yCstY6jWTY4WQgdfjRhVHvNTEV8fdJk09mFVVX3xCL7f5R hcioGNhqMxMv0U/BP+D0OP9hCZ/NNav+wpI+5qAdE2rvRS2TYLv5jBtMvazOGR/hMZ IRGQqv408IoiGCY/os9eA/HvFsgLxiIE63aBgAVsJKhhZJ1W4vosbQgoDlTW5Wh+jO oU5wHGj/AC3K4C4jhGQG6YsUqpygPqP5B1oRoErskfYHjRxdGE7Icrxomhp3++l3Pu ZLzB7bqS8oRvhYGzb/2iHO6s3DbJQpl/b+YOA1LqqNvHPgUM9DFzekfmFK4RWPsSWJ KHFbM24MgslJg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada , David Howells Subject: [PATCH v2 1/2] kbuild: revive "Entering directory" for Make >= 4.4.1 Date: Fri, 16 Jun 2023 23:57:50 +0900 Message-Id: <20230616145751.945864-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768873384957891207?= X-GMAIL-MSGID: =?utf-8?q?1768873384957891207?= 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 Tested-by: Nicolas Schier --- Changes in v2: - Fix the code. V1 did not work. - Remove the version check to simplify the code 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 From patchwork Fri Jun 16 14:57:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 109184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1415387vqr; Fri, 16 Jun 2023 08:13:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4AokvhhJTYvYrDPHIhojb+YrRmt3ofp89QzFstqxzykiy0I90yAzmd0u2XhqNGB2BlMuXH X-Received: by 2002:a17:902:cecc:b0:1ad:ea13:1914 with SMTP id d12-20020a170902cecc00b001adea131914mr10818922plg.30.1686928438933; Fri, 16 Jun 2023 08:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686928438; cv=none; d=google.com; s=arc-20160816; b=MulFOL3MyahsxPgDEgh+fOqeHmUa8wbV+ka2EvOiJYdrcnu2danerxF+xC0AWPqcNk Z5tcKnGVFrloyTpoFDf/O2o24WK6HZgHCOlqm6HihuAcZYeJRWbTM+IIx74uQbRr6D8v yb6304R2xr/nAwfsLVjJLCxvT0YyybsAn/cUwYGdQA/y4ybouEqGZLgbMb/L4eJX12d5 6azhMovUuKnUUBVClN/nF9FZCHP2hr1M6+LXbMXvyHU2VQNgyKXDgv8XqMCyjf5gjuYU XJ2Fq1GGpbDnKgSYouosdcPtQtgxzXaCVTzO6eeIh9KlgPjKiBcK4ykCIJbULVhNnQCM gVmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4ZfeEVfEQ14jI7lTZZy2jECAz0J9MYSnhLxLi2USaX8=; b=AgPc8tQbvu1+n+sdOdDOqSeeVkU/gUbC/G9djWD/ICOE57RtJT5TR+S6HXnFGLq/I4 EFliow8XSZis6Jx/VLnoSDK3HILO3dgRiN4xVqpJFmuRQVSjXIfU6ZZt4OfQT+Ixl/o/ eaUjvyU7/cLpkRLhNV7iA2fIWVQcHCgihzRrQykgTDoG9n9VrMwRil0qLdD7YsEreqYo +eHfel114MU2PcsvLaH+ml6oS5++PqRv933175uK+096hZaVRtuW8Acokkq+wA8XZRx8 9yV0woldaTME5EHLu2ItZksYkcod+ElBVktm9EmJo7Pa/IQTt9zlBmLUKyvCJwGR+6h9 FtKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HO3j+fdw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i131-20020a639d89000000b0054febc069d3si4477042pgd.19.2023.06.16.08.13.44; Fri, 16 Jun 2023 08:13:58 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HO3j+fdw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345361AbjFPO6D (ORCPT + 99 others); Fri, 16 Jun 2023 10:58:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345756AbjFPO6A (ORCPT ); Fri, 16 Jun 2023 10:58:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BE930DD; Fri, 16 Jun 2023 07:57:59 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 78B4B62FBB; Fri, 16 Jun 2023 14:57:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61B3EC433CB; Fri, 16 Jun 2023 14:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686927478; bh=VEgG/e8fspM0F601IZYMqwpkaszvh+z+6C3I9ZOUdPU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HO3j+fdwDlPrXg3XbH0O26oU15mWSLLDR2qPmFPbvajv34VOWB/sQQld0y23xbCj4 L4wRcf90mHcgw8kYasEMrNj/YsZs3OY5IVbQIJ4amINKsobefTlLIzAhnn0kW25Xnj N9sNVT+BPpCmT45KGzy5arrBBufxwCI/KUi6+jR56gSeITKiaTRutVEaEhL0pqGFxO ymS2vKOVQ68AUMUmOPTxjJAQJfZ2u/IiSjByXYdA8qm0BcDxdh3qQtiv4QCwaV1Alr ji9EEm5AJaM3+RlaE1Yg7cG1qgKaRcQuE78JtWdZR6kSP4R2F8XDoICDL20szGiji5 J52n7UFrx7XJQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada Subject: [PATCH v2 2/2] kbuild: respect GNU Make -w flag Date: Fri, 16 Jun 2023 23:57:51 +0900 Message-Id: <20230616145751.945864-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230616145751.945864-1-masahiroy@kernel.org> References: <20230616145751.945864-1-masahiroy@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768872674716959095?= X-GMAIL-MSGID: =?utf-8?q?1768872674716959095?= Currently, -w (--print-directory) option is ignored, but it is better to respect the user's choice. This commit changes the behavior of "Entering directory ..." logging. If -w (or --print-directory) is given via the command line or the MAKEFLAGS environment variable, print "Entering directory ..." for every sub make. If --no-print-directory is given via the command line or the MAKEFLAGS environment variable, suppress "Entering directory ..." completely. If none of them is given, print "Entering directory ..." only when Kbuild changes the working directory. (default) Signed-off-by: Masahiro Yamada Tested-by: Nicolas Schier --- Changes in v2: - new patch Makefile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 916c1a7984b0..3867cdc3de5d 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,12 @@ __all: # descending is started. They are now explicitly listed as the # prepare rule. +ifeq ($(filter 3.%,$(MAKE_VERSION)),) +short-opts := $(firstword -$(MAKEFLAGS)) +else +short-opts := $(filter-out --%,$(MAKEFLAGS)) +endif + ifneq ($(sub_make_done),1) # Do not use make's built-in rules and variables @@ -91,12 +97,6 @@ endif # commands # make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS. -ifeq ($(filter 3.%,$(MAKE_VERSION)),) -short-opts := $(firstword -$(MAKEFLAGS)) -else -short-opts := $(filter-out --%,$(MAKEFLAGS)) -endif - ifneq ($(findstring s,$(short-opts)),) quiet=silent_ override KBUILD_VERBOSE := @@ -217,12 +217,16 @@ else need-sub-make := 1 endif +ifeq ($(findstring w, $(short-opts)),) 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 +else +no-print-directory := +endif ifeq ($(need-sub-make),1)