setup.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import os
  2. import re
  3. from distutils.core import setup, Extension
  4. # https://docs.python.org/3/extending/building.html#building
  5. def find_libwwt_config():
  6. # First try environment var
  7. defs = os.environ.get("LIBWWT_DEFS", None)
  8. if defs is not None:
  9. return defs
  10. search_paths = ["/usr/lib/", "/usr/local/lib/", "./libwwt/"]
  11. for path in search_paths:
  12. filepath = os.path.join(path, "libwwtConfig.sh")
  13. if os.path.exists(filepath):
  14. with open(filepath, "r") as f:
  15. for line in f:
  16. if line.startswith("LIBWWT_DEFS="):
  17. lineLen = len(line)
  18. return line[13:lineLen - 2]
  19. raise Exception("Could not find configuration (libwwtConfig.sh) for libwwt")
  20. def get_define_macros():
  21. defs = find_libwwt_config()
  22. return list(re.findall("-D([a-zA-Z0-9_]+)=?([a-zA-Z0-9_]+)?", defs))
  23. pywwt = Extension(
  24. "pywwt",
  25. define_macros = get_define_macros(),
  26. libraries = ["wwt"],
  27. include_dirs = ["/usr/include/libwwt/",
  28. "/usr/include/libwwt/libwbfs",
  29. "/usr/include/libwwt/crypto"],
  30. sources = ["src/pywwt-module.c"]
  31. )
  32. def main():
  33. setup(name = "pywwt",
  34. version = "0.1",
  35. description = "Brings the power of WWT (Wiimms WBFS Tool) to Python",
  36. author = "CYBERDEViL",
  37. author_email = "cyberdevil@notabug.org",
  38. url = "https://notabug.org/cyberdevil",
  39. ext_modules = [pywwt])
  40. if __name__ == "__main__":
  41. main()