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 ADC50EB64D7 for ; Sat, 17 Jun 2023 00:28:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229667AbjFQA2s (ORCPT ); Fri, 16 Jun 2023 20:28:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjFQA2r (ORCPT ); Fri, 16 Jun 2023 20:28:47 -0400 Received: from out-25.mta1.migadu.com (out-25.mta1.migadu.com [95.215.58.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B5B63A89 for ; Fri, 16 Jun 2023 17:28:45 -0700 (PDT) Date: Fri, 16 Jun 2023 20:28:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686961721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=oaftPGbxTf99h6Fvwz7OHzGqbqcVrb1RXHFkd6rrmXw=; b=fKlV+AGxmu+h/W/Jn5jJBFeL1MLg45etldxQesWiJCJjkmwcvZ/279GGwUifwYEm8YOsQ+ G+4PnSiB0sJvS6QSrEUisjT4ITOZ1S6UkkKRnqM/BSx/WvvZ7I3KIYetv0RA2KBuSz80S0 1MDcFoDvsk23gNfCIdiqkB9+S+B6l4E= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Peter Oberparleiter Cc: Nick Desaulniers , Masahiro Yamada , Nathan Chancellor , linux-kbuild@vger.kernel.org Subject: Re: Specifying CFLAGS for a directory on the command line Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org On Fri, Jun 16, 2023 at 08:10:44PM +0200, Peter Oberparleiter wrote: > Not that I know of. Here's how it could be made to work using Makefile > magic alone (as a pure programming exercise :) > > This will expand a directory to a list of all parent directories: > > # expand_parents(a/b/c) = a/b/c a/b a > expand_parents2 = $(if $(subst .,,$(1)),$(call expand_parents,$(1)),) > expand_parents = $(1) $(call expand_parents2,$(patsubst %/,%,$(dir $(1)))) > > This list could then be turned into variable suffixes: > > # flatten_dirs(a/b/c) = a_b_c a_b a > flatten_dirs = $(subst /,_,$(call expand_parents,$(1))) > > And finally the resulting list of suffixed variables could be evaluated: > > # eval_vars(X_,a/b/c) = $(X_a_b_c) $(X_a_b) $(X_a) > eval_vars = $(foreach var,$(call flatten_dirs,$(2)),$($(1)$(var))) > > So a call like this > > $(call eval_vars,GCOV_PROFILE_,a/b/c) I just hooked it up and it works perfectly - I owe you a beer :) > would evaluate to the concatenation of the contents of the following > variables: > > GCOV_PROFILE_a_b_c > GCOV_PROFILE_a_b > GCOV_PROFILE_a > > The first non-empty variable would then determine whether profiling > should be enabled for the associated source file or not. This would even > implement the correct order of precedence (specific to generic) > > Not sure if this amount of magic is suitable for kbuild though. An > alternative, less complex approach would be to move this decision logic > to a helper script. Now that I've spent a couple days starting to wrap my head more around make, it doesn't look terribly magic to me. I'd hate to have to spawn off a subshell for this.