Without this patch the value of sysconfig.get_config_var('LDSHARED')
is wrong when PY_LDFLAGS is not empty.

The bug was caused by LDSHARED getting expanded *before* sysconfig
renamed PY_LDSHARED (and simular values) to names without a PY_
prefix.

The patch tries to maintain the intended behaviour of allowing users
to set LDFLAGS in the environment and have that affect the build.

Without this patch a universal build on OSX cannot build universal
(fat binary) extensions.
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index 28731df..2fec910 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -225,6 +225,12 @@
     # do variable interpolation here
     variables = list(notdone.keys())
 
+    # Variables with a 'PY_' prefix in the makefile. These need to
+    # be made available without that prefix through sysconfig.
+    # Special care is needed to ensure that variable expansion works, even
+    # if the expansion uses the name without a prefix.
+    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
+
     while len(variables) > 0:
         for name in tuple(variables):
             value = notdone[name]
@@ -240,8 +246,20 @@
                 elif n in os.environ:
                     # do it like make: fall back to environment
                     item = os.environ[n]
+
+                elif n in renamed_variables:
+                    if name.startswith('PY_') and name[3:] in renamed_variables:
+                        item = ""
+
+                    elif 'PY_' + n in notdone:
+                        found = False
+
+                    else:
+                        item = str(done['PY_' + n])
+
                 else:
                     done[n] = item = ""
+
                 if found:
                     after = value[m.end():]
                     value = value[:m.start()] + item + after
@@ -255,17 +273,19 @@
                         else:
                             done[name] = value
                         variables.remove(name)
+
+                        if name.startswith('PY_') \
+                                and name[3:] in renamed_variables:
+
+                            name = name[3:]
+                            if name not in done:
+                                done[name] = value
+
+
             else:
                 # bogus variable reference; just drop it since we can't deal
                 variables.remove(name)
 
-    # Add in CFLAGS, LDFLAGS, and CPPFLAGS, which are named with a
-    # prefix in the Makefile.
-    for var in ('CFLAGS', 'LDFLAGS', 'CPPFLAGS'):
-        makefile_value = done.get('PY_' + var)
-        if makefile_value is not None:
-            done[var] = makefile_value
-
     # save the results in the global dictionary
     vars.update(done)
     return vars