Fix libnl static linking
cover Fix libnl static linking
Hello,
This set of patches was triggered by the batctl static linking patch sent by Jens Zettelmeyer.
It turns out that batctl properly uses pkg-config to know how to link with libnl, so it's ctually libnl pkg-config that aren't correct. This is what the first two patches are fixing. This fixes batctl static linking.
As a follow-up, I reviewed some of the packages that link against libnl and have special handling for static linking, and did some related cleanups.
Thomas
Thomas Petazzoni (5):
libnl: use the backported patch for poll.h issue
libnl: add patch to add Libs.private in libnl-3.0.pc
crda: remove static library handling
ti-utils: simplify static linking case by using pkg-config
iw: simplify static linking handling
package/crda/crda.mk | 13 ---------- package/iw/iw.mk | 6 ----- ...etlink-h-use-poll-h-instead-of-sys-poll-h.patch | 18 ------------- ...link.h-fix-build-including-poll.h-with-th.patch | 30 ++++++++++++++++++++++ ...ibs.private-field-in-libnl-pkg-config-fil.patch | 30 ++++++++++++++++++++++ package/ti-utils/ti-utils.mk | 9 ++++--- 6 files changed, 66 insertions(+), 40 deletions(-) delete mode 100644 package/libnl/0001-netlink-netlink-h-use-poll-h-instead-of-sys-poll-h.patch create mode 100644 package/libnl/0001-netlink-netlink.h-fix-build-including-poll.h-with-th.patch create mode 100644 package/libnl/0002-build-add-Libs.private-field-in-libnl-pkg-config-fil.patch
Signature · 1 line
2.1.0
PATCH 1/5 libnl: use the backported patch for poll.h issue
Now that J?rg's patch has been merged upstream, let's use the backported version, in a git format.
--- ...etlink-h-use-poll-h-instead-of-sys-poll-h.patch | 18 ------------- ...link.h-fix-build-including-poll.h-with-th.patch | 30 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 18 deletions(-) delete mode 100644 package/libnl/0001-netlink-netlink-h-use-poll-h-instead-of-sys-poll-h.patch create mode 100644 package/libnl/0001-netlink-netlink.h-fix-build-including-poll.h-with-th.patch
package/libnl/0001-netlink-netlink-h-use-poll-h-instead-of-sys-poll-h.patch deleted +0 -18
@@ -1,18 +0,0 @@ -netlink/netlink.h: As the poll() man page recommends include the <poll.h> -instead of <sys/poll.h>. This removes an error when building libdl against -the musl C library. - -Signed-off-by: J?rg Krause <[email protected]> - -diff -purN libnl-3.2.25.orig/include/netlink/netlink.h libnl-3.2.25/include/netlink/netlink.h ---- libnl-3.2.25.orig/include/netlink/netlink.h 2014-09-01 11:42:37.254724124 +0200 -+++ libnl-3.2.25/include/netlink/netlink.h 2014-09-01 11:42:58.254724255 +0200 -@@ -16,7 +16,7 @@ - #include <stdint.h> - #include <string.h> - #include <stdlib.h> --#include <sys/poll.h> -+#include <poll.h> - #include <sys/socket.h> - #include <sys/types.h> - #include <sys/time.h>
package/libnl/0001-netlink-netlink.h-fix-build-including-poll.h-with-th.patch new file +30 -0
@@ -0,0 +1,30 @@ +From 14128766e80823f79a3b2c97573da1aea5c16ea8 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?J=C3=B6rg=20Krause?= <[email protected]> +Date: Mon, 1 Sep 2014 12:38:10 +0200 +Subject: [PATCH 1/2] netlink/netlink.h: fix build including <poll.h> with the + musl C library + +https://github.com/thom311/libnl/pull/64 + +Signed-off-by: Thomas Haller <[email protected]> +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + include/netlink/netlink.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/include/netlink/netlink.h b/include/netlink/netlink.h +index 28dba06..61656b3 100644 +--- a/include/netlink/netlink.h ++++ b/include/netlink/netlink.h +@@ -16,7 +16,7 @@ + #include <stdint.h> + #include <string.h> + #include <stdlib.h> +-#include <sys/poll.h> ++#include <poll.h> + #include <sys/socket.h> + #include <sys/types.h> + #include <sys/time.h> +-- +2.1.0 +
Signature · 1 line
2.1.0
PATCH 2/5 libnl: add patch to add Libs.private in libnl-3.0.pc
In reply to Thomas PetazzoniHaving a properly defined Libs.private field allows to make sure static linking against libnl-3.0 works fine, at least as long as pkg-config is used.
--- ...ibs.private-field-in-libnl-pkg-config-fil.patch | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 package/libnl/0002-build-add-Libs.private-field-in-libnl-pkg-config-fil.patch
package/libnl/0002-build-add-Libs.private-field-in-libnl-pkg-config-fil.patch new file +30 -0
@@ -0,0 +1,30 @@ +From db0d59cd06f3ffd350379847c0885e1bfb85af0f Mon Sep 17 00:00:00 2001 +From: Thomas Petazzoni <[email protected]> +Date: Sat, 7 Mar 2015 11:34:42 +0100 +Subject: [PATCH 2/2] build: add Libs.private field in libnl pkg-config file + +In order to support static linking, the libnl pkg-config file should +indicate in its Libs.private field the libraries that libnl-3.0.a +requires. The LIBS variable contains the appropriate list of +libraries: -lm in all cases, and -lpthread when pthread support is +enabled. This allows to statically link applications against libnl +properly. + +Signed-off-by: Thomas Petazzoni <[email protected]> +--- + libnl-3.0.pc.in | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/libnl-3.0.pc.in b/libnl-3.0.pc.in +index b87e3dc..ddbc999 100644 +--- a/libnl-3.0.pc.in ++++ b/libnl-3.0.pc.in +@@ -7,4 +7,5 @@ Name: libnl + Description: Convenience library for netlink sockets + Version: @PACKAGE_VERSION@ + Libs: -L${libdir} -lnl- at MAJ_VERSION@ ++Libs.private: @LIBS@ + Cflags: -I${includedir}/libnl at MAJ_VERSION@ +-- +2.1.0 +
Signature · 1 line
2.1.0
PATCH 2/5 libnl: add patch to add Libs.private in libnl-3.0.pc
Quoted 5 lines · Thomas Petazzoni
Having a properly defined Libs.private field allows to make sure static linking against libnl-3.0 works fine, at least as long as pkg-config is used.
Signed-off-by Thomas Petazzoni <[email protected]>
Very...
PATCH 3/5 crda: remove static library handling
In reply to Thomas PetazzoniIn commit d54418f2bcd9267fd049511d6236fb91c83b94ea ("crda: fix static build failure"), some static linking handling was added in crda. But in a later commit, 7c08fa935f55d108e20834e6b4bba664e1d2d408 ("crda:
needs dynamic library support"), crda was marked as not available for static only builds.
This means that the static linking logic in crda.mk is now just dead code, so this commit gets rid of it.
--- package/crda/crda.mk | 13 ------------- 1 file changed, 13 deletions(-)
package/crda/crda.mk +0 -13
@@ -12,17 +12,6 @@ CRDA_DEPENDENCIES = host-pkgconf host-python-m2crypto \ CRDA_LICENSE = ISC CRDA_LICENSE_FILES = LICENSE -# libnl-3 needs -lm (for rint) and -lpthread if linking statically. -# And library order matters hence stick -lnl-3 first since it's appended -# in the crda Makefiles as in NLLIBS+=-lnl-3 ... thus failing. -# -# libgcrypt needs -lgpg-error if linking statically, which is correctly -# set by the libgcrypt-config script (and in the right order). -ifeq ($(BR2_STATIC_LIBS),y) -CRDA_NLLIBS += -lnl-3 -lm -lpthread -CRDA_LDLIBS += `$(STAGING_DIR)/usr/bin/libgcrypt-config --libs` -endif - # * key2pub.py currently is not python3 compliant (though python2/python3 # compliance could rather easily be achieved. # * key2pub.py uses M2Crypto python module, which is only available for
@@ -30,8 +19,6 @@ endif # interpreter, hence the host-python dependency and the PYTHON variable. define CRDA_BUILD_CMDS $(TARGET_CONFIGURE_OPTS) \ - LDLIBS="$(CRDA_LDLIBS)" \ - NLLIBS="$(CRDA_NLLIBS)" \ PYTHON=$(HOST_DIR)/usr/bin/python2 \ $(MAKE) all_noverify -C $(@D) endef
Signature · 1 line
2.1.0
PATCH 3/5 crda: remove static library handling
Quoted 10 lines · Thomas Petazzoni
In commit
d54418f2bcd9267fd049511d6236fb91c83b94ea("crda: fix static build failure"), some static linking handling was added in crda. But in a later commit,7c08fa935f55d108e20834e6b4bba664e1d2d408("crda:
needs dynamic library support"), crda was marked as not available for static only builds.This means that the static linking logic in crda.mk is now just dead code, so this commit gets rid of it.
Signed-off-by Thomas Petazzoni <[email protected]>
Regards,
Signature · 1 line
Samuel
Thomas Petazzoni
AppliedPATCH 3/5 crda: remove static library handling
In reply to Thomas PetazzoniHello,
Quoted 10 lines · Thomas Petazzoni
In commit
d54418f2bcd9267fd049511d6236fb91c83b94ea("crda: fix static build failure"), some static linking handling was added in crda. But in a later commit,7c08fa935f55d108e20834e6b4bba664e1d2d408("crda:
needs dynamic library support"), crda was marked as not available for static only builds.This means that the static linking logic in crda.mk is now just dead code, so this commit gets rid of it.
Signed-off-by Thomas Petazzoni <[email protected]>
Applied.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 4/5 ti-utils: simplify static linking case by using pkg-config
In reply to Thomas PetazzoniInstead of hardcoding the dependencies of libnl, use pkg-config to discover them.
--- package/ti-utils/ti-utils.mk | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
package/ti-utils/ti-utils.mk +6 -3
@@ -6,14 +6,17 @@ TI_UTILS_VERSION = 06dbdb2727354b5f3ad7c723897f40051fddee49 TI_UTILS_SITE = $(call github,gxk,ti-utils,$(TI_UTILS_VERSION)) -TI_UTILS_DEPENDENCIES = libnl +TI_UTILS_DEPENDENCIES = libnl host-pkgconf TI_UTILS_LICENSE = BSD-3c TI_UTILS_LICENSE_FILES = COPYING +TI_UTILS_CFLAGS = $(shell $(PKG_CONFIG_HOST_BINARY) --cflags libnl-genl-3.0) +TI_UTILS_LIBS = $(shell $(PKG_CONFIG_HOST_BINARY) --libs libnl-genl-3.0) + define TI_UTILS_BUILD_CMDS $(MAKE1) NFSROOT="$(STAGING_DIR)" \ - CC="$(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -I$(STAGING_DIR)/usr/include/libnl3" \ - LIBS="-lnl-3 -lnl-genl-3 -lpthread -lm" -C $(@D) all + CC="$(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) $(TI_UTILS_CFLAGS)" \ + LIBS="$(TI_UTILS_LIBS)" -C $(@D) all endef define TI_UTILS_INSTALL_TARGET_CMDS
Signature · 1 line
2.1.0
PATCH 5/5 iw: simplify static linking handling
In reply to Thomas PetazzoniNow that libnl pkg-config file is correct, there is no need to have special handling for static linking in the iw package: it already uses pkg-config to get the necessary flags to link with libnl.
--- package/iw/iw.mk | 6 ------ 1 file changed, 6 deletions(-)
package/iw/iw.mk +0 -6
@@ -14,12 +14,6 @@ IW_MAKE_OPTS = CC="$(TARGET_CC)" LD="$(TARGET_LD)" LDFLAGS="$(TARGET_LDFLAGS)" IW_MAKE_ENV = PKG_CONFIG="$(HOST_DIR)/usr/bin/pkg-config" \ GIT_DIR=$(IW_DIR) -ifeq ($(BR2_STATIC_LIBS),y) -# libnl needs pthread/m, so we need to explicitly with them when static -# these need to added AFTER libnl, so we have to override LIBS completely -IW_MAKE_OPTS += LIBS='-lnl-genl-3 -lnl-3 -lpthread -lm' -endif - define IW_BUILD_CMDS $(IW_MAKE_ENV) $(MAKE) $(IW_MAKE_OPTS) -C $(@D) endef
Signature · 1 line
2.1.0
Thomas Petazzoni
Appliedcover Fix libnl static linking
In reply to Thomas PetazzoniHello,
Quoted 3 lines · Thomas Petazzoni
Thomas Petazzoni (5):
libnl: use the backported patch forpoll.hissue
libnl: add patch to add Libs.private in libnl-3.0.pc
Applied.
Quoted 2 lines
ti-utils: simplify static linking case by using pkg-config
iw: simplify static linking handling
Applied.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com