xmake.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. set_license("GPL-2.0")
  5. add_urls("https://code.videolan.org/videolan/x264.git",
  6. "https://github.com/mirror/x264.git")
  7. add_versions("v2024.02.27", "c24e06c2e184345ceb33eb20a15d1024d9fd3497")
  8. add_versions("v2023.04.04", "eaa68fad9e5d201d42fde51665f2d137ae96baf0")
  9. add_versions("v2021.09.29", "66a5bc1bd1563d8227d5d18440b525a09bcf17ca")
  10. add_versions("v2018.09.25", "545de2ffec6ae9a80738de1b2c8cf820249a2530")
  11. add_configs("cli", {description = "enable cli", default = false, type = "boolean"})
  12. add_configs("bashcompletion", {description = "enable installation of bash-completion script", default = false, type = "boolean"})
  13. add_configs("opencl", {description = "enable OpenCL features", default = true, type = "boolean"})
  14. add_configs("gpl", {description = "enable GPL-only features", default = false, type = "boolean"})
  15. add_configs("thread", {description = "enable multithreaded encoding", default = true, type = "boolean"})
  16. add_configs("interlaced", {description = "enable interlaced encoding support", default = true, type = "boolean"})
  17. add_configs("bit-depth", {description = "set output bit depth", default = "all", value = {8, 10, "all"}})
  18. add_configs("chroma-format", {description = "output chroma format", default = "all", value = {400, 420, 422, 444, "all"}})
  19. -- Advanced options
  20. add_configs("asm", {description = "enable platform-specific assembly optimizations", default = true, type = "boolean"})
  21. -- External library support
  22. add_configs("avs", {description = "enable avisynth support", default = false, type = "boolean"})
  23. add_configs("swscale", {description = "enable swscale support", default = false, type = "boolean"})
  24. add_configs("lavf", {description = "enable libavformat support", default = false, type = "boolean"})
  25. add_configs("ffms", {description = "enable ffmpegsource support", default = false, type = "boolean"})
  26. add_configs("gpac", {description = "enable gpac support", default = false, type = "boolean"})
  27. add_configs("lsmash", {description = "enable lsmash support", default = false, type = "boolean"})
  28. add_configs("toolchains", {readonly = true, description = "Set package toolchains only for cross-compilation."})
  29. if is_plat("wasm") then
  30. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  31. end
  32. if is_plat("linux", "macosx", "bsd") then
  33. add_syslinks("pthread", "dl")
  34. end
  35. add_deps("nasm")
  36. on_load(function (package)
  37. if is_subhost("windows") and os.arch() == "x64" then
  38. local msystem = "MINGW" .. (package:is_targetarch("i386", "x86", "i686") and "32" or "64")
  39. package:add("deps", "msys2", {configs = {msystem = msystem, base_devel = true}})
  40. end
  41. if package:config("shared") then
  42. package:add("defines", "X264_API_IMPORTS")
  43. end
  44. end)
  45. on_install("!iphoneos and !bsd", function (package)
  46. if is_host("windows") then
  47. io.replace("Makefile",
  48. "ln -f -s $(SONAME) $(DESTDIR)$(libdir)/libx264.$(SOSUFFIX)",
  49. "mv $(SONAME) libx264.$(SOSUFFIX)", {plain = true})
  50. io.replace("Makefile",
  51. "$(INSTALL) -m 755 $(SONAME) $(DESTDIR)$(libdir)",
  52. "$(INSTALL) -m 755 libx264.$(SOSUFFIX) $(DESTDIR)$(libdir)", {plain = true})
  53. end
  54. if package:is_plat("android") and package:is_arch("armeabi-v7a") then
  55. local ndk_sdkver = package:toolchain("ndk"):config("ndk_sdkver")
  56. if ndk_sdkver and tonumber(ndk_sdkver) < 24 then
  57. io.replace("configure", "define fseek fseek", "", {plain = true})
  58. io.replace("configure", "define ftell ftell", "", {plain = true})
  59. end
  60. end
  61. local configs = {}
  62. table.insert(configs, "--enable-" .. (package:config("shared") and "shared" or "static"))
  63. table.insert(configs, "--" .. (package:is_debug() and "enable" or "disable") .. "-debug")
  64. table.insert(configs, "--" .. (package:config("lto") and "enable" or "disable") .. "-lto")
  65. table.insert(configs, "--" .. (package:config("pic") and "enable" or "disable") .. "-pic")
  66. if package:is_plat("wasm") then
  67. table.insert(configs, "--host=i686-gnu")
  68. package:config_set("asm", false)
  69. package:config_set("cli", false)
  70. elseif package:is_plat("android") then
  71. local ndk_bindir = package:toolchain("ndk"):config("bindir")
  72. ndk_bindir = path.unix(assert(ndk_bindir)) .. "/llvm-"
  73. table.insert(configs, "--cross-prefix=" .. ndk_bindir)
  74. elseif package:is_plat("mingw") then
  75. local triples = {
  76. i386 = "i686-w64-mingw32",
  77. x86_64 = "x86_64-w64-mingw32"
  78. }
  79. table.insert(configs, "--host=" .. (triples[package:arch()] or triples.i386))
  80. if not is_host("windows") then
  81. package:config_set("asm", false)
  82. end
  83. end
  84. for name, value in pairs(package:configs()) do
  85. if not package:extraconf("configs", name, "builtin") then
  86. if type(value) == "boolean" then
  87. table.insert(configs, "--" .. (value and "enable" or "disable") .. "-" .. name)
  88. else
  89. table.insert(configs, "--" .. name .. "=" .. value)
  90. end
  91. end
  92. end
  93. local opt = {}
  94. if package:is_plat("windows") then
  95. import("core.base.option")
  96. import("core.tool.toolchain")
  97. local msvc = package:toolchain("msvc") or toolchain.load("msvc", {plat = package:plat(), arch = package:arch()})
  98. assert(msvc:check(), "msvs not found!")
  99. io.replace("configure", "x264.dll.lib", "x264.lib", {plain = true})
  100. -- keep msys2 envs in front to prevent conflict with possibly installed sh.exe
  101. local envs = os.joinenvs(os.getenvs(), msvc:runenvs())
  102. envs.CC = path.filename(package:build_getenv("cc"))
  103. envs.SHELL = "sh"
  104. table.insert(configs, "--toolchain=msvc")
  105. table.insert(configs, "--prefix=" .. path.unix(package:installdir()))
  106. opt.envs = envs
  107. end
  108. import("package.tools.autoconf").install(package, configs, opt)
  109. end)
  110. on_test(function (package)
  111. assert(package:has_cfuncs("x264_encoder_open", {includes = {"stdint.h", "x264.h"}}))
  112. end)