Makefile.flags: fix the OS detection for libresolv

054493350 ("Do not add -lresolv on non-Linux systems") adds a condition
to link with libresolv only on linux systems.

The check requires that CONFIG_UNAME_OSNAME equals Linux. This works only
if the uname applet is enabled. Otherwise, CONFIG_UNAME_OSNAME is empty,
regardless of the platform.

By default, CONFIG_UNAME_OSNAME is the output of uname -o. For most
linux systems, uname -o returns "GNU/Linux" and the check fails. In this
case, linking a static busybox fails because of missing symbols from
libresolv.

networking/lib.a(nslookup.o): In function `add_query':
nslookup.c:789: undefined reference to `__res_mkquery'
networking/lib.a(nslookup.o): In function `parse_reply':
nslookup.c:355: undefined reference to `ns_initparse'
nslookup.c:361: undefined reference to `ns_parserr'
nslookup.c:404: undefined reference to `ns_name_uncompress'
nslookup.c:418: undefined reference to `ns_get16'
nslookup.c:419: undefined reference to `ns_name_uncompress'
..
nslookup.c:456: undefined reference to `ns_get16'
...
nslookup.c:469: undefined reference to `ns_name_uncompress'
...
nslookup.c:489: undefined reference to `ns_get32'
...
collect2: error: ld returned 1 exit status

This patch uses the output of $CC -dumpmachine to detect the target platform
for which we compile. Both gcc and clang support -dumpmachine. Like the
original patch, we link against libresolv only if our target platform is
linux-based.

Fixes: 054493350 ("Do not add -lresolv on non-Linux systems")
Signed-off-by: Martin Kaiser <martin@kaiser.cx>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
Martin Kaiser 2021-01-22 22:24:05 +01:00 committed by Bernhard Reutner-Fischer
parent cad3fc743a
commit d40358a1c5

View File

@ -181,7 +181,7 @@ LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%
endif
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
ifeq ($(CONFIG_UNAME_OSNAME),Linux)
ifneq (,$(findstring linux,$(shell $(CC) $(CFLAGS) -dumpmachine)))
LDLIBS += resolv
endif
endif