From 68bda219526d22c3b9014d6e0179c7e82da3bdac Mon Sep 17 00:00:00 2001 From: graysky Date: Sat, 16 Aug 2025 07:01:21 -0400 Subject: [PATCH] Fix iconv linking detection for glibc-based builds The current iconv detection checks if libiconv.so exists via ldconfig, but fails on glibc systems where iconv is built into libc and doesn't require separate linking. This causes build failures: ld: cannot find -liconv: No such file or directory Replace the ldconfig check with a compile test that actually verifies if iconv functions are available without additional libraries. This correctly detects glibc's built-in iconv while still linking -liconv on musl/uclibc systems that need it. Fixes build on glibc-based systems including OpenWrt glibc targets. --- Makefile | 17 +++++++++++++++++ prog/sensors/Module.mk | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 10a088db..2adae708 100644 --- a/Makefile +++ b/Makefile @@ -171,6 +171,23 @@ LIBCFLAGS := -fpic -D_REENTRANT $(ALL_CFLAGS) ALL_LDFLAGS := $(LDFLAGS) +# Determine iconv linking requirements +# glibc has built-in iconv, other libc implementations may need -liconv +ifndef LIBICONV + ICONV_TEST := $(shell printf '%s\n' \ + '#include ' \ + 'int main() { iconv_t cd = iconv_open("UTF-8", "ASCII"); return 0; }' \ + | $(CC) $(ALL_CPPFLAGS) -x c - -o /tmp/lm_sensors_iconv_test 2>/dev/null && echo "builtin" || echo "external") + + ifeq ($(ICONV_TEST),builtin) + LIBICONV := + else + LIBICONV := -liconv + endif + + $(shell rm -f /tmp/lm_sensors_iconv_test) +endif + EXLDFLAGS := -Wl,-rpath,$(LIBDIR) $(ALL_LDFLAGS) .PHONY: all user clean install user_install uninstall user_uninstall diff --git a/prog/sensors/Module.mk b/prog/sensors/Module.mk index 18710f69..3130668e 100644 --- a/prog/sensors/Module.mk +++ b/prog/sensors/Module.mk @@ -39,7 +39,10 @@ REMOVESENSORSBIN := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(BINDIR)/%,$(PROGSENSO REMOVESENSORSMAN := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(PROGSENSORSMAN1DIR)/%,$(PROGSENSORSMAN1FILES)) REMOVESENSORSZSH := $(patsubst $(MODULE_DIR)/%,$(DESTDIR)$(ZSHCOMPDIR)/%,$(PROGSENSORSZSHCOMPFILES)) -LIBICONV := $(shell if /sbin/ldconfig -p | grep -q '/libiconv\.so$$' ; then echo \-liconv; else echo; fi) +LIBICONV := $(shell printf '%s\n' \ + '#include ' \ + 'int main() { iconv_t cd = iconv_open("UTF-8", "ASCII"); return 0; }' \ + | $(CC) $(ALL_CPPFLAGS) -x c - 2>/dev/null && echo || echo \-liconv) $(PROGSENSORSTARGETS): $(PROGSENSORSSOURCES:.c=.ro) lib/$(LIBDEP_FOR_PROGS) $(CC) -o $@ $(PROGSENSORSSOURCES:.c=.ro) $(LIBICONV) $(EXLDFLAGS) -Llib -lsensors -lm