From 153fc0abe1997bbc1fd6d994a2b6e174141e1300 Mon Sep 17 00:00:00 2001
From: Saikari <lin@sz.cn.eu.org>
Date: Mon, 6 Jan 2025 05:12:20 +0300
Subject: [PATCH] revise miniz (#6137)

* revise

* retry for android

* fix

* fmt
---
 packages/m/miniz/xmake.lua | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/packages/m/miniz/xmake.lua b/packages/m/miniz/xmake.lua
index 2b4b1f1db26..832e69c50f0 100644
--- a/packages/m/miniz/xmake.lua
+++ b/packages/m/miniz/xmake.lua
@@ -6,24 +6,18 @@ package("miniz")
 
     add_urls("https://github.com/richgel999/miniz/archive/refs/tags/$(version).tar.gz",
              "https://github.com/richgel999/miniz.git")
-    add_versions("2.1.0", "95f9b23c92219ad2670389a23a4ed5723b7329c82c3d933b7047673ecdfc1fea")
-    add_versions("2.2.0", "bd1136d0a1554520dcb527a239655777148d90fd2d51cf02c36540afc552e6ec")
+
     add_versions("3.0.2", "c4b4c25a4eb81883448ff8924e6dba95c800094a198dc9ce66a292ac2ef8e018")
 
-    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+    add_deps("cmake")
 
     on_install(function (package)
-        io.writefile("miniz_export.h", "#define MINIZ_EXPORT")
-        io.writefile("xmake.lua", [[
-            add_rules("mode.debug", "mode.release")
-            target("miniz")
-                set_kind("static")
-                add_files("miniz.c", "miniz_zip.c", "miniz_tinfl.c", "miniz_tdef.c")
-                add_headerfiles("miniz.h", "miniz_export.h", "miniz_common.h", "miniz_zip.h", "miniz_tinfl.h", "miniz_tdef.h")
-        ]])
-        import("package.tools.xmake").install(package)
+        local configs = {"-DCMAKE_POLICY_DEFAULT_CMP0057=NEW", "-DBUILD_EXAMPLES=OFF", "-DBUILD_TESTS=OFF", "-DINSTALL_PROJECT=ON"}
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
+        import("package.tools.cmake").install(package, configs)
     end)
 
     on_test(function (package)
-        assert(package:has_cfuncs("mz_compress", {includes = "miniz.h"}))
+        assert(package:has_cfuncs("mz_compress", {includes = "miniz/miniz.h"}))
     end)