Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1436069rdb; Tue, 30 Jan 2024 20:25:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJBbDfTvv9KmWXL+FAEmqR/iY4pGP3+eZGIMVkWIC6gRMW9iLHyaKYIIXi/CtFPamWFg++ X-Received: by 2002:a25:6b4f:0:b0:dc2:364f:9a8 with SMTP id o15-20020a256b4f000000b00dc2364f09a8mr535791ybm.63.1706675131462; Tue, 30 Jan 2024 20:25:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706675131; cv=pass; d=google.com; s=arc-20160816; b=vIzDPgijOysOrmAmi8PO/YV/k7nUBG9+4HI8UJwSR2pfmBq1uTgnAfOq3FzPJRdm5G Hbr25xBJowX+YGUp7mXSO/3pwN/qYKT9HmKW5CnPP/J6Ck021Onna9Uyg1vl0Ann4QaB cRhNSVQ/t+ojDj3wpUitgnaYDSwqSGntVkUdv2HypEH+sb/hgkzwpf/3e2FWKqj1DjRA XfyKg22fOe1t3LxxOZ7fMj64u5pNK311MjR5hSrJsEgy9BQNZOv5kMQJ4+9NWrpDN5oi xLB3YSyn2aEPKn/RMzZ5umDuIVLzCDkb4vrIWNJzuN7s+ZHbN9sKCGukEzx7Kl40nEAO lZcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Zha8wYy8WlcwDCuU60s5IZGwiNRJ0LRFCCEU2An/LwY=; fh=WtQTVxJWCcHwONLcvMbLIB0QS+5KgUjW/OAGVe9RAvM=; b=dFNlGBJQKQEsaZjzxJS73bxq2y+Swc3muDaFr4JG6ui7TF1+7jGhelqh9j8bF9vEwb ARQaKWz6cA0uR0DgcgnqqFkPEn09P4IFeeJFbmsFsM0qcgtrf4ax9CsD4Gl6N9QHh8n9 8+i0gkS0fruVdYpWXGsXNwTLTqvg++9dvb8+SjFd+SH0yz996/H76ZahqxsYJxjh1+e6 CbnkWrGl9I1t2GVjb10EiU3Qq2uvQ0dfkNRAnWLpOPzNzIVSlzDo7Ypd8djEWGTCYPWL UxUAEAMA3DztSrW4NbPgmZCnczkFxURILZ5AT0wN9F73VyVSsAbVQu4ZDeeFTYV/7uVi tvdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aBkCTfS5; 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-45741-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45741-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCWLKzjcjriJe2B9roXjBMG0KnfyBr9WEqU2ed7UDsK3VtRSLgd0kQ7HNJzTLJwwYq8CZZVf+k2R2DcpMF7pvIQgK6tM3oGlfjo8r6YygQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k132-20020a636f8a000000b005ced4fbeb75si8741106pgc.581.2024.01.30.20.25.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 20:25:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45741-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=aBkCTfS5; 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-45741-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45741-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 1A2382868F1 for ; Wed, 31 Jan 2024 04:25:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7746A17BD1; Wed, 31 Jan 2024 04:25:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aBkCTfS5" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (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 1F71E20DDA; Wed, 31 Jan 2024 04:25:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706675120; cv=none; b=iqI7nvMTk7vRFJmaQ29X9/ZMxy3GdPWTx3lMhxbk/S40l78Aw5RG3sGZxRu6D+B+RcdKPsMIN0diAivaaPWgXfF9jTF0pWkKrHZjJDJZA/XA/guE/mbqesyDtNIIzNJzm+kl0B+PJqPAFHEx+Z1QaGaDrhDWppGhabHSN9VH21Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706675120; c=relaxed/simple; bh=xMlVeUsFGxYNCpqcspWBNL05NuVM6y84tCrJBreSpAw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=R8gH72pPo4RtnnJqZvScASIMIwMW8KRi98/zW1jkWTAAz3Pkyl0OmPXNrunAoPEBWKk2HDx1p03dXKQyvH/kDO4fIcZ61xtP8WjK/bU+YNUYtdSqwaEO4elaYRJYx8Wavpvn2xjty2fXmrysi1mSGD7ktTes6qUhwUjL+qk+ogI= 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=aBkCTfS5; arc=none smtp.client-ip=209.85.215.182 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-pg1-f182.google.com with SMTP id 41be03b00d2f7-5d8ddbac4fbso1686073a12.0; Tue, 30 Jan 2024 20:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706675118; x=1707279918; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Zha8wYy8WlcwDCuU60s5IZGwiNRJ0LRFCCEU2An/LwY=; b=aBkCTfS5Bi959Su/buIrBA2WqVA8zgYLVxzY2m2bo0O+hg8gmW9mFaIt7tXqCkRc0G Rq/gF3WWx1ghPkD7Yy+fB+8uymQGB9EAAh6cwTwLtldScawlpW0OwEN1tgdyPCPOxWM+ wfmFI0SBCRIuzanIj58sf39EdcSYfagRJDcF0KWKIFFbbgULMw/Ik8Q4FoLwGjoinC++ bvSpxWFYJ8RFl6Ncvn4gx+wxlfw39X9hW7FpSOdzWPwgONmrqQqL+zI7BOgZzXmUicXX oSrOBl9Pbk6pXNVfSuDO5JF4WHjZH6vH5s2h4RZtqpP6ni77u0Il18us7kfIF9tbzOIQ bz2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706675118; x=1707279918; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zha8wYy8WlcwDCuU60s5IZGwiNRJ0LRFCCEU2An/LwY=; b=BjINOOgKh2DLXDChcN4jZR9mVOIpysPaLZ7N2/VIFZUl1EZ0jD9nbTY/ixf5Qz+SJ5 p+9WlC6/w+E4KuFWafyrZg5SnFdLzOLy0MIDk4Ds70WSGdjlxl2e3qXqf9ckgkDt2iVQ e9fxzGbZV+8JqMQxM64K65ZSpbauWrF/JyXpux8oz2uQG0UValDz5bCNYxRizae7zQxk KlQljvZ2ezIx9g/ATl66g8oXfFinR+qFYrBHIjEaT02962mXQzGJYcOxnq1da0YfA6KQ RsftaynGE99yKLUO5BGZLAi8y1xty1ODbe+XJpjZPt7VMQdOkOxzfV/B0PC65O7uyV7x szaA== X-Gm-Message-State: AOJu0YwIt4R3eISe76mMfcv18/hXb5RYxd+1rTb62BMm+KgAUva5FKIV 4j2vIWbjmM/MVXsn7tUTSXsAABrkZOVmin1I8lyfAuXXUMNZ1GG9puh94LMr X-Received: by 2002:a05:6a20:1824:b0:19c:a2aa:67f8 with SMTP id bk36-20020a056a20182400b0019ca2aa67f8mr461436pzb.24.1706675117928; Tue, 30 Jan 2024 20:25:17 -0800 (PST) Received: from octofox.hsd1.ca.comcast.net (c-73-63-239-93.hsd1.ca.comcast.net. [73.63.239.93]) by smtp.gmail.com with ESMTPSA id e13-20020a17090ac20d00b00290ffbe5ca3sm274867pjt.55.2024.01.30.20.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 20:25:17 -0800 (PST) From: Max Filippov 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 , Max Filippov , stable@vger.kernel.org Subject: [PATCH v2] kbuild: tools: drop overridden CFLAGS from MAKEOVERRIDES Date: Tue, 30 Jan 2024 20:25:09 -0800 Message-Id: <20240131042509.4034723-1-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some Makefiles under tools/ use the 'override CFLAGS += ...' 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=... make ... and not in case when CFLAGS are passed as make command line arguments: make ... CFLAGS=... It happens because in the latter case CFLAGS=... is recorded in the make 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 := $(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 := $(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.include index 6fba29f3222d..0f68b95cf55c 100644 --- a/tools/scripts/Makefile.include +++ b/tools/scripts/Makefile.include @@ -51,6 +51,15 @@ define allow-override $(eval $(1) = $(2))) endef +# When a Makefile overrides a variable and exports it for the nested $(MAKE) +# invocations to use its modified value, it must remove that variable definition +# from the MAKEOVERRIDES variable, otherwise the original definition from the +# MAKEOVERRIDES takes precedence over the exported value. +drop-var-from-overrides = $(eval $(drop-var-from-overrides-code)) +define drop-var-from-overrides-code +MAKEOVERRIDES := $(subst \-,\\,$(subst \_,\ ,$(filter-out $(1)=%,$(subst \ ,\_,$(subst \\,\-,$(MAKEOVERRIDES)))))) +endef + ifneq ($(LLVM),) ifneq ($(filter %/,$(LLVM)),) LLVM_PREFIX := $(LLVM) -- 2.39.2