From 575edffb4bf4e8a98949a368efa9ba5905c08462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Fri, 22 Jan 2021 19:14:59 +0100 Subject: Add configure option to create static htop binary --- linux/LibSensors.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'linux/LibSensors.c') diff --git a/linux/LibSensors.c b/linux/LibSensors.c index 158829aa..f94bcff7 100644 --- a/linux/LibSensors.c +++ b/linux/LibSensors.c @@ -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; -- cgit v1.2.3