setup_crypto.py 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. # Support code for building a C extension with crypto from OpenSSL
  2. #
  3. # Copyright (c) 2016-present, Gregory Szorc (original code for zstd)
  4. # 2017-present, Thomas Waldmann (mods to make it more generic, code for openssl)
  5. # All rights reserved.
  6. #
  7. # This software may be modified and distributed under the terms
  8. # of the BSD license. See the LICENSE file for details.
  9. import os
  10. def crypto_ext_kwargs():
  11. """return kwargs with crypto stuff for a distutils.extension.Extension initialization.
  12. returns: kwargs for this lib
  13. """
  14. def multi_join(paths, *path_segments):
  15. """apply os.path.join on a list of paths"""
  16. return [os.path.join(*(path_segments + (path, ))) for path in paths]
  17. system_prefix = os.environ.get('BORG_OPENSSL_PREFIX')
  18. if system_prefix:
  19. print('Detected system OpenSSL')
  20. else:
  21. raise Exception('Could not find OpenSSL lib/headers, please set BORG_OPENSSL_PREFIX')
  22. include_dirs = multi_join(['include'], system_prefix)
  23. library_dirs = multi_join(['lib'], system_prefix)
  24. libraries = ['crypto', ]
  25. return dict(include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries)