diff --git a/Makefile.pre.in b/Makefile.pre.in
index bf3aed7..7ff5c79 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -464,6 +464,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt
 	$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
 		_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
 		PYTHONXCPREFIX='$(DESTDIR)$(prefix)' \
+		CONFIG_ARGS="$(CONFIG_ARGS)" \
 		$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
 
 libpython$(VERSION).so: $(LIBRARY_OBJS)
@@ -1104,6 +1105,7 @@ libainstall:	all python-config
 # This goes into $(exec_prefix)
 sharedinstall: sharedmods
 	CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
+	CONFIG_ARGS="$(CONFIG_ARGS)" \
 	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
 		--skip-build \
 	   	--prefix=$(prefix) \
diff --git a/setup.py b/setup.py
index 6426b22..d2776dd 100644
--- a/setup.py
+++ b/setup.py
@@ -32,6 +32,9 @@ host_platform = get_platform()
 # Were we compiled --with-pydebug or with #define Py_DEBUG?
 COMPILED_WITH_PYDEBUG = ('--with-pydebug' in sysconfig.get_config_var("CONFIG_ARGS"))
 
+sysconfig.get_config_vars()
+sysconfig._CONFIG_VARS.update(os.environ)
+
 # This global variable is used to hold the list of modules to be disabled.
 try:
     disabled_module_list = os.environ["PYTHON_DISABLE_MODULES"].split()
