Переглянути джерело

Remake bzip2 using xmake.lua (#627)

* Remake bzip2 using xmake.lua

* bzip2: Fix shared

* bzip2: Add back PATH setting

* bzip2: move PATH env to on_load

* bzip2: don't build/run binaries when cross-compiling
Jérôme Leclercq 3 роки тому
батько
коміт
a9e4a0815f

+ 26 - 0
packages/b/bzip2/patches/dllexport.patch

@@ -0,0 +1,26 @@
+--- bzlib.h	2019-07-13 19:50:05.000000000 +0200
++++ bzlib.h	2021-09-08 10:18:55.838440200 +0200
+@@ -75,19 +75,13 @@
+ #include <stdio.h>
+ #endif
+ 
+-#ifdef _WIN32
+-#   include <windows.h>
+-#   ifdef small
+-      /* windows.h define small to char */
+-#      undef small
+-#   endif
++#if defined(_WIN32) && !defined(BZ_STATIC)
++#   define BZ_API(func)  func
+ #   ifdef BZ_EXPORT
+-#   define BZ_API(func) WINAPI func
+-#   define BZ_EXTERN extern
++#   define BZ_EXTERN __declspec(dllexport)
+ #   else
+    /* import windows dll dynamically */
+-#   define BZ_API(func) (WINAPI * func)
+-#   define BZ_EXTERN
++#   define BZ_EXTERN __declspec(dllimport)
+ #   endif
+ #else
+ #   define BZ_API(func) func

+ 63 - 0
packages/b/bzip2/port/xmake.lua

@@ -0,0 +1,63 @@
+add_rules("mode.debug", "mode.release")
+
+option("build_bin")
+    set_default(true)
+    set_showmenu(true)
+
+target("bz2")
+    set_kind("$(kind)")
+    set_languages("c89")
+    if is_kind("static") then
+        add_defines("BZ_STATIC", {public = true})
+    else
+        add_defines("BZ_EXPORT")
+    end
+
+    add_headerfiles("bzlib.h")
+    add_files("blocksort.c")
+    add_files("bzlib.c")
+    add_files("compress.c")
+    add_files("crctable.c")
+    add_files("decompress.c")
+    add_files("huffman.c")
+    add_files("randtable.c")
+
+if has_config("build_bin") then
+
+    target("bzip2")
+        set_kind("binary")
+        add_deps("bz2")
+        add_files("bzip2.c")
+
+        after_install(function (target)
+            -- copy/link additional executables/scripts (behavior is altered by checking the program name)
+            if target:is_plat("windows", "mingw") then
+                local binarydir = path.join(target:installdir(), "bin")
+                os.vcp(path.join(binarydir, "bzip2.exe"), path.join(binarydir, "bzcat.exe"))
+                os.vcp(path.join(binarydir, "bzip2.exe"), path.join(binarydir, "bunzip2.exe"))
+            else
+                local binarydir = path.join(target:installdir(), "bin")
+                os.ln(path.join(binarydir, "bzip2"), path.join(binarydir, "bzcat"))
+                os.ln(path.join(binarydir, "bzip2"), path.join(binarydir, "bunzip2"))
+
+                -- copy shell scripts
+                os.vcp("bzdiff", binarydir)
+                os.vcp("bzgrep", binarydir)
+                os.vcp("bzmore", binarydir)
+
+                -- and renamed copies
+                os.ln(path.join(binarydir, "bzdiff"), path.join(binarydir, "bzcmp"))
+
+                os.ln(path.join(binarydir, "bzgrep"), path.join(binarydir, "bzegrep"))
+                os.ln(path.join(binarydir, "bzgrep"), path.join(binarydir, "bzfgrep"))
+
+                os.ln(path.join(binarydir, "bzmore"), path.join(binarydir, "bzless"))
+            end
+        end)
+
+    target("bzip2recover")
+        set_kind("binary")
+        add_deps("bz2")
+        add_files("bzip2recover.c")
+
+end

+ 19 - 18
packages/b/bzip2/xmake.lua

@@ -5,31 +5,32 @@ package("bzip2")
 
     add_urls("https://sourceware.org/pub/bzip2/bzip2-$(version).tar.gz")
     add_versions("1.0.8", "ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269")
+    add_patches("1.0.8", path.join(os.scriptdir(), "patches", "dllexport.patch"), "f72679b2ad55262bbc9da49f352f6cf128db85047aaa04ca42126c839b709461")
 
-    on_load("windows", function (package)
-        package:add("links", "libbz2")
-    end)
-
-    on_install("windows", function (package)
+    on_load(function (package)
         package:addenv("PATH", "bin")
-        io.gsub("makefile.msc", "%-MD", "-" .. package:config("vs_runtime"))
-        import("package.tools.nmake").build(package, {"-f", "makefile.msc", "bzip2"})
-        os.cp("libbz2.lib", package:installdir("lib"))
-        os.cp("*.h", package:installdir("include"))
-        os.cp("*.exe", package:installdir("bin"))
+
+        if not package:config("shared") then
+            package:add("defines", "BZ_STATIC")
+        end
     end)
 
-    on_install("macosx", "linux", function (package)
-        package:addenv("PATH", "bin")
+    on_install(function (package)
         local configs = {}
-        if package:config("pic") ~= false then
-            table.insert(configs, "CFLAGS=-fPIC")
-        end
-        io.gsub("Makefile", "PREFIX=.-\n", "PREFIX=" .. package:installdir() .. "\n")
-        import("package.tools.make").install(package, configs)
+        configs.kind = package:config("shared") and "shared" or "static"
+        configs.mode = package:debug() and "debug" or "release"
+        configs.build_bin = not package:is_plat("cross", "iphoneos", "android")
+
+        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
+        import("package.tools.xmake").install(package, configs)
     end)
 
     on_test(function (package)
-        os.vrun("bzip2 --help")
+        if not package:is_plat("cross", "iphoneos", "android") then
+            os.vrun("bunzip2 --help")
+            os.vrun("bzcat --help")
+            os.vrun("bzip2 --help")
+        end
+
         assert(package:has_cfuncs("BZ2_bzCompressInit", {includes = "bzlib.h"}))
     end)