xmake.lua 4.5 KB

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