From 837e5d27fc97903b519f283c08d859a233323836 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?=
 <10796600+picnixz@users.noreply.github.com>
Date: Mon, 20 Jan 2025 14:27:14 +0100
Subject: [PATCH] gh-128978: Fix a `NameError` in
 `sysconfig.expand_makefile_vars` (GH-128979)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes a regression introduced by 4a53a397c311567f05553bc25a28aebaba4f6f65.
(cherry picked from commit df66ff14b49f4388625212f6bc86b754cb51d4eb)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
---
 Lib/sysconfig.py                                               | 3 +++
 .../Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst     | 2 ++
 2 files changed, 5 insertions(+)
 create mode 100644 Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst

diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index 517b13acaf6823..c747f0b4d4ad23 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -845,6 +845,9 @@ def expand_makefile_vars(s, vars):
     """
     import re
 
+    _findvar1_rx = r"\$\(([A-Za-z][A-Za-z0-9_]*)\)"
+    _findvar2_rx = r"\${([A-Za-z][A-Za-z0-9_]*)}"
+
     # This algorithm does multiple expansion, so if vars['foo'] contains
     # "${bar}", it will expand ${foo} to ${bar}, and then expand
     # ${bar}... and so forth.  This is fine as long as 'vars' comes from
diff --git a/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst b/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst
new file mode 100644
index 00000000000000..521496d6a2f8c2
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-01-18-11-04-44.gh-issue-128978.hwg7-w.rst
@@ -0,0 +1,2 @@
+Fix a :exc:`NameError` in :func:`!sysconfig.expand_makefile_vars`. Patch by
+Bénédikt Tran.