From 7969ae37c481c3fe6d83cec168c213de60bb70c0 Mon Sep 17 00:00:00 2001 From: star9029 Date: Thu, 23 May 2024 06:38:42 +0800 Subject: [PATCH] giflib: refractor (#4112) * giflib: refractor * add 5.2.2 --- .../g/giflib/patches/5.2.1/unistd.h.patch | 14 ++++ packages/g/giflib/port/xmake.lua | 51 +++++++++++++ packages/g/giflib/xmake.lua | 72 ++++++------------- 3 files changed, 85 insertions(+), 52 deletions(-) create mode 100644 packages/g/giflib/patches/5.2.1/unistd.h.patch create mode 100644 packages/g/giflib/port/xmake.lua diff --git a/packages/g/giflib/patches/5.2.1/unistd.h.patch b/packages/g/giflib/patches/5.2.1/unistd.h.patch new file mode 100644 index 000000000..36cef4491 --- /dev/null +++ b/packages/g/giflib/patches/5.2.1/unistd.h.patch @@ -0,0 +1,14 @@ +diff --git a/gif_hash.h b/gif_hash.h +index 6a1b585..e6712e8 100644 +--- a/gif_hash.h ++++ b/gif_hash.h +@@ -9,7 +9,9 @@ SPDX-License-Identifier: MIT + #ifndef _GIF_HASH_H_ + #define _GIF_HASH_H_ + ++#ifndef _MSC_VER + #include ++#endif + #include + + #define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */ diff --git a/packages/g/giflib/port/xmake.lua b/packages/g/giflib/port/xmake.lua new file mode 100644 index 000000000..09b84eda4 --- /dev/null +++ b/packages/g/giflib/port/xmake.lua @@ -0,0 +1,51 @@ +set_project("giflib") + +option("utils", {showmenu = true, default = false}) + +add_rules("mode.debug", "mode.release") + +target("gif") + set_kind("$(kind)") + add_files( + "dgif_lib.c", + "egif_lib.c", + "gifalloc.c", + "gif_err.c", + "gif_font.c", + "gif_hash.c", + "openbsd-reallocarray.c" + ) + + add_headerfiles("gif_lib.h") + + if is_plat("windows") then + add_files("gif_font.c", {defines = "strtok_r=strtok_s"}) + if is_kind("shared") then + add_rules("utils.symbols.export_all") + end + end +target_end() + +if has_config("utils") then + if is_plat("windows") then + add_requires("cgetopt") + end + + target("utils") + set_kind("$(kind)") + add_files("getarg.c", "qprintf.c", "quantize.c") + add_deps("gif") + if is_plat("windows") and is_kind("shared") then + add_rules("utils.symbols.export_all") + end + + for _, tool in ipairs({"gif2rgb", "gifbuild", "gifclrmp", "giffix", "giftext", "giftool"}) do + target(tool) + set_kind("binary") + add_files(tool .. ".c") + add_deps("utils") + if is_plat("windows") then + add_packages("cgetopt") + end + end +end diff --git a/packages/g/giflib/xmake.lua b/packages/g/giflib/xmake.lua index 558fbe120..25772ef37 100644 --- a/packages/g/giflib/xmake.lua +++ b/packages/g/giflib/xmake.lua @@ -1,70 +1,38 @@ package("giflib") - set_homepage("https://sourceforge.net/projects/giflib/") set_description("A library for reading and writing gif images.") set_license("MIT") add_urls("https://github.com/xmake-mirror/giflib/releases/download/$(version)/giflib-$(version).tar.gz", "https://downloads.sourceforge.net/project/giflib/giflib-$(version).tar.gz") + + add_versions("5.2.2", "be7ffbd057cadebe2aa144542fd90c6838c6a083b5e8a9048b8ee3b66b29d5fb") add_versions("5.2.1", "31da5562f44c5f15d63340a09a4fd62b48c45620cd302f77a6d9acf0077879bd") - add_configs("utils", {description = "Build utility binaries.", default = true, type = "boolean"}) + add_patches("5.2.1", "patches/5.2.1/unistd.h.patch", "0f1f7b9a295c9965529608f7e9d810b7f7a2642b3b18910402d5d7ce8b86fc13") - if is_plat("windows") then - add_deps("cgetopt") - end + add_configs("utils", {description = "Build utility binaries.", default = true, type = "boolean"}) - on_install("linux", "macosx", "windows", "mingw", "android", "iphoneos", "bsd", function (package) - local lib_sources = {"dgif_lib.c", "egif_lib.c", "gifalloc.c", "gif_err.c", "gif_font.c", "gif_hash.c", "openbsd-reallocarray.c"} - local kind = "static" - if package:config("shared") then - if package:is_plat("windows") then - cprint("${yellow}No support for dll on windows!${clear}") - else - kind = "shared" - end + on_load(function (package) + if package:config("utils") and package:is_plat("windows") then + package:add("deps", "cgetopt") end - if package:is_plat("windows") then - io.gsub("gif_hash.h", "\n#include \n", [[ - #ifndef _MSC_VER - #include - #endif - ]]) - io.gsub("gif_font.c", "\n#include \"gif_lib.h\"\n", "\n#include \"gif_lib.h\"\n#define strtok_r strtok_s\n") - end - local xmake_lua = string.format([[ - add_rules("mode.debug", "mode.release") - if is_plat("windows") then - add_requires("cgetopt") - end - target("gif") - set_kind("%s") - add_files("%s") - add_headerfiles("gif_lib.h") - ]], kind, table.concat(lib_sources, "\", \"")) - if package:config("utils") then - local util_table = {"gif2rgb", "gifbuild", "gifclrmp", "giffix", "giftext", "giftool"} - for _, util in ipairs(util_table) do - if package:is_plat("windows") then - -- fix unresolved external symbol snprintf before vs2013 - io.replace(util .. ".c", "snprintf", "_snprintf") - end - xmake_lua = xmake_lua .. string.format([[ - target("%s") - set_kind("binary") - if is_plat("windows") then - add_packages("cgetopt") - end - add_files("%s.c", "getarg.c", "qprintf.c", "quantize.c", "%s") - ]], util, util, table.concat(lib_sources, "\", \"")) + end) + + on_install(function (package) + local utils = package:config("utils") + if utils and package:is_plat("windows") then + -- fix unresolved external symbol snprintf before vs2013 + for _, file in ipairs({"gif2rgb.c", "gifbuild.c", "gifclrmp.c", "giffix.c", "giftext.c", "giftool.c"}) do + io.replace(file, "snprintf", "_snprintf", {plain = true}) end end - io.writefile("xmake.lua", xmake_lua) - local configs = {} - if package:is_plat("linux") and package:config("pic") ~= false then - configs.cxflags = "-fPIC" + + os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua") + import("package.tools.xmake").install(package, {utils = utils}) + if utils then + package:addenv("PATH", "bin") end - import("package.tools.xmake").install(package, configs) end) on_test(function (package)