100-Provide-variant-pkg-config-file-for-multi-threaded-s.patch 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. From 5886e6a45b3c20c8d8f837657d1506b580434136 Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Sat, 6 Apr 2024 14:41:54 +0200
  4. Subject: [PATCH] Provide variant pkg-config file for multi-threaded static lib
  5. Multi-threaded static library require -pthread to correctly link and works.
  6. The pkg-config we provide tho only works with dynamic multi-threaded library
  7. and won't provide the correct libs and cflags values if lib-mt is used.
  8. To handle this, introduce a variant of libzstd.pc.in, mt-libzstd.pc.in
  9. and intoduce a new make target, install-mt-pc to permit advanced user to
  10. install and generate a correct pkg-config file for lib-mt.
  11. This was notice while migrating from meson to make build system where
  12. meson generates a correct .pc file while make doesn't.
  13. Signed-off-by: Christian Marangi <[email protected]>
  14. ---
  15. lib/Makefile | 16 ++++++++++++++++
  16. lib/README.md | 4 ++++
  17. lib/mt-libzstd.pc.in | 15 +++++++++++++++
  18. 3 files changed, 35 insertions(+)
  19. create mode 100644 lib/mt-libzstd.pc.in
  20. diff --git a/lib/Makefile b/lib/Makefile
  21. index 8bfdade9..4933f0e9 100644
  22. --- a/lib/Makefile
  23. +++ b/lib/Makefile
  24. @@ -319,6 +319,17 @@ libzstd.pc: libzstd.pc.in
  25. -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
  26. $< >$@
  27. +mt-libzstd.pc: mt-libzstd.pc.in
  28. + @echo creating pkgconfig
  29. + @sed \
  30. + -e 's|@PREFIX@|$(PREFIX)|' \
  31. + -e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
  32. + -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
  33. + -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
  34. + -e 's|@VERSION@|$(VERSION)|' \
  35. + -e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
  36. + $< >$@
  37. +
  38. .PHONY: install
  39. install: install-pc install-static install-shared install-includes
  40. @echo zstd static and shared library installed
  41. @@ -328,6 +339,11 @@ install-pc: libzstd.pc
  42. [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
  43. $(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
  44. +.PHONY: install-mt-pc
  45. +install-mt-pc: mt-libzstd.pc
  46. + [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
  47. + $(INSTALL_DATA) mt-libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
  48. +
  49. .PHONY: install-static
  50. install-static:
  51. # only generate libzstd.a if it's not already present
  52. diff --git a/lib/README.md b/lib/README.md
  53. index a560f06c..3038bc7a 100644
  54. --- a/lib/README.md
  55. +++ b/lib/README.md
  56. @@ -33,6 +33,10 @@ For convenience, we provide a build target to generate multi and single threaded
  57. When linking a POSIX program with a multithreaded version of `libzstd`,
  58. note that it's necessary to invoke the `-pthread` flag during link stage.
  59. +The `.pc` generated from `make install` or `make install-pc` always assume a single-threaded static library
  60. +is compiled. If `make lib-mt` is used, to correctly generate a `.pc` for the multi-threaded static library,
  61. +`make install-mt-pc` is needed.
  62. +
  63. Multithreading capabilities are exposed
  64. via the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.4.3/lib/zstd.h#L351).
  65. diff --git a/lib/mt-libzstd.pc.in b/lib/mt-libzstd.pc.in
  66. new file mode 100644
  67. index 00000000..cd93301a
  68. --- /dev/null
  69. +++ b/lib/mt-libzstd.pc.in
  70. @@ -0,0 +1,15 @@
  71. +# ZSTD - standard compression algorithm
  72. +# Copyright (c) Meta Platforms, Inc. and affiliates.
  73. +# BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
  74. +
  75. +prefix=@PREFIX@
  76. +exec_prefix=@EXEC_PREFIX@
  77. +includedir=@INCLUDEDIR@
  78. +libdir=@LIBDIR@
  79. +
  80. +Name: zstd
  81. +Description: fast lossless compression algorithm library
  82. +URL: https://facebook.github.io/zstd/
  83. +Version: @VERSION@
  84. +Libs: -L${libdir} -lzstd @LIBS_PRIVATE@
  85. +Cflags: -I${includedir} @LIBS_PRIVATE@
  86. --
  87. 2.43.0