Bladeren bron

libnfc: add package. (#7852)

* libnfc: add package.

* update.

---------

Co-authored-by: star9029 <[email protected]>
RedbeanW 3 weken geleden
bovenliggende
commit
b3274a716a

+ 138 - 0
packages/l/libnfc/xmake.lua

@@ -0,0 +1,138 @@
+package("libnfc")
+    set_homepage("https://github.com/nfc-tools/libnfc")
+    set_description("Header-only binary fuse and xor filter library.")
+    set_license("LGPL-3.0")
+
+    add_urls("https://github.com/nfc-tools/libnfc/archive/refs/tags/libnfc-$(version).tar.gz", {alias = "tarball"})
+    add_urls("https://github.com/nfc-tools/libnfc.git", {alias = "git"})
+    add_versions("tarball:1.8.0", "0ab7d9b41442e7edc2af7c54630396edc73ce51128aa28a5c6e4135dc5595495")
+    add_versions("tarball:1.7.1", "30de35b4f1af3f57dab40d91ffb2275664a35859ff2b014ba7b226aa3f5465f5")
+    add_versions("git:1.8.0", "libnfc-1.8.0")
+    add_versions("git:1.7.1", "libnfc-1.7.1")
+
+    add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
+
+    add_configs("logging",      {description = "Enable log facility. (errors, warning, info and debug messages)", default = true, type = "boolean"})
+    add_configs("envvars",      {description = "Enable envvars facility.", default = true, type = "boolean"})
+    add_configs("configurable", {description = "Enable configuration files.", default = true, type = "boolean"})
+
+    -- drivers
+    add_configs("pcsc",         {description = "Enable PC/SC reader support (Depends on PC/SC)", default = false, type = "boolean"})
+    add_configs("acr122_pcsc",  {description = "Enable ACR122 support (Depends on PC/SC)", default = false, type = "boolean"})
+    add_configs("acr122_usb",   {description = "Enable ACR122 support (Direct USB connection)", default = true, type = "boolean"})
+    add_configs("acr122s",      {description = "Enable ACR122S support (Use serial port)", default = true, type = "boolean"})
+    add_configs("arygon",       {description = "Enable ARYGON support (Use serial port)", default = true, type = "boolean"})
+    add_configs("pn532_i2c",    {description = "Enable PN532 I2C support (Use I2C bus)", default = is_plat("linux"), type = "boolean"})
+    add_configs("pn532_spi",    {description = "Enable PN532 SPI support (Use SPI bus)", default = is_plat("linux"), type = "boolean"})
+    add_configs("pn532_uart",   {description = "Enable PN532 UART support (Use serial port)", default = true, type = "boolean"})
+    add_configs("pn53x_usb",    {description = "Enable PN531 and PN531 USB support (Depends on libusb)", default = true, type = "boolean"})
+
+    if not is_plat("bsd") then
+        if not is_plat("windows", "mingw", "msys", "cygwin") then
+            add_deps("libusb-compat")
+        else
+            add_deps("libusb-win32")
+            add_syslinks("wsock32")
+        end
+    end
+
+    add_deps("cmake")
+    if not is_subhost("windows") then
+        add_deps("pkg-config")
+    else
+        add_deps("pkgconf")
+    end
+
+    on_check("!linux", function (package)
+        assert(not package:config("pn532_i2c") and not package:config("pn532_spi"), "package(libnfc): I2C/SPI is only (yet) supported in Linux!")
+    end)
+
+    on_load(function (package)
+        if package:config("pcsc") or package:config("acr122_pcsc") then
+            if package:is_plat("linux", "bsd") then
+                package:add("deps", "libpcsclite")
+            end
+        end
+        if package:version():le("1.7.1") and package:is_plat("windows", "mingw", "msys", "cygwin") then
+            package:add("deps", "pcre")
+        end
+    end)
+
+    -- about windows:
+    -- @see https://github.com/nfc-tools/libnfc/pull/734
+    on_install("!iphoneos and !wasm and !windows", function (package)
+        local configs = {
+            "-DBUILD_UTILS=OFF",
+            "-DBUILD_EXAMPLES=OFF"
+        }
+        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
+
+        table.insert(configs, "-DLIBNFC_LOG=" .. (package:config("logging") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_ENVVARS=" .. (package:config("envvars") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_CONFFILES_MODE=" .. (package:config("configurable") and "ON" or "OFF"))
+
+        table.insert(configs, "-DLIBNFC_DRIVER_PCSC=" .. (package:config("pcsc") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_ACR122_PCSC=" .. (package:config("acr122_pcsc") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_ACR122_USB=" .. (package:config("acr122_usb") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_ACR122S=" .. (package:config("acr122s") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_ARYGON=" .. (package:config("arygon") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_PN532_I2C=" .. (package:config("pn532_i2c") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_PN532_SPI=" .. (package:config("pn532_spi") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_PN532_UART=" .. (package:config("pn532_uart") and "ON" or "OFF"))
+        table.insert(configs, "-DLIBNFC_DRIVER_PN53X_USB=" .. (package:config("pn53x_usb") and "ON" or "OFF"))
+
+        if package:is_plat("windows", "mingw", "msys", "cygwin") then
+            local usb = package:dep("libusb-win32")
+            if usb then
+                local fetchinfo = usb:fetch()
+                if fetchinfo then
+                    local includedirs = table.wrap(fetchinfo.includedirs or fetchinfo.sysincludedirs)
+                    if #includedirs > 0 then
+                        table.insert(configs, "-DLIBUSB_INCLUDE_DIRS=" .. table.concat(includedirs, ";"))
+                    end
+                    local libfiles = table.wrap(fetchinfo.libfiles)
+                    if #libfiles > 0 then
+                        table.insert(configs, "-DLIBUSB_LIBRARIES=" .. libfiles[1])
+                    end
+                end
+            end
+        end
+        if package:is_plat("mingw") then
+            table.insert(configs, "-DDLLTOOL=" .. package:tool("dlltool"))
+            if package:version():le("1.7.1") then
+                io.replace("libnfc/CMakeLists.txt", "dlltool", "${DLLTOOL}", {plain = true})
+            end
+        end
+        local opts = {}
+        if package:is_plat("macosx") then
+            opts.shflags = {"-framework", "CoreFoundation", "-framework", "IOKit", "-framework", "Security"}
+        end
+        if package:is_plat("windows", "mingw", "msys", "cygwin") then
+            opts.cflags = [[-DSYSCONFDIR="./config"]]
+            io.replace("CMakeLists.txt", "FIND_PACKAGE(PCRE REQUIRED)", [[
+                find_package(PkgConfig REQUIRED)
+                pkg_check_modules(PCRECORE REQUIRED libpcre)
+                pkg_check_modules(PCRE REQUIRED libpcreposix)
+                add_compile_options(${PCRE_CFLAGS})
+            ]], {plain = true})
+            io.replace("libnfc/CMakeLists.txt", "${PCRE_LIBRARIES}", "${PCRE_LIBRARIES} ${PCRECORE_LIBRARIES}", {plain = true})
+            io.replace("libnfc/conf.c", "#include <regex.h>", "#include <pcreposix.h>", {plain = true})
+        end
+        if package:version():le("1.7.1") then
+            io.replace("CMakeLists.txt", "# version.rc for Windows\nIF(WIN32)", "IF(0)", {plain = true})
+            io.replace("CMakeLists.txt", "ADD_SUBDIRECTORY(utils)", "", {plain = true})
+            io.replace("CMakeLists.txt", "ADD_SUBDIRECTORY(examples)", "", {plain = true})
+        end
+        io.replace("CMakeLists.txt", [[CMAKE_SYSTEM_PROCESSOR STREQUAL "x86"]], [[CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86|i[3-6]86)$"]], {plain = true})
+        io.replace("libnfc/CMakeLists.txt", [[LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../windows/libnfc.rc)]], "", {plain = true})
+        io.replace("libnfc/CMakeLists.txt", "DESTINATION bin", "DESTINATION ${CMAKE_INSTALL_LIBDIR}", {plain = true})
+        io.replace("cmake/modules/FindLIBUSB.cmake", "PKG_CHECK_MODULES(LIBUSB REQUIRED libusb)", "PKG_CHECK_MODULES(LIBUSB REQUIRED libusb-compat)", {plain = true})
+        io.replace("contrib/win32/stdlib.c", "char *str[32];", "char str[32];", {plain = true})
+
+        io.replace("CMakeLists.txt", "INCLUDE(UseDoxygen)", "", {plain = true})
+        import("package.tools.cmake").install(package, configs, opts)
+    end)
+
+    on_test(function (package)
+        assert(package:has_cfuncs("nfc_version", {configs = {languages = "c99"}, includes = "nfc/nfc.h"}))
+    end)

+ 45 - 0
packages/l/libpcsclite/xmake.lua

@@ -0,0 +1,45 @@
+package("libpcsclite")
+    set_homepage("https://pcsclite.apdu.fr/")
+    set_description("Middleware to access a smart card using SCard API (PC/SC).")
+
+    add_urls("https://github.com/LudovicRousseau/PCSC/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/LudovicRousseau/PCSC.git")
+
+    add_versions("2.3.3", "00b667aa71504ed1d39a48ad377de048c70dbe47229e8c48a3239ab62979c70f")
+
+    add_configs("embedded", {description = "For embedded systems [limit RAM and CPU resources by disabling features (log)].", default = false, type = "boolean"})
+
+    add_deps("meson", "ninja")
+    add_includedirs("include/PCSC")
+    on_install("linux", "bsd", "cross", function (package)
+        io.replace("meson.build", "executable%s*%b()", "")
+        io.replace("meson.build", "library%('pcscspy'.-%)", "")
+        io.replace("meson.build", "run_command%('pod2man'.-%)", "")
+        io.replace("meson.build", [[install_data('pcsc-spy.1',
+  install_dir : join_paths(get_option('mandir'), 'man1'))]], "", {plain = true})
+        io.replace("meson.build", [[gen_flex = generator(find_program('flex'),
+  output : '@[email protected]',
+  arguments : ['-o', '@OUTPUT@', '--prefix=@BASENAME@', '@INPUT@'])]], "", {plain = true})
+        io.replace("meson.build", [[gen_src = gen_flex.process('src/configfile.l', 'src/tokenparser.l')
+pcscd_src += gen_src]], "", {plain = true})
+        io.replace("meson.build", "doxygen.found()", "false", {plain = true})
+
+        local configs = {
+            '-Dlibsystemd=false',
+            '-Dlibudev=false',
+            '-Dpolkit=false'
+        }
+        table.insert(configs, "-Ddefault_library=" .. (package:config("shared") and "shared" or "static"))
+        table.insert(configs, "-Dembedded=" .. (package:config("embedded") and "true" or "false"))
+
+        import("package.tools.meson").install(package, configs)
+    end)
+
+    on_test(function (package)
+        assert(package:check_csnippets({test = [[
+            void test() {
+                SCARDCONTEXT hSC;
+                SCardEstablishContext(SCARD_SCOPE_USER, 0, 0, &hSC);
+            }
+        ]]}, {configs = {languages = "c99"}, includes = "winscard.h"}))
+    end)

+ 40 - 0
packages/l/libusb-compat/xmake.lua

@@ -0,0 +1,40 @@
+package("libusb-compat")
+    set_homepage("https://github.com/libusb/libusb-compat-0.1")
+    set_description("A compatibility layer allowing applications written for libusb-0.1 to work with libusb-1.0.")
+    set_license("LGPL-2.1")
+
+    add_urls("https://github.com/libusb/libusb-compat-0.1/archive/refs/tags/$(version).tar.gz",
+             "https://github.com/libusb/libusb-compat-0.1.git")
+
+    add_versions("v0.1.8", "73f8023b91a4359781c6f1046ae84156e06816aa5c2916ebd76f353d41e0c685")
+
+    add_deps("libusb")
+
+    on_load("wasm", function (package)
+        package:add("defines", "PATH_MAX=4096")
+    end)
+
+    -- libusb does not support iOS and FreeBSD.
+    -- libusb-compat compatibility layer does not support bare win32
+    on_install("!iphoneos and !bsd and !windows", function (package)
+        io.writefile("config.h", [[
+            #define API_EXPORTED __attribute__((visibility("default")))
+            #define ENABLE_DEBUG_LOGGING 0
+            #define ENABLE_LOGGING 1
+        ]])
+        io.writefile("xmake.lua", [[
+            add_rules("mode.debug", "mode.release")
+            add_requires("libusb")
+            target("libusb-compat")
+                set_kind("$(kind)")
+                add_files("libusb/core.c")
+                add_includedirs(".")
+                add_headerfiles("libusb/usb.h")
+                add_packages("libusb")
+        ]])
+        import("package.tools.xmake").install(package)
+    end)
+
+    on_test(function (package)
+        assert(package:has_cfuncs("usb_init", {configs = {languages = "c99"}, includes = "usb.h"}))
+    end)

+ 50 - 0
packages/l/libusb-win32/xmake.lua

@@ -0,0 +1,50 @@
+package("libusb-win32")
+    set_homepage("https://github.com/mcuee/libusb-win32")
+    set_description("libusb-win32 is a port of the libusb-0.1 API for Windows with some additional asynchronous transfer support.")
+    set_license("LGPL-2.0-or-later")
+
+    add_urls("https://github.com/mcuee/libusb-win32/archive/refs/tags/release_$(version).0.tar.gz", {alias = "tarball"})
+    add_urls("https://github.com/mcuee/libusb-win32.git", {alias = "git"})
+
+    add_versions("tarball:1.4.0", "78a002442e98d2f01c469ac7d01283f9655e257e18c4ad7670d00494b48deb8d")
+    add_versions("git:1.4.0", "release_1.4.0.0")
+
+    on_install("windows", "mingw", "msys", "cygwin", function (package)
+        os.cd("libusb")
+        io.writefile("xmake.lua", [[
+            add_rules("mode.debug", "mode.release")
+            target("libusb0")
+                set_kind("$(kind)")
+                add_files(
+                    "src/descriptors.c",
+                    "src/error.c",
+                    "src/install.c",
+                    "src/registry.c",
+                    "src/usb.c",
+                    "src/windows.c"
+                )
+                add_headerfiles(
+                    "src/error.h",
+                    "src/lusb0_usb.h",
+                    "src/registry.h",
+                    "src/usbi.h"
+                )
+                -- add_files("src/resource.rc")
+                add_syslinks("advapi32", "gdi32", "setupapi", "user32")
+                add_files("libusb0.def")
+                add_defines("LOG_APPNAME=\"libusb-dll\"")
+                add_includedirs(
+                    "src",
+                    "src/driver"
+                )
+        ]])
+        import("package.tools.xmake").install(package)
+    end)
+
+    on_test(function (package)
+        assert(package:check_csnippets({test = [[
+            void test() {
+                usb_init();
+            }
+        ]]}, {configs = {languages = "c99"}, includes = "lusb0_usb.h"}))
+    end)

+ 44 - 0
packages/l/libusb/patches/windows-add-clock-gettime-check.patch

@@ -0,0 +1,44 @@
+From 5691f303ad272a2514f68a96d6c18aeff62eb33d Mon Sep 17 00:00:00 2001
+From: Rosen Penev <[email protected]>
+Date: Sun, 12 Jun 2022 22:22:39 -0700
+Subject: [PATCH] windows: Add clock_gettime check
+
+Under MSYS2, the windows usbi_get_monotonic_time interferes with the
+static inline function under libusbi.h
+
+Closes #1151
+---
+ libusb/os/windows_common.c | 2 ++
+ libusb/version_nano.h      | 2 +-
+ 2 files changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/libusb/os/windows_common.c b/libusb/os/windows_common.c
+index 24ac095c..1f4b6835 100644
+--- a/libusb/os/windows_common.c
++++ b/libusb/os/windows_common.c
+@@ -848,6 +848,7 @@ static int windows_handle_transfer_completion(struct usbi_transfer *itransfer)
+ 		return usbi_handle_transfer_completion(itransfer, status);
+ }
+ 
++#ifndef HAVE_CLOCK_GETTIME
+ void usbi_get_monotonic_time(struct timespec *tp)
+ {
+ 	static LONG hires_counter_init;
+@@ -872,6 +873,7 @@ void usbi_get_monotonic_time(struct timespec *tp)
+ 	tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
+ 	tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) * hires_ticks_to_ps) / UINT64_C(1000));
+ }
++#endif
+ 
+ // NB: MSVC6 does not support named initializers.
+ const struct usbi_os_backend usbi_backend = {
+# diff --git a/libusb/version_nano.h b/libusb/version_nano.h
+# index 045fb83c..35ee140b 100644
+# --- a/libusb/version_nano.h
+# +++ b/libusb/version_nano.h
+# @@ -1 +1 @@
+# -#define LIBUSB_NANO 11730
+# +#define LIBUSB_NANO 11731
+# -- 
+# 2.50.1
+

+ 9 - 0
packages/l/libusb/xmake.lua

@@ -13,6 +13,8 @@ package("libusb")
 
     add_resources(">=1.0.26", "libusb-cmake", "https://github.com/libusb/libusb-cmake.git", "8f0b4a38fc3eefa2b26a99dff89e1c12bf37afd4")
 
+    add_patches("v1.0.26", "patches/windows-add-clock-gettime-check.patch", "38cc23fd5a9c2445951dbe6c6f19e677d333f82332ff5be18a4f362637265f0d")
+
     if is_plat("macosx") then
         add_extsources("brew::libusb")
     elseif is_plat("linux") then
@@ -38,6 +40,13 @@ package("libusb")
         add_ldflags("--bind", "-s ASYNCIFY=1")
     end
 
+    on_check("wasm", function (package)
+        if package:version() and package:version():le("1.0.26") then
+            raise("package(libusb <=1.0.26) unsupported platform!")
+        end
+    end)
+
+    -- @see https://github.com/libusb/libusb-cmake/issues/33#issuecomment-3028680966
     on_install("!iphoneos and !bsd", function (package)
         local dir = package:resourcefile("libusb-cmake")
         os.cp(path.join(dir, "CMakeLists.txt"), os.curdir())

+ 0 - 1
scripts/test.lua

@@ -290,7 +290,6 @@ end
 -- @see https://github.com/xmake-io/xmake-repo/issues/6940
 function _lock_packages(packages)
     local locked_packages = {
-        "libnfc",
         "flashlight",
         "telegram-bot-api",
         "systemd",