xmake.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package("lua")
  2. set_homepage("http://lua.org")
  3. set_description("A powerful, efficient, lightweight, embeddable scripting language.")
  4. add_urls("https://www.lua.org/ftp/lua-$(version).tar.gz", {version = function (version)
  5. return version:sub(2)
  6. end})
  7. add_urls("https://github.com/lua/lua.git")
  8. add_versions("v5.4.4", "164c7849653b80ae67bec4b7473b884bf5cc8d2dca05653475ec2ed27b9ebf61")
  9. add_versions("v5.4.3", "f8612276169e3bfcbcfb8f226195bfc6e466fe13042f1076cbde92b7ec96bbfb")
  10. add_versions("v5.4.2", "11570d97e9d7303c0a59567ed1ac7c648340cd0db10d5fd594c09223ef2f524f")
  11. add_versions("v5.4.1", "4ba786c3705eb9db6567af29c91a01b81f1c0ac3124fdbf6cd94bdd9e53cca7d")
  12. add_versions("v5.3.6", "fc5fd69bb8736323f026672b1b7235da613d7177e72558893a0bdcd320466d60")
  13. add_versions("v5.2.3", "13c2fb97961381f7d06d5b5cea55b743c163800896fd5c5e2356201d3619002d")
  14. add_versions("v5.1.1", "c5daeed0a75d8e4dd2328b7c7a69888247868154acbda69110e97d4a6e17d1f0")
  15. add_versions("v5.1.5", "2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333")
  16. if is_plat("mingw") and is_subhost("msys") then
  17. add_extsources("pacman::lua", "pacman::lua51")
  18. elseif is_plat("linux") then
  19. add_extsources("pacman::lua", "pacman::lua51", "pacman::lua52", "pacman::lua53", "apt::liblua5.1-0-dev", "apt::liblua5.2-dev", "apt::liblua5.3-dev", "apt::liblua5.4-dev")
  20. elseif is_plat("macosx") then
  21. add_extsources("brew::lua", "brew::[email protected]")
  22. end
  23. add_includedirs("include/lua")
  24. if not is_plat("windows", "mingw") then
  25. add_syslinks("dl", "m")
  26. end
  27. on_load(function (package)
  28. package:addenv("PATH", "bin")
  29. end)
  30. on_install(function (package)
  31. local sourcedir = os.isdir("src") and "src/" or "" -- for tar.gz or git source
  32. if is_plat("iphoneos", "android") then
  33. -- disable system() calls as they're not supported on these platforms
  34. local luaconf = io.open(sourcedir .. "/luaconf.h", "a")
  35. luaconf:write([[
  36. #ifndef lconfig_h_ext
  37. #define lconfig_h_ext
  38. #if defined(LUA_LIB)
  39. /* disable system calls as it's not available on this sytem */
  40. #define system(s) ((s)==NULL ? 0 : -1)
  41. #endif
  42. #endif
  43. ]])
  44. luaconf:close()
  45. end
  46. io.writefile("xmake.lua", format([[
  47. local sourcedir = "%s"
  48. local kind = "%s"
  49. local enabled = %s
  50. target("lualib")
  51. set_kind(kind)
  52. set_basename("lua")
  53. add_headerfiles(sourcedir .. "*.h", {prefixdir = "lua"})
  54. add_files(sourcedir .. "*.c|lua.c|luac.c|onelua.c")
  55. add_defines("LUA_COMPAT_5_2", "LUA_COMPAT_5_1")
  56. if is_plat("linux", "bsd", "cross") then
  57. add_defines("LUA_USE_LINUX")
  58. add_defines("LUA_DL_DLOPEN")
  59. elseif is_plat("macosx", "iphoneos") then
  60. add_defines("LUA_USE_MACOSX")
  61. add_defines("LUA_DL_DYLD")
  62. elseif is_plat("windows", "mingw") then
  63. -- Lua already detects Windows and sets according defines
  64. if is_kind("shared") then
  65. add_defines("LUA_BUILD_AS_DLL", {public = true})
  66. end
  67. end
  68. target("lua")
  69. set_enabled(enabled)
  70. set_kind("binary")
  71. add_files(sourcedir .. "lua.c")
  72. add_deps("lualib")
  73. if not is_plat("windows", "mingw") then
  74. add_syslinks("dl")
  75. end
  76. ]], sourcedir,
  77. package:config("shared") and "shared" or "static",
  78. package:is_cross() and "false" or "true"))
  79. local configs = {}
  80. if package:config("shared") then
  81. configs.kind = "shared"
  82. end
  83. import("package.tools.xmake").install(package, configs)
  84. end)
  85. on_test(function (package)
  86. if not package:is_cross() then
  87. os.vrun("lua -e \"print('hello xmake!')\"")
  88. end
  89. assert(package:has_cfuncs("lua_getinfo", {includes = "lua.h"}))
  90. end)