Debian Codegraph @

ext/xxHash/Makefile

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