xmake.lua 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package("gfortran")
  2. set_homepage("https://gcc.gnu.org/fortran/")
  3. set_description("The GNU Fortran compiler")
  4. on_fetch(function (package, opt)
  5. import("lib.detect.find_library")
  6. if opt.system then
  7. local fortran = package:find_tool("gfortran", opt)
  8. if not fortran then return end
  9. if package:is_binary() then
  10. return {}
  11. else
  12. local installdir = path.directory(path.directory(fortran.program))
  13. local target
  14. local out, version = os.iorunv(fortran.program, {"-v", "-E"})
  15. if version then
  16. target = version:match("Target: (.-)\n")
  17. version = version:match("version (%d+%.%d+%.%d+)")
  18. vmajor = version:split("%.")[1]
  19. local paths = {
  20. "/usr/lib",
  21. "/usr/lib64",
  22. "/usr/local/lib",
  23. path.join(installdir, "lib"),
  24. }
  25. if target then
  26. table.insert(paths, path.join("/usr/lib", target))
  27. table.insert(paths, path.join("/usr/lib/gcc", target, vmajor))
  28. table.insert(paths, path.join(installdir, "lib", target, vmajor))
  29. if package:is_plat("macosx") then
  30. table.insert(paths, path.join("/opt/homebrew/Cellar/gcc", version, "/lib/gcc", vmajor))
  31. end
  32. end
  33. local linkinfo = find_library("gfortran", paths)
  34. if linkinfo then
  35. return {
  36. version = version,
  37. links = "gfortran",
  38. linkdirs = {linkinfo.linkdir},
  39. }
  40. end
  41. end
  42. end
  43. end
  44. end)