From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1723516-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 607E91582EF
	for <garchives@archives.gentoo.org>; Mon, 03 Mar 2025 19:27:14 +0000 (UTC)
Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	(Authenticated sender: relay-lists.gentoo.org@gentoo.org)
	by smtp.gentoo.org (Postfix) with ESMTPSA id 4795834315D
	for <garchives@archives.gentoo.org>; Mon, 03 Mar 2025 19:27:14 +0000 (UTC)
Received: from bobolink.gentoo.org (localhost [127.0.0.1])
	by bobolink.gentoo.org (Postfix) with ESMTP id E69ED1102F2;
	Mon, 03 Mar 2025 19:27:08 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by bobolink.gentoo.org (Postfix) with ESMTPS id E15711102F2
	for <gentoo-commits@lists.gentoo.org>; Mon, 03 Mar 2025 19:27:08 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256)
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 8FEE2343155
	for <gentoo-commits@lists.gentoo.org>; Mon, 03 Mar 2025 19:27:08 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id DFCD32810
	for <gentoo-commits@lists.gentoo.org>; Mon, 03 Mar 2025 19:27:06 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" <sam@gentoo.org>
Message-ID: <1741029986.55503135684b929613e6d432f4b1d4ee3851961d.sam@gentoo>
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
X-VCS-Repository: repo/gentoo
X-VCS-Files: eclass/zig-utils.eclass
X-VCS-Directories: eclass/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: 55503135684b929613e6d432f4b1d4ee3851961d
X-VCS-Branch: master
Date: Mon, 03 Mar 2025 19:27:06 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 7a8053ac-98b9-4620-8eb1-8cb50e479051
X-Archives-Hash: 8c39fe4bff96e71d51f8f5862bee211e

commit:     55503135684b929613e6d432f4b1d4ee3851961d
Author:     Eric Joldasov <bratishkaerik <AT> landless-city <DOT> net>
AuthorDate: Sat Jan 18 17:04:54 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Mar  3 19:26:26 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=55503135

zig-utils.eclass: add function to get the rightmost flag from CFLAGS

Similar to `get-flag` from toolchain.eclass, but searches from the end,
uses only CFLAGS, and returns value only.

Signed-off-by: Eric Joldasov <bratishkaerik <AT> landless-city.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/zig-utils.eclass | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/eclass/zig-utils.eclass b/eclass/zig-utils.eclass
index 5502d997935e..d92fd0724b17 100644
--- a/eclass/zig-utils.eclass
+++ b/eclass/zig-utils.eclass
@@ -202,6 +202,35 @@ fi
 # 0.13.0
 # @CODE
 
+# @FUNCTION: _get-c-option
+# @INTERNAL
+# @USAGE: <option-name>
+# @DESCRIPTION:
+# Gets value of some compiler option from CFLAGS, starting from the end.
+# Must be a full name, without "-" and "=..." part.
+#
+# Example:
+# @CODE
+# CFLAGS="-march=i686 -march=i586"
+# _get-c-option march # returns i586
+# @CODE
+_get-c-option() {
+	if [[ ${#} -ne 1 ]]; then
+		die "${FUNCNAME[0]}: expected 1 argument, got ${#}"
+	fi
+
+	local prefix="-${1}="
+	local c_flags=( ${CFLAGS} )
+	for (( i=${#c_flags[@]} - 1; i >= 0; i -= 1 )); do
+		local c_flag="${c_flags[i]}"
+		if [[ "${c_flag}" == ${prefix}* ]]; then
+			echo "${c_flag#${prefix}}"
+			return
+	    fi
+	done
+	echo ""
+}
+
 # @FUNCTION: zig-utils_c_env_to_zig_target
 # @USAGE: <C-style target tuple> <CFLAGS>
 # @DESCRIPTION:
@@ -224,8 +253,8 @@ zig-utils_c_env_to_zig_target() {
 	local c_arch="${c_tuple%%-*}"
 	local c_abi="${c_tuple##*-}"
 
-	local c_flags="${2}"
-	local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)"
+	local -x CFLAGS="${2}"
+	local c_flags_march="$(_get-c-option march)"
 
 	local arch os abi
 
@@ -279,11 +308,11 @@ zig-utils_c_env_to_zig_cpu() {
 	local c_tuple="${1}"
 	local c_arch="${c_tuple%%-*}"
 
-	local c_flags="${2}"
-	local c_flags_mabi="$(CFLAGS="${c_flags}" get-flag mabi)"
-	local c_flags_march="$(CFLAGS="${c_flags}" get-flag march)"
-	local c_flags_mcpu="$(CFLAGS="${c_flags}" get-flag mcpu)"
-	local c_flags_mfpu="$(CFLAGS="${c_flags}" get-flag mfpu)"
+	local -x CFLAGS="${2}"
+	local c_flags_mabi="$(_get-c-option mabi)"
+	local c_flags_march="$(_get-c-option march)"
+	local c_flags_mcpu="$(_get-c-option mcpu)"
+	local c_flags_mfpu="$(_get-c-option mfpu)"
 
 	local base_cpu features=""