2018-11-08 11:52:06 +00:00
|
|
|
# ################################################################
|
|
|
|
# xxHash Makefile
|
2021-05-16 07:51:17 +00:00
|
|
|
# Copyright (C) 2012-2020 Yann Collet
|
2018-11-08 11:52:06 +00:00
|
|
|
#
|
|
|
|
# GPL v2 License
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2021-05-16 07:51:17 +00:00
|
|
|
# You can contact the author at:
|
|
|
|
# - xxHash homepage: https://www.xxhash.com
|
|
|
|
# - xxHash source repository: https://github.com/Cyan4973/xxHash
|
2018-11-08 11:52:06 +00:00
|
|
|
# ################################################################
|
2021-05-16 07:51:17 +00:00
|
|
|
# xxhsum: provides 32/64 bits hash of one or multiple files, or stdin
|
2018-11-08 11:52:06 +00:00
|
|
|
# ################################################################
|
2021-05-16 07:51:17 +00:00
|
|
|
Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
# Version numbers
|
2021-05-16 07:51:17 +00:00
|
|
|
SED ?= sed
|
|
|
|
SED_ERE_OPT ?= -E
|
|
|
|
LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
|
|
|
|
LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define XXH_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
|
|
|
|
LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define XXH_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
|
2018-11-08 11:52:06 +00:00
|
|
|
LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
|
|
|
|
LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
|
|
|
|
LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
|
|
|
|
LIBVER := $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
CFLAGS ?= -O3
|
|
|
|
DEBUGFLAGS+=-Wall -Wextra -Wconversion -Wcast-qual -Wcast-align -Wshadow \
|
|
|
|
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
|
|
|
|
-Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
|
|
|
|
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
|
|
|
|
-Wredundant-decls -Wstrict-overflow=2
|
|
|
|
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
|
|
|
|
FLAGS = $(CFLAGS) $(CPPFLAGS)
|
|
|
|
XXHSUM_VERSION = $(LIBVER)
|
|
|
|
UNAME := $(shell uname)
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
# Define *.exe as extension for Windows systems
|
|
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
|
|
EXT =.exe
|
|
|
|
else
|
|
|
|
EXT =
|
|
|
|
endif
|
|
|
|
|
|
|
|
# OS X linker doesn't support -soname, and use different extension
|
2021-05-16 07:51:17 +00:00
|
|
|
# see: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
|
|
|
|
ifeq ($(UNAME), Darwin)
|
2018-11-08 11:52:06 +00:00
|
|
|
SHARED_EXT = dylib
|
|
|
|
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
|
|
|
|
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
|
|
|
|
SONAME_FLAGS = -install_name $(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
|
|
|
|
else
|
|
|
|
SONAME_FLAGS = -Wl,-soname=libxxhash.$(SHARED_EXT).$(LIBVER_MAJOR)
|
|
|
|
SHARED_EXT = so
|
|
|
|
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
|
|
|
|
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
|
|
|
|
endif
|
|
|
|
|
|
|
|
LIBXXH = libxxhash.$(SHARED_EXT_VER)
|
|
|
|
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
## generate CLI and libraries in release mode (default for `make`)
|
2018-11-08 11:52:06 +00:00
|
|
|
.PHONY: default
|
2021-05-16 07:51:17 +00:00
|
|
|
default: DEBUGFLAGS=
|
2018-11-08 11:52:06 +00:00
|
|
|
default: lib xxhsum_and_links
|
|
|
|
|
|
|
|
.PHONY: all
|
|
|
|
all: lib xxhsum xxhsum_inlinedXXH
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
## xxhsum is the command line interface (CLI)
|
|
|
|
ifeq ($(DISPATCH),1)
|
|
|
|
xxhsum: CPPFLAGS += -DXXHSUM_DISPATCH=1
|
|
|
|
xxhsum: xxh_x86dispatch.o
|
|
|
|
endif
|
|
|
|
xxhsum: xxhash.o xxhsum.o
|
|
|
|
$(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
|
|
|
|
|
|
|
|
xxhsum32: CFLAGS += -m32 ## generate CLI in 32-bits mode
|
|
|
|
xxhsum32: xxhash.c xxhsum.c ## do not generate object (avoid mixing different ABI)
|
|
|
|
$(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
|
|
|
|
|
|
|
|
## dispatch only works for x86/x64 systems
|
|
|
|
dispatch: CPPFLAGS += -DXXHSUM_DISPATCH=1
|
|
|
|
dispatch: xxhash.o xxh_x86dispatch.o xxhsum.c
|
|
|
|
$(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
|
|
|
|
|
|
|
|
xxhash.o: xxhash.c xxhash.h
|
|
|
|
xxhsum.o: xxhsum.c xxhash.h xxh_x86dispatch.h
|
|
|
|
xxh_x86dispatch.o: xxh_x86dispatch.c xxh_x86dispatch.h xxhash.h
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
.PHONY: xxhsum_and_links
|
2021-05-16 07:51:17 +00:00
|
|
|
xxhsum_and_links: xxhsum xxh32sum xxh64sum xxh128sum
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
xxh32sum xxh64sum xxh128sum: xxhsum
|
|
|
|
ln -sf $<$(EXT) $@$(EXT)
|
|
|
|
|
|
|
|
xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL
|
2018-11-08 11:52:06 +00:00
|
|
|
xxhsum_inlinedXXH: xxhsum.c
|
2021-05-16 07:51:17 +00:00
|
|
|
$(CC) $(FLAGS) $^ -o $@$(EXT)
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
# library
|
|
|
|
|
|
|
|
libxxhash.a: ARFLAGS = rcs
|
|
|
|
libxxhash.a: xxhash.o
|
2021-05-16 07:51:17 +00:00
|
|
|
$(AR) $(ARFLAGS) $@ $^
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
$(LIBXXH): LDFLAGS += -shared
|
|
|
|
ifeq (,$(filter Windows%,$(OS)))
|
2021-05-16 07:51:17 +00:00
|
|
|
$(LIBXXH): CFLAGS += -fPIC
|
|
|
|
endif
|
|
|
|
ifeq ($(DISPATCH),1)
|
|
|
|
$(LIBXXH): xxh_x86dispatch.c
|
2018-11-08 11:52:06 +00:00
|
|
|
endif
|
|
|
|
$(LIBXXH): xxhash.c
|
2021-05-16 07:51:17 +00:00
|
|
|
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
|
|
|
ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR)
|
|
|
|
ln -sf $@ libxxhash.$(SHARED_EXT)
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: libxxhash
|
|
|
|
libxxhash: ## generate dynamic xxhash library
|
|
|
|
libxxhash: $(LIBXXH)
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: lib
|
|
|
|
lib: ## generate static and dynamic xxhash libraries
|
2018-11-08 11:52:06 +00:00
|
|
|
lib: libxxhash.a libxxhash
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
# helper targets
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
AWK = awk
|
|
|
|
GREP = grep
|
|
|
|
SORT = sort
|
|
|
|
|
|
|
|
.PHONY: list
|
|
|
|
list: ## list all Makefile targets
|
|
|
|
$(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
|
|
|
|
|
|
|
|
.PHONY: help
|
|
|
|
help: ## list documented targets
|
|
|
|
$(Q)$(GREP) -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
|
|
|
|
$(SORT) | \
|
|
|
|
$(AWK) 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean: ## remove all build artifacts
|
|
|
|
$(Q)$(RM) -r *.dSYM # Mac OS-X specific
|
|
|
|
$(Q)$(RM) core *.o *.$(SHARED_EXT) *.$(SHARED_EXT).* *.a libxxhash.pc
|
|
|
|
$(Q)$(RM) xxhsum$(EXT) xxhsum32$(EXT) xxhsum_inlinedXXH$(EXT) dispatch$(EXT)
|
|
|
|
$(Q)$(RM) xxh32sum$(EXT) xxh64sum$(EXT) xxh128sum$(EXT)
|
|
|
|
@echo cleaning completed
|
|
|
|
|
|
|
|
|
|
|
|
# =================================================
|
2018-11-08 11:52:06 +00:00
|
|
|
# tests
|
2021-05-16 07:51:17 +00:00
|
|
|
# =================================================
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
# make check can be run with cross-compiled binaries on emulated environments (qemu user mode)
|
|
|
|
# by setting $(RUN_ENV) to the target emulation environment
|
2018-11-08 11:52:06 +00:00
|
|
|
.PHONY: check
|
2021-05-16 07:51:17 +00:00
|
|
|
check: xxhsum ## basic tests for xxhsum CLI, set RUN_ENV for emulated environments
|
2018-11-08 11:52:06 +00:00
|
|
|
# stdin
|
2021-05-16 07:51:17 +00:00
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) < xxhash.c
|
2018-11-08 11:52:06 +00:00
|
|
|
# multiple files
|
2021-05-16 07:51:17 +00:00
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) xxhash.* xxhsum.*
|
2018-11-08 11:52:06 +00:00
|
|
|
# internal bench
|
2021-05-16 07:51:17 +00:00
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -bi0
|
|
|
|
# long bench command
|
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) --benchmark-all -i0
|
|
|
|
# bench multiple variants
|
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -b1,2,3 -i0
|
2018-11-08 11:52:06 +00:00
|
|
|
# file bench
|
2021-05-16 07:51:17 +00:00
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -bi0 xxhash.c
|
|
|
|
# 32-bit
|
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -H0 xxhash.c
|
|
|
|
# 128-bit
|
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -H2 xxhash.c
|
|
|
|
# request incorrect variant
|
|
|
|
$(RUN_ENV) ./xxhsum$(EXT) -H9 xxhash.c ; test $$? -eq 1
|
|
|
|
@printf "\n ....... checks completed successfully ....... \n"
|
|
|
|
|
|
|
|
.PHONY: test-unicode
|
|
|
|
test-unicode:
|
|
|
|
$(MAKE) -C tests test_unicode
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
.PHONY: test-mem
|
2021-05-16 07:51:17 +00:00
|
|
|
VALGRIND = valgrind --leak-check=yes --error-exitcode=1
|
|
|
|
test-mem: RUN_ENV = $(VALGRIND)
|
|
|
|
test-mem: xxhsum check
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
.PHONY: test32
|
|
|
|
test32: clean xxhsum32
|
|
|
|
@echo ---- test 32-bit ----
|
|
|
|
./xxhsum32 -bi1 xxhash.c
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: test-xxhsum-c
|
2018-11-08 11:52:06 +00:00
|
|
|
test-xxhsum-c: xxhsum
|
|
|
|
# xxhsum to/from pipe
|
2021-05-16 07:51:17 +00:00
|
|
|
./xxhsum xxh* | ./xxhsum -c -
|
|
|
|
./xxhsum -H0 xxh* | ./xxhsum -c -
|
|
|
|
# xxhsum -q does not display "Loading" message into stderr (#251)
|
|
|
|
! ./xxhsum -q xxh* 2>&1 | grep Loading
|
|
|
|
# xxhsum does not display "Loading" message into stderr either
|
|
|
|
! ./xxhsum xxh* 2>&1 | grep Loading
|
|
|
|
# Check that xxhsum do display filename that it failed to open.
|
|
|
|
LC_ALL=C ./xxhsum nonexistent 2>&1 | grep "Error: Could not open 'nonexistent'"
|
2018-11-08 11:52:06 +00:00
|
|
|
# xxhsum to/from file, shell redirection
|
2021-05-16 07:51:17 +00:00
|
|
|
./xxhsum xxh* > .test.xxh64
|
|
|
|
./xxhsum --tag xxh* > .test.xxh64_tag
|
|
|
|
./xxhsum --little-endian xxh* > .test.le_xxh64
|
|
|
|
./xxhsum --tag --little-endian xxh* > .test.le_xxh64_tag
|
|
|
|
./xxhsum -H0 xxh* > .test.xxh32
|
|
|
|
./xxhsum -H0 --tag xxh* > .test.xxh32_tag
|
|
|
|
./xxhsum -H0 --little-endian xxh* > .test.le_xxh32
|
|
|
|
./xxhsum -H0 --tag --little-endian xxh* > .test.le_xxh32_tag
|
|
|
|
./xxhsum -H2 xxh* > .test.xxh128
|
|
|
|
./xxhsum -H2 --tag xxh* > .test.xxh128_tag
|
|
|
|
./xxhsum -H2 --little-endian xxh* > .test.le_xxh128
|
|
|
|
./xxhsum -H2 --tag --little-endian xxh* > .test.le_xxh128_tag
|
|
|
|
./xxhsum -c .test.xxh*
|
|
|
|
./xxhsum -c --little-endian .test.le_xxh*
|
|
|
|
./xxhsum -c .test.*_tag
|
|
|
|
# read list of files from stdin
|
2018-11-08 11:52:06 +00:00
|
|
|
./xxhsum -c < .test.xxh64
|
|
|
|
./xxhsum -c < .test.xxh32
|
2021-05-16 07:51:17 +00:00
|
|
|
cat .test.xxh* | ./xxhsum -c -
|
|
|
|
# check variant with '*' marker as second separator
|
|
|
|
$(SED) 's/ / \*/' .test.xxh32 | ./xxhsum -c
|
|
|
|
# bsd-style output
|
|
|
|
./xxhsum --tag xxhsum* | $(GREP) XXH64
|
|
|
|
./xxhsum --tag -H0 xxhsum* | $(GREP) XXH32
|
|
|
|
./xxhsum --tag -H1 xxhsum* | $(GREP) XXH64
|
|
|
|
./xxhsum --tag -H2 xxhsum* | $(GREP) XXH128
|
|
|
|
./xxhsum --tag -H32 xxhsum* | $(GREP) XXH32
|
|
|
|
./xxhsum --tag -H64 xxhsum* | $(GREP) XXH64
|
|
|
|
./xxhsum --tag -H128 xxhsum* | $(GREP) XXH128
|
|
|
|
./xxhsum --tag -H0 --little-endian xxhsum* | $(GREP) XXH32_LE
|
|
|
|
./xxhsum --tag -H1 --little-endian xxhsum* | $(GREP) XXH64_LE
|
|
|
|
./xxhsum --tag -H2 --little-endian xxhsum* | $(GREP) XXH128_LE
|
|
|
|
./xxhsum --tag -H32 --little-endian xxhsum* | $(GREP) XXH32_LE
|
|
|
|
./xxhsum --tag -H64 --little-endian xxhsum* | $(GREP) XXH64_LE
|
|
|
|
./xxhsum --tag -H128 --little-endian xxhsum* | $(GREP) XXH128_LE
|
|
|
|
# check bsd-style
|
|
|
|
./xxhsum --tag xxhsum* | ./xxhsum -c
|
|
|
|
./xxhsum --tag -H32 --little-endian xxhsum* | ./xxhsum -c
|
2018-11-08 11:52:06 +00:00
|
|
|
# xxhsum -c warns improperly format lines.
|
2021-05-16 07:51:17 +00:00
|
|
|
echo '12345678 ' >>.test.xxh32
|
|
|
|
./xxhsum -c .test.xxh32 | $(GREP) improperly
|
|
|
|
echo '123456789 file' >>.test.xxh64
|
|
|
|
./xxhsum -c .test.xxh64 | $(GREP) improperly
|
2018-11-08 11:52:06 +00:00
|
|
|
# Expects "FAILED"
|
|
|
|
echo "0000000000000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
|
|
|
|
echo "00000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
|
|
|
|
# Expects "FAILED open or read"
|
|
|
|
echo "0000000000000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
|
|
|
|
echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
|
2021-05-16 07:51:17 +00:00
|
|
|
@$(RM) .test.*
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: armtest
|
2018-11-08 11:52:06 +00:00
|
|
|
armtest: clean
|
|
|
|
@echo ---- test ARM compilation ----
|
2021-05-16 07:51:17 +00:00
|
|
|
CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: clangtest
|
2018-11-08 11:52:06 +00:00
|
|
|
clangtest: clean
|
|
|
|
@echo ---- test clang compilation ----
|
2021-05-16 07:51:17 +00:00
|
|
|
CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: cxxtest
|
|
|
|
cxxtest: clean
|
|
|
|
@echo ---- test C++ compilation ----
|
|
|
|
CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC"
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: c90test
|
|
|
|
ifeq ($(NO_C90_TEST),true)
|
|
|
|
c90test:
|
|
|
|
@echo no c90 compatibility test
|
|
|
|
else
|
|
|
|
c90test: CPPFLAGS += -DXXH_NO_LONG_LONG
|
|
|
|
c90test: CFLAGS += -std=c90 -Werror -pedantic
|
|
|
|
c90test: xxhash.c
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo ---- test strict C90 compilation [xxh32 only] ----
|
|
|
|
$(RM) xxhash.o
|
2021-05-16 07:51:17 +00:00
|
|
|
$(CC) $(FLAGS) $^ $(LDFLAGS) -c
|
|
|
|
$(RM) xxhash.o
|
|
|
|
endif
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: usan
|
2018-11-08 11:52:06 +00:00
|
|
|
usan: CC=clang
|
2021-05-16 07:51:17 +00:00
|
|
|
usan: CXX=clang++
|
|
|
|
usan: ## check CLI runtime for undefined behavior, using clang's sanitizer
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo ---- check undefined behavior - sanitize ----
|
2021-05-16 07:51:17 +00:00
|
|
|
$(MAKE) clean
|
|
|
|
$(MAKE) test CC=$(CC) CXX=$(CXX) MOREFLAGS="-g -fsanitize=undefined -fno-sanitize-recover=all"
|
|
|
|
|
|
|
|
.PHONY: staticAnalyze
|
|
|
|
SCANBUILD ?= scan-build
|
|
|
|
staticAnalyze: clean ## check C source files using $(SCANBUILD) static analyzer
|
|
|
|
@echo ---- static analyzer - $(SCANBUILD) ----
|
|
|
|
CFLAGS="-g -Werror" $(SCANBUILD) --status-bugs -v $(MAKE) all
|
|
|
|
|
|
|
|
CPPCHECK ?= cppcheck
|
|
|
|
.PHONY: cppcheck
|
|
|
|
cppcheck: ## check C source files using $(CPPCHECK) static analyzer
|
|
|
|
@echo ---- static analyzer - $(CPPCHECK) ----
|
|
|
|
$(CPPCHECK) . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
|
|
|
|
|
|
|
|
.PHONY: namespaceTest
|
|
|
|
namespaceTest: ## ensure XXH_NAMESPACE redefines all public symbols
|
2018-11-08 11:52:06 +00:00
|
|
|
$(CC) -c xxhash.c
|
|
|
|
$(CC) -DXXH_NAMESPACE=TEST_ -c xxhash.c -o xxhash2.o
|
|
|
|
$(CC) xxhash.o xxhash2.o xxhsum.c -o xxhsum2 # will fail if one namespace missing (symbol collision)
|
|
|
|
$(RM) *.o xxhsum2 # clean
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
MD2ROFF ?= ronn
|
|
|
|
MD2ROFF_FLAGS ?= --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)"
|
|
|
|
xxhsum.1: xxhsum.1.md xxhash.h
|
|
|
|
cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: man
|
|
|
|
man: xxhsum.1 ## generate man page from markdown source
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: clean-man
|
2018-11-08 11:52:06 +00:00
|
|
|
clean-man:
|
|
|
|
$(RM) xxhsum.1
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: preview-man
|
|
|
|
preview-man: man
|
2018-11-08 11:52:06 +00:00
|
|
|
man ./xxhsum.1
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: test
|
|
|
|
test: DEBUGFLAGS += -DXXH_DEBUGLEVEL=1
|
|
|
|
test: all namespaceTest check test-xxhsum-c c90test test-tools
|
|
|
|
|
|
|
|
.PHONY: test-inline
|
|
|
|
test-inline:
|
|
|
|
$(MAKE) -C tests test_multiInclude
|
2018-11-08 11:52:06 +00:00
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
.PHONY: test-all
|
|
|
|
test-all: CFLAGS += -Werror
|
|
|
|
test-all: test test32 clangtest cxxtest usan test-inline listL120 trailingWhitespace test-unicode
|
|
|
|
|
|
|
|
.PHONY: test-tools
|
|
|
|
test-tools:
|
|
|
|
CFLAGS=-Werror $(MAKE) -C tests/bench
|
|
|
|
CFLAGS=-Werror $(MAKE) -C tests/collisions
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
.PHONY: listL120
|
2021-05-16 07:51:17 +00:00
|
|
|
listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note: $$, for Makefile compatibility)
|
2018-11-08 11:52:06 +00:00
|
|
|
find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done
|
|
|
|
|
|
|
|
.PHONY: trailingWhitespace
|
|
|
|
trailingWhitespace:
|
2021-05-16 07:51:17 +00:00
|
|
|
! $(GREP) -E "`printf '[ \\t]$$'`" xxhsum.1 *.c *.h LICENSE Makefile cmake_unofficial/CMakeLists.txt
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
# =========================================================
|
2018-11-08 11:52:06 +00:00
|
|
|
# make install is validated only for the following targets
|
2021-05-16 07:51:17 +00:00
|
|
|
# =========================================================
|
|
|
|
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS CYGWIN% , $(UNAME)))
|
2018-11-08 11:52:06 +00:00
|
|
|
|
|
|
|
DESTDIR ?=
|
2021-05-16 07:51:17 +00:00
|
|
|
# directory variables: GNU conventions prefer lowercase
|
2018-11-08 11:52:06 +00:00
|
|
|
# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
|
|
|
|
# support both lower and uppercase (BSD), use uppercase in script
|
|
|
|
prefix ?= /usr/local
|
|
|
|
PREFIX ?= $(prefix)
|
|
|
|
exec_prefix ?= $(PREFIX)
|
2021-05-16 07:51:17 +00:00
|
|
|
EXEC_PREFIX ?= $(exec_prefix)
|
|
|
|
libdir ?= $(EXEC_PREFIX)/lib
|
2018-11-08 11:52:06 +00:00
|
|
|
LIBDIR ?= $(libdir)
|
|
|
|
includedir ?= $(PREFIX)/include
|
|
|
|
INCLUDEDIR ?= $(includedir)
|
2021-05-16 07:51:17 +00:00
|
|
|
bindir ?= $(EXEC_PREFIX)/bin
|
2018-11-08 11:52:06 +00:00
|
|
|
BINDIR ?= $(bindir)
|
|
|
|
datarootdir ?= $(PREFIX)/share
|
|
|
|
mandir ?= $(datarootdir)/man
|
|
|
|
man1dir ?= $(mandir)/man1
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
ifneq (,$(filter $(UNAME),FreeBSD NetBSD DragonFly))
|
|
|
|
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
|
|
|
|
else
|
|
|
|
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq (,$(filter $(UNAME),OpenBSD FreeBSD NetBSD DragonFly SunOS))
|
2018-11-08 11:52:06 +00:00
|
|
|
MANDIR ?= $(PREFIX)/man/man1
|
|
|
|
else
|
|
|
|
MANDIR ?= $(man1dir)
|
|
|
|
endif
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
ifneq (,$(filter $(UNAME),SunOS))
|
2018-11-08 11:52:06 +00:00
|
|
|
INSTALL ?= ginstall
|
|
|
|
else
|
|
|
|
INSTALL ?= install
|
|
|
|
endif
|
|
|
|
|
|
|
|
INSTALL_PROGRAM ?= $(INSTALL)
|
|
|
|
INSTALL_DATA ?= $(INSTALL) -m 644
|
|
|
|
|
|
|
|
|
2021-05-16 07:51:17 +00:00
|
|
|
PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX)(/|$$)@@p")
|
|
|
|
PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX)(/|$$)@@p")
|
|
|
|
PCEXECDIR?= $(if $(filter $(PREFIX),$(EXEC_PREFIX)),$$\{prefix\},$(EXEC_PREFIX))
|
|
|
|
|
|
|
|
ifeq (,$(PCLIBDIR))
|
|
|
|
# Additional prefix check is required, since the empty string is technically a
|
|
|
|
# valid PCLIBDIR
|
|
|
|
ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX)(/|$$)@ p"))
|
|
|
|
$(error configured libdir ($(LIBDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq (,$(PCINCDIR))
|
|
|
|
# Additional prefix check is required, since the empty string is technically a
|
|
|
|
# valid PCINCDIR
|
|
|
|
ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX)(/|$$)@ p"))
|
|
|
|
$(error configured includedir ($(INCLUDEDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
libxxhash.pc: libxxhash.pc.in
|
|
|
|
@echo creating pkgconfig
|
|
|
|
$(Q)$(SED) $(SED_ERE_OPT) -e 's|@PREFIX@|$(PREFIX)|' \
|
|
|
|
-e 's|@EXECPREFIX@|$(PCEXECDIR)|' \
|
|
|
|
-e 's|@LIBDIR@|$(PCLIBDIR)|' \
|
|
|
|
-e 's|@INCLUDEDIR@|$(PCINCDIR)|' \
|
|
|
|
-e 's|@VERSION@|$(VERSION)|' \
|
|
|
|
$< > $@
|
|
|
|
|
|
|
|
|
2018-11-08 11:52:06 +00:00
|
|
|
.PHONY: install
|
2021-05-16 07:51:17 +00:00
|
|
|
install: lib libxxhash.pc xxhsum ## install libraries, CLI, links and man page
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo Installing libxxhash
|
2021-05-16 07:51:17 +00:00
|
|
|
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)
|
|
|
|
$(Q)$(INSTALL_DATA) libxxhash.a $(DESTDIR)$(LIBDIR)
|
|
|
|
$(Q)$(INSTALL_PROGRAM) $(LIBXXH) $(DESTDIR)$(LIBDIR)
|
|
|
|
$(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
|
|
|
|
$(Q)ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
|
|
|
|
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR) # includes
|
|
|
|
$(Q)$(INSTALL_DATA) xxhash.h $(DESTDIR)$(INCLUDEDIR)
|
|
|
|
$(Q)$(INSTALL_DATA) xxh3.h $(DESTDIR)$(INCLUDEDIR) # for compatibility, will be removed in v0.9.0
|
|
|
|
ifeq ($(DISPATCH),1)
|
|
|
|
$(Q)$(INSTALL_DATA) xxh_x86dispatch.h $(DESTDIR)$(INCLUDEDIR)
|
|
|
|
endif
|
|
|
|
@echo Installing pkgconfig
|
|
|
|
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
|
|
|
|
$(Q)$(INSTALL_DATA) libxxhash.pc $(DESTDIR)$(PKGCONFIGDIR)/
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo Installing xxhsum
|
2021-05-16 07:51:17 +00:00
|
|
|
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
|
|
|
|
$(Q)$(INSTALL_PROGRAM) xxhsum $(DESTDIR)$(BINDIR)/xxhsum
|
|
|
|
$(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh32sum
|
|
|
|
$(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh64sum
|
|
|
|
$(Q)ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh128sum
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo Installing man pages
|
2021-05-16 07:51:17 +00:00
|
|
|
$(Q)$(INSTALL_DATA) xxhsum.1 $(DESTDIR)$(MANDIR)/xxhsum.1
|
|
|
|
$(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh32sum.1
|
|
|
|
$(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh64sum.1
|
|
|
|
$(Q)ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh128sum.1
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo xxhash installation completed
|
|
|
|
|
|
|
|
.PHONY: uninstall
|
2021-05-16 07:51:17 +00:00
|
|
|
uninstall: ## uninstall libraries, CLI, links and man page
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.a
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/$(LIBXXH)
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxhash.h
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh3.h
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/xxh_x86dispatch.h
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libxxhash.pc
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh32sum
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh64sum
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(BINDIR)/xxh128sum
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(BINDIR)/xxhsum
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh32sum.1
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh64sum.1
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(MANDIR)/xxh128sum.1
|
|
|
|
$(Q)$(RM) $(DESTDIR)$(MANDIR)/xxhsum.1
|
2018-11-08 11:52:06 +00:00
|
|
|
@echo xxhsum successfully uninstalled
|
|
|
|
|
|
|
|
endif
|