xmake.lua 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package("lame")
  2. set_homepage("https://lame.sourceforge.io/")
  3. set_description("High quality MPEG Audio Layer III (MP3) encoder")
  4. set_license("LGPL-2.0-or-later")
  5. add_urls("https://downloads.sourceforge.net/project/lame/lame/$(version)/lame-$(version).tar.gz")
  6. add_versions("3.100", "ddfe36cab873794038ae2c1210557ad34857a4b6bdc515785d1da9e175b1da1e")
  7. -- @see https://github.com/xmake-io/xmake-repo/pull/8377#issuecomment-3405442429
  8. if is_plat("linux") and is_arch("arm.*", "mips.*") then
  9. add_configs("debug", {description = "Enable debug symbols.", default = false, type = "boolean", readonly = true})
  10. end
  11. add_deps("nasm")
  12. on_install("linux", "macosx", "bsd", function (package)
  13. local configs = {"--enable-nasm"}
  14. -- fix undefined symbol error _lame_init_old
  15. -- https://sourceforge.net/p/lame/mailman/message/36081038/
  16. io.replace("include/libmp3lame.sym", "lame_init_old\n", "", {plain = true})
  17. import("package.tools.autoconf").install(package, configs)
  18. end)
  19. on_install("windows", function (package)
  20. -- slight adjustments according to https://github.com/conan-io/conan-center-index/blob/b39954231875c1350964a658c408c8a840a9eb20/recipes/libmp3lame/all/conanfile.py
  21. -- Honor vc runtime
  22. io.replace("Makefile.MSVC", "CC_OPTS = $(CC_OPTS) /MT", "", {plain = true})
  23. -- Do not hardcode LTO
  24. io.replace("Makefile.MSVC", " /GL", "", {plain = true})
  25. io.replace("Makefile.MSVC", " /LTCG", "", {plain = true})
  26. io.replace("Makefile.MSVC", "ADDL_OBJ = bufferoverflowU.lib", "", {plain = true})
  27. -- lame install guide says to `copy configMS.h config.h`
  28. -- then to `nmake -f Makefile.MSVC comp=msvc asm=no`
  29. os.cp("configMS.h", "config.h")
  30. -- this was here before, who knows if it's needed
  31. io.gsub("Makefile.MSVC", "nasmw", "nasm")
  32. -- more stuff from conan-io
  33. local configs = {"-f", "Makefile.MSVC", "comp=msvc"}
  34. if package:is_arch("x86") then
  35. table.insert(configs, "asm=yes")
  36. elseif package:is_arch("x64") then
  37. io.replace("Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:X64", {plain = true})
  38. table.insert(configs, "MSVCVER=Win64")
  39. table.insert(configs, "asm=yes")
  40. elseif package:is_arch("arm64") then
  41. io.replace("Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:ARM64", {plain = true})
  42. table.insert(configs, "MSVCVER=Win64")
  43. else
  44. table.insert(configs, "asm=yes")
  45. end
  46. import("package.tools.nmake").build(package, configs)
  47. os.cp("output/*.lib", package:installdir("lib"))
  48. os.cp("output/*.exe", package:installdir("bin"))
  49. os.cp("include/*.h", package:installdir("include/lame"))
  50. end)
  51. on_test(function (package)
  52. assert(package:has_cfuncs("lame_encode_buffer", {includes = "lame/lame.h"}))
  53. end)