Skip to content

Commit 71fbe04

Browse files
yelnineiCarterLi
authored andcommitted
Start work on GNU
1 parent f2f9b10 commit 71fbe04

File tree

8 files changed

+121
-8
lines changed

8 files changed

+121
-8
lines changed

CMakeLists.txt

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
3232
set(SunOS TRUE CACHE BOOL "..." FORCE)
3333
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
3434
set(Haiku TRUE CACHE BOOL "..." FORCE)
35+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
36+
set(GNU TRUE CACHE BOOL "..." FORCE)
3537
elseif(NOT APPLE AND NOT WIN32)
3638
message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
3739
endif()
@@ -1192,6 +1194,83 @@ elseif(Haiku)
11921194
src/util/binary_linux.c
11931195
src/util/haiku/version.cpp
11941196
)
1197+
elseif(GNU)
1198+
list(APPEND LIBFASTFETCH_SRC
1199+
src/common/dbus.c
1200+
src/common/io/io_unix.c
1201+
src/common/netif/netif_linux.c
1202+
src/common/networking/networking_linux.c
1203+
src/common/processing_linux.c
1204+
src/detection/battery/battery_nosupport.c
1205+
src/detection/bios/bios_nosupport.c
1206+
src/detection/board/board_nosupport.c
1207+
src/detection/bootmgr/bootmgr_nosupport.c
1208+
src/detection/brightness/brightness_nosupport.c
1209+
src/detection/btrfs/btrfs_nosupport.c
1210+
src/detection/chassis/chassis_nosupport.c
1211+
src/detection/cpu/cpu_linux.c
1212+
src/detection/cpucache/cpucache_nosupport.c
1213+
src/detection/cpuusage/cpuusage_linux.c
1214+
src/detection/cursor/cursor_linux.c
1215+
src/detection/bluetooth/bluetooth_linux.c
1216+
src/detection/bluetoothradio/bluetoothradio_linux.c
1217+
src/detection/disk/disk_linux.c
1218+
src/detection/dns/dns_linux.c
1219+
src/detection/physicaldisk/physicaldisk_nosupport.c
1220+
src/detection/physicalmemory/physicalmemory_nosupport.c
1221+
src/detection/diskio/diskio_nosupport.c
1222+
src/detection/displayserver/linux/displayserver_linux.c
1223+
src/detection/displayserver/linux/drm.c
1224+
src/detection/displayserver/linux/wayland/wayland.c
1225+
src/detection/displayserver/linux/wayland/global-output.c
1226+
src/detection/displayserver/linux/wayland/zwlr-output.c
1227+
src/detection/displayserver/linux/wayland/wlr-output-management-unstable-v1-protocol.c
1228+
src/detection/displayserver/linux/wmde.c
1229+
src/detection/displayserver/linux/xcb.c
1230+
src/detection/displayserver/linux/xlib.c
1231+
src/detection/font/font_linux.c
1232+
src/detection/gpu/gpu_nosupport.c
1233+
src/detection/gpu/gpu_pci.c
1234+
src/detection/gtk_qt/gtk.c
1235+
src/detection/host/host_nosupport.c
1236+
src/detection/icons/icons_linux.c
1237+
src/detection/initsystem/initsystem_linux.c
1238+
src/detection/keyboard/keyboard_nosupport.c
1239+
src/detection/libc/libc_linux.c
1240+
src/detection/lm/lm_linux.c
1241+
src/detection/loadavg/loadavg_linux.c
1242+
src/detection/locale/locale_linux.c
1243+
src/detection/localip/localip_linux.c
1244+
src/detection/gamepad/gamepad_nosupport.c
1245+
src/detection/media/media_linux.c
1246+
src/detection/memory/memory_linux.c
1247+
src/detection/mouse/mouse_nosupport.c
1248+
src/detection/netio/netio_nosupport.c
1249+
src/detection/opengl/opengl_linux.c
1250+
src/detection/os/os_linux.c
1251+
src/detection/packages/packages_linux.c
1252+
src/detection/poweradapter/poweradapter_nosupport.c
1253+
src/detection/processes/processes_linux.c
1254+
src/detection/gtk_qt/qt.c
1255+
src/detection/sound/sound_linux.c
1256+
src/detection/swap/swap_linux.c
1257+
src/detection/terminalfont/terminalfont_linux.c
1258+
src/detection/terminalshell/terminalshell_linux.c
1259+
src/detection/terminalsize/terminalsize_linux.c
1260+
src/detection/theme/theme_linux.c
1261+
src/detection/tpm/tpm_nosupport.c
1262+
src/detection/uptime/uptime_linux.c
1263+
src/detection/users/users_linux.c
1264+
src/detection/wallpaper/wallpaper_linux.c
1265+
src/detection/wifi/wifi_linux.c
1266+
src/detection/wm/wm_nosupport.c
1267+
src/detection/de/de_linux.c
1268+
src/detection/wmtheme/wmtheme_linux.c
1269+
src/detection/camera/camera_nosupport.c
1270+
src/detection/zpool/zpool_nosupport.c
1271+
src/util/platform/FFPlatform_unix.c
1272+
src/util/binary_linux.c
1273+
)
11951274
endif()
11961275

11971276
if(ENABLE_DIRECTX_HEADERS)
@@ -1315,6 +1394,10 @@ elseif(NetBSD)
13151394
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto
13161395
elseif(Haiku)
13171396
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
1397+
elseif(GNU)
1398+
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
1399+
# On Hurd PATH_MAX is not defined. Set an arbitrary limit as workaround.
1400+
target_compile_definitions(libfastfetch PUBLIC PATH_MAX=4096)
13181401
endif()
13191402

13201403
if(FreeBSD OR OpenBSD OR NetBSD)
@@ -1639,6 +1722,10 @@ elseif(SunOS)
16391722
PRIVATE "nvpair"
16401723
PRIVATE "devinfo"
16411724
)
1725+
elseif(GNU)
1726+
target_link_libraries(libfastfetch
1727+
PRIVATE "m"
1728+
)
16421729
elseif(ANDROID)
16431730
CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
16441731
if(HAVE_LIBANDROID_WORDEXP_STATIC)

src/common/processing_linux.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void ffProcessGetInfoLinux(pid_t pid, FFstrbuf* processName, FFstrbuf* exe, cons
234234
assert(processName->length > 0);
235235
ffStrbufClear(exe);
236236

237-
#ifdef __linux__
237+
#if defined(__linux__) || defined(__GNU__)
238238

239239
char filePath[64];
240240
snprintf(filePath, sizeof(filePath), "/proc/%d/cmdline", (int)pid);
@@ -436,7 +436,7 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
436436
if (pid <= 0)
437437
return "Invalid pid";
438438

439-
#ifdef __linux__
439+
#if defined(__linux__) || defined(__GNU__)
440440

441441
char procFilePath[64];
442442
if (ppid)
@@ -465,11 +465,30 @@ const char* ffProcessGetBasicInfoLinux(pid_t pid, FFstrbuf* name, pid_t* ppid, i
465465
}
466466
else
467467
{
468+
#ifndef __GNU__
468469
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/comm", (int)pid);
469470
ssize_t nRead = ffReadFileBuffer(procFilePath, name);
470471
if(nRead <= 0)
471472
return "ffReadFileBuffer(/proc/pid/comm, name) failed";
472473
ffStrbufTrimRightSpace(name);
474+
#else
475+
// No /proc/1/comm on Hurd so read /proc/1/stat again
476+
snprintf(procFilePath, sizeof(procFilePath), "/proc/%d/stat", (int)pid);
477+
char buf[PROC_FILE_BUFFSIZ];
478+
ssize_t nRead = ffReadFileData(procFilePath, sizeof(buf) - 1, buf);
479+
if(nRead <= 8)
480+
return "ffReadFileData(/proc/pid/stat, PROC_FILE_BUFFSIZ-1, buf) failed";
481+
buf[nRead] = '\0';
482+
483+
ffStrbufEnsureFixedLengthFree(name, 255);
484+
if(
485+
sscanf(buf, "%*s (%255[^)]) %*c %*d %*d %*d %*d", name->chars) == 0 || //stat (comm) state ppid pgrp session tty
486+
name->chars[0] == '\0'
487+
)
488+
return "sscanf(stat) failed";
489+
490+
ffStrbufRecalculateLength(name);
491+
#endif
473492
}
474493

475494
#elif defined(__APPLE__)

src/detection/loadavg/loadavg_linux.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ const char* ffDetectLoadavg(double result[3])
1919
}
2020

2121
#endif
22-
22+
#ifndef __GNU__
2323
// getloadavg requires higher ANDROID_API version
2424
struct sysinfo si;
2525
if (sysinfo(&si) < 0)
2626
return "sysinfo() failed";
2727

2828
for (int i = 0; i < 3; i++)
2929
result[i] = (double) si.loads[i] / (1 << SI_LOAD_SHIFT);
30+
#endif
3031
return NULL;
3132
}

src/detection/localip/localip_linux.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__) || defined(__HAIKU__)
3030
#include <net/if_media.h>
3131
#include <net/if_dl.h>
32+
#elif defined(__GNU__)
3233
#else
3334
#include <netpacket/packet.h>
3435
#endif
@@ -69,12 +70,14 @@ static const FFLocalIpNIFlag niFlagOptions[] = {
6970
#ifdef IFF_NOTRAILERS
7071
FF_LOCALIP_NIFLAG(NOTRAILERS),
7172
#endif
72-
#ifdef __linux__
73+
#if defined( __linux__) || defined (__GNU__)
7374
FF_LOCALIP_NIFLAG(MASTER),
7475
FF_LOCALIP_NIFLAG(SLAVE),
7576
FF_LOCALIP_NIFLAG(PORTSEL),
7677
FF_LOCALIP_NIFLAG(AUTOMEDIA),
7778
FF_LOCALIP_NIFLAG(DYNAMIC),
79+
#endif
80+
#ifdef __linux__
7881
FF_LOCALIP_NIFLAG(LOWER_UP),
7982
FF_LOCALIP_NIFLAG(DORMANT),
8083
FF_LOCALIP_NIFLAG(ECHO),
@@ -562,6 +565,7 @@ const char* ffDetectLocalIps(const FFLocalIpOptions* options, FFlist* results)
562565
FF_DEBUG("No MAC address available for interface %s", adapter->mac->ifa_name);
563566
}
564567
}
568+
#elif defined(__GNU__)
565569
#else
566570
(void) adapter;
567571
#endif

src/detection/uptime/uptime_linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ const char* ffDetectUptime(FFUptimeResult* result)
2626
}
2727

2828
#endif
29-
29+
#ifndef __GNU__
3030
struct timespec uptime;
3131
if (clock_gettime(CLOCK_BOOTTIME, &uptime) != 0)
3232
return "clock_gettime(CLOCK_BOOTTIME) failed";
3333

3434
result->uptime = (uint64_t) uptime.tv_sec * 1000 + (uint64_t) uptime.tv_nsec / 1000000;
3535
result->bootTime = ffTimeGetNow() - result->uptime;
36-
36+
#endif
3737
return NULL;
3838
}

src/detection/version/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#define FF_SYSNAME "NetBSD"
5555
#elif defined(__HAIKU__)
5656
#define FF_SYSNAME "Haiku"
57+
#elif defined(__GNU__)
58+
#define FF_SYSNAME "GNU"
5759
#else
5860
#define FF_SYSNAME "Unknown"
5961
#endif

src/options/general.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ typedef struct FFOptionsGeneral
1616
bool detectVersion;
1717

1818
// Module options that cannot be put in module option structure
19-
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
19+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__sun) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(__GNU__)
2020
FFstrbuf playerName;
2121
FFDsForceDrmType dsForceDrm;
2222
#elif defined(_WIN32)

src/util/platform/FFPlatform_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
static void getExePath(FFPlatform* platform)
2323
{
2424
char exePath[PATH_MAX + 1];
25-
#ifdef __linux__
25+
#if defined(__linux__) || defined (__GNU__)
2626
ssize_t exePathLen = readlink("/proc/self/exe", exePath, sizeof(exePath) - 1);
2727
if (exePathLen >= 0)
2828
exePath[exePathLen] = '\0';

0 commit comments

Comments
 (0)