setup_checksums.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Support code for building a C extension with checksums code
  2. import os
  3. def multi_join(paths, *path_segments):
  4. """apply os.path.join on a list of paths"""
  5. return [os.path.join(*(path_segments + (path,))) for path in paths]
  6. # xxhash files, structure as seen in xxhash project repository:
  7. # path relative (to this file) to the bundled library source code files
  8. xxhash_bundled_path = 'src/borg/algorithms/xxh64'
  9. xxhash_sources = [
  10. 'xxhash.c',
  11. ]
  12. xxhash_includes = [
  13. '',
  14. ]
  15. def xxhash_ext_kwargs(pc, prefer_system, system_prefix):
  16. if prefer_system:
  17. if system_prefix:
  18. print('Detected and preferring libxxhash [via BORG_LIBXXHASH_PREFIX]')
  19. return dict(include_dirs=[os.path.join(system_prefix, 'include')],
  20. library_dirs=[os.path.join(system_prefix, 'lib')],
  21. libraries=['xxhash'])
  22. if pc and pc.installed('libxxhash', '>= 0.7.3'):
  23. print('Detected and preferring libxxhash [via pkg-config]')
  24. return pc.parse('libxxhash')
  25. print('Using bundled xxhash')
  26. sources = multi_join(xxhash_sources, xxhash_bundled_path)
  27. include_dirs = multi_join(xxhash_includes, xxhash_bundled_path)
  28. define_macros = [('BORG_USE_BUNDLED_XXHASH', 'YES')]
  29. return dict(sources=sources, include_dirs=include_dirs, define_macros=define_macros)