setup.py 2.2 KB

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