xmake.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 true
  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. end
  30. local linkinfo = find_library("gfortran", paths)
  31. if linkinfo then
  32. return {
  33. version = version,
  34. links = "gfortran",
  35. linkdirs = {linkinfo.linkdir},
  36. }
  37. end
  38. end
  39. end
  40. end
  41. end)