diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2021-01-22 19:14:59 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2021-01-25 18:01:39 +0100 |
commit | 575edffb4bf4e8a98949a368efa9ba5905c08462 (patch) | |
tree | d6a1ebf7745d5aba9112d48fb07ae7d70479c80f /linux/LibSensors.c | |
parent | 759a34039c10081e510b9217d9d25ce6e9f200ae (diff) |
Add configure option to create static htop binary
Diffstat (limited to 'linux/LibSensors.c')
-rw-r--r-- | linux/LibSensors.c | 34 |
1 files changed, 34 insertions, 0 deletions
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; |