Browse Source

improve and fix libusb (#278)

* libusb: Add support for windows, version 1.0.24 and fix includes

* Improve libusb

* Add back add_includedirs

* libusb: Fix windows

* libusb: fix windows

* Fix windows for real

* improve libusb for macosx and linux

* add eudev

* improve windows

* fix msvc for libusb

Co-authored-by: Jérôme Leclercq <[email protected]>
ruki 4 years ago
parent
commit
8c8eccb4f3
2 changed files with 77 additions and 4 deletions
  1. 29 0
      packages/e/eudev/xmake.lua
  2. 48 4
      packages/l/libusb/xmake.lua

+ 29 - 0
packages/e/eudev/xmake.lua

@@ -0,0 +1,29 @@
+package("eudev")
+
+    set_homepage("https://dev.gentoo.org/~blueness/eudev/")
+    set_description("A fork of systemd with the aim of isolating udev from any particular flavor of system initialization.")
+
+    add_urls("https://dev.gentoo.org/~blueness/eudev/eudev-$(version).tar.gz")
+    add_versions("3.2.9", "89618619084a19e1451d373c43f141b469c9fd09767973d73dd268b92074d4fc")
+
+    if is_plat("linux") then
+        add_deps("autoconf", "automake", "libtool", "pkg-config", "gperf")
+    end
+
+    on_install("linux", function (package)
+        local configs = {}
+        if package:config("shared") then
+            table.insert(configs, "--enable-shared=yes")
+        else
+            table.insert(configs, "--enable-shared=no")
+        end
+        if package:config("pic") ~= false then
+            table.insert(configs, "--with-pic")
+        end
+        import("package.tools.autoconf").install(package, configs)
+    end)
+
+
+    on_test(function (package)
+        assert(package:has_cfuncs("udev_new", {includes = "libudev.h"}))
+    end)

+ 48 - 4
packages/l/libusb/xmake.lua

@@ -5,18 +5,62 @@ package("libusb")
 
 
     set_urls("https://github.com/libusb/libusb/archive/$(version).tar.gz",
     set_urls("https://github.com/libusb/libusb/archive/$(version).tar.gz",
              "https://github.com/libusb/libusb.git")
              "https://github.com/libusb/libusb.git")
+    add_versions("v1.0.24", "b7724c272dfc5713dce88ff717efd60f021ca5b7c8e30f08ebb2c42d2eea08ae")
     add_versions("v1.0.23", "02620708c4eea7e736240a623b0b156650c39bfa93a14bcfa5f3e05270313eba")
     add_versions("v1.0.23", "02620708c4eea7e736240a623b0b156650c39bfa93a14bcfa5f3e05270313eba")
 
 
-    if not is_host("windows") then
+    if is_plat("macosx", "linux") then
         add_deps("autoconf", "automake", "libtool", "pkg-config")
         add_deps("autoconf", "automake", "libtool", "pkg-config")
+        if is_plat("linux") then
+            add_deps("eudev")
+        end
     end
     end
 
 
-    add_includedirs("include/libusb-1.0")
+    if is_plat("macosx") then
+        add_frameworks("CoreFoundation", "IOKit")
+    elseif is_plat("linux") then
+        add_syslinks("pthread")
+    end
+
+    add_includedirs("include", "include/libusb-1.0")
+
+    on_install("windows", function (package)
+        import("core.tool.toolchain")
+        local arch = package:is_arch("x86") and "Win32" or "x64"
+        local mode = package:debug() and "Debug" or "Release"
+        local vs = toolchain.load("msvc"):config("vs") or "2019"
+        local configs = {"libusb_" .. vs .. ".sln"}
+        table.insert(configs, "/property:Configuration=" .. mode)
+        table.insert(configs, "/property:Platform=" .. arch)
+        local oldir = os.cd("msvc")
+        import("package.tools.msbuild").build(package, configs)
+        os.cd(oldir)
+        os.vcp("libusb/*.h", package:installdir("include/libusb-1.0"))
+        if package:config("shared") then
+            os.vcp(path.join(arch, mode, "dll/libusb-1.0.dll"), package:installdir("lib"))
+            os.vcp(path.join(arch, mode, "dll/libusb-1.0.lib"), package:installdir("lib"))
+        else
+            os.vcp(path.join(arch, mode, "lib/libusb-1.0.lib"), package:installdir("lib"))
+        end
+    end)
 
 
     on_install("macosx", "linux", function (package)
     on_install("macosx", "linux", function (package)
-        import("package.tools.autoconf").install(package)
+        local configs = {}
+        if package:config("shared") then
+            table.insert(configs, "--enable-shared=yes")
+        else
+            table.insert(configs, "--enable-shared=no")
+        end
+        if package:config("pic") ~= false then
+            table.insert(configs, "--with-pic")
+        end
+        local cflags, ldflags
+        if package:is_plat("linux") then
+            cflags = "-I" .. package:dep("eudev"):installdir("include")
+            ldflags = "-L" .. package:dep("eudev"):installdir("lib")
+        end
+        import("package.tools.autoconf").install(package, configs, {cflags = cflags, ldflags = ldflags})
     end)
     end)
 
 
     on_test(function (package)
     on_test(function (package)
-        assert(package:has_cfuncs("libusb_init", {includes = "libusb.h"}))
+        assert(package:has_cfuncs("libusb_init", {includes = "libusb-1.0/libusb.h"}))
     end)
     end)