mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-09-30 21:43:05 +07:00
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.
This commit is contained in:
@@ -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 <iconv.h>' \
|
||||
'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
|
||||
|
||||
@@ -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 <iconv.h>' \
|
||||
'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
|
||||
|
||||
Reference in New Issue
Block a user