Add configure option to create static htop binary

This commit is contained in:
Christian Göttsche
2021-01-22 19:14:59 +01:00
parent 759a34039c
commit 575edffb4b
5 changed files with 171 additions and 33 deletions

View File

@ -10,6 +10,19 @@
#include "XUtils.h"
#ifdef BUILD_STATIC
#define sym_sensors_init sensors_init
#define sym_sensors_cleanup sensors_cleanup
#define sym_sensors_get_detected_chips sensors_get_detected_chips
#define sym_sensors_snprintf_chip_name sensors_snprintf_chip_name
#define sym_sensors_get_features sensors_get_features
#define sym_sensors_get_subfeature sensors_get_subfeature
#define sym_sensors_get_value sensors_get_value
#define sym_sensors_get_label sensors_get_label
#else
static int (*sym_sensors_init)(FILE*);
static void (*sym_sensors_cleanup)(void);
static const sensors_chip_name* (*sym_sensors_get_detected_chips)(const sensors_chip_name*, int*);
@ -21,7 +34,15 @@ static char* (*sym_sensors_get_label)(const sensors_chip_name*, const sensors_fe
static void* dlopenHandle = NULL;
#endif /* BUILD_STATIC */
int LibSensors_init(FILE* input) {
#ifdef BUILD_STATIC
return sym_sensors_init(input);
#else
if (!dlopenHandle) {
/* Find the unversioned libsensors.so (symlink) and prefer that, but Debian has .so.5 and Fedora .so.4 without
matching symlinks (unless people install the -dev packages) */
@ -56,29 +77,42 @@ int LibSensors_init(FILE* input) {
return sym_sensors_init(input);
dlfailure:
if (dlopenHandle) {
dlclose(dlopenHandle);
dlopenHandle = NULL;
}
return -1;
#endif /* BUILD_STATIC */
}
void LibSensors_cleanup(void) {
#ifdef BUILD_STATIC
sym_sensors_cleanup();
#else
if (dlopenHandle) {
sym_sensors_cleanup();
dlclose(dlopenHandle);
dlopenHandle = NULL;
}
#endif /* BUILD_STATIC */
}
void LibSensors_getCPUTemperatures(CPUData* cpus, unsigned int cpuCount) {
for (unsigned int i = 0; i <= cpuCount; i++)
cpus[i].temperature = NAN;
#ifndef BUILD_STATIC
if (!dlopenHandle)
return;
#endif /* !BUILD_STATIC */
unsigned int coreTempCount = 0;