zstd-ruby 1.4.5.0 → 1.4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) 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 +237 -138
  5. data/ext/zstdruby/libzstd/README.md +28 -0
  6. data/ext/zstdruby/libzstd/common/bitstream.h +25 -16
  7. data/ext/zstdruby/libzstd/common/compiler.h +118 -4
  8. data/ext/zstdruby/libzstd/common/cpu.h +1 -3
  9. data/ext/zstdruby/libzstd/common/debug.c +1 -1
  10. data/ext/zstdruby/libzstd/common/debug.h +12 -19
  11. data/ext/zstdruby/libzstd/common/entropy_common.c +189 -43
  12. data/ext/zstdruby/libzstd/common/error_private.c +2 -1
  13. data/ext/zstdruby/libzstd/common/error_private.h +2 -2
  14. data/ext/zstdruby/libzstd/common/fse.h +40 -12
  15. data/ext/zstdruby/libzstd/common/fse_decompress.c +124 -17
  16. data/ext/zstdruby/libzstd/common/huf.h +27 -6
  17. data/ext/zstdruby/libzstd/common/mem.h +67 -94
  18. data/ext/zstdruby/libzstd/common/pool.c +23 -17
  19. data/ext/zstdruby/libzstd/common/pool.h +2 -2
  20. data/ext/zstdruby/libzstd/common/threading.c +6 -5
  21. data/ext/zstdruby/libzstd/common/xxhash.c +19 -57
  22. data/ext/zstdruby/libzstd/common/xxhash.h +2 -2
  23. data/ext/zstdruby/libzstd/common/zstd_common.c +10 -10
  24. data/ext/zstdruby/libzstd/common/zstd_deps.h +111 -0
  25. data/ext/zstdruby/libzstd/common/zstd_errors.h +2 -1
  26. data/ext/zstdruby/libzstd/common/zstd_internal.h +90 -59
  27. data/ext/zstdruby/libzstd/common/zstd_trace.c +42 -0
  28. data/ext/zstdruby/libzstd/common/zstd_trace.h +152 -0
  29. data/ext/zstdruby/libzstd/compress/fse_compress.c +31 -24
  30. data/ext/zstdruby/libzstd/compress/hist.c +27 -29
  31. data/ext/zstdruby/libzstd/compress/hist.h +2 -2
  32. data/ext/zstdruby/libzstd/compress/huf_compress.c +217 -101
  33. data/ext/zstdruby/libzstd/compress/zstd_compress.c +1495 -478
  34. data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +143 -44
  35. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.c +7 -7
  36. data/ext/zstdruby/libzstd/compress/zstd_compress_literals.h +1 -1
  37. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.c +18 -4
  38. data/ext/zstdruby/libzstd/compress/zstd_compress_sequences.h +1 -1
  39. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.c +25 -21
  40. data/ext/zstdruby/libzstd/compress/zstd_compress_superblock.h +1 -1
  41. data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +62 -26
  42. data/ext/zstdruby/libzstd/compress/zstd_double_fast.c +23 -23
  43. data/ext/zstdruby/libzstd/compress/zstd_double_fast.h +1 -1
  44. data/ext/zstdruby/libzstd/compress/zstd_fast.c +21 -21
  45. data/ext/zstdruby/libzstd/compress/zstd_fast.h +1 -1
  46. data/ext/zstdruby/libzstd/compress/zstd_lazy.c +352 -78
  47. data/ext/zstdruby/libzstd/compress/zstd_lazy.h +21 -1
  48. data/ext/zstdruby/libzstd/compress/zstd_ldm.c +276 -209
  49. data/ext/zstdruby/libzstd/compress/zstd_ldm.h +8 -2
  50. data/ext/zstdruby/libzstd/compress/zstd_ldm_geartab.h +103 -0
  51. data/ext/zstdruby/libzstd/compress/zstd_opt.c +191 -46
  52. data/ext/zstdruby/libzstd/compress/zstd_opt.h +1 -1
  53. data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +79 -410
  54. data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +27 -109
  55. data/ext/zstdruby/libzstd/decompress/huf_decompress.c +303 -201
  56. data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +9 -9
  57. data/ext/zstdruby/libzstd/decompress/zstd_ddict.h +2 -2
  58. data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +370 -87
  59. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +153 -45
  60. data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +6 -3
  61. data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +28 -11
  62. data/ext/zstdruby/libzstd/deprecated/zbuff.h +1 -1
  63. data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +1 -1
  64. data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +1 -1
  65. data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +1 -1
  66. data/ext/zstdruby/libzstd/dictBuilder/cover.c +40 -31
  67. data/ext/zstdruby/libzstd/dictBuilder/cover.h +2 -2
  68. data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1 -1
  69. data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +26 -25
  70. data/ext/zstdruby/libzstd/dictBuilder/zdict.c +22 -24
  71. data/ext/zstdruby/libzstd/dictBuilder/zdict.h +5 -4
  72. data/ext/zstdruby/libzstd/dll/example/Makefile +1 -1
  73. data/ext/zstdruby/libzstd/dll/example/README.md +16 -22
  74. data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +1 -1
  75. data/ext/zstdruby/libzstd/legacy/zstd_v01.c +6 -2
  76. data/ext/zstdruby/libzstd/legacy/zstd_v01.h +1 -1
  77. data/ext/zstdruby/libzstd/legacy/zstd_v02.c +6 -2
  78. data/ext/zstdruby/libzstd/legacy/zstd_v02.h +1 -1
  79. data/ext/zstdruby/libzstd/legacy/zstd_v03.c +6 -2
  80. data/ext/zstdruby/libzstd/legacy/zstd_v03.h +1 -1
  81. data/ext/zstdruby/libzstd/legacy/zstd_v04.c +7 -3
  82. data/ext/zstdruby/libzstd/legacy/zstd_v04.h +1 -1
  83. data/ext/zstdruby/libzstd/legacy/zstd_v05.c +10 -6
  84. data/ext/zstdruby/libzstd/legacy/zstd_v05.h +1 -1
  85. data/ext/zstdruby/libzstd/legacy/zstd_v06.c +10 -6
  86. data/ext/zstdruby/libzstd/legacy/zstd_v06.h +1 -1
  87. data/ext/zstdruby/libzstd/legacy/zstd_v07.c +10 -6
  88. data/ext/zstdruby/libzstd/legacy/zstd_v07.h +1 -1
  89. data/ext/zstdruby/libzstd/libzstd.pc.in +3 -3
  90. data/ext/zstdruby/libzstd/zstd.h +414 -54
  91. data/lib/zstd-ruby/version.rb +1 -1
  92. metadata +7 -3
  93. data/.travis.yml +0 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3fb9daf94529e91f7b648c1d29d5d562463553adb5d4ac420121bac1804fbeab
4
- data.tar.gz: bdcebd2d2709f7b1c1736343846bf78c8b528237a78e45d3e7fd7c1473275ed4
3
+ metadata.gz: 1b9fb489baa649ba5ee4d0eab2a8eff41dca8aed169decbcbb94f2b743fff4b9
4
+ data.tar.gz: 466460ae250bdf1b41ad9a520cf22c3457647c64c87f6479bf59a7d5876eb08c
5
5
  SHA512:
6
- metadata.gz: 3e615781ba60a8525498fc5329917762411cfc4edf465ce9be06dbee5d9f08ff4bcf119142e2d61e5285f5efb94accc28d50f356d1f91cbf7d34d4531fb341f4
7
- data.tar.gz: 87fa77e13997a63109ba65e6cf38ad429192ca62991bb600a27660762fc1381c4dfd3ea9e5561b3a17774b3e3967483a095481259bcd653aa72469c823aa929f
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.5 (https://github.com/facebook/zstd/tree/v1.4.5)
13
+ v1.4.9 (https://github.com/facebook/zstd/tree/v1.4.9)
14
14
 
15
15
  ## Installation
16
16
 
@@ -1,5 +1,5 @@
1
1
  # ################################################################
2
- # Copyright (c) 2015-2020, 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
@@ -8,15 +8,16 @@
8
8
  # You may select, at your option, one of the above-listed licenses.
9
9
  # ################################################################
10
10
 
11
- Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
11
+ .PHONY: default
12
+ default: lib-release
12
13
 
13
- # When cross-compiling from linux to windows, you might
14
- # need to specify this as "Windows." Fedora build fails
15
- # without it.
16
- #
17
- # Note: mingw-w64 build from linux to windows does not
18
- # fail on other tested distros (ubuntu, debian) even
19
- # without manually specifying the TARGET_SYSTEM.
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)
20
21
  TARGET_SYSTEM ?= $(OS)
21
22
 
22
23
  # Version numbers
@@ -31,24 +32,49 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
31
32
  VERSION?= $(LIBVER)
32
33
  CCVER := $(shell $(CC) --version)
33
34
 
34
- CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_
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
57
+
58
+ DEBUGLEVEL ?= 0
59
+ CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
35
60
  ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
36
- CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
61
+ CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
37
62
  endif
38
63
  DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
39
64
  -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
40
65
  -Wstrict-prototypes -Wundef -Wpointer-arith \
41
66
  -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
42
67
  -Wredundant-decls -Wmissing-prototypes -Wc++-compat
43
- CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
44
- FLAGS = $(CPPFLAGS) $(CFLAGS)
68
+ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
69
+ FLAGS = $(CPPFLAGS) $(CFLAGS)
45
70
 
46
71
  HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
47
72
  GREP_OPTIONS ?=
48
73
  ifeq ($HAVE_COLORNEVER, 1)
49
- GREP_OPTIONS += --color=never
74
+ GREP_OPTIONS += --color=never
50
75
  endif
51
76
  GREP = grep $(GREP_OPTIONS)
77
+ SED_ERE_OPT ?= -E
52
78
 
53
79
  ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
54
80
  ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
@@ -58,30 +84,7 @@ ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
58
84
  ZSTD_FILES := $(ZSTDCOMMON_FILES)
59
85
 
60
86
  ifeq ($(findstring GCC,$(CCVER)),GCC)
61
- decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
62
- endif
63
-
64
- # This is a helper variable that configures a bunch of other variables to new,
65
- # space-optimized defaults.
66
- ZSTD_LIB_MINIFY ?= 0
67
- ifneq ($(ZSTD_LIB_MINIFY), 0)
68
- HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
69
- ZSTD_LEGACY_SUPPORT ?= 0
70
- ZSTD_LIB_DEPRECATED ?= 0
71
- HUF_FORCE_DECOMPRESS_X1 ?= 1
72
- ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
73
- ZSTD_NO_INLINE ?= 1
74
- ZSTD_STRIP_ERROR_STRINGS ?= 1
75
- ifneq ($(HAVE_CC_OZ), 0)
76
- # Some compilers (clang) support an even more space-optimized setting.
77
- CFLAGS += -Oz
78
- else
79
- CFLAGS += -Os
80
- endif
81
- CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
82
- -DDYNAMIC_BMI2=0 -DNDEBUG
83
- else
84
- CFLAGS += -O3
87
+ decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
85
88
  endif
86
89
 
87
90
  # Modules
@@ -103,116 +106,186 @@ ZSTD_NO_INLINE ?= 0
103
106
  ZSTD_STRIP_ERROR_STRINGS ?= 0
104
107
 
105
108
  ifeq ($(ZSTD_LIB_COMPRESSION), 0)
106
- ZSTD_LIB_DICTBUILDER = 0
107
- ZSTD_LIB_DEPRECATED = 0
109
+ ZSTD_LIB_DICTBUILDER = 0
110
+ ZSTD_LIB_DEPRECATED = 0
108
111
  endif
109
112
 
110
113
  ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
111
- ZSTD_LEGACY_SUPPORT = 0
112
- ZSTD_LIB_DEPRECATED = 0
114
+ ZSTD_LEGACY_SUPPORT = 0
115
+ ZSTD_LIB_DEPRECATED = 0
113
116
  endif
114
117
 
115
118
  ifneq ($(ZSTD_LIB_COMPRESSION), 0)
116
- ZSTD_FILES += $(ZSTDCOMP_FILES)
119
+ ZSTD_FILES += $(ZSTDCOMP_FILES)
117
120
  endif
118
121
 
119
122
  ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
120
- ZSTD_FILES += $(ZSTDDECOMP_FILES)
123
+ ZSTD_FILES += $(ZSTDDECOMP_FILES)
121
124
  endif
122
125
 
123
126
  ifneq ($(ZSTD_LIB_DEPRECATED), 0)
124
- ZSTD_FILES += $(ZDEPR_FILES)
127
+ ZSTD_FILES += $(ZDEPR_FILES)
125
128
  endif
126
129
 
127
130
  ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
128
- ZSTD_FILES += $(ZDICT_FILES)
131
+ ZSTD_FILES += $(ZDICT_FILES)
129
132
  endif
130
133
 
131
134
  ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
132
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
135
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
133
136
  endif
134
137
 
135
138
  ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
136
- CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
139
+ CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
137
140
  endif
138
141
 
139
142
  ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
140
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
143
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
141
144
  endif
142
145
 
143
146
  ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
144
- CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
147
+ CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
145
148
  endif
146
149
 
147
150
  ifneq ($(ZSTD_NO_INLINE), 0)
148
- CFLAGS += -DZSTD_NO_INLINE
151
+ CFLAGS += -DZSTD_NO_INLINE
149
152
  endif
150
153
 
151
154
  ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
152
- CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
155
+ CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
153
156
  endif
154
157
 
155
158
  ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
156
- CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
159
+ CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
157
160
  endif
158
161
 
159
162
  ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
160
163
  ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
161
- 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]')
162
165
  endif
163
166
  endif
164
167
  CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
165
168
 
166
- 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
+
167
197
 
168
198
  # macOS linker doesn't support -soname, and use different extension
169
199
  # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
170
- ifeq ($(shell uname), Darwin)
171
- SHARED_EXT = dylib
172
- SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
173
- SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
174
- 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)
175
205
  else
176
- SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
177
- SHARED_EXT = so
178
- SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
179
- 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)
180
210
  endif
181
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)"
182
218
 
183
- .PHONY: default lib-all all clean install uninstall
184
219
 
185
- default: lib-release
220
+ .PHONY: all
221
+ all: lib
186
222
 
187
- # alias
188
- lib-all: all
189
223
 
190
- all: lib
224
+ .PHONY: libzstd.a # must be run every time
191
225
 
192
- libzstd.a: ARFLAGS = rcs
193
- libzstd.a: $(ZSTD_OBJ)
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)
194
241
  @echo compiling static library
195
- $(Q)$(AR) $(ARFLAGS) $@ $^
242
+ $(AR) $(ARFLAGS) $@ $^
243
+
244
+ libzstd.a: $(ZSTD_STATLIB)
245
+ cp -f $< $@
246
+
247
+ endif
196
248
 
197
249
  ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
198
250
 
199
- LIBZSTD = dll\libzstd.dll
251
+ LIBZSTD = dll/libzstd.dll
200
252
  $(LIBZSTD): $(ZSTD_FILES)
201
253
  @echo compiling dynamic library $(LIBVER)
202
- $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
254
+ $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll/libzstd.dll.a -shared $^ -o $@
203
255
 
204
- else
256
+ else # not Windows
205
257
 
206
258
  LIBZSTD = libzstd.$(SHARED_EXT_VER)
207
- $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
208
- $(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)
209
278
  @echo compiling dynamic library $(LIBVER)
210
- $(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
279
+ $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
211
280
  @echo creating versioned links
212
- $(Q)ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
213
- $(Q)ln -sf $@ libzstd.$(SHARED_EXT)
281
+ ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
282
+ ln -sf $@ libzstd.$(SHARED_EXT)
214
283
 
215
- endif
284
+ $(LIBZSTD): $(ZSTD_DYNLIB)
285
+ cp -f $< $@
286
+
287
+ endif # ifndef BUILD_DIR
288
+ endif # if windows
216
289
 
217
290
  .PHONY: libzstd
218
291
  libzstd : $(LIBZSTD)
@@ -220,18 +293,42 @@ libzstd : $(LIBZSTD)
220
293
  .PHONY: lib
221
294
  lib : libzstd.a libzstd
222
295
 
223
- .PHONY: lib-mt
296
+
297
+ # note : do not define lib-mt or lib-release as .PHONY
298
+ # make does not consider implicit pattern rule for .PHONY target
299
+
224
300
  %-mt : CPPFLAGS += -DZSTD_MULTITHREAD
225
301
  %-mt : LDFLAGS += -pthread
226
302
  %-mt : %
227
303
  @echo multi-threading build completed
228
304
 
229
- .PHONY: lib-release
230
305
  %-release : DEBUGFLAGS :=
231
306
  %-release : %
232
307
  @echo release build completed
233
308
 
234
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))
330
+
331
+
235
332
  # Special case : building library in single-thread mode _and_ without zstdmt_compress.c
236
333
  ZSTDMT_FILES = compress/zstdmt_compress.c
237
334
  ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
@@ -239,22 +336,25 @@ libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
239
336
  libzstd-nomt: $(ZSTD_NOMT_FILES)
240
337
  @echo compiling single-thread dynamic library $(LIBVER)
241
338
  @echo files : $(ZSTD_NOMT_FILES)
242
- $(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
339
+ $(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
243
340
 
341
+ .PHONY: clean
244
342
  clean:
245
- $(Q)$(RM) -r *.dSYM # macOS-specific
246
- $(Q)$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
247
- $(Q)$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
248
- $(Q)$(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/*
249
347
  @echo Cleaning library completed
250
348
 
251
349
  #-----------------------------------------------------------------------------
252
350
  # make install is validated only for below listed environments
253
351
  #-----------------------------------------------------------------------------
254
- 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))
255
353
 
256
354
  all: libzstd.pc
257
355
 
356
+ HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
357
+
258
358
  DESTDIR ?=
259
359
  # directory variables : GNU conventions prefer lowercase
260
360
  # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
@@ -268,35 +368,28 @@ LIBDIR ?= $(libdir)
268
368
  includedir ?= $(PREFIX)/include
269
369
  INCLUDEDIR ?= $(includedir)
270
370
 
271
- PCLIBDIR ?= $(shell echo "$(LIBDIR)" | sed -n -E -e "s@^$(EXEC_PREFIX)(/|$$)@@p")
272
- PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | sed -n -E -e "s@^$(PREFIX)(/|$$)@@p")
371
+ PCINCDIR := $(patsubst $(PREFIX)%,%,$(INCLUDEDIR))
372
+ PCLIBDIR := $(patsubst $(EXEC_PREFIX)%,%,$(LIBDIR))
273
373
 
274
- ifeq (,$(PCLIBDIR))
275
- # Additional prefix check is required, since the empty string is technically a
276
- # valid PCLIBDIR
277
- ifeq (,$(shell echo "$(LIBDIR)" | sed -n -E -e "\\@^$(EXEC_PREFIX)(/|$$)@ p"))
278
- $(error configured libdir ($(LIBDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file)
279
- endif
280
- endif
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})
281
378
 
282
- ifeq (,$(PCINCDIR))
283
- # Additional prefix check is required, since the empty string is technically a
284
- # valid PCINCDIR
285
- ifeq (,$(shell echo "$(INCLUDEDIR)" | sed -n -E -e "\\@^$(PREFIX)(/|$$)@ p"))
286
- $(error configured includedir ($(INCLUDEDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file)
287
- endif
288
- endif
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})
289
382
 
290
- ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
291
- PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
383
+ ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
384
+ PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
292
385
  else
293
- PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
386
+ PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
294
387
  endif
295
388
 
296
- ifneq (,$(filter $(shell uname),SunOS))
297
- INSTALL ?= ginstall
389
+ ifneq (,$(filter $(UNAME),SunOS))
390
+ INSTALL ?= ginstall
298
391
  else
299
- INSTALL ?= install
392
+ INSTALL ?= install
300
393
  endif
301
394
 
302
395
  INSTALL_PROGRAM ?= $(INSTALL)
@@ -306,49 +399,55 @@ INSTALL_DATA ?= $(INSTALL) -m 644
306
399
  libzstd.pc:
307
400
  libzstd.pc: libzstd.pc.in
308
401
  @echo creating pkgconfig
309
- $(Q)@sed -E -e 's|@PREFIX@|$(PREFIX)|' \
310
- -e 's|@LIBDIR@|$(PCLIBDIR)|' \
311
- -e 's|@INCLUDEDIR@|$(PCINCDIR)|' \
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)|' \
312
407
  -e 's|@VERSION@|$(VERSION)|' \
313
408
  $< >$@
314
409
 
410
+ .PHONY: install
315
411
  install: install-pc install-static install-shared install-includes
316
412
  @echo zstd static and shared library installed
317
413
 
318
414
  install-pc: libzstd.pc
319
- $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
320
- $(Q)$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
415
+ [ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
416
+ $(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
321
417
 
322
- 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)/
323
422
  @echo Installing static library
324
- $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
325
- $(Q)$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
423
+ $(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
326
424
 
327
- 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)/
328
429
  @echo Installing shared library
329
- $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
330
- $(Q)$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
331
- $(Q)ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
332
- $(Q)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)
333
433
 
334
434
  install-includes:
435
+ [ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
335
436
  @echo Installing includes
336
- $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
337
- $(Q)$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
338
- $(Q)$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
339
- $(Q)$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
340
- $(Q)$(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)
341
440
 
441
+ .PHONY: uninstall
342
442
  uninstall:
343
- $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
344
- $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
345
- $(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
346
- $(Q)$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
347
- $(Q)$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
348
- $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
349
- $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
350
- $(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
351
- $(Q)$(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
352
451
  @echo zstd libraries successfully uninstalled
353
452
 
354
453
  endif