Skip to content

Commit 5774737

Browse files
committed
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. With MT env set on calling make install-pc, libzstd.pc.in generated a pkg-config file for a multi-threaded static library. 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 <[email protected]>
1 parent 72c16b1 commit 5774737

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi
6363
LDFLAGS_DYNLIB += -pthread
6464
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
6565

66+
# pkg-config library define.
67+
# For static single-threaded library declare -pthread in Libs.private
68+
# For static multi-threaded library declare -pthread in Libs and Cflags
69+
ifneq ($(MT),)
70+
PC_MT_LIB := $(LDFLAGS_DYNLIB)
71+
else
72+
PC_LIB := $(LDFLAGS_DYNLIB)
73+
endif
74+
6675

6776
ifeq ($(findstring GCC,$(CCVER)),GCC)
6877
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
@@ -316,7 +325,8 @@ libzstd.pc: libzstd.pc.in
316325
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
317326
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
318327
-e 's|@VERSION@|$(VERSION)|' \
319-
-e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
328+
-e 's|@MT_LIBS@|$(PC_MT_LIB)|' \
329+
-e 's|@LIBS_PRIVATE@|$(PC_LIB)|' \
320330
$< >$@
321331

322332
.PHONY: install

lib/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ For convenience, we provide a build target to generate multi and single threaded
3333
When linking a POSIX program with a multithreaded version of `libzstd`,
3434
note that it's necessary to invoke the `-pthread` flag during link stage.
3535

36+
The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library
37+
is compiled. If `make lib-mt` is used, to correctly generate a `.pc` for the multi-threaded static library,
38+
`make install-mt-pc` is needed.
39+
3640
Multithreading capabilities are exposed
3741
via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351).
3842

lib/libzstd.pc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ Name: zstd
1111
Description: fast lossless compression algorithm library
1212
URL: https://facebook.github.io/zstd/
1313
Version: @VERSION@
14-
Libs: -L${libdir} -lzstd
14+
Libs: -L${libdir} -lzstd @MT_LIBS@
1515
Libs.private: @LIBS_PRIVATE@
16-
Cflags: -I${includedir}
16+
Cflags: -I${includedir} @MT_LIBS@

0 commit comments

Comments
 (0)