Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp129270rdb; Wed, 21 Feb 2024 20:48:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWc3sLFm5INBq4+Eum/xnwrgUmXFo9tZiFnwt8pjmbl34Y4FRes8F2xc2Sr3eqkIo+cogCFMKAQwvpj/E2SvgN/+H1OTC1oWys0ddH8KA== X-Google-Smtp-Source: AGHT+IGSXIbI5+xDn+T98ADtEp9AqyUQ3y/Oj4H5c0FSq7n/nUO7GQ1qKz6YvBAEyp612uVn3CMJ X-Received: by 2002:a05:6830:2090:b0:6e4:756a:4f57 with SMTP id y16-20020a056830209000b006e4756a4f57mr390574otq.3.1708577281757; Wed, 21 Feb 2024 20:48:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708577281; cv=pass; d=google.com; s=arc-20160816; b=a2AKnjoIJmdeCTRqqQ3HdQ6KCEQcDHu0Np46vghTpPLitP9e5BpGIUF3Tdy4dVxB9s IeXZmko0Xf5sWHHC+JJrn+Bs9CkZVUZMP/Px+Ro9nYX2srYIUl2qATC4aT6vgEI8ycNX oupyaXf3m7TpyTKxuryj3VA9WJHgNCMtDmDdidSwPqfsfv27/27CpnDtMe9N2dauP/9W PKhUOPqgPXlRrqptToyuQJMql8PDZqHZVJBnvodXhMCVRlqXBc29HXe+JS04lFSx9upi 7RPiKxuCvA5skl5LKkguSIU1MyFkAIF7VqTzXAhRLSTGErhBWhcpBxGqrH/0+28jYfFK 5g3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=+0AD0YCnQqqjpDGFWW9RzaHFEvNTNgA3R308dgKQBK0=; fh=bckLTgZQrSys06pF56P3uZNolJodW6SpDOfHVxHRenM=; b=v0z4hSliHk2mCEqN9V7ojQKrBG6/1F2alu0B/9S5A8K2U/aClRjZ/zk7mdbRfpUZd8 avl89vFt6AGdEc/FI7ZdKXQCNWTEIl6cykoNAWOBtJi4MZUZSSGXlKZfOJkOKqsI9zSP R66RmWABS64dwqBcfOG+cHhu2EgDLrAvpoMD3SNQsDtvDH0qJWU2U4BniBC5MAYYhHsr Y/pl4pccp7zukPjqSp6FQYpA956frHNySMZhASR49wix9/1jvA8b8RiQFIzryTCuxu5h zD81Uizez2RJ/mADecgyBXRMQYQYGsecW/c6rBkjZZeL8sfkrstvLJ5NhdYOV00V8hoJ 42kA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gUZxXtRv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id cc11-20020a056a02074b00b005dc42fd8c40si9358698pgb.404.2024.02.21.20.48.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 20:48:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=gUZxXtRv; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-75907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75907-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 67B25B225F8 for ; Thu, 22 Feb 2024 04:47:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 517FD4C8A; Thu, 22 Feb 2024 04:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gUZxXtRv" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2C4110E6; Thu, 22 Feb 2024 04:47:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708577267; cv=none; b=rRQxPVuyxySzOI6I0M0UPR6R5gGKn/F55E8+VkuCTup/wygYR//c40OGOv5opj1tHy4a33PD0zOFEUR/2txjGkGQSz6x/gP0Oakwm2+7NL6SFuAJd9vveW5eP6zgbKubYJdJEQmoa3yT7JhKRN1son/Zr6ZD4kC3xS1m0OyZ8Do= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708577267; c=relaxed/simple; bh=UeNo7Treptz3RUyiQTbwwLEw6a+8/F6tea3I16MzUxc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Eq7i1Vs0oSj939y8P+cOK2G7ULyDICHwzkJFYduktA0X4UiIBjBmtVY7VKdFNSFp6HbsbOGhZcoERgSkgP0m+tUmJHaAuYBUzl9csCpPsizqw+3HyzKX919NjYrwkGdjHYkTfc0kogVaOlPN1Hv/R2P80xjuFBEsXWxUdAnsz8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gUZxXtRv; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-595aa5b1fe0so4864510eaf.2; Wed, 21 Feb 2024 20:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708577264; x=1709182064; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+0AD0YCnQqqjpDGFWW9RzaHFEvNTNgA3R308dgKQBK0=; b=gUZxXtRvgbVGvAOidc1qfrexj0Ae8g9f98Iu64/LILGAGg1sMxYIi+atw6rFFLuMcm FeGJ/d7hMeiIT9KJMX3gyvEuBoPv/Tmasx+2GaaPQUiIFufReOATGRBslaudGTt8g02W IWm6UVT1dPsdHsRi7BEU/faBKIlQBgbgfVUX1cOqqhFfZiuIaD5lyJUIbAabSFJGBk9z ZfzCeLfWq1eRNYtmfO9ws1zHkUJwgtiNsUWCqu3ja3TqRiqe2cOjl1ceVfB4bxRTkZit A3Y9NVqZuIN04tefs/DY70EvGt2QyBsa9OaAH614Y14au08XuyPn4to54zdW9OZRnnkV chig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708577264; x=1709182064; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+0AD0YCnQqqjpDGFWW9RzaHFEvNTNgA3R308dgKQBK0=; b=a99jMzKZ/ACwKNak0idrkenFZbu9gzxuhBk1SAXwLqFcNNBgaFSerrTEGtYQH7wULl qYAbFYoIFOKLBQX/gH1X43TjS0xlL1IScAp+032/6KKWPUMie+gEc11eNyDna1cczIi+ kfmHr0Y+cm37wLZKlYHAxdUwLg/J9xHKmDdfDihpjqZp/dymkZBFvU8Z+v+4yWfOgw+p hoPNJWo2OYFDoWBhE6mqhgj4fAgnT9/COILObn+SkRw86Xf/PMfev+xXSTX1JbB9RaJN Jg25gdGkTfRYp6t2bQxOA6fubOhJ7mDmGI73xDRmYu2OWnKQTlKrFS/nOwAAT0GXDTvI EErw== X-Forwarded-Encrypted: i=1; AJvYcCU4UcVGiNTd6D7zZZyQL+rQqtsyeokuKsBUn0h7LFeYsid85bX4fkSG+dIueIKZEyZTQy0380/CEstudOY4h/PL3OgwCH1NOYm1R2hveThL3UX+Gq8zSGSjjx2T/d0KA31j9NCj1/+88qhDC6YRVnpzxOK/Y4nvBJY3rRyQjA== X-Gm-Message-State: AOJu0YxlF9MbMYaDIzhK8aPUEbCPL2aAbNtxOpVjdgwW/BcN5YMQslC3 JE4WQowVvJpVZoYRGBnAZpyE5QS9MksxnOMalpCwc40XdJmiq4CqZ2BanH7LeFid2KahQ2zoDAO 0+YZulUhO3gGVH0TbsrV+DmVcUNLGfcuk X-Received: by 2002:a05:6358:5919:b0:176:cf18:d0bb with SMTP id g25-20020a056358591900b00176cf18d0bbmr21288902rwf.13.1708577264582; Wed, 21 Feb 2024 20:47:44 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240131042509.4034723-1-jcmvbkbc@gmail.com> In-Reply-To: <20240131042509.4034723-1-jcmvbkbc@gmail.com> From: Max Filippov Date: Wed, 21 Feb 2024 20:47:33 -0800 Message-ID: Subject: Re: [PATCH v2] kbuild: tools: drop overridden CFLAGS from MAKEOVERRIDES To: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Jiri Olsa , Bartosz Golaszewski , Kent Gibson , Jonathan Cameron , Lars-Peter Clausen , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Ping? On Tue, Jan 30, 2024 at 8:25=E2=80=AFPM Max Filippov w= rote: > > Some Makefiles under tools/ use the 'override CFLAGS +=3D ...' construct > to add a few required options to CFLAGS passed by the user. > Unfortunately that only works when user passes CFLAGS as an environment > variable, i.e. > CFLAGS=3D... make ... > and not in case when CFLAGS are passed as make command line arguments: > make ... CFLAGS=3D... > It happens because in the latter case CFLAGS=3D... is recorded in the mak= e > variable MAKEOVERRIDES and this variable is passed in its original form > to all $(MAKE) subcommands, taking precedence over modified CFLAGS value > passed in the environment variable. E.g. this causes build failure for > gpio and iio tools when the build is run with user CFLAGS because of > missing _GNU_SOURCE definition needed for the asprintf(). > > One way to fix it is by removing overridden variables from the > MAKEOVERRIDES. Add macro 'drop-var-from-overrides' that removes a > definition of a variable passed to it from the MAKEOVERRIDES and use it > to fix CFLAGS passing for tools/gpio and tools/iio. > > This implementation tries to be precise in string processing and handle > variables with embedded spaces and backslashes correctly. To achieve > that it replaces every '\\' sequence with '\-' to make sure that every > '\' in the resulting string is an escape character. It then replaces > every '\ ' sequence with '\_' to turn string values with embedded spaces > into single words. After filtering the overridden variable definition > out of the resulting string these two transformations are reversed. > > Cc: stable@vger.kernel.org > Fixes: 4ccc98a48958 ("tools gpio: Allow overriding CFLAGS") > Fixes: 572974610273 ("tools iio: Override CFLAGS assignments") > Signed-off-by: Max Filippov > --- > Changes v1->v2: > - make drop-var-from-overrides-code work correctly with arbitrary > variables, including thoses ending with '\'. > > tools/gpio/Makefile | 1 + > tools/iio/Makefile | 1 + > tools/scripts/Makefile.include | 9 +++++++++ > 3 files changed, 11 insertions(+) > > diff --git a/tools/gpio/Makefile b/tools/gpio/Makefile > index d29c9c49e251..46fc38d51639 100644 > --- a/tools/gpio/Makefile > +++ b/tools/gpio/Makefile > @@ -24,6 +24,7 @@ ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS= )) > all: $(ALL_PROGRAMS) > > export srctree OUTPUT CC LD CFLAGS > +$(call drop-var-from-overrides,CFLAGS) > include $(srctree)/tools/build/Makefile.include > > # > diff --git a/tools/iio/Makefile b/tools/iio/Makefile > index fa720f062229..04307588dd3f 100644 > --- a/tools/iio/Makefile > +++ b/tools/iio/Makefile > @@ -20,6 +20,7 @@ ALL_PROGRAMS :=3D $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS= )) > all: $(ALL_PROGRAMS) > > export srctree OUTPUT CC LD CFLAGS > +$(call drop-var-from-overrides,CFLAGS) > include $(srctree)/tools/build/Makefile.include > > # > diff --git a/tools/scripts/Makefile.include b/tools/scripts/Makefile.incl= ude > index 6fba29f3222d..0f68b95cf55c 100644 > --- a/tools/scripts/Makefile.include > +++ b/tools/scripts/Makefile.include > @@ -51,6 +51,15 @@ define allow-override > $(eval $(1) =3D $(2))) > endef > > +# When a Makefile overrides a variable and exports it for the nested $(M= AKE) > +# invocations to use its modified value, it must remove that variable de= finition > +# from the MAKEOVERRIDES variable, otherwise the original definition fro= m the > +# MAKEOVERRIDES takes precedence over the exported value. > +drop-var-from-overrides =3D $(eval $(drop-var-from-overrides-code)) > +define drop-var-from-overrides-code > +MAKEOVERRIDES :=3D $(subst \-,\\,$(subst \_,\ ,$(filter-out $(1)=3D%,$(s= ubst \ ,\_,$(subst \\,\-,$(MAKEOVERRIDES)))))) > +endef > + > ifneq ($(LLVM),) > ifneq ($(filter %/,$(LLVM)),) > LLVM_PREFIX :=3D $(LLVM) > -- > 2.39.2 > --=20 Thanks. -- Max