setup_lz4.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Support code for building a C extension with lz4 files
  2. import os
  3. # lz4 files, structure as seen in lz4 project repository:
  4. # bundled_path: relative (to this file) path to the bundled library source code files
  5. bundled_path = 'src/borg/algorithms/lz4'
  6. lz4_sources = [
  7. 'lib/lz4.c',
  8. ]
  9. lz4_includes = [
  10. 'lib',
  11. ]
  12. def multi_join(paths, *path_segments):
  13. """apply os.path.join on a list of paths"""
  14. return [os.path.join(*(path_segments + (path,))) for path in paths]
  15. def lz4_ext_kwargs(prefer_system):
  16. if prefer_system:
  17. system_prefix = os.environ.get('BORG_LIBLZ4_PREFIX')
  18. if system_prefix:
  19. print('Detected and preferring liblz4 [via BORG_LIBLZ4_PREFIX]')
  20. return dict(include_dirs=[os.path.join(system_prefix, 'include')],
  21. library_dirs=[os.path.join(system_prefix, 'lib')],
  22. libraries=['lz4'])
  23. import pkgconfig
  24. if pkgconfig.installed('liblz4', '>= 1.7.0'):
  25. print('Detected and preferring liblz4 [via pkg-config]')
  26. return pkgconfig.parse('liblz4')
  27. print('Using bundled LZ4')
  28. sources = multi_join(lz4_sources, bundled_path)
  29. include_dirs = multi_join(lz4_includes, bundled_path)
  30. define_macros = [('BORG_USE_BUNDLED_LZ4', 'YES')]
  31. return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)