aboutsummaryrefslogtreecommitdiff
path: root/examples/redis-unstable/deps/xxhash/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'examples/redis-unstable/deps/xxhash/Makefile')
-rw-r--r--examples/redis-unstable/deps/xxhash/Makefile687
1 files changed, 687 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/xxhash/Makefile b/examples/redis-unstable/deps/xxhash/Makefile
new file mode 100644
index 0000000..a9fa95a
--- /dev/null
+++ b/examples/redis-unstable/deps/xxhash/Makefile
@@ -0,0 +1,687 @@
1# ################################################################
2# xxHash Makefile
3# Copyright (C) 2012-2024 Yann Collet
4#
5# GPL v2 License
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# You can contact the author at:
22# - xxHash homepage: https://www.xxhash.com
23# - xxHash source repository: https://github.com/Cyan4973/xxHash
24# ################################################################
25# xxhsum: provides 32/64 bits hash of one or multiple files, or stdin
26# ################################################################
27
28# Version numbers
29SED ?= sed
30SED_ERE_OPT ?= -E
31LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
32LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
33LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define XXH_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
34LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
35LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
36LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
37LIBVER := $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
38
39MAKEFLAGS += --no-print-directory
40CFLAGS ?= -O3
41DEBUGFLAGS+=-Wall -Wextra -Wconversion -Wcast-qual -Wcast-align -Wshadow \
42 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
43 -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
44 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
45 -Wredundant-decls -Wstrict-overflow=2
46CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
47FLAGS = $(CFLAGS) $(CPPFLAGS)
48XXHSUM_VERSION = $(LIBVER)
49
50# Define *.exe as extension for Windows systems
51ifneq (,$(filter Windows%,$(OS)))
52EXT =.exe
53else
54EXT =
55endif
56
57# automatically enable runtime vector dispatch on x86/64 targets
58detect_x86_arch = $(shell $(CC) -dumpmachine | grep -E 'i[3-6]86|x86_64')
59ifneq ($(strip $(call detect_x86_arch)),)
60 #note: can be overridden at compile time, by setting DISPATCH=0
61 DISPATCH ?= 1
62else
63 ifeq ($(DISPATCH),1)
64 $(info "Note: DISPATCH=1 is only supported on x86/x64 targets")
65 endif
66 override DISPATCH := 0
67endif
68
69ifeq ($(NODE_JS),1)
70 # Link in unrestricted filesystem support
71 LDFLAGS += -sNODERAWFS
72 # Set flag to fix isatty() support
73 CPPFLAGS += -DXSUM_NODE_JS=1
74endif
75
76# OS X linker doesn't support -soname, and use different extension
77# see: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
78UNAME ?= $(shell uname)
79ifeq ($(UNAME), Darwin)
80 SHARED_EXT = dylib
81 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
82 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
83 SONAME_FLAGS = -install_name $(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
84else
85 SONAME_FLAGS = -Wl,-soname=libxxhash.$(SHARED_EXT).$(LIBVER_MAJOR)
86 SHARED_EXT = so
87 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
88 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
89endif
90
91LIBXXH = libxxhash.$(SHARED_EXT_VER)
92
93CLI_DIR = cli
94CLI_SRCS = $(wildcard $(CLI_DIR)/*.c)
95CLI_OBJS = $(CLI_SRCS:.c=.o)
96
97## define default before including multiconf.make
98## generate CLI and libraries in release mode (default for `make`)
99.PHONY: default
100default: DEBUGFLAGS=
101default: lib xxhsum_and_links
102
103C_SRCDIRS = . $(CLI_DIR) fuzz
104include build/make/multiconf.make
105
106.PHONY: all
107all: lib xxhsum xxhsum_inlinedXXH
108
109## xxhsum is the command line interface (CLI)
110ifeq ($(DISPATCH),1)
111xxhsum: CPPFLAGS += -DXXHSUM_DISPATCH=1
112XXHSUM_ADD_O = xxh_x86dispatch.o
113endif
114$(eval $(call c_program,xxhsum,xxhash.o $(CLI_OBJS) $(XXHSUM_ADD_O)))
115
116.PHONY: xxhsum_and_links
117xxhsum_and_links: xxhsum xxh32sum xxh64sum xxh128sum xxh3sum
118
119LN ?= ln
120
121xxh32sum xxh64sum xxh128sum xxh3sum: xxhsum
122 $(LN) -sf $<$(EXT) $@$(EXT)
123
124## generate CLI in 32-bits mode
125xxhsum32: CFLAGS += -m32
126ifeq ($(DISPATCH),1)
127xxhsum32: CPPFLAGS += -DXXHSUM_DISPATCH=1
128endif
129$(eval $(call c_program,xxhsum32,xxhash.o $(CLI_OBJS) $(XXHSUM_ADD_O)))
130
131## Warning: dispatch only works for x86/x64 systems
132dispatch: CPPFLAGS += -DXXHSUM_DISPATCH=1
133$(eval $(call c_program,dispatch,xxhash.o xxh_x86dispatch.o $(CLI_OBJS)))
134
135xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL
136$(eval $(call c_program,xxhsum_inlinedXXH,$(CLI_OBJS)))
137
138
139# =================================================
140# library
141
142libxxhash.a:
143$(eval $(call static_library,libxxhash.a,xxhash.o))
144
145$(LIBXXH): LDFLAGS += $(SONAME_FLAGS)
146ifeq (,$(filter Windows%,$(OS)))
147$(LIBXXH): CFLAGS += -fPIC
148endif
149LIBXXHASH_OBJS := xxhash.o $(if $(filter 1,$(LIBXXH_DISPATCH)),xxh_x86dispatch.o)
150$(eval $(call c_dynamic_library,$(LIBXXH),$(LIBXXHASH_OBJS)))
151
152libxxhash.$(SHARED_EXT_MAJOR): $(LIBXXH)
153 $(LN) -sf $< $@
154
155libxxhash.$(SHARED_EXT): libxxhash.$(SHARED_EXT_MAJOR)
156 $(LN) -sf $< $@
157
158.PHONY: libxxhash ## generate dynamic xxhash library
159libxxhash: $(LIBXXH) libxxhash.$(SHARED_EXT_MAJOR) libxxhash.$(SHARED_EXT)
160
161.PHONY: lib ## generate static and dynamic xxhash libraries
162lib: libxxhash.a libxxhash
163
164
165# helper targets
166
167AWK ?= awk
168GREP ?= grep
169SORT ?= sort
170NM ?= nm
171
172.PHONY: list
173list: ## list all Makefile targets
174 $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | $(AWK) -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | $(SORT) | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
175
176.PHONY: help
177help: ## list documented targets
178 $(GREP) -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
179 $(SORT) | \
180 $(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
181
182.PHONY: clean
183clean:
184 $(RM) -r *.dSYM # Mac OS-X specific
185 $(RM) core *.o *.obj *.$(SHARED_EXT) *.$(SHARED_EXT).* *.a libxxhash.pc
186 $(RM) xxhsum.wasm xxhsum.js xxhsum.html
187 $(RM) xxh32sum$(EXT) xxh64sum$(EXT) xxh128sum$(EXT) xxh3sum$(EXT)
188 $(RM) fuzzer
189 $(MAKE) -C tests clean
190 $(MAKE) -C tests/bench clean
191 $(MAKE) -C tests/collisions clean
192 @echo cleaning completed
193
194
195# =================================================
196# tests
197# =================================================
198
199# make check can be run with cross-compiled binaries on emulated environments (qemu user mode)
200# by setting $(RUN_ENV) to the target emulation environment
201.PHONY: check
202check: xxhsum test_sanity ## basic tests for xxhsum CLI, set RUN_ENV for emulated environments
203 # stdin
204 # If you get "Wrong parameters" on Emscripten+Node.js, recompile with `NODE_JS=1`
205 $(RUN_ENV) ./xxhsum$(EXT) < xxhash.c
206 # multiple files
207 $(RUN_ENV) ./xxhsum$(EXT) xxhash.*
208 # internal bench
209 $(RUN_ENV) ./xxhsum$(EXT) -bi0
210 # long bench command
211 $(RUN_ENV) ./xxhsum$(EXT) --benchmark-all -i0
212 # bench multiple variants
213 $(RUN_ENV) ./xxhsum$(EXT) -b1,2,3 -i0
214 # file bench
215 $(RUN_ENV) ./xxhsum$(EXT) -bi0 xxhash.c
216 # 32-bit
217 $(RUN_ENV) ./xxhsum$(EXT) -H0 xxhash.c
218 # 128-bit
219 $(RUN_ENV) ./xxhsum$(EXT) -H2 xxhash.c
220 # XXH3 (enforce BSD style)
221 $(RUN_ENV) ./xxhsum$(EXT) -H3 xxhash.c | grep "XXH3"
222 # request incorrect variant
223 $(RUN_ENV) ./xxhsum$(EXT) -H9 xxhash.c ; test $$? -eq 1
224 @printf "\n ....... checks completed successfully ....... \n"
225
226.PHONY: test-unicode
227test-unicode:
228 $(MAKE) -C tests test_unicode
229
230.PHONY: test_sanity
231test_sanity:
232 $(MAKE) -C tests test_sanity
233
234.PHONY: test-mem
235VALGRIND = valgrind --leak-check=yes --error-exitcode=1
236test-mem: RUN_ENV = $(VALGRIND)
237test-mem: xxhsum check
238
239.PHONY: test32
240test32: xxhsum32
241 @echo ---- test 32-bit ----
242 ./xxhsum32 -bi0 xxhash.c
243
244TEST_FILES = xxhsum$(EXT) xxhash.c xxhash.h
245.PHONY: test-xxhsum-c
246test-xxhsum-c: xxhsum
247 # xxhsum to/from pipe
248 ./xxhsum $(TEST_FILES) | ./xxhsum -c -
249 ./xxhsum -H0 $(TEST_FILES) | ./xxhsum -c -
250 # xxhsum -c is unable to verify checksum of file from STDIN (#470)
251 ./xxhsum < README.md > .test.README.md.xxh
252 ./xxhsum -c .test.README.md.xxh < README.md
253 # xxhsum -q does not display "Loading" message into stderr (#251)
254 ! ./xxhsum -q $(TEST_FILES) 2>&1 | grep Loading
255 # xxhsum does not display "Loading" message into stderr either
256 ! ./xxhsum $(TEST_FILES) 2>&1 | grep Loading
257 # Check that xxhsum do display filename that it failed to open.
258 LC_ALL=C ./xxhsum nonexistent 2>&1 | grep "Error: Could not open 'nonexistent'"
259 # xxhsum to/from file, shell redirection
260 ./xxhsum $(TEST_FILES) > .test.xxh64
261 ./xxhsum --tag $(TEST_FILES) > .test.xxh64_tag
262 ./xxhsum --little-endian $(TEST_FILES) > .test.le_xxh64
263 ./xxhsum --tag --little-endian $(TEST_FILES) > .test.le_xxh64_tag
264 ./xxhsum -H0 $(TEST_FILES) > .test.xxh32
265 ./xxhsum -H0 --tag $(TEST_FILES) > .test.xxh32_tag
266 ./xxhsum -H0 --little-endian $(TEST_FILES) > .test.le_xxh32
267 ./xxhsum -H0 --tag --little-endian $(TEST_FILES) > .test.le_xxh32_tag
268 ./xxhsum -H2 $(TEST_FILES) > .test.xxh128
269 ./xxhsum -H2 --tag $(TEST_FILES) > .test.xxh128_tag
270 ./xxhsum -H2 --little-endian $(TEST_FILES) > .test.le_xxh128
271 ./xxhsum -H2 --tag --little-endian $(TEST_FILES) > .test.le_xxh128_tag
272 ./xxhsum -H3 $(TEST_FILES) > .test.xxh3
273 ./xxhsum -H3 --tag $(TEST_FILES) > .test.xxh3_tag
274 ./xxhsum -H3 --little-endian $(TEST_FILES) > .test.le_xxh3
275 ./xxhsum -H3 --tag --little-endian $(TEST_FILES) > .test.le_xxh3_tag
276 ./xxhsum -c .test.xxh*
277 ./xxhsum -c --little-endian .test.le_xxh*
278 ./xxhsum -c .test.*_tag
279 # read list of files from stdin
280 ./xxhsum -c < .test.xxh32
281 ./xxhsum -c < .test.xxh64
282 ./xxhsum -c < .test.xxh128
283 ./xxhsum -c < .test.xxh3
284 cat .test.xxh* | ./xxhsum -c -
285 # check variant with '*' marker as second separator
286 $(SED) 's/ / \*/' .test.xxh32 | ./xxhsum -c
287 # bsd-style output
288 ./xxhsum --tag xxhsum* | $(GREP) XXH64
289 ./xxhsum --tag -H0 xxhsum* | $(GREP) XXH32
290 ./xxhsum --tag -H1 xxhsum* | $(GREP) XXH64
291 ./xxhsum --tag -H2 xxhsum* | $(GREP) XXH128
292 ./xxhsum --tag -H3 xxhsum* | $(GREP) XXH3
293 ./xxhsum -H3 xxhsum* | $(GREP) XXH3_ # prefix for GNU format
294 ./xxhsum --tag -H32 xxhsum* | $(GREP) XXH32
295 ./xxhsum --tag -H64 xxhsum* | $(GREP) XXH64
296 ./xxhsum --tag -H128 xxhsum* | $(GREP) XXH128
297 ./xxhsum --tag -H0 --little-endian xxhsum* | $(GREP) XXH32_LE
298 ./xxhsum --tag -H1 --little-endian xxhsum* | $(GREP) XXH64_LE
299 ./xxhsum --tag -H2 --little-endian xxhsum* | $(GREP) XXH128_LE
300 ./xxhsum --tag -H3 --little-endian xxhsum* | $(GREP) XXH3_LE
301 ./xxhsum --tag -H32 --little-endian xxhsum* | $(GREP) XXH32_LE
302 ./xxhsum --tag -H64 --little-endian xxhsum* | $(GREP) XXH64_LE
303 ./xxhsum --tag -H128 --little-endian xxhsum* | $(GREP) XXH128_LE
304 # check bsd-style
305 ./xxhsum --tag xxhsum* | ./xxhsum -c
306 ./xxhsum --tag -H32 --little-endian xxhsum* | ./xxhsum -c
307 # xxhsum -c warns improperly format lines.
308 echo '12345678 ' >>.test.xxh32
309 ./xxhsum -c .test.xxh32 | $(GREP) improperly
310 echo '123456789 file' >>.test.xxh64
311 ./xxhsum -c .test.xxh64 | $(GREP) improperly
312 # Expects "FAILED"
313 echo "0000000000000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
314 echo "00000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
315 # Expects "FAILED open or read"
316 echo "0000000000000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
317 echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
318 # --filelist
319 echo xxhash.c > .test.filenames
320 $(RUN_ENV) ./xxhsum$(EXT) --filelist .test.filenames
321 # --filelist from stdin
322 cat .test.filenames | $(RUN_ENV) ./xxhsum$(EXT) --filelist
323 @$(RM) .test.*
324
325CC_VERSION := $(shell $(CC) --version 2>/dev/null)
326ifneq (,$(findstring clang,$(CC_VERSION)))
327fuzzer: CFLAGS += -fsanitize=fuzzer
328$(eval $(call c_program,fuzzer, fuzz/fuzzer.o xxhash.o))
329else
330fuzzer: this_target_requires_clang # intentional fail
331endif
332
333.PHONY: test-filename-escape
334test-filename-escape:
335 $(MAKE) -C tests test_filename_escape
336
337.PHONY: test-cli-comment-line
338test-cli-comment-line:
339 $(MAKE) -C tests test_cli_comment_line
340
341.PHONY: test-cli-ignore-missing
342test-cli-ignore-missing:
343 $(MAKE) -C tests test_cli_ignore_missing
344
345.PHONY: armtest
346armtest:
347 @echo ---- test ARM compilation ----
348 CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum
349
350.PHONY: arm64test
351arm64test:
352 @echo ---- test ARM64 compilation ----
353 CC=aarch64-linux-gnu-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum
354
355.PHONY: clangtest
356clangtest:
357 @echo ---- test clang compilation ----
358 CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all
359
360.PHONY: gcc-og-test
361gcc-og-test:
362 @echo ---- test gcc -Og compilation ----
363 CFLAGS="-Og -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC" CPPFLAGS="-DXXH_NO_INLINE_HINTS" MOREFLAGS="-Werror" $(MAKE) all
364
365.PHONY: cxxtest
366cxxtest:
367 @echo ---- test C++ compilation ----
368 CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC"
369
370# In strict C90 mode, there is no `long long` type support,
371# consequently, only XXH32 can be compiled.
372.PHONY: c90test
373ifeq ($(NO_C90_TEST),true)
374c90test:
375 @echo no c90 compatibility test
376else
377c90test: CPPFLAGS += -DXXH_NO_LONG_LONG
378c90test: CFLAGS += -std=c90 -Werror -pedantic
379c90test: xxhash.c
380 @echo ---- test strict C90 compilation [xxh32 only] ----
381 $(RM) xxhash.o
382 $(CC) $(FLAGS) $^ -c
383 $(NM) xxhash.o | $(GREP) XXH64 ; test $$? -eq 1
384 $(RM) xxhash.o
385endif
386
387.PHONY: noxxh3test
388noxxh3test: CPPFLAGS += -DXXH_NO_XXH3
389noxxh3test: CFLAGS += -Werror -pedantic -Wno-long-long # XXH64 requires long long support
390noxxh3test: OFILE = xxh_noxxh3.o
391noxxh3test: xxhash.c
392 @echo ---- test compilation without XXH3 ----
393 $(CC) $(FLAGS) -c $^ -o $(OFILE)
394 $(NM) $(OFILE) | $(GREP) XXH3_ ; test $$? -eq 1
395 $(RM) $(OFILE)
396
397.PHONY: nostreamtest
398nostreamtest: CPPFLAGS += -DXXH_NO_STREAM
399nostreamtest: CFLAGS += -Werror -pedantic -Wno-long-long # XXH64 requires long long support
400nostreamtest: OFILE = xxh_nostream.o
401nostreamtest: xxhash.c
402 @echo ---- test compilation without streaming ----
403 $(CC) $(FLAGS) -c $^ -o $(OFILE)
404 $(NM) $(OFILE) | $(GREP) update ; test $$? -eq 1
405 $(RM) $(OFILE)
406
407.PHONY: nostdlibtest
408nostdlibtest: CPPFLAGS += -DXXH_NO_STDLIB
409nostdlibtest: CFLAGS += -Werror -pedantic -Wno-long-long # XXH64 requires long long support
410nostdlibtest: OFILE = xxh_nostdlib.o
411nostdlibtest: xxhash.c
412 @echo ---- test compilation without \<stdlib.h\> ----
413 $(CC) $(FLAGS) -c $^ -o $(OFILE)
414 $(NM) $(OFILE) | $(GREP) "U _free\|U free" ; test $$? -eq 1
415 $(RM) $(OFILE)
416
417.PHONY: usan
418usan: CC=clang
419usan: CXX=clang++
420usan: ## check CLI runtime for undefined behavior, using clang's sanitizer
421 @echo ---- check undefined behavior - sanitize ----
422 $(MAKE) test CC=$(CC) CXX=$(CXX) MOREFLAGS="-g -fsanitize=undefined -fno-sanitize-recover=all"
423
424.PHONY: staticAnalyze
425SCANBUILD ?= scan-build
426staticAnalyze: clean ## check C source files using $(SCANBUILD) static analyzer
427 @echo ---- static analyzer - $(SCANBUILD) ----
428 CFLAGS="-g -Werror" $(SCANBUILD) --status-bugs -v $(MAKE) all
429
430CPPCHECK ?= cppcheck
431.PHONY: cppcheck
432cppcheck: ## check C source files using $(CPPCHECK) static analyzer
433 @echo ---- static analyzer - $(CPPCHECK) ----
434 $(CPPCHECK) . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
435
436.PHONY: namespaceTest
437namespaceTest: ## ensure XXH_NAMESPACE redefines all public symbols
438 $(CC) -c xxhash.c
439 $(CC) -DXXH_NAMESPACE=TEST_ -c xxhash.c -o xxhash2.o
440 $(CC) xxhash.o xxhash2.o $(CLI_SRCS) -o xxhsum2 # will fail if one namespace missing (symbol collision)
441 $(RM) *.o xxhsum2 # clean
442
443MAN = $(CLI_DIR)/xxhsum.1
444MD2ROFF ?= ronn
445MD2ROFF_FLAGS ?= --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)"
446$(MAN): $(CLI_DIR)/xxhsum.1.md xxhash.h
447 cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@
448
449.PHONY: man
450man: $(MAN) ## generate man page from markdown source
451
452.PHONY: clean-man
453clean-man:
454 $(RM) xxhsum.1
455
456.PHONY: preview-man
457preview-man: man
458 man ./xxhsum.1
459
460.PHONY: test
461test: DEBUGFLAGS += -DXXH_DEBUGLEVEL=1
462test: all namespaceTest check test-xxhsum-c c90test test-tools noxxh3test nostdlibtest
463
464# this test checks that including "xxhash.h" multiple times and with different directives still compiles properly
465.PHONY: test-multiInclude
466test-multiInclude:
467 $(MAKE) -C tests test_multiInclude
468
469.PHONY: test-inline-notexposed
470test-inline-notexposed: xxhsum_inlinedXXH
471 $(NM) xxhsum_inlinedXXH | $(GREP) "t _XXH32_" ; test $$? -eq 1 # no XXH32 symbol should be left
472 $(NM) xxhsum_inlinedXXH | $(GREP) "t _XXH64_" ; test $$? -eq 1 # no XXH64 symbol should be left
473
474.PHONY: test-inline
475test-inline: test-inline-notexposed test-multiInclude
476
477
478.PHONY: test-all
479test-all: CFLAGS += -Werror
480test-all: test test32 test-unicode clangtest gcc-og-test cxxtest usan test-inline listL120 trailingWhitespace test-xxh-nnn-sums
481
482.PHONY: test-tools
483test-tools:
484 CFLAGS=-Werror $(MAKE) -C tests/bench
485 CFLAGS=-Werror $(MAKE) -C tests/collisions check
486
487.PHONY: test-xxh-nnn-sums
488test-xxh-nnn-sums: xxhsum_and_links
489 ./xxhsum README.md > tmp.xxhsum.out # xxhsum outputs xxh64
490 ./xxh32sum README.md > tmp.xxh32sum.out
491 ./xxh64sum README.md > tmp.xxh64sum.out
492 ./xxh128sum README.md > tmp.xxh128sum.out
493 ./xxh3sum README.md > tmp.xxh3sum.out
494 cat tmp.xxhsum.out
495 cat tmp.xxh32sum.out
496 cat tmp.xxh64sum.out
497 cat tmp.xxh128sum.out
498 cat tmp.xxh3sum.out
499 ./xxhsum -c tmp.xxhsum.out
500 ./xxhsum -c tmp.xxh32sum.out
501 ./xxhsum -c tmp.xxh64sum.out
502 ./xxhsum -c tmp.xxh128sum.out
503 ./xxhsum -c tmp.xxh3sum.out
504 ./xxh32sum -c tmp.xxhsum.out ; test $$? -eq 1 # expects "no properly formatted"
505 ./xxh32sum -c tmp.xxh32sum.out
506 ./xxh32sum -c tmp.xxh64sum.out ; test $$? -eq 1 # expects "no properly formatted"
507 ./xxh32sum -c tmp.xxh128sum.out ; test $$? -eq 1 # expects "no properly formatted"
508 ./xxh32sum -c tmp.xxh3sum.out ; test $$? -eq 1 # expects "no properly formatted"
509 ./xxh64sum -c tmp.xxhsum.out
510 ./xxh64sum -c tmp.xxh32sum.out ; test $$? -eq 1 # expects "no properly formatted"
511 ./xxh64sum -c tmp.xxh64sum.out
512 ./xxh64sum -c tmp.xxh128sum.out ; test $$? -eq 1 # expects "no properly formatted"
513 ./xxh64sum -c tmp.xxh3sum.out ; test $$? -eq 1 # expects "no properly formatted"
514 ./xxh128sum -c tmp.xxhsum.out ; test $$? -eq 1 # expects "no properly formatted"
515 ./xxh128sum -c tmp.xxh32sum.out ; test $$? -eq 1 # expects "no properly formatted"
516 ./xxh128sum -c tmp.xxh64sum.out ; test $$? -eq 1 # expects "no properly formatted"
517 ./xxh128sum -c tmp.xxh128sum.out
518 ./xxh128sum -c tmp.xxh3sum.out ; test $$? -eq 1 # expects "no properly formatted"
519 ./xxh3sum -c tmp.xxhsum.out ; test $$? -eq 1 # expects "no properly formatted"
520 ./xxh3sum -c tmp.xxh32sum.out ; test $$? -eq 1 # expects "no properly formatted"
521 ./xxh3sum -c tmp.xxh64sum.out ; test $$? -eq 1 # expects "no properly formatted"
522 ./xxh3sum -c tmp.xxh128sum.out ; test $$? -eq 1 # expects "no properly formatted"
523 ./xxh3sum -c tmp.xxh3sum.out
524
525.PHONY: listL120
526listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note: $$, for Makefile compatibility)
527 find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done
528
529.PHONY: trailingWhitespace
530trailingWhitespace:
531 ! $(GREP) -E "`printf '[ \\t]$$'`" cli/*.c cli/*.h cli/*.1 *.c *.h LICENSE Makefile build/cmake/CMakeLists.txt
532
533.PHONY: lint-unicode
534lint-unicode:
535 ./tests/unicode_lint.sh
536
537# =========================================================
538# make install is validated only for the following targets
539# =========================================================
540ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU Haiku OpenBSD FreeBSD NetBSD DragonFly SunOS CYGWIN% , $(UNAME)))
541
542DESTDIR ?=
543# directory variables: GNU conventions prefer lowercase
544# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
545# support both lower and uppercase (BSD), use uppercase in script
546prefix ?= /usr/local
547PREFIX ?= $(prefix)
548exec_prefix ?= $(PREFIX)
549EXEC_PREFIX ?= $(exec_prefix)
550libdir ?= $(EXEC_PREFIX)/lib
551LIBDIR ?= $(libdir)
552includedir ?= $(PREFIX)/include
553INCLUDEDIR ?= $(includedir)
554bindir ?= $(EXEC_PREFIX)/bin
555BINDIR ?= $(bindir)
556datarootdir ?= $(PREFIX)/share
557mandir ?= $(datarootdir)/man
558man1dir ?= $(mandir)/man1
559
560ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
561PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
562else
563PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
564endif
565
566ifneq (,$(filter $(UNAME),OpenBSD NetBSD DragonFly SunOS))
567MANDIR ?= $(PREFIX)/man/man1
568else
569MANDIR ?= $(man1dir)
570endif
571
572ifneq (,$(filter $(UNAME),SunOS))
573INSTALL ?= ginstall
574else
575INSTALL ?= install
576endif
577
578INSTALL_PROGRAM ?= $(INSTALL)
579INSTALL_DATA ?= $(INSTALL) -m 644
580MAKE_DIR ?= $(INSTALL) -d -m 755
581
582
583# Escape special symbols by putting each character into its separate class
584EXEC_PREFIX_REGEX ?= $(shell echo "$(EXEC_PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g")
585PREFIX_REGEX ?= $(shell echo "$(PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g")
586
587PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX_REGEX)(/|$$)@@p")
588PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX_REGEX)(/|$$)@@p")
589PCEXECDIR?= $(if $(filter $(PREFIX),$(EXEC_PREFIX)),$$\{prefix\},$(EXEC_PREFIX))
590
591ifeq (,$(PCLIBDIR))
592# Additional prefix check is required, since the empty string is technically a
593# valid PCLIBDIR
594ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX_REGEX)(/|$$)@ p"))
595$(error configured libdir ($(LIBDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file)
596endif
597endif
598
599ifeq (,$(PCINCDIR))
600# Additional prefix check is required, since the empty string is technically a
601# valid PCINCDIR
602ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX_REGEX)(/|$$)@ p"))
603$(error configured includedir ($(INCLUDEDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file)
604endif
605endif
606
607libxxhash.pc: libxxhash.pc.in
608 @echo creating pkgconfig
609 $(SED) $(SED_ERE_OPT) -e 's|@PREFIX@|$(PREFIX)|' \
610 -e 's|@EXECPREFIX@|$(PCEXECDIR)|' \
611 -e 's|@LIBDIR@|$$\{exec_prefix\}/$(PCLIBDIR)|' \
612 -e 's|@INCLUDEDIR@|$$\{prefix\}/$(PCINCDIR)|' \
613 -e 's|@VERSION@|$(LIBVER)|' \
614 $< > $@
615
616
617install_libxxhash.a: libxxhash.a
618 @echo Installing libxxhash.a
619 $(MAKE_DIR) $(DESTDIR)$(LIBDIR)
620 $(INSTALL_DATA) libxxhash.a $(DESTDIR)$(LIBDIR)
621
622install_libxxhash: libxxhash
623 @echo Installing libxxhash
624 $(MAKE_DIR) $(DESTDIR)$(LIBDIR)
625 $(INSTALL_PROGRAM) $(LIBXXH) $(DESTDIR)$(LIBDIR)
626 ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
627 ln -sf libxxhash.$(SHARED_EXT_MAJOR) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
628
629install_libxxhash.includes:
630 $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR) # includes
631 $(INSTALL_DATA) xxhash.h $(DESTDIR)$(INCLUDEDIR)
632 $(INSTALL_DATA) xxh3.h $(DESTDIR)$(INCLUDEDIR) # for compatibility, will be removed in v0.9.0
633ifeq ($(LIBXXH_DISPATCH),1)
634 $(INSTALL_DATA) xxh_x86dispatch.h $(DESTDIR)$(INCLUDEDIR)
635endif
636
637install_libxxhash.pc: libxxhash.pc
638 @echo Installing pkgconfig
639 $(MAKE_DIR) $(DESTDIR)$(PKGCONFIGDIR)/
640 $(INSTALL_DATA) libxxhash.pc $(DESTDIR)$(PKGCONFIGDIR)/
641
642install_xxhsum: xxhsum
643 @echo Installing xxhsum
644 $(MAKE_DIR) $(DESTDIR)$(BINDIR)/
645 $(INSTALL_PROGRAM) xxhsum$(EXT) $(DESTDIR)$(BINDIR)/xxhsum$(EXT)
646 ln -sf xxhsum$(EXT) $(DESTDIR)$(BINDIR)/xxh32sum$(EXT)
647 ln -sf xxhsum$(EXT) $(DESTDIR)$(BINDIR)/xxh64sum$(EXT)
648 ln -sf xxhsum$(EXT) $(DESTDIR)$(BINDIR)/xxh128sum$(EXT)
649 ln -sf xxhsum$(EXT) $(DESTDIR)$(BINDIR)/xxh3sum$(EXT)
650
651install_man:
652 @echo Installing man pages
653 $(MAKE_DIR) $(DESTDIR)$(MANDIR)/
654 $(INSTALL_DATA) $(MAN) $(DESTDIR)$(MANDIR)/xxhsum.1
655 ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh32sum.1
656 ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh64sum.1
657 ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh128sum.1
658 ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh3sum.1
659
660.PHONY: install
661## install libraries, CLI, links and man pages
662install: install_libxxhash.a install_libxxhash install_libxxhash.includes install_libxxhash.pc install_xxhsum install_man
663 @echo xxhash installation completed
664
665.PHONY: uninstall
666uninstall: ## uninstall libraries, CLI, links and man page
667 $(RM) $(DESTDIR)$(LIBDIR)/libxxhash.a
668 $(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
669 $(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
670 $(RM) $(DESTDIR)$(LIBDIR)/$(LIBXXH)
671 $(RM) $(DESTDIR)$(INCLUDEDIR)/xxhash.h
672 $(RM) $(DESTDIR)$(INCLUDEDIR)/xxh3.h
673 $(RM) $(DESTDIR)$(INCLUDEDIR)/xxh_x86dispatch.h
674 $(RM) $(DESTDIR)$(PKGCONFIGDIR)/libxxhash.pc
675 $(RM) $(DESTDIR)$(BINDIR)/xxh32sum
676 $(RM) $(DESTDIR)$(BINDIR)/xxh64sum
677 $(RM) $(DESTDIR)$(BINDIR)/xxh128sum
678 $(RM) $(DESTDIR)$(BINDIR)/xxh3sum
679 $(RM) $(DESTDIR)$(BINDIR)/xxhsum
680 $(RM) $(DESTDIR)$(MANDIR)/xxh32sum.1
681 $(RM) $(DESTDIR)$(MANDIR)/xxh64sum.1
682 $(RM) $(DESTDIR)$(MANDIR)/xxh128sum.1
683 $(RM) $(DESTDIR)$(MANDIR)/xxh3sum.1
684 $(RM) $(DESTDIR)$(MANDIR)/xxhsum.1
685 @echo xxhsum successfully uninstalled
686
687endif