zstd-ruby 1.4.0.0 → 1.4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +35 -0
  3. data/README.md +2 -2
  4. data/ext/zstdruby/libzstd/Makefile +274 -107
  5. data/ext/zstdruby/libzstd/README.md +75 -16
  6. data/ext/zstdruby/libzstd/common/bitstream.h +59 -51
  7. data/ext/zstdruby/libzstd/common/compiler.h +154 -5
  8. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  9. data/ext/zstdruby/libzstd/common/debug.c +11 -31
  10. data/ext/zstdruby/libzstd/common/debug.h +22 -49
  11. data/ext/zstdruby/libzstd/common/entropy_common.c +201 -75
  12. data/ext/zstdruby/libzstd/common/error_private.c +3 -1
  13. data/ext/zstdruby/libzstd/common/error_private.h +7 -3
  14. data/ext/zstdruby/libzstd/common/fse.h +50 -42
  15. data/ext/zstdruby/libzstd/common/fse_decompress.c +134 -50
  16. data/ext/zstdruby/libzstd/common/huf.h +41 -38
  17. data/ext/zstdruby/libzstd/common/mem.h +68 -22
  18. data/ext/zstdruby/libzstd/common/pool.c +30 -20
  19. data/ext/zstdruby/libzstd/common/pool.h +3 -3
  20. data/ext/zstdruby/libzstd/common/threading.c +51 -4
  21. data/ext/zstdruby/libzstd/common/threading.h +36 -4
  22. data/ext/zstdruby/libzstd/common/xxhash.c +39 -89
  23. data/ext/zstdruby/libzstd/common/xxhash.h +12 -32
  24. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  25. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  26. data/ext/zstdruby/libzstd/common/zstd_errors.h +3 -1
  27. data/ext/zstdruby/libzstd/common/zstd_internal.h +231 -72
  28. data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
  29. data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -0
  30. data/ext/zstdruby/libzstd/compress/fse_compress.c +47 -63
  31. data/ext/zstdruby/libzstd/compress/hist.c +41 -63
  32. data/ext/zstdruby/libzstd/compress/hist.h +13 -33
  33. data/ext/zstdruby/libzstd/compress/huf_compress.c +288 -172
  34. data/ext/zstdruby/libzstd/compress/zstd_compress.c +2504 -1626
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +446 -85
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +158 -0
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +29 -0
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +433 -0
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +54 -0
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +849 -0
  41. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +32 -0
  42. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +561 -0
  43. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +82 -60
  44. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +2 -2
  45. data/ext/zstdruby/libzstd/compress/zstd_fast.c +106 -80
  46. data/ext/zstdruby/libzstd/compress/zstd_fast.h +2 -2
  47. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +411 -105
  48. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +296 -207
  50. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +14 -3
  51. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
  52. data/ext/zstdruby/libzstd/compress/zstd_opt.c +260 -148
  53. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  54. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +153 -440
  55. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +29 -110
  56. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +356 -238
  57. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +20 -16
  58. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +3 -3
  59. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +641 -238
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +600 -371
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +8 -5
  62. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +40 -9
  63. data/ext/zstdruby/libzstd/deprecated/zbuff.h +9 -8
  64. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +2 -2
  65. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  66. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  67. data/ext/zstdruby/libzstd/dictBuilder/cover.c +197 -78
  68. data/ext/zstdruby/libzstd/dictBuilder/cover.h +52 -7
  69. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  70. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +84 -66
  71. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +58 -36
  72. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +60 -31
  73. data/ext/zstdruby/libzstd/dll/example/Makefile +2 -1
  74. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  75. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +8 -4
  76. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +115 -111
  77. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  78. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +28 -14
  79. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  80. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +28 -14
  81. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  82. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +36 -19
  83. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  84. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +122 -107
  85. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +2 -2
  86. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +29 -23
  87. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  88. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +34 -24
  89. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  90. data/ext/zstdruby/libzstd/libzstd.pc.in +2 -1
  91. data/ext/zstdruby/libzstd/zstd.h +655 -118
  92. data/lib/zstd-ruby/version.rb +1 -1
  93. data/zstd-ruby.gemspec +1 -1
  94. metadata +20 -10
  95. data/.travis.yml +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d3a2e484e068296e89977e4bda01284174aeb6738d7ca0b81ab286abcd3b3be
4
- data.tar.gz: 736d1180bf2aaa4f958ced167b133810dabb5b9dc8eae969a4385aac96776300
3
+ metadata.gz: 1b9fb489baa649ba5ee4d0eab2a8eff41dca8aed169decbcbb94f2b743fff4b9
4
+ data.tar.gz: 466460ae250bdf1b41ad9a520cf22c3457647c64c87f6479bf59a7d5876eb08c
5
5
  SHA512:
6
- metadata.gz: e4bba80e9b2e894bd3d9e734cd4d332073f7ab583f2a45e096a7e7eb015eca7a13be32790a88c6fa1b132977b22278f4e86c2d8a67af0188ce74de2fc84cf98d
7
- data.tar.gz: 7759f59d24166a83c36822934de188b18fb6b7674ab1990da1ec7985c1fdb95bc020c6b40de2de987026553a3947dcb77dc110662d6db3a1504118afbc8f73f7
6
+ metadata.gz: ba520ce0a01a96bfb292bea7d093998e21fa27a19309e8e708d09b1bd033c02101442d7572da9ef02e190932cc4caf348771e9dac5b72bd4479d96c0a14791ec
7
+ data.tar.gz: a1ad48b44fefedd472de63ee6069e9fe928ed436a6c6fe7739ad8666c05420ff75b0ab5a5273fe87d8cdd41be39372ffae8bd707437c16f137e3ad63ca566a17
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on: [push, pull_request]
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
24
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
25
+ # uses: ruby/setup-ruby@v1
26
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Compile
33
+ run: bundle exec rake compile
34
+ - name: Run tests
35
+ run: bundle exec rspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/zstd-ruby.svg)](https://badge.fury.io/rb/zstd-ruby)
2
- [![Build Status](https://travis-ci.org/SpringMT/zstd-ruby.svg?branch=master)](https://travis-ci.org/SpringMT/zstd-ruby)
2
+ ![Build Status](https://github.com/SpringMT/zstd-ruby/actions/workflows/ruby.yml/badge.svg?branch=master)
3
3
 
4
4
  # zstd-ruby
5
5
 
@@ -10,7 +10,7 @@ See https://github.com/facebook/zstd
10
10
  Fork from https://github.com/jarredholman/ruby-zstd.
11
11
 
12
12
  ## Zstd version
13
- v1.4.0 (https://github.com/facebook/zstd/tree/v1.4.0)
13
+ v1.4.9 (https://github.com/facebook/zstd/tree/v1.4.9)
14
14
 
15
15
  ## Installation
16
16
 
@@ -1,12 +1,25 @@
1
1
  # ################################################################
2
- # Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
2
+ # Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
3
3
  # All rights reserved.
4
4
  #
5
5
  # This source code is licensed under both the BSD-style license (found in the
6
6
  # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
7
  # in the COPYING file in the root directory of this source tree).
8
+ # You may select, at your option, one of the above-listed licenses.
8
9
  # ################################################################
9
10
 
11
+ .PHONY: default
12
+ default: lib-release
13
+
14
+ # define silent mode as default (verbose mode with V=1 or VERBOSE=1)
15
+ $(V)$(VERBOSE).SILENT:
16
+
17
+ # When cross-compiling from linux to windows,
18
+ # one might need to specify TARGET_SYSTEM as "Windows."
19
+ # Building from Fedora fails without it.
20
+ # (but Ubuntu and Debian don't need to set anything)
21
+ TARGET_SYSTEM ?= $(OS)
22
+
10
23
  # Version numbers
11
24
  LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
12
25
  LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
@@ -17,26 +30,51 @@ LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
17
30
  LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
18
31
  LIBVER := $(shell echo $(LIBVER_SCRIPT))
19
32
  VERSION?= $(LIBVER)
33
+ CCVER := $(shell $(CC) --version)
34
+
35
+ # ZSTD_LIB_MINIFY is a helper variable that
36
+ # configures a bunch of other variables to space-optimized defaults.
37
+ ZSTD_LIB_MINIFY ?= 0
38
+ ifneq ($(ZSTD_LIB_MINIFY), 0)
39
+ HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
40
+ ZSTD_LEGACY_SUPPORT ?= 0
41
+ ZSTD_LIB_DEPRECATED ?= 0
42
+ HUF_FORCE_DECOMPRESS_X1 ?= 1
43
+ ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
44
+ ZSTD_NO_INLINE ?= 1
45
+ ZSTD_STRIP_ERROR_STRINGS ?= 1
46
+ ifneq ($(HAVE_CC_OZ), 0)
47
+ # Some compilers (clang) support an even more space-optimized setting.
48
+ CFLAGS += -Oz
49
+ else
50
+ CFLAGS += -Os
51
+ endif
52
+ CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
53
+ -DDYNAMIC_BMI2=0 -DNDEBUG
54
+ else
55
+ CFLAGS += -O3
56
+ endif
20
57
 
21
- CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
22
- ifeq ($(OS),Windows_NT) # MinGW assumed
23
- CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
58
+ DEBUGLEVEL ?= 0
59
+ CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
60
+ ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
61
+ CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
24
62
  endif
25
- CFLAGS ?= -O3
26
63
  DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
27
64
  -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
28
65
  -Wstrict-prototypes -Wundef -Wpointer-arith \
29
66
  -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
30
67
  -Wredundant-decls -Wmissing-prototypes -Wc++-compat
31
- CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
32
- FLAGS = $(CPPFLAGS) $(CFLAGS)
68
+ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
69
+ FLAGS = $(CPPFLAGS) $(CFLAGS)
33
70
 
34
71
  HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
35
72
  GREP_OPTIONS ?=
36
73
  ifeq ($HAVE_COLORNEVER, 1)
37
- GREP_OPTIONS += --color=never
74
+ GREP_OPTIONS += --color=never
38
75
  endif
39
76
  GREP = grep $(GREP_OPTIONS)
77
+ SED_ERE_OPT ?= -E
40
78
 
41
79
  ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
42
80
  ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
@@ -45,146 +83,251 @@ ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
45
83
  ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
46
84
  ZSTD_FILES := $(ZSTDCOMMON_FILES)
47
85
 
48
- ZSTD_LEGACY_SUPPORT ?= 5
86
+ ifeq ($(findstring GCC,$(CCVER)),GCC)
87
+ decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
88
+ endif
89
+
90
+ # Modules
49
91
  ZSTD_LIB_COMPRESSION ?= 1
50
92
  ZSTD_LIB_DECOMPRESSION ?= 1
51
93
  ZSTD_LIB_DICTBUILDER ?= 1
52
94
  ZSTD_LIB_DEPRECATED ?= 1
95
+
96
+ # Legacy support
97
+ ZSTD_LEGACY_SUPPORT ?= 5
98
+ ZSTD_LEGACY_MULTITHREADED_API ?= 0
99
+
100
+ # Build size optimizations
53
101
  HUF_FORCE_DECOMPRESS_X1 ?= 0
54
102
  HUF_FORCE_DECOMPRESS_X2 ?= 0
55
103
  ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
56
104
  ZSTD_FORCE_DECOMPRESS_LONG ?= 0
57
105
  ZSTD_NO_INLINE ?= 0
58
106
  ZSTD_STRIP_ERROR_STRINGS ?= 0
59
- ZSTD_LEGACY_MULTITHREADED_API ?= 0
60
107
 
61
108
  ifeq ($(ZSTD_LIB_COMPRESSION), 0)
62
- ZSTD_LIB_DICTBUILDER = 0
63
- ZSTD_LIB_DEPRECATED = 0
109
+ ZSTD_LIB_DICTBUILDER = 0
110
+ ZSTD_LIB_DEPRECATED = 0
64
111
  endif
65
112
 
66
113
  ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
67
- ZSTD_LEGACY_SUPPORT = 0
68
- ZSTD_LIB_DEPRECATED = 0
114
+ ZSTD_LEGACY_SUPPORT = 0
115
+ ZSTD_LIB_DEPRECATED = 0
69
116
  endif
70
117
 
71
118
  ifneq ($(ZSTD_LIB_COMPRESSION), 0)
72
- ZSTD_FILES += $(ZSTDCOMP_FILES)
119
+ ZSTD_FILES += $(ZSTDCOMP_FILES)
73
120
  endif
74
121
 
75
122
  ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
76
- ZSTD_FILES += $(ZSTDDECOMP_FILES)
123
+ ZSTD_FILES += $(ZSTDDECOMP_FILES)
77
124
  endif
78
125
 
79
126
  ifneq ($(ZSTD_LIB_DEPRECATED), 0)
80
- ZSTD_FILES += $(ZDEPR_FILES)
127
+ ZSTD_FILES += $(ZDEPR_FILES)
81
128
  endif
82
129
 
83
130
  ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
84
- ZSTD_FILES += $(ZDICT_FILES)
131
+ ZSTD_FILES += $(ZDICT_FILES)
85
132
  endif
86
133
 
87
134
  ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
88
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
135
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
89
136
  endif
90
137
 
91
138
  ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
92
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
139
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
93
140
  endif
94
141
 
95
142
  ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
96
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
143
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
97
144
  endif
98
145
 
99
146
  ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
100
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
147
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
101
148
  endif
102
149
 
103
150
  ifneq ($(ZSTD_NO_INLINE), 0)
104
- CFLAGS += -DZSTD_NO_INLINE
151
+ CFLAGS += -DZSTD_NO_INLINE
105
152
  endif
106
153
 
107
154
  ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
108
- CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
155
+ CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
109
156
  endif
110
157
 
111
158
  ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
112
- CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
159
+ CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
113
160
  endif
114
161
 
115
162
  ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
116
163
  ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
117
- ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
164
+ ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
118
165
  endif
119
- CPPFLAGS += -I./legacy
120
166
  endif
121
167
  CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
122
168
 
123
- ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
169
+ ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
170
+ ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
171
+
172
+ ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
173
+ vpath %.c $(ZSTD_SUBDIR)
174
+
175
+ UNAME := $(shell uname)
176
+
177
+ ifndef BUILD_DIR
178
+ ifeq ($(UNAME), Darwin)
179
+ HASH ?= md5
180
+ else ifeq ($(UNAME), FreeBSD)
181
+ HASH ?= gmd5sum
182
+ else ifeq ($(UNAME), NetBSD)
183
+ HASH ?= md5 -n
184
+ else ifeq ($(UNAME), OpenBSD)
185
+ HASH ?= md5
186
+ endif
187
+ HASH ?= md5sum
188
+
189
+ HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
190
+ HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
191
+ ifeq ($(HAVE_HASH),0)
192
+ $(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
193
+ BUILD_DIR := obj/generic_noconf
194
+ endif
195
+ endif # BUILD_DIR
196
+
124
197
 
125
198
  # macOS linker doesn't support -soname, and use different extension
126
199
  # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
127
- ifeq ($(shell uname), Darwin)
128
- SHARED_EXT = dylib
129
- SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
130
- SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
131
- SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
200
+ ifeq ($(UNAME), Darwin)
201
+ SHARED_EXT = dylib
202
+ SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
203
+ SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
204
+ SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
132
205
  else
133
- SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
134
- SHARED_EXT = so
135
- SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
136
- SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
206
+ SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
207
+ SHARED_EXT = so
208
+ SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
209
+ SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
137
210
  endif
138
211
 
212
+ SET_CACHE_DIRECTORY = \
213
+ +$(MAKE) --no-print-directory $@ \
214
+ BUILD_DIR=obj/$(HASH_DIR) \
215
+ CPPFLAGS="$(CPPFLAGS)" \
216
+ CFLAGS="$(CFLAGS)" \
217
+ LDFLAGS="$(LDFLAGS)"
139
218
 
140
- .PHONY: default all clean install uninstall
141
-
142
- default: lib-release
143
219
 
220
+ .PHONY: all
144
221
  all: lib
145
222
 
146
- libzstd.a: ARFLAGS = rcs
147
- libzstd.a: $(ZSTD_OBJ)
223
+
224
+ .PHONY: libzstd.a # must be run every time
225
+
226
+ ifndef BUILD_DIR
227
+ # determine BUILD_DIR from compilation flags
228
+
229
+ libzstd.a:
230
+ $(SET_CACHE_DIRECTORY)
231
+
232
+ else
233
+ # BUILD_DIR is defined
234
+
235
+ ZSTD_STATLIB_DIR := $(BUILD_DIR)/static
236
+ ZSTD_STATLIB := $(ZSTD_STATLIB_DIR)/libzstd.a
237
+ ZSTD_STATLIB_OBJ := $(addprefix $(ZSTD_STATLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
238
+ $(ZSTD_STATLIB): ARFLAGS = rcs
239
+ $(ZSTD_STATLIB): | $(ZSTD_STATLIB_DIR)
240
+ $(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
148
241
  @echo compiling static library
149
- @$(AR) $(ARFLAGS) $@ $^
242
+ $(AR) $(ARFLAGS) $@ $^
243
+
244
+ libzstd.a: $(ZSTD_STATLIB)
245
+ cp -f $< $@
150
246
 
151
- libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
152
- libzstd.a-mt: libzstd.a
247
+ endif
153
248
 
154
- ifneq (,$(filter Windows%,$(OS)))
249
+ ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
155
250
 
156
- LIBZSTD = dll\libzstd.dll
251
+ LIBZSTD = dll/libzstd.dll
157
252
  $(LIBZSTD): $(ZSTD_FILES)
158
253
  @echo compiling dynamic library $(LIBVER)
159
- $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.lib -shared $^ -o $@
254
+ $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll/libzstd.dll.a -shared $^ -o $@
160
255
 
161
- else
256
+ else # not Windows
162
257
 
163
258
  LIBZSTD = libzstd.$(SHARED_EXT_VER)
164
- $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
165
- $(LIBZSTD): $(ZSTD_FILES)
259
+ .PHONY: $(LIBZSTD) # must be run every time
260
+ $(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
261
+ $(LIBZSTD): LDFLAGS += -shared
262
+
263
+ ifndef BUILD_DIR
264
+ # determine BUILD_DIR from compilation flags
265
+
266
+ $(LIBZSTD):
267
+ $(SET_CACHE_DIRECTORY)
268
+
269
+ else
270
+ # BUILD_DIR is defined
271
+
272
+ ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynamic
273
+ ZSTD_DYNLIB := $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
274
+ ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
275
+
276
+ $(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
277
+ $(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
166
278
  @echo compiling dynamic library $(LIBVER)
167
- @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
279
+ $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
168
280
  @echo creating versioned links
169
- @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
170
- @ln -sf $@ libzstd.$(SHARED_EXT)
281
+ ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
282
+ ln -sf $@ libzstd.$(SHARED_EXT)
171
283
 
172
- endif
284
+ $(LIBZSTD): $(ZSTD_DYNLIB)
285
+ cp -f $< $@
173
286
 
287
+ endif # ifndef BUILD_DIR
288
+ endif # if windows
174
289
 
290
+ .PHONY: libzstd
175
291
  libzstd : $(LIBZSTD)
176
292
 
177
- libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
178
- libzstd-mt : libzstd
293
+ .PHONY: lib
294
+ lib : libzstd.a libzstd
295
+
296
+
297
+ # note : do not define lib-mt or lib-release as .PHONY
298
+ # make does not consider implicit pattern rule for .PHONY target
179
299
 
180
- lib: libzstd.a libzstd
300
+ %-mt : CPPFLAGS += -DZSTD_MULTITHREAD
301
+ %-mt : LDFLAGS += -pthread
302
+ %-mt : %
303
+ @echo multi-threading build completed
181
304
 
182
- lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD
183
- lib-mt: lib
305
+ %-release : DEBUGFLAGS :=
306
+ %-release : %
307
+ @echo release build completed
308
+
309
+
310
+ # Generate .h dependencies automatically
311
+
312
+ DEPFLAGS = -MT $@ -MMD -MP -MF
313
+
314
+ $(ZSTD_DYNLIB_DIR)/%.o : %.c $(ZSTD_DYNLIB_DIR)/%.d | $(ZSTD_DYNLIB_DIR)
315
+ @echo CC $@
316
+ $(COMPILE.c) $(DEPFLAGS) $(ZSTD_DYNLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
317
+
318
+ $(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
319
+ @echo CC $@
320
+ $(COMPILE.c) $(DEPFLAGS) $(ZSTD_STATLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
321
+
322
+ MKDIR ?= mkdir
323
+ $(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATLIB_DIR):
324
+ $(MKDIR) -p $@
325
+
326
+ DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATLIB_OBJ:.o=.d)
327
+ $(DEPFILES):
328
+
329
+ include $(wildcard $(DEPFILES))
184
330
 
185
- lib-release lib-release-mt: DEBUGFLAGS :=
186
- lib-release: lib
187
- lib-release-mt: lib-mt
188
331
 
189
332
  # Special case : building library in single-thread mode _and_ without zstdmt_compress.c
190
333
  ZSTDMT_FILES = compress/zstdmt_compress.c
@@ -193,19 +336,24 @@ libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
193
336
  libzstd-nomt: $(ZSTD_NOMT_FILES)
194
337
  @echo compiling single-thread dynamic library $(LIBVER)
195
338
  @echo files : $(ZSTD_NOMT_FILES)
196
- @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
339
+ $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
197
340
 
341
+ .PHONY: clean
198
342
  clean:
199
- @$(RM) -r *.dSYM # macOS-specific
200
- @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
201
- @$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
202
- @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
343
+ $(RM) -r *.dSYM # macOS-specific
344
+ $(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
345
+ $(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
346
+ $(RM) -r obj/*
203
347
  @echo Cleaning library completed
204
348
 
205
349
  #-----------------------------------------------------------------------------
206
- # make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
350
+ # make install is validated only for below listed environments
207
351
  #-----------------------------------------------------------------------------
208
- ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
352
+ ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
353
+
354
+ all: libzstd.pc
355
+
356
+ HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
209
357
 
210
358
  DESTDIR ?=
211
359
  # directory variables : GNU conventions prefer lowercase
@@ -214,21 +362,34 @@ DESTDIR ?=
214
362
  prefix ?= /usr/local
215
363
  PREFIX ?= $(prefix)
216
364
  exec_prefix ?= $(PREFIX)
217
- libdir ?= $(exec_prefix)/lib
365
+ EXEC_PREFIX ?= $(exec_prefix)
366
+ libdir ?= $(EXEC_PREFIX)/lib
218
367
  LIBDIR ?= $(libdir)
219
368
  includedir ?= $(PREFIX)/include
220
369
  INCLUDEDIR ?= $(includedir)
221
370
 
222
- ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
223
- PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
371
+ PCINCDIR := $(patsubst $(PREFIX)%,%,$(INCLUDEDIR))
372
+ PCLIBDIR := $(patsubst $(EXEC_PREFIX)%,%,$(LIBDIR))
373
+
374
+ # If we successfully stripped off a prefix, we'll add a reference to the
375
+ # relevant pc variable.
376
+ PCINCPREFIX := $(if $(findstring $(INCLUDEDIR),$(PCINCDIR)),,$${prefix})
377
+ PCLIBPREFIX := $(if $(findstring $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
378
+
379
+ # If no explicit EXEC_PREFIX was set by the caller, write it out as a reference
380
+ # to PREFIX, rather than as a resolved value.
381
+ PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix})
382
+
383
+ ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
384
+ PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
224
385
  else
225
- PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
386
+ PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
226
387
  endif
227
388
 
228
- ifneq (,$(filter $(shell uname),SunOS))
229
- INSTALL ?= ginstall
389
+ ifneq (,$(filter $(UNAME),SunOS))
390
+ INSTALL ?= ginstall
230
391
  else
231
- INSTALL ?= install
392
+ INSTALL ?= install
232
393
  endif
233
394
 
234
395
  INSTALL_PROGRAM ?= $(INSTALL)
@@ -238,49 +399,55 @@ INSTALL_DATA ?= $(INSTALL) -m 644
238
399
  libzstd.pc:
239
400
  libzstd.pc: libzstd.pc.in
240
401
  @echo creating pkgconfig
241
- @sed -e 's|@PREFIX@|$(PREFIX)|' \
242
- -e 's|@LIBDIR@|$(LIBDIR)|' \
243
- -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
244
- -e 's|@VERSION@|$(VERSION)|' \
245
- $< >$@
246
-
402
+ @sed $(SED_ERE_OPT) \
403
+ -e 's|@PREFIX@|$(PREFIX)|' \
404
+ -e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
405
+ -e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
406
+ -e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
407
+ -e 's|@VERSION@|$(VERSION)|' \
408
+ $< >$@
409
+
410
+ .PHONY: install
247
411
  install: install-pc install-static install-shared install-includes
248
412
  @echo zstd static and shared library installed
249
413
 
250
414
  install-pc: libzstd.pc
251
- @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
252
- @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
415
+ [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
416
+ $(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
253
417
 
254
- install-static: libzstd.a
418
+ install-static:
419
+ # only generate libzstd.a if it's not already present
420
+ [ -e libzstd.a ] || $(MAKE) libzstd.a-release
421
+ [ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
255
422
  @echo Installing static library
256
- @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
257
- @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
423
+ $(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
258
424
 
259
- install-shared: libzstd
425
+ install-shared:
426
+ # only generate libzstd.so if it's not already present
427
+ [ -e $(LIBZSTD) ] || $(MAKE) libzstd-release
428
+ [ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
260
429
  @echo Installing shared library
261
- @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
262
- @$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
263
- @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
264
- @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
430
+ $(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
431
+ ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
432
+ ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
265
433
 
266
434
  install-includes:
435
+ [ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
267
436
  @echo Installing includes
268
- @$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
269
- @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
270
- @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
271
- @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
272
- @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
437
+ $(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
438
+ $(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
439
+ $(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
273
440
 
441
+ .PHONY: uninstall
274
442
  uninstall:
275
- @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
276
- @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
277
- @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
278
- @$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
279
- @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
280
- @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
281
- @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
282
- @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
283
- @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
443
+ $(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
444
+ $(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
445
+ $(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
446
+ $(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
447
+ $(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
448
+ $(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
449
+ $(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
450
+ $(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
284
451
  @echo zstd libraries successfully uninstalled
285
452
 
286
453
  endif