xmake.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package("giflib")
  2. set_homepage("https://sourceforge.net/projects/giflib/")
  3. set_description("A library for reading and writing gif images.")
  4. set_license("MIT")
  5. add_urls("https://github.com/xmake-mirror/giflib/releases/download/$(version)/giflib-$(version).tar.gz",
  6. "https://downloads.sourceforge.net/project/giflib/giflib-$(version).tar.gz")
  7. add_versions("5.2.1", "31da5562f44c5f15d63340a09a4fd62b48c45620cd302f77a6d9acf0077879bd")
  8. add_configs("utils", {description = "Build utility binaries.", default = true, type = "boolean"})
  9. if is_plat("windows") then
  10. add_deps("cgetopt")
  11. end
  12. on_install("linux", "macosx", "windows", "mingw", "android", "iphoneos", "bsd", function (package)
  13. local lib_sources = {"dgif_lib.c", "egif_lib.c", "gifalloc.c", "gif_err.c", "gif_font.c", "gif_hash.c", "openbsd-reallocarray.c"}
  14. local kind = "static"
  15. if package:config("shared") then
  16. if package:is_plat("windows") then
  17. cprint("${yellow}No support for dll on windows!${clear}")
  18. else
  19. kind = "shared"
  20. end
  21. end
  22. if package:is_plat("windows") then
  23. io.gsub("gif_hash.h", "\n#include <unistd.h>\n", [[
  24. #ifndef _MSC_VER
  25. #include <unistd.h>
  26. #endif
  27. ]])
  28. io.gsub("gif_font.c", "\n#include \"gif_lib.h\"\n", "\n#include \"gif_lib.h\"\n#define strtok_r strtok_s\n")
  29. end
  30. local xmake_lua = string.format([[
  31. add_rules("mode.debug", "mode.release")
  32. if is_plat("windows") then
  33. add_requires("cgetopt")
  34. end
  35. target("gif")
  36. set_kind("%s")
  37. add_files("%s")
  38. add_headerfiles("gif_lib.h")
  39. ]], kind, table.concat(lib_sources, "\", \""))
  40. if package:config("utils") then
  41. local util_table = {"gif2rgb", "gifbuild", "gifclrmp", "giffix", "giftext", "giftool"}
  42. for _, util in ipairs(util_table) do
  43. if package:is_plat("windows") then
  44. -- fix unresolved external symbol snprintf before vs2013
  45. io.replace(util .. ".c", "snprintf", "_snprintf")
  46. end
  47. xmake_lua = xmake_lua .. string.format([[
  48. target("%s")
  49. set_kind("binary")
  50. if is_plat("windows") then
  51. add_packages("cgetopt")
  52. end
  53. add_files("%s.c", "getarg.c", "qprintf.c", "quantize.c", "%s")
  54. ]], util, util, table.concat(lib_sources, "\", \""))
  55. end
  56. end
  57. io.writefile("xmake.lua", xmake_lua)
  58. local configs = {}
  59. if package:is_plat("linux") and package:config("pic") ~= false then
  60. configs.cxflags = "-fPIC"
  61. end
  62. import("package.tools.xmake").install(package, configs)
  63. end)
  64. on_test(function (package)
  65. assert(package:has_cfuncs("GifMakeMapObject", {includes = "gif_lib.h"}))
  66. end)