xmake.lua 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package("mpdecimal")
  2. set_homepage("https://www.bytereef.org/mpdecimal/index.html")
  3. set_description("mpdecimal is a package for correctly-rounded arbitrary precision decimal floating point arithmetic.")
  4. set_license("BSD-2-Clause")
  5. add_urls("https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-$(version).tar.gz")
  6. add_versions("2.5.1", "9f9cd4c041f99b5c49ffb7b59d9f12d95b683d88585608aa56a6307667b2b21f")
  7. on_install("windows", function (package)
  8. for _, header in ipairs({"libmpdec/mpdecimal32vc.h", "libmpdec/mpdecimal64vc.h", "libmpdec++/decimal.hh"}) do
  9. io.replace(header, "if defined(_DLL)", "if defined(MPDEC_DLL)", {plain = true})
  10. end
  11. local configs = {}
  12. table.insert(configs, "DEBUG=" .. (package:debug() and "1" or "0"))
  13. table.insert(configs, "MACHINE=" .. (package:is_arch("x64") and "x64" or "ppro"))
  14. for _, library in ipairs({"libmpdec", "libmpdec++"}) do
  15. local oldir = os.cd(library)
  16. os.mv("Makefile.vc", "Makefile")
  17. io.replace("Makefile", "/MD", "/MD /DMPDEC_DLL", {plain = true})
  18. if package:config("vs_runtime"):startswith("MT") then
  19. io.replace("Makefile", "/MD", "/MT", {plain = true})
  20. else
  21. io.replace("Makefile", "/MT", "/MD", {plain = true})
  22. end
  23. import("package.tools.nmake").build(package, configs)
  24. if package:config("shared") then
  25. os.cp("*.dll", package:installdir("bin"))
  26. os.cp("*.dll.lib", package:installdir("lib"))
  27. else
  28. os.cp("*.lib|*.dll.lib", package:installdir("lib"))
  29. end
  30. os.cd(oldir)
  31. end
  32. io.replace("libmpdec/mpdecimal.h", "defined(MPDEC_DLL)", (package:config("shared") and "1" or "0"), {plain = true})
  33. os.cp("libmpdec/mpdecimal.h", package:installdir("include"))
  34. io.replace("libmpdec++/decimal.hh", "defined(MPDEC_DLL)", (package:config("shared") and "1" or "0"), {plain = true})
  35. os.cp("libmpdec++/decimal.hh", package:installdir("include"))
  36. end)
  37. on_install("macosx", "linux", function (package)
  38. local configs = {}
  39. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  40. import("package.tools.autoconf").install(package, configs)
  41. if package:config("shared") then
  42. os.rm(path.join(package:installdir("lib"), "*.a"))
  43. end
  44. end)
  45. on_test(function (package)
  46. assert(package:has_cfuncs("mpd_version", {includes = "mpdecimal.h"}))
  47. end)