install_clib.py 1.4 KB

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