fetch.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import("lib.detect.find_library")
  2. import("lib.detect.find_tool")
  3. import("core.base.semver")
  4. function _get_python_libs()
  5. local opt = {version = true}
  6. local result = find_tool("python3", opt)
  7. if not result then
  8. result = find_tool("python", opt)
  9. end
  10. local libs = {}
  11. local version = result.version
  12. if version then
  13. local py_ver = semver.new(version)
  14. py_ver = py_ver:major() .. py_ver:minor()
  15. table.insert(libs, "python" .. py_ver)
  16. table.insert(libs, "numpy" .. py_ver)
  17. end
  18. return libs
  19. end
  20. function _add_info(linkinfo, result)
  21. if linkinfo then
  22. table.insert(result.linkdirs, linkinfo.linkdir)
  23. table.insert(result.libfiles, linkinfo.filename)
  24. table.insert(result.links, linkinfo.link)
  25. end
  26. end
  27. function main(package, opt)
  28. if opt.system then
  29. import("libs", {rootdir = package:scriptdir()})
  30. local paths = {
  31. "/usr/lib",
  32. "/usr/lib64",
  33. "/usr/local/lib",
  34. "/usr/lib/x86_64-linux-gnu",
  35. }
  36. local result = {
  37. libfiles = {},
  38. linkdirs = {},
  39. links = {},
  40. }
  41. local opt = {
  42. plat = package:plat(),
  43. kind = package:config("shared") and "shared" or "static",
  44. }
  45. local sub_libs_map = libs.get_sub_libs(package)
  46. sub_libs_map["python"] = _get_python_libs()
  47. table.insert(sub_libs_map.test, "test_exec_monitor")
  48. libs.for_each(function (libname)
  49. local sub_libs = sub_libs_map[libname]
  50. if sub_libs then
  51. for _, sub_libname in ipairs(sub_libs) do
  52. local linkinfo = find_library("boost_" .. sub_libname, paths, opt)
  53. _add_info(linkinfo, result)
  54. end
  55. else
  56. local linkinfo = find_library("boost_" .. libname, paths, opt)
  57. _add_info(linkinfo, result)
  58. end
  59. end)
  60. result.linkdirs = table.unique(result.linkdirs)
  61. return result
  62. end
  63. end