From nobody Wed Dec 17 18:59:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFB98C27C40 for ; Wed, 22 Nov 2023 23:55:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344400AbjKVXzm (ORCPT ); Wed, 22 Nov 2023 18:55:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231410AbjKVXzk (ORCPT ); Wed, 22 Nov 2023 18:55:40 -0500 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5128C110 for ; Wed, 22 Nov 2023 15:55:36 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1700697334; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=APd5R7wj7h+UmDndBcpcrIZgyAl8kblJEa7hsW1VzXE=; b=Fr7LKUrQ1+DPyV59aRzL3jODD/CLS6w6QtYL7iNfwY43PhntlV2CnZKhxbzNFOmlLBi4SO q/aFPu3vTEVHuChpUq6NShLz2quOOZh/wFX/lb+bTnnZ+Dw4sLO0OWd2YBvoSKoAlmsb8F Hv3l1Yk8Wxh1XvSZjFlhrcEx5+wnTsc= From: Kent Overstreet To: linux-kernel@vger.kernel.org Cc: Kent Overstreet , Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-kbuild@vger.kernel.org Subject: [PATCH] kbuild: Allow gcov to be enabled on the command line Date: Wed, 22 Nov 2023 18:55:27 -0500 Message-ID: <20231122235527.180507-1-kent.overstreet@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This allows gcov to be enabled for a particular kernel source subdirectory on the command line, without editing makefiles, like so: make GCOV_PROFILE_fs_bcachefs=3Dy Cc: Masahiro Yamada Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Nicolas Schier Cc: linux-kbuild@vger.kernel.org Signed-off-by: Kent Overstreet --- scripts/Kbuild.include | 10 ++++++++++ scripts/Makefile.lib | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 7778cc97a4e0..5341736f2e30 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -277,3 +277,13 @@ ifneq ($(and $(filter notintermediate, $(.FEATURES)),$= (filter-out 4.4,$(MAKE_VER else .SECONDARY: endif + + # expand_parents(a/b/c) =3D a/b/c a/b a +expand_parents2 =3D $(if $(subst .,,$(1)),$(call expand_parents,$(1)),) +expand_parents =3D $(1) $(call expand_parents2,$(patsubst %/,%,$(dir $(1)= ))) + +# flatten_dirs(a/b/c) =3D a_b_c a_b a +flatten_dirs =3D $(subst /,_,$(call expand_parents,$(1))) + +# eval_vars(X_,a/b/c) =3D $(X_a_b_c) $(X_a_b) $(X_a) +eval_vars =3D $(foreach var,$(call flatten_dirs,$(2)),$($(1)$(var))) diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 1a965fe68e01..0b4581a8bc33 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -148,7 +148,7 @@ _cpp_flags =3D $(KBUILD_CPPFLAGS) $(cppflags-y) $(C= PPFLAGS_$(target-stem).lds) # ifeq ($(CONFIG_GCOV_KERNEL),y) _c_flags +=3D $(if $(patsubst n%,, \ - $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)= ), \ + $(GCOV_PROFILE_$(basetarget).o)$(call eval_vars,GCOV_PROFILE_,$(src))$(G= COV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ $(CFLAGS_GCOV)) endif =20 --=20 2.42.0