install_clib.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import division, absolute_import, print_function
  2. import os
  3. from distutils.core import Command
  4. from distutils.ccompiler import new_compiler
  5. from numpy.distutils.misc_util import get_cmd
  6. class install_clib(Command):
  7. description = "Command to install installable C libraries"
  8. user_options = []
  9. def initialize_options(self):
  10. self.install_dir = None
  11. self.outfiles = []
  12. def finalize_options(self):
  13. self.set_undefined_options('install', ('install_lib', 'install_dir'))
  14. def run (self):
  15. build_clib_cmd = get_cmd("build_clib")
  16. if not build_clib_cmd.build_clib:
  17. # can happen if the user specified `--skip-build`
  18. build_clib_cmd.finalize_options()
  19. build_dir = build_clib_cmd.build_clib
  20. # We need the compiler to get the library name -> filename association
  21. if not build_clib_cmd.compiler:
  22. compiler = new_compiler(compiler=None)
  23. compiler.customize(self.distribution)
  24. else:
  25. compiler = build_clib_cmd.compiler
  26. for l in self.distribution.installed_libraries:
  27. target_dir = os.path.join(self.install_dir, l.target_dir)
  28. name = compiler.library_filename(l.name)
  29. source = os.path.join(build_dir, name)
  30. self.mkpath(target_dir)
  31. self.outfiles.append(self.copy_file(source, target_dir)[0])
  32. def get_outputs(self):
  33. return self.outfiles