setup.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. from __future__ import division, print_function
  2. from os.path import join
  3. import sys
  4. from distutils.dep_util import newer
  5. from distutils.msvccompiler import get_build_version as get_msvc_build_version
  6. def needs_mingw_ftime_workaround():
  7. # We need the mingw workaround for _ftime if the msvc runtime version is
  8. # 7.1 or above and we build with mingw ...
  9. # ... but we can't easily detect compiler version outside distutils command
  10. # context, so we will need to detect in randomkit whether we build with gcc
  11. msver = get_msvc_build_version()
  12. if msver and msver >= 8:
  13. return True
  14. return False
  15. def configuration(parent_package='',top_path=None):
  16. from numpy.distutils.misc_util import Configuration, get_mathlibs
  17. config = Configuration('random', parent_package, top_path)
  18. def generate_libraries(ext, build_dir):
  19. config_cmd = config.get_config_cmd()
  20. libs = get_mathlibs()
  21. if sys.platform == 'win32':
  22. libs.append('Advapi32')
  23. ext.libraries.extend(libs)
  24. return None
  25. # enable unix large file support on 32 bit systems
  26. # (64 bit off_t, lseek -> lseek64 etc.)
  27. if sys.platform[:3] == "aix":
  28. defs = [('_LARGE_FILES', None)]
  29. else:
  30. defs = [('_FILE_OFFSET_BITS', '64'),
  31. ('_LARGEFILE_SOURCE', '1'),
  32. ('_LARGEFILE64_SOURCE', '1')]
  33. if needs_mingw_ftime_workaround():
  34. defs.append(("NPY_NEEDS_MINGW_TIME_WORKAROUND", None))
  35. libs = []
  36. # Configure mtrand
  37. config.add_extension('mtrand',
  38. sources=[join('mtrand', x) for x in
  39. ['mtrand.c', 'randomkit.c', 'initarray.c',
  40. 'distributions.c']]+[generate_libraries],
  41. libraries=libs,
  42. depends=[join('mtrand', '*.h'),
  43. join('mtrand', '*.pyx'),
  44. join('mtrand', '*.pxi'),],
  45. define_macros=defs,
  46. )
  47. config.add_data_files(('.', join('mtrand', 'randomkit.h')))
  48. config.add_data_dir('tests')
  49. return config
  50. if __name__ == '__main__':
  51. from numpy.distutils.core import setup
  52. setup(configuration=configuration)