Browse Source

libkmod: fix pkg-config and upgrade to v34. (#8165)

* libkmod: fix pkg-config and upgrade to v33.

* aigc

* Update xmake.lua

* update.

* test autotools.

* update.

* rm patch

* disable zlib by default (pkg-config problem)

* Revert "rm patch"

This reverts commit 7a84acb18478d9a8cf7450231b21dff71fc62e4b.

* test.

* update.

* fix.

* fix.

* fix.

* update.

* libkmod: prepend `libkmod` folder next to `include` folder

* Update xmake.lua

* Update xmake.lua

---------

Co-authored-by: Saikari <[email protected]>
RedbeanW 2 months ago
parent
commit
6aa9e90582

+ 0 - 54
packages/l/libkmod/patches/31/basename.patch

@@ -1,54 +0,0 @@
-diff --git a/libkmod/libkmod-config.c b/libkmod/libkmod-config.c
-index e83621b..8aa555a 100644
---- a/libkmod/libkmod-config.c
-+++ b/libkmod/libkmod-config.c
-@@ -794,7 +794,7 @@ static int conf_files_insert_sorted(struct kmod_ctx *ctx,
- 	bool is_single = false;
- 
- 	if (name == NULL) {
--		name = basename(path);
-+		name = gnu_basename(path);
- 		is_single = true;
- 	}
- 
-diff --git a/shared/util.c b/shared/util.c
-index e2bab83..0e16670 100644
---- a/shared/util.c
-+++ b/shared/util.c
-@@ -172,9 +172,9 @@ char *modname_normalize(const char *modname, char buf[static PATH_MAX], size_t *
- 
- char *path_to_modname(const char *path, char buf[static PATH_MAX], size_t *len)
- {
--	char *modname;
-+	const char *modname;
- 
--	modname = basename(path);
-+	modname = gnu_basename(path);
- 	if (modname == NULL || modname[0] == '\0')
- 		return NULL;
- 
-diff --git a/shared/util.h b/shared/util.h
-index c4a3916..073dc5a 100644
---- a/shared/util.h
-+++ b/shared/util.h
-@@ -5,6 +5,7 @@
- #include <stdbool.h>
- #include <stdlib.h>
- #include <stdio.h>
-+#include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <time.h>
-@@ -76,6 +77,12 @@ do {						\
- 	__p->__v = (val);			\
- } while(0)
- 
-+static _always_inline_ const char *gnu_basename(const char *s)
-+{
-+  const char *p = strrchr(s, '/');
-+  return p ? p+1 : s;
-+}
-+
- static _always_inline_ unsigned int ALIGN_POWER2(unsigned int u)
- {
- 	return 1 << ((sizeof(u) * 8) - __builtin_clz(u - 1));

+ 0 - 194
packages/l/libkmod/port/config.h

@@ -1,194 +0,0 @@
-/* config.h.  Generated from config.h.in by configure.  */
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Debug messages. */
-/* #undef ENABLE_DEBUG */
-
-/* Experimental features. */
-/* #undef ENABLE_EXPERIMENTAL */
-
-/* System logging. */
-#define ENABLE_LOGGING 1
-
-/* Enable openssl for modinfo. */
-/* #undef ENABLE_OPENSSL */
-
-/* Enable Xz for modules. */
-/* #undef ENABLE_XZ */
-
-/* Enable zlib for modules. */
-/* #undef ENABLE_ZLIB */
-
-/* Define to 1 if you have the declaration of `be32toh', and to 0 if you
-   don't. */
-#define HAVE_DECL_BE32TOH 1
-
-/* Define to 1 if you have the declaration of `strndupa', and to 0 if you
-   don't. */
-/* #define HAVE_DECL_STRNDUPA */
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#define HAVE_DLFCN_H 1
-
-/* Define to 1 if you have the `finit_module' function. */
-/* #undef HAVE_FINIT_MODULE */
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#define HAVE_INTTYPES_H 1
-
-/* Define to 1 if you have the <linux/module.h> header file. */
-/* #undef HAVE_LINUX_MODULE_H */
-
-/* Define to 1 if you have the <memory.h> header file. */
-#define HAVE_MEMORY_H 1
-
-/* Define if _Noreturn is available */
-#define HAVE_NORETURN 1
-
-/* Define to 1 if you have the `secure_getenv' function. */
-#define HAVE_SECURE_GETENV 1
-
-/* Define if _Static_assert() is available */
-#define HAVE_STATIC_ASSERT 1
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#define HAVE_STDINT_H 1
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#define HAVE_STDLIB_H 1
-
-/* Define to 1 if you have the <strings.h> header file. */
-#define HAVE_STRINGS_H 1
-
-/* Define to 1 if you have the <string.h> header file. */
-#define HAVE_STRING_H 1
-
-/* Define to 1 if `st_mtim' is a member of `struct stat'. */
-/*#define HAVE_STRUCT_STAT_ST_MTIM 1*/
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#define HAVE_SYS_STAT_H 1
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#define HAVE_SYS_TYPES_H 1
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define to 1 if compiler has __builtin_clz() builtin function */
-#define HAVE___BUILTIN_CLZ 1
-
-/* Define to 1 if compiler has __builtin_types_compatible_p() builtin function
-   */
-#define HAVE___BUILTIN_TYPES_COMPATIBLE_P 1
-
-/* Define to 1 if compiler has __builtin_uaddll_overflow() builtin function */
-#define HAVE___BUILTIN_UADDLL_OVERFLOW 0
-
-/* Define to 1 if compiler has __builtin_uaddl_overflow() builtin function */
-#define HAVE___BUILTIN_UADDL_OVERFLOW 0
-
-/* Define to 1 if you have the `__secure_getenv' function. */
-/* #undef HAVE___SECURE_GETENV */
-
-/* Define to 1 if you have the `__xstat' function. */
-#define HAVE___XSTAT 1
-
-/* Features in this build */
-#define KMOD_FEATURES "-XZ -ZLIB -OPENSSL -EXPERIMENTAL"
-
-/* Define to the sub-directory where libtool stores uninstalled libraries. */
-#define LT_OBJDIR ".libs/"
-
-/* Name of package */
-#define PACKAGE "kmod"
-
-/* Define to the address where bug reports for this package should be sent. */
-#define PACKAGE_BUGREPORT "[email protected]"
-
-/* Define to the full name of this package. */
-#define PACKAGE_NAME "kmod"
-
-/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "kmod 26"
-
-/* Define to the one symbol short name of this package. */
-#define PACKAGE_TARNAME "kmod"
-
-/* Define to the home page for this package. */
-#define PACKAGE_URL "http://git.kernel.org/?p=utils/kernel/kmod/kmod.git"
-
-/* Define to the version of this package. */
-#define PACKAGE_VERSION "26"
-
-/* Define to 1 if you have the ANSI C header files. */
-#define STDC_HEADERS 1
-
-/* Enable extensions on AIX 3, Interix.  */
-#ifndef _ALL_SOURCE
-# define _ALL_SOURCE 1
-#endif
-/* Enable GNU extensions on systems that have them.  */
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE 1
-#endif
-/* Enable threading extensions on Solaris.  */
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# define _POSIX_PTHREAD_SEMANTICS 1
-#endif
-/* Enable extensions on HP NonStop.  */
-#ifndef _TANDEM_SOURCE
-# define _TANDEM_SOURCE 1
-#endif
-/* Enable general extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# define __EXTENSIONS__ 1
-#endif
-
-
-/* Version number of package */
-#define VERSION "26"
-
-/* Enable large inode numbers on Mac OS X 10.5.  */
-#ifndef _DARWIN_USE_64_BIT_INODE
-# define _DARWIN_USE_64_BIT_INODE 1
-#endif
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-/* #undef _FILE_OFFSET_BITS */
-
-/* Define for large files, on AIX-style hosts. */
-/* #undef _LARGE_FILES */
-
-/* Define to 1 if on MINIX. */
-/* #undef _MINIX */
-
-/* Define to 2 if the system does not provide POSIX.1 features except with
-   this defined. */
-/* #undef _POSIX_1_SOURCE */
-
-/* Define to 1 if you need to in order for `stat' and other things to work. */
-/* #undef _POSIX_SOURCE */
-
-#if defined(__APPLE__)
-
-#define get_current_dir_name()	getwd(malloc(128))
-#define strndupa(_s,_l)        strdup(_s)
-char* basename(const char*);
-#define init_module	darwin_init_module
-#define delete_module	darwin_delete_module
-#define program_invocation_short_name "depmod"
-#include <endian-darwin.h>
-#else
-#include <endian.h>
-
-#endif
-
-#if defined(__ANDROID__)
-#include <stdlib.h>
-#include <unistd.h>
-static inline char *get_current_dir_name(void)
-{
-    return getcwd(malloc(PATH_MAX), PATH_MAX);
-}
-#endif

+ 0 - 118
packages/l/libkmod/port/endian-darwin.h

@@ -1,118 +0,0 @@
-// "License": Public Domain
-// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
-// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
-// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
-// an example on how to get the endian conversion functions on different platforms.
-
-#ifndef PORTABLE_ENDIAN_H__
-#define PORTABLE_ENDIAN_H__
-
-#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
-
-#	define __WINDOWS__
-
-#endif
-
-#if defined(__linux__) || defined(__CYGWIN__)
-
-#	include <endian.h>
-
-#elif defined(__APPLE__)
-
-#	include <libkern/OSByteOrder.h>
-
-#	define htobe16(x) OSSwapHostToBigInt16(x)
-#	define htole16(x) OSSwapHostToLittleInt16(x)
-#	define be16toh(x) OSSwapBigToHostInt16(x)
-#	define le16toh(x) OSSwapLittleToHostInt16(x)
-
-#	define htobe32(x) OSSwapHostToBigInt32(x)
-#	define htole32(x) OSSwapHostToLittleInt32(x)
-#	define be32toh(x) OSSwapBigToHostInt32(x)
-#	define le32toh(x) OSSwapLittleToHostInt32(x)
-
-#	define htobe64(x) OSSwapHostToBigInt64(x)
-#	define htole64(x) OSSwapHostToLittleInt64(x)
-#	define be64toh(x) OSSwapBigToHostInt64(x)
-#	define le64toh(x) OSSwapLittleToHostInt64(x)
-
-#	define __BYTE_ORDER    BYTE_ORDER
-#	define __BIG_ENDIAN    BIG_ENDIAN
-#	define __LITTLE_ENDIAN LITTLE_ENDIAN
-#	define __PDP_ENDIAN    PDP_ENDIAN
-
-#elif defined(__OpenBSD__)
-
-#	include <sys/endian.h>
-
-#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
-
-#	include <sys/endian.h>
-
-#	define be16toh(x) betoh16(x)
-#	define le16toh(x) letoh16(x)
-
-#	define be32toh(x) betoh32(x)
-#	define le32toh(x) letoh32(x)
-
-#	define be64toh(x) betoh64(x)
-#	define le64toh(x) letoh64(x)
-
-#elif defined(__WINDOWS__)
-
-#	include <winsock2.h>
-#	include <sys/param.h>
-
-#	if BYTE_ORDER == LITTLE_ENDIAN
-
-#		define htobe16(x) htons(x)
-#		define htole16(x) (x)
-#		define be16toh(x) ntohs(x)
-#		define le16toh(x) (x)
-
-#		define htobe32(x) htonl(x)
-#		define htole32(x) (x)
-#		define be32toh(x) ntohl(x)
-#		define le32toh(x) (x)
-
-#		define htobe64(x) htonll(x)
-#		define htole64(x) (x)
-#		define be64toh(x) ntohll(x)
-#		define le64toh(x) (x)
-
-#	elif BYTE_ORDER == BIG_ENDIAN
-
-		/* that would be xbox 360 */
-#		define htobe16(x) (x)
-#		define htole16(x) __builtin_bswap16(x)
-#		define be16toh(x) (x)
-#		define le16toh(x) __builtin_bswap16(x)
-
-#		define htobe32(x) (x)
-#		define htole32(x) __builtin_bswap32(x)
-#		define be32toh(x) (x)
-#		define le32toh(x) __builtin_bswap32(x)
-
-#		define htobe64(x) (x)
-#		define htole64(x) __builtin_bswap64(x)
-#		define be64toh(x) (x)
-#		define le64toh(x) __builtin_bswap64(x)
-
-#	else
-
-#		error byte order not supported
-
-#	endif
-
-#	define __BYTE_ORDER    BYTE_ORDER
-#	define __BIG_ENDIAN    BIG_ENDIAN
-#	define __LITTLE_ENDIAN LITTLE_ENDIAN
-#	define __PDP_ENDIAN    PDP_ENDIAN
-
-#else
-
-#	error platform not supported
-
-#endif
-
-#endif

+ 0 - 28
packages/l/libkmod/port/xmake.lua

@@ -1,28 +0,0 @@
-add_rules("mode.debug", "mode.release")
-
-target("kmod")
-    set_kind("$(kind)")
-    set_languages("gnu99")
-    add_headerfiles("(libkmod/libkmod.h)")
-    add_headerfiles("(libkmod/libkmod-index.h)")
-    add_includedirs(".")
-    add_defines("PATH_MAX=4096")
-    add_defines("ANOTHER_BRICK_IN_THE")
-    add_defines("SYSCONFDIR=\"/tmp\"")
-    add_defines("secure_getenv=getenv")
-    add_cflags("-include config.h")
-    add_files(
-        "libkmod/libkmod.c",
-        "libkmod/libkmod-builtin.c",
-        "libkmod/libkmod-file.c",
-        "libkmod/libkmod-module.c",
-        "libkmod/libkmod-config.c",
-        "libkmod/libkmod-index.c",
-        "libkmod/libkmod-elf.c",
-        "libkmod/libkmod-list.c",
-        "libkmod/libkmod-signature.c",
-        "shared/array.c",
-        "shared/scratchbuf.c",
-        "shared/util.c",
-        "shared/hash.c",
-        "shared/strbuf.c")

+ 121 - 6
packages/l/libkmod/xmake.lua

@@ -6,18 +6,133 @@ package("libkmod")
     add_urls("https://github.com/kmod-project/kmod/archive/refs/tags/$(version).tar.gz",
              "https://github.com/kmod-project/kmod.git")
 
+    add_versions("v34", "cb47be49366b596e4554eeeb7595b128feb261619c7675603e004b07c5ebbd5b")
+    add_versions("v33", "c72120a2582ae240221671ddc1aa53ee522764806f50f8bf1522bbf055679985")
+    add_versions("v32", "9477fa096acfcddaa56c74b988045ad94ee0bac22e0c1caa84ba1b7d408da76e")
     add_versions("v31", "16c40aaa50fc953035b4811b29ce3182f220e95f3c9e5eacb4b07b1abf85f003")
     add_versions("v30", "1fa3974abd80b992d61324bcc04fa65ea96cfe2e9e1150f48394833030c4b583")
 
-    add_patches("31", path.join(os.scriptdir(), "patches", "31", "basename.patch"), "83d07e169882cc91f3af162912ae97cd4b62ff48876ca83b0317c40a388773ad")
+    -- "--enable-static" is not supported by kmod
+    add_configs("shared",  {description = "Build shared library", default = true, type = "boolean", readonly = true})
 
-    on_install("linux", "android", function (package)
-        os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
-        os.cp(path.join(package:scriptdir(), "port", "config.h"), "config.h")
-        os.cp(path.join(package:scriptdir(), "port", "endian-darwin.h"), "endian-darwin.h")
-        import("package.tools.xmake").install(package)
+    add_configs("logging", {description = "Enable system logging.", default = true, type = "boolean"})
+    add_configs("zstd",    {description = "Enable Zstandard-compressed modules support.", default = true, type = "boolean"})
+    add_configs("zlib",    {description = "Enable gzipped modules support.", default = true, type = "boolean"})
+    add_configs("xz",      {description = "Enable Xz-compressed modules support.", default = true, type = "boolean"})
+    add_configs("openssl", {description = "Enable PKCS7 signatures support", default = "openssl3", values = {false, "openssl", "openssl3"}})
+
+    add_includedirs("include", "include/libkmod")
+
+    on_check("android", function (package)
+        -- bionic, fread_unlocked
+        if package:version():ge("v34") then
+            local ndk_sdkver = package:toolchain("ndk"):config("ndk_sdkver")
+            assert(ndk_sdkver and tonumber(ndk_sdkver) >= 28, "package(libkmod): require ndk api level >= 28")
+        end
+    end)
+
+    on_load(function (package)
+        if package:version():lt("v34") then
+            package:add("deps", "autotools")
+        else
+            package:add("deps", "meson", "ninja")
+        end
+
+        for _, lib in ipairs({"zstd", "zlib", "xz"}) do
+            if package:config(lib) then
+                package:add("deps", lib)
+            end
+        end
+        local openssl = package:config("openssl")
+        if openssl then
+            package:add("deps", openssl)
+        end
+    end)
+
+    on_install("linux", "android@linux,macosx", function (package)
+        if package:is_plat("android") then
+            local ndk_sdkver = package:toolchain("ndk"):config("ndk_sdkver")
+            if package:version():lt("v33") and tonumber(ndk_sdkver) <= 23 then
+                io.replace("shared/util.h", "#include <time.h>", [[
+                    #include <time.h>
+                    #include <string.h>
+
+                    // from libkmod v33
+                    static inline const char *basename(const char *s)
+                    {
+                        const char *p = strrchr(s, '/');
+                        return p ? p + 1 : s;
+                    }
+                ]], {plain = true})
+            end
+            io.replace("shared/util.h", "#include <time.h>", [[
+                #include <time.h>
+                #include <unistd.h>
+
+                // from https://android.googlesource.com/kernel/common/+/03c04a7cba972/tools/perf/util/get_current_dir_name.c
+                static inline char *get_current_dir_name(void)
+                {
+                    char pwd[PATH_MAX];
+                    return getcwd(pwd, sizeof(pwd)) == NULL ? NULL : strdup(pwd);
+                }
+            ]], {plain = true})
+        end
+
+        if package:version():lt("v34") then
+            local configs = {
+                "--disable-dependency-tracking",
+                "--disable-manpages",
+                "--disable-test-modules",
+                "--disable-tools"
+            }
+
+            table.insert(configs, "--enable-logging=" .. (package:config("logging") and "yes" or "no"))
+            table.insert(configs, "--with-zstd=" .. (package:config("zstd") and "yes" or "no"))
+            table.insert(configs, "--with-zlib=" .. (package:config("zlib") and "yes" or "no"))
+            table.insert(configs, "--with-xz=" .. (package:config("xz") and "yes" or "no"))
+            table.insert(configs, "--with-openssl=" .. (package:config("openssl") and "yes" or "no"))
+
+            local packagedeps = {}
+            for _, dep in ipairs(package:librarydeps()) do
+                table.insert(packagedeps, dep:name())
+            end
+
+            io.replace("Makefile.am", [[dist_bashcompletion_DATA = \
+	shell-completion/bash/kmod]], "", {plain = true})
+
+            import("package.tools.autoconf").configure(package, configs, {packagedeps = packagedeps})
+
+            io.replace("libtool", "      -all-static)", [[      --target=* )
+        func_append compiler_flags " $arg"
+        func_append linker_flags " $arg"
+        ;;
+      -all-static)]], {plain = true})
+
+            os.vrunv("make")
+            os.vrunv("make install")
+        else
+            local configs = {
+                "-Dbashcompletiondir=no",
+                "-Dfishcompletiondir=no",
+                "-Dzshcompletiondir=no",
+                "-Dmanpages=false",
+                "-Dtools=false"
+            }
+
+            table.insert(configs, "-Dlogging=" .. (package:config("logging") and "true" or "false"))
+            table.insert(configs, "-Dzstd=" .. (package:config("zstd") and "enabled" or "disabled"))
+            table.insert(configs, "-Dzlib=" .. (package:config("zlib") and "enabled" or "disabled"))
+            table.insert(configs, "-Dxz=" .. (package:config("xz") and "enabled" or "disabled"))
+            table.insert(configs, "-Dopenssl=" .. (package:config("openssl") and "enabled" or "disabled"))
+
+            io.replace("meson.build", "_tools = %[(.-)%]", "_tools = []")
+
+            import("package.tools.meson").install(package, configs)
+        end
+        os.mv(path.join(package:installdir("include"), "libkmod.h"), path.join(package:installdir("include/libkmod"), "libkmod.h"))
     end)
 
     on_test(function (package)
+        assert(package:has_cfuncs("kmod_new", {includes = "libkmod.h"}))
         assert(package:has_cfuncs("kmod_new", {includes = "libkmod/libkmod.h"}))
     end)