Selaa lähdekoodia

fix(libvpx): fix cross build error

冰雪殇璃陌梦 2 vuotta sitten
vanhempi
commit
1c26694bc0
2 muutettua tiedostoa jossa 80 lisäystä ja 5 poistoa
  1. 78 3
      packages/l/libvpx/xmake.lua
  2. 2 2
      packages/w/which/xmake.lua

+ 78 - 3
packages/l/libvpx/xmake.lua

@@ -30,7 +30,82 @@ package("libvpx")
         add_configs("shared",  {description = "Build shared library.", default = false, type = "boolean", readonly = true})
         add_configs("shared",  {description = "Build shared library.", default = false, type = "boolean", readonly = true})
     end
     end
 
 
-    add_deps("which")
+    if is_host("freebsd", "linux", "macosx") then
+        add_deps("which")
+    end
+
+    -- array utils
+    function filter(array, filter)
+      local result = {}
+      for idx, val in ipairs(array) do
+          if filter(val, idx, array) then
+            table.insert(result, val)
+          end
+      end
+      return result
+    end
+
+    function find(array, filter)
+      for idx, val in ipairs(array) do
+          if filter(val, idx, array) then
+              return val
+          end
+      end
+      return nil
+    end
+
+    function get_target(package)
+        import("core.tool.compiler")
+        local default_plat = "generic-gnu"
+
+        local platforms = {}
+        for plat in io.readfile("configure"):gmatch("all_platforms=\"%${all_platforms} ([%a%d-]-)\"") do
+            table.insert(targets, plat:split("-", {plain = true}))
+        end
+
+        local arch = package:targetarch()
+        if arch:startswith("arm64") then
+            arch = "arm64"
+        elseif arch == "armeabi-v7a" then
+            arch = "armv7"
+        elseif arch == "x64" then
+            arch = "x86_64"
+        end
+
+        local os
+        if package:is_targetos("iphoneos") then
+            if package:is_targetarch("x64", "x86", "x86_64") then
+                os = "iphonesimulator"
+            else
+                os = "darwin"
+            end
+        elseif package:is_targetos("macosx", "watchos") then
+            os = "darwin"
+        elseif package:is_targetos("cygwin", "mingw", "windows") then
+            os = "win"
+        else
+            os = package:targetos()
+        end
+
+        local cc = path.basename(compiler.compcmd("foo.c")):split(" ", {plain = true})[1]:lower()
+        if cc == "clang" or cc == "emcc" then
+            cc = "gcc"
+        elseif cc == "cl" then
+            cc = "vs"
+        end
+
+        local matched_plats
+        matched_plats = filter(platforms, function (p) return p[1] == arch end)
+        local tmp = filter(matched_plats, function (p) return p[2] == os end)
+        matched_plats = #tmp == 0 and filter(matched_plats, function (p) return p[2]:startswith(plat) end) or tmp
+        tmp = nil
+        if #matched_plats == 0 then
+            cprint("${yellow}warning: ${clear}no matching platform for " .. os .. "-" .. arch " " .. cc .. ", use " .. default_plat)
+        end
+        local result = find(platforms, function(p) return p[3] == cc end) or find(platforms, function(p) return p[3]:startswith(cc) end) or platforms[1]
+        cprint("${green}info: ${clear}use target platform ${blue}" .. result .. "${clear}")
+        return result
+    end
 
 
     on_load(function (package)
     on_load(function (package)
         if package:is_targetarch("x64", "x86_64") then
         if package:is_targetarch("x64", "x86_64") then
@@ -42,7 +117,7 @@ package("libvpx")
         end
         end
     end)
     end)
 
 
-    on_install("@freebsd", "@linux", "@macosx", "mingw", "wasm", function (package)
+    on_install("@bsd", "@linux", "@macosx", "mingw", "wasm", function (package)
         local configs = {}
         local configs = {}
         table.insert(configs, "--prefix=" .. package:installdir())
         table.insert(configs, "--prefix=" .. package:installdir())
         for name, enabled in pairs(package:configs()) do
         for name, enabled in pairs(package:configs()) do
@@ -54,7 +129,7 @@ package("libvpx")
         if package:is_plat("wasm") then
         if package:is_plat("wasm") then
             table.join2(configs, {"--target=generic-gnu", "--disable-install-bins"})
             table.join2(configs, {"--target=generic-gnu", "--disable-install-bins"})
         elseif package:is_cross() then
         elseif package:is_cross() then
-            table.insert(configs, "--target=" .. package:targetarch() .. "-" .. package:targetos())
+            table.insert(configs, "--target=" .. get_target(package))
         end
         end
 
 
         local source_dir = os.curdir()
         local source_dir = os.curdir()

+ 2 - 2
packages/w/which/xmake.lua

@@ -13,8 +13,8 @@ package("which")
     add_versions("2.20", "d417b65c650d88ad26a208293c1c6e3eb60d4b6d847f01ff8f66aca63e2857f8")
     add_versions("2.20", "d417b65c650d88ad26a208293c1c6e3eb60d4b6d847f01ff8f66aca63e2857f8")
     add_versions("2.21", "f4a245b94124b377d8b49646bf421f9155d36aa7614b6ebf83705d3ffc76eaad")
     add_versions("2.21", "f4a245b94124b377d8b49646bf421f9155d36aa7614b6ebf83705d3ffc76eaad")
 
 
-    on_install("@freebsd", "@linux", "@macosx", "mingw", "which", function (package)
-        import("package.tools.autoconf").install(package, {"--disable-dependency-tracking", "--disable-gtk", "--disable-silent-rules"})
+    on_install("@bsd", "@linux", "@macosx", function (package)
+        import("package.tools.autoconf").install(package)
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)