From 2b6923bc7601c732a62d0e169c69106638af0a84 Mon Sep 17 00:00:00 2001 From: Christian Marangi Date: Wed, 17 Apr 2024 11:28:58 +0200 Subject: [PATCH] tools: zstd: update patch with upstream version Proposed fixup has been replaced and merged with an advanced version. install-pc-mt has been dropped and replaced for intall-pc MT=1 to generate a .pc file with multithread libs. Signed-off-by: Christian Marangi --- tools/zstd/Makefile | 3 +- ...pkg-config-file-for-multi-threaded-s.patch | 126 ++++++++++++++++++ ...pkg-config-file-for-multi-threaded-s.patch | 97 -------------- 3 files changed, 128 insertions(+), 98 deletions(-) create mode 100644 tools/zstd/patches/001-Provide-variant-pkg-config-file-for-multi-threaded-s.patch delete mode 100644 tools/zstd/patches/100-Provide-variant-pkg-config-file-for-multi-threaded-s.patch diff --git a/tools/zstd/Makefile b/tools/zstd/Makefile index 0264ac2422..f962809f82 100644 --- a/tools/zstd/Makefile +++ b/tools/zstd/Makefile @@ -31,7 +31,8 @@ define Host/Compile endef define Host/Install - +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR)/lib install-mt-pc install-static install-includes PREFIX=$(HOST_BUILD_PREFIX) + +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR)/lib install-static install-includes PREFIX=$(HOST_BUILD_PREFIX) + +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR)/lib install-pc MT=1 PREFIX=$(HOST_BUILD_PREFIX) +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR)/programs install PREFIX=$(HOST_BUILD_PREFIX) endef diff --git a/tools/zstd/patches/001-Provide-variant-pkg-config-file-for-multi-threaded-s.patch b/tools/zstd/patches/001-Provide-variant-pkg-config-file-for-multi-threaded-s.patch new file mode 100644 index 0000000000..1bbcaf4c8a --- /dev/null +++ b/tools/zstd/patches/001-Provide-variant-pkg-config-file-for-multi-threaded-s.patch @@ -0,0 +1,126 @@ +From f1f1ae369a4cefd3474b3528e8d1847b18750605 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Sat, 6 Apr 2024 14:41:54 +0200 +Subject: [PATCH] Provide variant pkg-config file for multi-threaded static lib + +Multi-threaded static library require -pthread to correctly link and works. +The pkg-config we provide tho only works with dynamic multi-threaded library +and won't provide the correct libs and cflags values if lib-mt is used. + +To handle this, introduce an env variable MT to permit advanced user to +install and generate a correct pkg-config file for lib-mt or detect if +lib-mt target is called. + +With MT env set on calling make install-pc, libzstd.pc.in is a +pkg-config file for a multi-threaded static library. + +On calling make lib-mt, a libzstd.pc is generated for a multi-threaded +static library as it's what asked by the user by forcing it. + +libzstd.pc is changed to PHONY to force regeneration of it on calling +lib targets or install-pc to handle case where the same directory is +used for mixed compilation. + +This was notice while migrating from meson to make build system where +meson generates a correct .pc file while make doesn't. + +Signed-off-by: Christian Marangi +--- + lib/Makefile | 20 +++++++++++++++++++- + lib/README.md | 4 ++++ + lib/libzstd.pc.in | 4 ++-- + 3 files changed, 25 insertions(+), 3 deletions(-) + +--- a/lib/Makefile ++++ b/lib/Makefile +@@ -63,6 +63,8 @@ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # + LDFLAGS_DYNLIB += -pthread + CPPFLAGS_STATICLIB += # static library build defaults to single-threaded + ++# pkg-config Libs.private points to LDFLAGS_DYNLIB ++PCLIB := $(LDFLAGS_DYNLIB) + + ifeq ($(findstring GCC,$(CCVER)),GCC) + decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize +@@ -186,12 +188,15 @@ lib : libzstd.a libzstd + %-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD + %-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD + %-mt : LDFLAGS_DYNLIB := -pthread ++%-mt : PCLIB := ++%-mt : PCMTLIB := $(LDFLAGS_DYNLIB) + %-mt : % + @echo multi-threaded build completed + + %-nomt : CPPFLAGS_DYNLIB := + %-nomt : LDFLAGS_DYNLIB := + %-nomt : CPPFLAGS_STATICLIB := ++%-nomt : PCLIB := + %-nomt : % + @echo single-threaded build completed + +@@ -292,6 +297,14 @@ PCLIBPREFIX := $(if $(findstring $(LIBDI + # to PREFIX, rather than as a resolved value. + PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix}) + ++ ++ifneq ($(MT),) ++ PCLIB := ++ PCMTLIB := $(LDFLAGS_DYNLIB) ++else ++ PCLIB := $(LDFLAGS_DYNLIB) ++endif ++ + ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly)) + PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig + else +@@ -308,6 +321,10 @@ INSTALL_PROGRAM ?= $(INSTALL) + INSTALL_DATA ?= $(INSTALL) -m 644 + + ++# pkg-config library define. ++# For static single-threaded library declare -pthread in Libs.private ++# For static multi-threaded library declare -pthread in Libs and Cflags ++.PHONY: libzstd.pc + libzstd.pc: libzstd.pc.in + @echo creating pkgconfig + @sed \ +@@ -316,7 +333,8 @@ libzstd.pc: libzstd.pc.in + -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \ + -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \ + -e 's|@VERSION@|$(VERSION)|' \ +- -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \ ++ -e 's|@LIBS_MT@|$(PCMTLIB)|' \ ++ -e 's|@LIBS_PRIVATE@|$(PCLIB)|' \ + $< >$@ + + .PHONY: install +--- a/lib/README.md ++++ b/lib/README.md +@@ -27,12 +27,16 @@ Enabling multithreading requires 2 condi + + For convenience, we provide a build target to generate multi and single threaded libraries: + - Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`. ++ Note that the `.pc` generated on calling `make lib-mt` will already include the require Libs and Cflags. + - Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`. + - By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`. + + When linking a POSIX program with a multithreaded version of `libzstd`, + note that it's necessary to invoke the `-pthread` flag during link stage. + ++The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library ++is compiled. To correctly generate a `.pc` for the multi-threaded static library, set `MT=1` as ENV variable. ++ + Multithreading capabilities are exposed + via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351). + +--- a/lib/libzstd.pc.in ++++ b/lib/libzstd.pc.in +@@ -11,6 +11,6 @@ Name: zstd + Description: fast lossless compression algorithm library + URL: https://facebook.github.io/zstd/ + Version: @VERSION@ +-Libs: -L${libdir} -lzstd ++Libs: -L${libdir} -lzstd @LIBS_MT@ + Libs.private: @LIBS_PRIVATE@ +-Cflags: -I${includedir} ++Cflags: -I${includedir} @LIBS_MT@ diff --git a/tools/zstd/patches/100-Provide-variant-pkg-config-file-for-multi-threaded-s.patch b/tools/zstd/patches/100-Provide-variant-pkg-config-file-for-multi-threaded-s.patch deleted file mode 100644 index a7b3823e66..0000000000 --- a/tools/zstd/patches/100-Provide-variant-pkg-config-file-for-multi-threaded-s.patch +++ /dev/null @@ -1,97 +0,0 @@ -From 5886e6a45b3c20c8d8f837657d1506b580434136 Mon Sep 17 00:00:00 2001 -From: Christian Marangi -Date: Sat, 6 Apr 2024 14:41:54 +0200 -Subject: [PATCH] Provide variant pkg-config file for multi-threaded static lib - -Multi-threaded static library require -pthread to correctly link and works. -The pkg-config we provide tho only works with dynamic multi-threaded library -and won't provide the correct libs and cflags values if lib-mt is used. - -To handle this, introduce a variant of libzstd.pc.in, mt-libzstd.pc.in -and intoduce a new make target, install-mt-pc to permit advanced user to -install and generate a correct pkg-config file for lib-mt. - -This was notice while migrating from meson to make build system where -meson generates a correct .pc file while make doesn't. - -Signed-off-by: Christian Marangi ---- - lib/Makefile | 16 ++++++++++++++++ - lib/README.md | 4 ++++ - lib/mt-libzstd.pc.in | 15 +++++++++++++++ - 3 files changed, 35 insertions(+) - create mode 100644 lib/mt-libzstd.pc.in - -diff --git a/lib/Makefile b/lib/Makefile -index 8bfdade9..4933f0e9 100644 ---- a/lib/Makefile -+++ b/lib/Makefile -@@ -319,6 +319,17 @@ libzstd.pc: libzstd.pc.in - -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \ - $< >$@ - -+mt-libzstd.pc: mt-libzstd.pc.in -+ @echo creating pkgconfig -+ @sed \ -+ -e 's|@PREFIX@|$(PREFIX)|' \ -+ -e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \ -+ -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \ -+ -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \ -+ -e 's|@VERSION@|$(VERSION)|' \ -+ -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \ -+ $< >$@ -+ - .PHONY: install - install: install-pc install-static install-shared install-includes - @echo zstd static and shared library installed -@@ -328,6 +339,11 @@ install-pc: libzstd.pc - [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ - $(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/ - -+.PHONY: install-mt-pc -+install-mt-pc: mt-libzstd.pc -+ [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ -+ $(INSTALL_DATA) mt-libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc -+ - .PHONY: install-static - install-static: - # only generate libzstd.a if it's not already present -diff --git a/lib/README.md b/lib/README.md -index a560f06c..3038bc7a 100644 ---- a/lib/README.md -+++ b/lib/README.md -@@ -33,6 +33,10 @@ For convenience, we provide a build target to generate multi and single threaded - When linking a POSIX program with a multithreaded version of `libzstd`, - note that it's necessary to invoke the `-pthread` flag during link stage. - -+The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library -+is compiled. If `make lib-mt` is used, to correctly generate a `.pc` for the multi-threaded static library, -+`make install-mt-pc` is needed. -+ - Multithreading capabilities are exposed - via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351). - -diff --git a/lib/mt-libzstd.pc.in b/lib/mt-libzstd.pc.in -new file mode 100644 -index 00000000..cd93301a ---- /dev/null -+++ b/lib/mt-libzstd.pc.in -@@ -0,0 +1,15 @@ -+# ZSTD - standard compression algorithm -+# Copyright (c) Meta Platforms, Inc. and affiliates. -+# BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php) -+ -+prefix=@PREFIX@ -+exec_prefix=@EXEC_PREFIX@ -+includedir=@INCLUDEDIR@ -+libdir=@LIBDIR@ -+ -+Name: zstd -+Description: fast lossless compression algorithm library -+URL: https://facebook.github.io/zstd/ -+Version: @VERSION@ -+Libs: -L${libdir} -lzstd @LIBS_PRIVATE@ -+Cflags: -I${includedir} @LIBS_PRIVATE@ --- -2.43.0 - -- 2.30.2