xmake.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package("x264")
  2. set_homepage("https://www.videolan.org/developers/x264.html")
  3. set_description("A free software library and application for encoding video streams into the H.264/MPEG-4 AVC compression format.")
  4. add_urls("https://code.videolan.org/videolan/x264.git",
  5. "https://github.com/mirror/x264.git")
  6. add_versions("v2023.04.04", "eaa68fad9e5d201d42fde51665f2d137ae96baf0")
  7. add_versions("v2021.09.29", "66a5bc1bd1563d8227d5d18440b525a09bcf17ca")
  8. add_versions("v2018.09.25", "545de2ffec6ae9a80738de1b2c8cf820249a2530")
  9. add_deps("nasm")
  10. add_configs("cli", {description = "enable cli", default = false, type = "boolean"})
  11. add_configs("bashcompletion", {description = "enable installation of bash-completion script", default = false, type = "boolean"})
  12. add_configs("opencl", {description = "enable OpenCL features", default = true, type = "boolean"})
  13. add_configs("gpl", {description = "enable GPL-only features", default = false, type = "boolean"})
  14. add_configs("thread", {description = "enable multithreaded encoding", default = true, type = "boolean"})
  15. add_configs("interlaced", {description = "enable interlaced encoding support", default = true, type = "boolean"})
  16. add_configs("bit-depth", {description = "set output bit depth", default = "all", value = {8, 10, "all"}})
  17. add_configs("chroma-format", {description = "output chroma format", default = "all", value = {400, 420, 422, 444, "all"}})
  18. -- Advanced options
  19. add_configs("asm", {description = "enable platform-specific assembly optimizations", default = true, type = "boolean"})
  20. add_configs("lto", {description = "enable link-time optimization", default = false, type = "boolean"})
  21. add_configs("pic", {description = "build position-independent code", default = false, type = "boolean"})
  22. -- External library support
  23. add_configs("avs", {description = "enable avisynth support", default = false, type = "boolean"})
  24. add_configs("swscale", {description = "enable swscale support", default = false, type = "boolean"})
  25. add_configs("lavf", {description = "enable libavformat support", default = false, type = "boolean"})
  26. add_configs("ffms", {description = "enable ffmpegsource support", default = false, type = "boolean"})
  27. add_configs("gpac", {description = "enable gpac support", default = false, type = "boolean"})
  28. add_configs("lsmash", {description = "enable lsmash support", default = false, type = "boolean"})
  29. add_configs("toolchains", {readonly = true, description = "Set package toolchains only for cross-compilation."})
  30. if is_plat("linux", "macosx") then
  31. add_syslinks("pthread", "dl")
  32. end
  33. if is_plat("wasm") then
  34. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  35. end
  36. on_load("windows", "mingw", function (package)
  37. if is_subhost("windows") and os.arch() == "x64" then
  38. package:add("deps", "msys2", {configs = {msystem = "MINGW64", base_devel = true}})
  39. end
  40. end)
  41. on_install("windows", "mingw", "linux", "macosx", "wasm", function (package)
  42. local configs = {}
  43. table.insert(configs, "--enable-" .. (package:config("shared") and "shared" or "static"))
  44. if package:is_plat("mingw") then
  45. -- todo: fix a way to make it work
  46. package:config_set("asm", false)
  47. elseif package:is_plat("wasm") then
  48. table.insert(configs, "--host=i686-gnu")
  49. package:config_set("asm", false)
  50. package:config_set("cli", false)
  51. end
  52. for name, value in pairs(package:configs()) do
  53. if not package:extraconf("configs", name, "builtin") then
  54. if type(value) == "boolean" then
  55. table.insert(configs, "--" .. (value and "enable" or "disable") .. "-" .. name)
  56. else
  57. table.insert(configs, "--" .. name .. "=" .. value)
  58. end
  59. end
  60. end
  61. if package:is_plat("windows") then
  62. import("core.base.option")
  63. import("core.tool.toolchain")
  64. local msvc = package:toolchain("msvc") or toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
  65. assert(msvc:check(), "msvs not found!")
  66. -- keep msys2 envs in front to prevent conflict with possibly installed sh.exe
  67. local envs = os.joinenvs(os.getenvs(), msvc:runenvs())
  68. envs.CC = path.filename(package:build_getenv("cc"))
  69. envs.SHELL = "sh"
  70. table.insert(configs, "--toolchain=msvc")
  71. table.insert(configs, "--prefix=" .. package:installdir():gsub("\\", "/"))
  72. os.vrunv("./configure", configs, {shell = true, envs = envs})
  73. local njob = option.get("jobs") or tostring(os.default_njob())
  74. local argv = {"-j" .. njob}
  75. if option.get("verbose") then
  76. table.insert(argv, "V=1")
  77. end
  78. os.vrunv("make", argv, {envs = envs})
  79. os.vrunv("make", {"install"}, {envs = envs})
  80. else
  81. import("package.tools.autoconf").install(package, configs)
  82. end
  83. end)
  84. on_test(function (package)
  85. assert(package:has_cfuncs("x264_encoder_open", {includes = {"stdint.h", "x264.h"}}))
  86. end)