xmake.lua 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. add_configs("shared", {description = "Build static libraries", default = false, type = "boolean", readonly = true})
  8. add_deps("nasm")
  9. on_install("linux", "macosx", "bsd", function (package)
  10. local configs = {"--enable-nasm"}
  11. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  12. if package:debug() then
  13. table.insert(configs, "--enable-debug")
  14. end
  15. if package:is_plat("linux") and package:config("pic") ~= false then
  16. table.insert(configs, "--with-pic")
  17. end
  18. -- fix undefined symbol error _lame_init_old
  19. -- https://sourceforge.net/p/lame/mailman/message/36081038/
  20. io.replace("include/libmp3lame.sym", "lame_init_old\n", "", {plain = true})
  21. import("package.tools.autoconf").install(package, configs)
  22. end)
  23. on_install("windows", function (package)
  24. -- slight adjustments according to https://github.com/conan-io/conan-center-index/blob/b39954231875c1350964a658c408c8a840a9eb20/recipes/libmp3lame/all/conanfile.py
  25. -- Honor vc runtime
  26. io.replace("Makefile.MSVC", "CC_OPTS = $(CC_OPTS) /MT", "", {plain = true})
  27. -- Do not hardcode LTO
  28. io.replace("Makefile.MSVC", " /GL", "", {plain = true})
  29. io.replace("Makefile.MSVC", " /LTCG", "", {plain = true})
  30. io.replace("Makefile.MSVC", "ADDL_OBJ = bufferoverflowU.lib", "", {plain = true})
  31. -- lame install guide says to `copy configMS.h config.h`
  32. -- then to `nmake -f Makefile.MSVC comp=msvc asm=no`
  33. os.cp("configMS.h", "config.h")
  34. -- this was here before, who knows if it's needed
  35. io.gsub("Makefile.MSVC", "nasmw", "nasm")
  36. -- more stuff from conan-io
  37. local configs = {"-f", "Makefile.MSVC", "comp=msvc"}
  38. if package:is_arch("x86") then
  39. table.insert(configs, "asm=yes")
  40. elseif package:is_arch("x64") then
  41. io.replace("Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:X64", {plain = true})
  42. table.insert(configs, "MSVCVER=Win64")
  43. table.insert(configs, "asm=yes")
  44. elseif package:is_arch("arm64") then
  45. io.replace("Makefile.MSVC", "MACHINE = /machine:I386", "MACHINE =/machine:ARM64", {plain = true})
  46. table.insert(configs, "MSVCVER=Win64")
  47. else
  48. table.insert(configs, "asm=yes")
  49. end
  50. import("package.tools.nmake").build(package, configs)
  51. os.cp("output/*.lib", package:installdir("lib"))
  52. os.cp("output/*.exe", package:installdir("bin"))
  53. os.cp("include/*.h", package:installdir("include/lame"))
  54. end)
  55. on_test(function (package)
  56. assert(package:has_cfuncs("lame_encode_buffer", {includes = "lame/lame.h"}))
  57. end)