e3c54b7
--- Python-3.5.1/Makefile.pre.in.kh	2015-12-17 05:51:08.466546157 -0500
e3c54b7
+++ Python-3.5.1/Makefile.pre.in	2015-12-17 05:52:26.207761635 -0500
e3c54b7
@@ -587,11 +587,15 @@ pybuilddir.txt: $(BUILDPYTHON)
e3c54b7
 		exit 1 ; \
e3c54b7
 	fi
e3c54b7
 
e3c54b7
+# This is shared by the math and cmath modules
e3c54b7
+Modules/_math.o: Modules/_math.c Modules/_math.h
e3c54b7
+	$(CC) -c $(CCSHARED) $(PY_CORE_CFLAGS) -o $@ $<
e3c54b7
+
e3c54b7
 # Build the shared modules
e3c54b7
 # Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for
e3c54b7
 # -s, --silent or --quiet is always the first char.
e3c54b7
 # Under BSD make, MAKEFLAGS might be " -s -v x=y".
e3c54b7
-sharedmods: $(BUILDPYTHON) pybuilddir.txt
e3c54b7
+sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
e3c54b7
 	@case "$$MAKEFLAGS" in \
e3c54b7
 	    *\ -s*|s*) quiet="-q";; \
e3c54b7
 	    *) quiet="";; \
e3c54b7
--- Python-3.5.1/Misc/NEWS.kh	2015-12-17 05:53:40.898929946 -0500
e3c54b7
+++ Python-3.5.1/Misc/NEWS	2015-12-17 05:54:28.599676136 -0500
e3c54b7
@@ -464,6 +464,10 @@ Build
e3c54b7
 - Issue #24986: It is now possible to build Python on Windows without errors
e3c54b7
   when external libraries are not available.
e3c54b7
 
e3c54b7
+- Issue #24421: Compile Modules/_math.c once, before building extensions.
e3c54b7
+  Previously it could fail to compile properly if the math and cmath builds
e3c54b7
+  were concurrent.
e3c54b7
+
e3c54b7
 Windows
e3c54b7
 -------
e3c54b7
 
e3c54b7
--- Python-3.5.1/setup.py.kh	2015-12-17 06:38:30.950955607 -0500
e3c54b7
+++ Python-3.5.1/setup.py	2015-12-17 06:42:32.074722493 -0500
e3c54b7
@@ -582,13 +582,17 @@ class PyBuildExt(build_ext):
e3c54b7
 
e3c54b7
         # array objects
e3c54b7
         exts.append( Extension('array', ['arraymodule.c']) )
e3c54b7
+
e3c54b7
+        shared_math = 'Modules/_math.o'
e3c54b7
         # complex math library functions
e3c54b7
-        exts.append( Extension('cmath', ['cmathmodule.c', '_math.c'],
e3c54b7
-                               depends=['_math.h'],
e3c54b7
+        exts.append( Extension('cmath', ['cmathmodule.c'],
e3c54b7
+                               extra_objects=[shared_math],
e3c54b7
+                               depends=['_math.h', shared_math],
e3c54b7
                                libraries=math_libs) )
e3c54b7
         # math library functions, e.g. sin()
e3c54b7
-        exts.append( Extension('math',  ['mathmodule.c', '_math.c'],
e3c54b7
-                               depends=['_math.h'],
e3c54b7
+        exts.append( Extension('math',  ['mathmodule.c'],
e3c54b7
+                               extra_objects=[shared_math],
e3c54b7
+                               depends=['_math.h', shared_math],
e3c54b7
                                libraries=math_libs) )
e3c54b7
 
e3c54b7
         # time libraries: librt may be needed for clock_gettime()