@@ -480,6 +480,13 @@ def add_gcc_paths(self):
480480 finally :
481481 os .unlink (tmpfile )
482482
483+ def detect_math_libs (self ):
484+ # Check for MacOS X, which doesn't need libm.a at all
485+ if host_platform == 'darwin' :
486+ return []
487+ else :
488+ return ['m' ]
489+
483490 def detect_modules (self ):
484491 # Ensure that /usr/local is always used, but the local build
485492 # directories (i.e. '.' and 'Include') must be first. See issue
@@ -584,10 +591,7 @@ def detect_modules(self):
584591 if item .startswith ('-L' ):
585592 lib_dirs .append (item [2 :])
586593
587- # Check for MacOS X, which doesn't need libm.a at all
588- math_libs = ['m' ]
589- if host_platform == 'darwin' :
590- math_libs = []
594+ math_libs = self .detect_math_libs ()
591595
592596 # XXX Omitted modules: gl, pure, dl, SGI-specific modules
593597
@@ -620,7 +624,10 @@ def detect_modules(self):
620624 # time operations and variables
621625 exts .append ( Extension ('time' , ['timemodule.c' ],
622626 libraries = time_libs ) )
623- exts .append ( Extension ('_datetime' , ['_datetimemodule.c' ]) )
627+ # math_libs is needed by delta_new() that uses round() and by accum()
628+ # that uses modf().
629+ exts .append ( Extension ('_datetime' , ['_datetimemodule.c' ],
630+ libraries = math_libs ) )
624631 # random number generator implemented in C
625632 exts .append ( Extension ("_random" , ["_randommodule.c" ]) )
626633 # bisect
@@ -691,11 +698,14 @@ def detect_modules(self):
691698 # Multimedia modules
692699 # These don't work for 64-bit platforms!!!
693700 # These represent audio samples or images as strings:
694-
701+ #
695702 # Operations on audio samples
696703 # According to #993173, this one should actually work fine on
697704 # 64-bit platforms.
698- exts .append ( Extension ('audioop' , ['audioop.c' ]) )
705+ #
706+ # audioop needs math_libs for floor() in multiple functions.
707+ exts .append ( Extension ('audioop' , ['audioop.c' ],
708+ libraries = math_libs ) )
699709
700710 # readline
701711 do_readline = self .compiler .find_library_file (lib_dirs , 'readline' )
@@ -1937,6 +1947,7 @@ def detect_ctypes(self, inc_dirs, lib_dirs):
19371947 '_ctypes/stgdict.c' ,
19381948 '_ctypes/cfield.c' ]
19391949 depends = ['_ctypes/ctypes.h' ]
1950+ math_libs = self .detect_math_libs ()
19401951
19411952 if host_platform == 'darwin' :
19421953 sources .append ('_ctypes/malloc_closure.c' )
@@ -1967,8 +1978,10 @@ def detect_ctypes(self, inc_dirs, lib_dirs):
19671978 libraries = [],
19681979 sources = sources ,
19691980 depends = depends )
1981+ # function my_sqrt() needs math library for sqrt()
19701982 ext_test = Extension ('_ctypes_test' ,
1971- sources = ['_ctypes/_ctypes_test.c' ])
1983+ sources = ['_ctypes/_ctypes_test.c' ],
1984+ libraries = math_libs )
19721985 self .extensions .extend ([ext , ext_test ])
19731986
19741987 if not '--with-system-ffi' in sysconfig .get_config_var ("CONFIG_ARGS" ):
0 commit comments