From b39c84f81e5599e59504248c981fcbdb5946a9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 14 Aug 2023 10:03:53 +0800 Subject: [PATCH 1/4] IO (Android): fix compiler errors if `wordexp` is not available --- src/common/io/io_unix.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index d1e635e11..1941e6637 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -1,12 +1,16 @@ #include "io.h" #include "util/stringUtils.h" +#include "util/unused.h" #include #include #include #include #include + +#if __has_include() #include +#endif static void createSubfolders(const char* fileName) { @@ -108,9 +112,12 @@ bool ffPathExists(const char* path, FFPathType type) return false; } -bool ffPathExpandEnv(const char* in, FFstrbuf* out) +bool ffPathExpandEnv(FF_MAYBE_UNUSED const char* in, FF_MAYBE_UNUSED FFstrbuf* out) { bool result = false; + + #if __has_include() // https://github.com/termux/termux-packages/pull/7056 + wordexp_t exp; if(wordexp(in, &exp, WRDE_NOCMD) != 0) return false; @@ -123,6 +130,8 @@ bool ffPathExpandEnv(const char* in, FFstrbuf* out) wordfree(&exp); + #endif + return result; } From 65d25446fef88dd52cf1733db9b45bf67f56d29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 14 Aug 2023 10:05:43 +0800 Subject: [PATCH 2/4] Users: use `__has_include` --- CMakeLists.txt | 5 ----- src/detection/users/users_linux.c | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d461a209e..71f580cd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -630,11 +630,6 @@ if(WIN32) target_compile_definitions(libfastfetch PUBLIC WIN32_LEAN_AND_MEAN=1) endif() -CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX_H) -if(HAVE_UTMPX_H) - target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX_H) -endif() - if(HAVE_WCWIDTH) target_compile_definitions(libfastfetch PRIVATE FF_HAVE_WCWIDTH) endif() diff --git a/src/detection/users/users_linux.c b/src/detection/users/users_linux.c index 3b4963a14..c17bf139c 100644 --- a/src/detection/users/users_linux.c +++ b/src/detection/users/users_linux.c @@ -1,7 +1,7 @@ #include "fastfetch.h" #include "users.h" -#if FF_HAVE_UTMPX_H +#if __has_include() #include #else //for Android compatibility From 02adbb462adbcb9964bfc4872608da8a11a4d3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 14 Aug 2023 10:33:11 +0800 Subject: [PATCH 3/4] Android: link to `libandroid-wordexp` if available Ref: https://github.com/termux/termux-packages/tree/master/packages/libandroid-wordexp --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71f580cd4..dd7efea0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -824,6 +824,13 @@ elseif(BSD) target_link_libraries(libfastfetch PRIVATE "usbhid" ) +elseif(ANDROID) + CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP) + if(HAVE_LIBANDROID_WORDEXP) + target_link_libraries(libfastfetch + PRIVATE android-wordexp + ) + endif() endif() target_include_directories(libfastfetch From 86dffe751f8221bf4d8a518e31bf98ad461a491b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 14 Aug 2023 10:51:54 +0800 Subject: [PATCH 4/4] Android: prefer static linking to `libandroid-wordexp.a` --- CMakeLists.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd7efea0e..a4e49c373 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -825,11 +825,18 @@ elseif(BSD) PRIVATE "usbhid" ) elseif(ANDROID) - CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP) - if(HAVE_LIBANDROID_WORDEXP) + CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) + if(HAVE_LIBANDROID_WORDEXP_STATIC) target_link_libraries(libfastfetch - PRIVATE android-wordexp + PRIVATE -l:libandroid-wordexp.a ) + else() + CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP) + if(HAVE_LIBANDROID_WORDEXP) + target_link_libraries(libfastfetch + PRIVATE android-wordexp + ) + endif() endif() endif()