aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Collet <Cyan4973@users.noreply.github.com>2024-04-16 16:04:23 -0700
committerGitHub <noreply@github.com>2024-04-16 16:04:23 -0700
commitfb5a5e46a5303fdcd9b4b9dd6065970f1842f44e (patch)
tree7e4c74fdfbd588913cdfef520eda26e3b5bc9edc
parent592de198436a5f574293b9e5d83c87083416cd1a (diff)
parentf1f1ae369a4cefd3474b3528e8d1847b18750605 (diff)
downloadzstd-fb5a5e46a5303fdcd9b4b9dd6065970f1842f44e.tar.gz
Merge pull request #4020 from Ansuel/install-mt-pc
Provide variant pkg-config file for multi-threaded static lib
-rw-r--r--lib/Makefile20
-rw-r--r--lib/README.md4
-rw-r--r--lib/libzstd.pc.in4
3 files changed, 25 insertions, 3 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 8bfdade9..57097ce3 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -63,6 +63,8 @@ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi
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 $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
# 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
diff --git a/lib/README.md b/lib/README.md
index a560f06c..0f6c6474 100644
--- a/lib/README.md
+++ b/lib/README.md
@@ -27,12 +27,16 @@ Enabling multithreading requires 2 conditions :
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).
diff --git a/lib/libzstd.pc.in b/lib/libzstd.pc.in
index d5cc0270..d7b6c858 100644
--- 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@