Skip to content

Commit

Permalink
Simplify packaging for termux
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusDierheimer committed Apr 10, 2022
1 parent a032d37 commit bd0c593
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 55 deletions.
33 changes: 22 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ OPTION(ENABLE_XFCONF "Enable libxfconf-0" ON)
OPTION(ENABLE_RPM "Enable rpm" ON)
OPTION(ENABLE_IMAGEMAGICK "Enable imagemagick" ON)

# Track commits between version bumps for output in --version
if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_VERSION_TWEAK
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wconversion")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "-Wl,-O3")

# These variables are mainly here for android, which has a different root fs structure.
if(NOT TARGET_DIR_ROOT)
set(TARGET_DIR_ROOT "")
endif()
if(NOT TARGET_DIR_USR)
set(TARGET_DIR_USR "${TARGET_DIR_ROOT}/usr")
endif()
if(NOT TARGET_DIR_HOME)
set(TARGET_DIR_HOME "${TARGET_DIR_ROOT}/home")
endif()

function(fastfetch_load_text FILENAME OUTVAR)
file(READ "${FILENAME}" TEMP)
string(REPLACE "\n" "\\n" TEMP "${TEMP}")
Expand All @@ -56,6 +56,17 @@ function(fastfetch_load_text FILENAME OUTVAR)
set("${OUTVAR}" "${TEMP}" PARENT_SCOPE)
endfunction(fastfetch_load_text)

# Track commits between version bumps for output in --version
if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
execute_process(
COMMAND git describe --tags
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE PROJECT_VERSION_TWEAK
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}")
endif()

fastfetch_load_text(src/data/structure.txt DATATEXT_STRUCTURE)
fastfetch_load_text(src/data/config.txt DATATEXT_CONFIG)
fastfetch_load_text(src/data/modules.txt DATATEXT_MODULES)
Expand Down
4 changes: 2 additions & 2 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ static void initConfigDirs(FFstate* state)

FFstrbuf* systemConfigHome = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfigHome, 64);
ffStrbufAppendS(systemConfigHome, "/etc/xdg");
ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigHome)

FFstrbuf* systemConfig = ffListAdd(&state->configDirs);
ffStrbufInitA(systemConfig, 64);
ffStrbufAppendS(systemConfig, "/etc");
ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc");
FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfig)

#undef FF_ENSURE_ONLY_ONCE_IN_LIST
Expand Down
20 changes: 10 additions & 10 deletions src/detection/displayserver/wmde.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ static void getKDE(FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "plasmashell");
ffStrbufSetS(&result->dePrettyName, "KDE Plasma");
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion);
applyBetterWM(result, getenv("KDEWM"));
}

static void getGnome(FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "gnome-shell");
ffStrbufSetS(&result->dePrettyName, "GNOME");
ffParsePropFile("/usr/share/gnome-shell/org.gnome.Extensions", "version :", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/gnome-shell/org.gnome.Extensions", "version :", &result->deVersion);
}

static void getCinnamon(FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "cinnamon");
ffStrbufSetS(&result->dePrettyName, "Cinnamon");
ffParsePropFile("/usr/share/applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion);
}

static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
Expand All @@ -130,7 +130,7 @@ static void getMate(const FFinstance* instance, FFDisplayServerResult* result)
FFstrbuf micro;
ffStrbufInit(&micro);

ffParsePropFileValues("/usr/share/mate-about/mate-version.xml", 3, (FFpropquery[]) {
ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR"/share/mate-about/mate-version.xml", 3, (FFpropquery[]) {
{"<platform>", &major},
{"<minor>", &minor},
{"<micro>", &micro}
Expand Down Expand Up @@ -159,7 +159,7 @@ static void getXFCE4(const FFinstance* instance, FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "xfce4-session");
ffStrbufSetS(&result->dePrettyName, "Xfce4");
ffParsePropFile("/usr/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version", &result->deVersion);

if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
{
Expand All @@ -180,12 +180,12 @@ static void getLXQt(const FFinstance* instance, FFDisplayServerResult* result)
{
ffStrbufSetS(&result->deProcessName, "lxqt-session");
ffStrbufSetS(&result->dePrettyName, "LXQt");
ffParsePropFile("/usr/lib/pkgconfig/lxqt.pc", "Version:", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/lib/pkgconfig/lxqt.pc", "Version:", &result->deVersion);

if(result->deVersion.length == 0)
ffParsePropFile("/usr/share/cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion);
if(result->deVersion.length == 0)
ffParsePropFile("/usr/share/cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion);

if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
{
Expand Down Expand Up @@ -289,13 +289,13 @@ static void getWMProtocolNameFromEnv(FFDisplayServerResult* result)

static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* result)
{
DIR* proc = opendir("/proc");
DIR* proc = opendir(FASTFETCH_TARGET_DIR_ROOT"/proc");
if(proc == NULL)
return;

FFstrbuf procPath;
ffStrbufInitA(&procPath, 64);
ffStrbufAppendS(&procPath, "/proc/");
ffStrbufAppendS(&procPath, FASTFETCH_TARGET_DIR_ROOT"/proc/");

uint32_t procPathLength = procPath.length;

Expand Down
6 changes: 3 additions & 3 deletions src/detection/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const FFOSResult* ffDetectOS(const FFinstance* instance)
}
else
{
parseFile("/etc/os-release", &result);
parseFile("/usr/lib/os-release", &result);
parseFile("/etc/lsb-release", &result);
parseFile(FASTFETCH_TARGET_DIR_ROOT"/etc/os-release", &result);
parseFile(FASTFETCH_TARGET_DIR_USR"/lib/os-release", &result);
parseFile(FASTFETCH_TARGET_DIR_ROOT"/etc/lsb-release", &result);
}
#else
ffStrbufSetS(&result.name, "Android");
Expand Down
4 changes: 2 additions & 2 deletions src/detection/terminalShell.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb
{
FFstrbuf cmdlineFilePath;
ffStrbufInit(&cmdlineFilePath);
ffStrbufAppendS(&cmdlineFilePath, "/proc/");
ffStrbufAppendS(&cmdlineFilePath, FASTFETCH_TARGET_DIR_ROOT"/proc/");
ffStrbufAppendS(&cmdlineFilePath, pid);
ffStrbufAppendS(&cmdlineFilePath, "/cmdline");

Expand All @@ -36,7 +36,7 @@ static void getTerminalShell(FFTerminalShellResult* result, const char* pid)
{
FFstrbuf statFilePath;
ffStrbufInit(&statFilePath);
ffStrbufAppendS(&statFilePath, "/proc/");
ffStrbufAppendS(&statFilePath, FASTFETCH_TARGET_DIR_ROOT"/proc/");
ffStrbufAppendS(&statFilePath, pid);
ffStrbufAppendS(&statFilePath, "/stat");

Expand Down
4 changes: 2 additions & 2 deletions src/fastfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static inline void listAvailablePresets(FFinstance* instance)
ffStrbufAppendS(&folder, "/.local/share/fastfetch/presets/");
listAvailablePresetsFromFolder(&folder, 0, NULL);

ffStrbufSetS(&folder, "/usr/share/fastfetch/presets/");
ffStrbufSetS(&folder, FASTFETCH_TARGET_DIR_USR"/share/fastfetch/presets/");
listAvailablePresetsFromFolder(&folder, 0, NULL);

ffStrbufDestroy(&folder);
Expand Down Expand Up @@ -488,7 +488,7 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
return;
}

ffStrbufSetS(&filename, "/usr/share/fastfetch/presets/");
ffStrbufSetS(&filename, FASTFETCH_TARGET_DIR_USR"/share/fastfetch/presets/");
ffStrbufAppendS(&filename, value);

file = fopen(filename.chars, "r");
Expand Down
4 changes: 4 additions & 0 deletions src/fastfetch_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#define FASTFETCH_PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define FASTFETCH_PROJECT_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@"

#define FASTFETCH_TARGET_DIR_ROOT "@TARGET_DIR_ROOT@"
#define FASTFETCH_TARGET_DIR_USR "@TARGET_DIR_USR@"
#define FASTFETCH_TARGET_DIR_HOME "@TARGET_DIR_HOME@"

#define FASTFETCH_DATATEXT_STRUCTURE "@DATATEXT_STRUCTURE@"
#define FASTFETCH_DATATEXT_CONFIG "@DATATEXT_CONFIG@" //Requires FASTFETCH_PROJECT_VERSION and FASTFETCH_DATATEXT_STRUCTURE to be set
#define FASTFETCH_DATATEXT_MODULES "@DATATEXT_MODULES@"
Expand Down
4 changes: 2 additions & 2 deletions src/modules/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void ffPrintCPU(FFinstance* instance)
if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS))
return;

FILE* cpuinfo = fopen("/proc/cpuinfo", "r");
FILE* cpuinfo = fopen(FASTFETCH_TARGET_DIR_ROOT"/proc/cpuinfo", "r");
if(cpuinfo == NULL)
{
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "fopen(\"/proc/cpuinfo\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "fopen(\""FASTFETCH_TARGET_DIR_ROOT"/proc/cpuinfo\", \"r\") == NULL");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/cpuUsage.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
void ffPrintCPUUsage(FFinstance* instance)
{
long user, nice, system, idle, iowait, irq, softirq;
FILE* procStat = fopen("/proc/stat", "r");
FILE* procStat = fopen(FASTFETCH_TARGET_DIR_ROOT"/proc/stat", "r");
if(procStat == NULL)
{
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, FF_CPU_USAGE_NUM_FORMAT_ARGS, "fopen(\"/proc/stat\", \"r\") == NULL");
ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, FF_CPU_USAGE_NUM_FORMAT_ARGS, "fopen(\""FASTFETCH_TARGET_DIR_ROOT"/proc/stat\", \"r\") == NULL");
return;
}
if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0) goto exit;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static bool printCursorFromXDG(FFinstance* instance, bool user)
if(user)
ffParsePropFileHome(instance, ".icons/default/index.theme", "Inherits =", &theme);
else
ffParsePropFile("/usr/share/icons/default/index.theme", "Inherits =", &theme);
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/icons/default/index.theme", "Inherits =", &theme);

if(theme.length == 0)
{
Expand Down
7 changes: 3 additions & 4 deletions src/modules/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,17 @@ void ffPrintDisk(FFinstance* instance)
{
if(instance->config.diskFolders.length == 0)
{

struct statvfs fsRoot;
int rootRet = statvfs("/", &fsRoot);

struct statvfs fsHome;
int homeRet = statvfs("/home", &fsHome);
int homeRet = statvfs(FASTFETCH_TARGET_DIR_HOME, &fsHome);

if(rootRet != 0 && homeRet != 0)
{
FF_STRBUF_CREATE(key);
getKey(instance, &key, "", false);
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs failed for both / and /home");
ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME);
ffStrbufDestroy(&key);
return;
}
Expand All @@ -99,7 +98,7 @@ void ffPrintDisk(FFinstance* instance)
printStatvfsCreateKey(instance, "/", &fsRoot);

if(homeRet == 0 && (rootRet != 0 || fsRoot.f_fsid != fsHome.f_fsid))
printStatvfsCreateKey(instance, "/home", &fsHome);
printStatvfsCreateKey(instance, FASTFETCH_TARGET_DIR_HOME, &fsHome);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/modules/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void ffPrintLocale(FFinstance* instance)
FFstrbuf locale;
ffStrbufInit(&locale);

ffParsePropFile("/etc/locale.conf", "LANG =", &locale);
ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/locale.conf", "LANG =", &locale);

if (locale.length == 0)
getLocaleFromEnv(&locale);
Expand Down
6 changes: 3 additions & 3 deletions src/modules/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Impl inspired by: https://github.com/sam-barr/paleofetch/blob/b7c58a52c0de39b53c9b5f417889a5886d324bfa/paleofetch.c#L544
void ffPrintMemory(FFinstance* instance)
{
FILE* meminfo = fopen("/proc/meminfo", "r");
FILE* meminfo = fopen(FASTFETCH_TARGET_DIR_ROOT"/proc/meminfo", "r");
if(meminfo == NULL) {
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "fopen(\"/proc/meminfo\", \"r\") == NULL");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "fopen(\""FASTFETCH_TARGET_DIR_ROOT"/proc/meminfo\", \"r\") == NULL");
return;
}

Expand Down Expand Up @@ -42,7 +42,7 @@ void ffPrintMemory(FFinstance* instance)

if(used_mem == 0 && total_mem == 0 && percentage == 0)
{
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "/proc/meminfo could't be parsed");
ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, FASTFETCH_TARGET_DIR_ROOT"/proc/meminfo could't be parsed");
return;
}

Expand Down
18 changes: 7 additions & 11 deletions src/modules/packages.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,19 @@ static uint32_t countFilesIn(const char* dirname, const char* filename)

void ffPrintPackages(FFinstance* instance)
{
uint32_t pacman = getNumElements("/var/lib/pacman/local", DT_DIR);
uint32_t dpkg = getNumStrings("/var/lib/dpkg/status", "Status: ");

#if __ANDROID__
dpkg += getNumStrings("/data/data/com.termux/files/usr/var/lib/dpkg/status", "Status: ");
#endif
uint32_t pacman = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/lib/pacman/local", DT_DIR);
uint32_t dpkg = getNumStrings(FASTFETCH_TARGET_DIR_ROOT"/var/lib/dpkg/status", "Status: ");

#ifdef FF_HAVE_RPM
uint32_t rpm = getRpmPackageCount(instance);
#else
uint32_t rpm = 0;
#endif

uint32_t emerge = countFilesIn("/var/db/pkg", "SIZE");
uint32_t xbps = getNumElements("/var/db/xbps", DT_REG);
uint32_t flatpak = getNumElements("/var/lib/flatpak/app", DT_DIR);
uint32_t snap = getNumElements("/snap", DT_DIR);
uint32_t emerge = countFilesIn(FASTFETCH_TARGET_DIR_ROOT"/var/db/pkg", "SIZE");
uint32_t xbps = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/db/xbps", DT_REG);
uint32_t flatpak = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/var/lib/flatpak/app", DT_DIR);
uint32_t snap = getNumElements(FASTFETCH_TARGET_DIR_ROOT"/snap", DT_DIR);

//Accounting for the /snap/bin folder
if(snap > 0)
Expand All @@ -170,7 +166,7 @@ void ffPrintPackages(FFinstance* instance)

FFstrbuf manjaroBranch;
ffStrbufInit(&manjaroBranch);
if(ffParsePropFile("/etc/pacman-mirrors.conf", "Branch =", &manjaroBranch) && manjaroBranch.length == 0)
if(ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/pacman-mirrors.conf", "Branch =", &manjaroBranch) && manjaroBranch.length == 0)
ffStrbufSetS(&manjaroBranch, "stable");

if(instance->config.packagesFormat.length == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/terminalfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void printTTY(FFinstance* instance)
FFstrbuf fontName;
ffStrbufInit(&fontName);

ffParsePropFile("/etc/vconsole.conf", "Font =", &fontName);
ffParsePropFile(FASTFETCH_TARGET_DIR_ROOT"/etc/vconsole.conf", "Font =", &fontName);

if(fontName.length == 0)
{
Expand Down

0 comments on commit bd0c593

Please sign in to comment.