While working on a fix for #18211 I noticed two problems with the setup.py that's used to build the stdlib extensions.
1) setup.py uses sysconfig instead of distutils.sysconfig. The sematics of the two modules a slighty different.
2) The block of code starting with the this text is not necessary because distutils.sysconfig (which is used by the build_ext command) already does the right thing for environment variables:
# When you run "make CC=altcc" or something similar, you really want
# those environment variables passed into the setup.py phase. Here's
# a small set of useful ones.