xxHash/Makefile

356 lines
12 KiB
Makefile
Raw Normal View History

# ################################################################
# xxHash Makefile
2015-05-04 21:56:53 +00:00
# Copyright (C) Yann Collet 2012-2015
#
# 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.
#
# You can contact the author at :
# - xxHash source repository : http://code.google.com/p/xxhash/
# ################################################################
# xxhsum : provides 32/64 bits hash of one or multiple files, or stdin
# ################################################################
# Version numbers
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`
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)
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=5
CFLAGS += $(DEBUGFLAGS)
FLAGS = $(CFLAGS) $(CPPFLAGS) $(MOREFLAGS)
XXHSUM_VERSION = $(LIBVER)
2014-09-25 20:22:59 +00:00
# Define *.exe as extension for Windows systems
ifneq (,$(filter Windows%,$(OS)))
EXT =.exe
else
2014-09-25 20:22:59 +00:00
EXT =
endif
# OS X linker doesn't support -soname, and use different extension
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
ifeq ($(shell uname), Darwin)
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)
2017-09-08 08:24:43 +00:00
.PHONY: default
default: ## generate CLI and libraries in release mode (default for `make`)
default: DEBUGFLAGS=
default: lib xxhsum_and_links
2017-09-08 08:24:43 +00:00
.PHONY: all
all: lib xxhsum xxhsum_inlinedXXH
xxhsum: xxhash.o xxhsum.o ## generate command line interface (CLI)
xxhsum32: CFLAGS += -m32 ## generate CLI in 32-bits mode
xxhsum32: xxhash.c xxhsum.c
$(CC) $(FLAGS) $^ $(LDFLAGS) -o $@$(EXT)
xxhash.o: xxhash.h xxh3.h
xxhsum.o: xxhash.h
.PHONY: xxhsum_and_links
xxhsum_and_links: xxhsum xxh32sum xxh64sum
xxh32sum xxh64sum: xxhsum
ln -sf $^ $@
xxhsum_inlinedXXH: CPPFLAGS += -DXXH_INLINE_ALL
xxhsum_inlinedXXH: xxhsum.c
$(CC) $(FLAGS) $^ -o $@$(EXT)
2016-01-04 07:32:38 +00:00
# library
libxxhash.a: ARFLAGS = rcs
libxxhash.a: xxhash.o
$(AR) $(ARFLAGS) $@ $^
$(LIBXXH): LDFLAGS += -shared
2018-03-20 18:16:26 +00:00
ifeq (,$(filter Windows%,$(OS)))
$(LIBXXH): CFLAGS += -fPIC
endif
$(LIBXXH): xxhash.c
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
ln -sf $@ libxxhash.$(SHARED_EXT_MAJOR)
ln -sf $@ libxxhash.$(SHARED_EXT)
.PHONY: libxxhash
libxxhash: ## generate dynamic xxhash library
libxxhash: $(LIBXXH)
.PHONY: lib
lib: ## generate static and dynamic xxhash libraries
lib: libxxhash.a libxxhash
# helper targets
AWK = awk
GREP = grep
SORT = sort
.PHONY: list
list: ## list all Makefile targets
@$(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
@$(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
@$(RM) -r *.dSYM # Mac OS-X specific
@$(RM) core *.o libxxhash.*
@$(RM) xxhsum$(EXT) xxhsum32$(EXT) xxhsum_inlinedXXH$(EXT) xxh32sum xxh64sum
@echo cleaning completed
# =================================================
# tests
# =================================================
2019-03-12 19:44:42 +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
.PHONY: check
check: xxhsum ## basic tests for xxhsum CLI, set RUN_ENV for emulated environments
# stdin
2019-03-12 19:44:42 +00:00
$(RUN_ENV) ./xxhsum < xxhash.c
# multiple files
2019-03-12 19:44:42 +00:00
$(RUN_ENV) ./xxhsum xxhash.* xxhsum.*
# internal bench
2019-03-12 19:44:42 +00:00
$(RUN_ENV) ./xxhsum -bi1
# file bench
2019-03-12 19:44:42 +00:00
$(RUN_ENV) ./xxhsum -bi1 xxhash.c
2017-09-08 08:24:43 +00:00
2017-09-08 08:24:43 +00:00
.PHONY: test-mem
VALGRIND = valgrind --leak-check=yes --error-exitcode=1
test-mem: xxhsum ## valgrind tests for xxhsum CLI, looking for memory leaks
$(VALGRIND) ./xxhsum -bi1 xxhash.c
$(VALGRIND) ./xxhsum -H0 xxhash.c
$(VALGRIND) ./xxhsum -H1 xxhash.c
2017-09-08 08:24:43 +00:00
.PHONY: test32
2015-05-05 00:01:10 +00:00
test32: clean xxhsum32
2017-12-26 01:57:24 +00:00
@echo ---- test 32-bit ----
2015-05-05 00:01:10 +00:00
./xxhsum32 -bi1 xxhash.c
2019-05-03 17:29:39 +00:00
.PHONY: test-xxhsum-c
test-xxhsum-c: xxhsum
# xxhsum to/from pipe
./xxhsum lib* | ./xxhsum -c -
./xxhsum -H0 lib* | ./xxhsum -c -
# xxhsum to/from file, shell redirection
./xxhsum lib* > .test.xxh64
./xxhsum -H0 lib* > .test.xxh32
./xxhsum -c .test.xxh64
./xxhsum -c .test.xxh32
./xxhsum -c < .test.xxh64
./xxhsum -c < .test.xxh32
# xxhsum -c warns improperly format lines.
cat .test.xxh64 .test.xxh32 | ./xxhsum -c -
cat .test.xxh32 .test.xxh64 | ./xxhsum -c -
# 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
2016-08-10 04:55:55 +00:00
@$(RM) -f .test.xxh32 .test.xxh64
2019-05-03 17:29:39 +00:00
.PHONY: armtest
armtest: clean
2015-05-05 00:01:10 +00:00
@echo ---- test ARM compilation ----
2018-09-17 18:40:06 +00:00
CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror -static" $(MAKE) xxhsum
2015-05-05 00:01:10 +00:00
2019-05-03 17:29:39 +00:00
.PHONY: clangtest
clangtest: clean
2015-05-05 00:01:10 +00:00
@echo ---- test clang compilation ----
2018-09-17 18:40:06 +00:00
CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion" $(MAKE) all
2015-05-05 00:01:10 +00:00
2019-05-03 17:29:39 +00:00
.PHONY: cxxtest
2018-09-17 18:40:06 +00:00
cxxtest: clean
@echo ---- test C++ compilation ----
2018-09-17 18:40:06 +00:00
CC="$(CXX) -Wno-deprecated" $(MAKE) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -fPIC"
2015-05-05 00:01:10 +00:00
.PHONY: c90test
c90test: CPPFLAGS += -DXXH_NO_LONG_LONG
c90test: CFLAGS += -std=c90 -Werror -pedantic
c90test: xxhash.c
@echo ---- test strict C90 compilation [xxh32 only] ----
$(RM) xxhash.o
$(CC) $(FLAGS) $^ $(LDFLAGS) -c
$(RM) xxhash.o
usan: CC=clang
2019-05-03 17:29:39 +00:00
usan: ## check CLI runtime for undefined behavior, using clang's sanitizer
2015-05-05 00:01:10 +00:00
@echo ---- check undefined behavior - sanitize ----
2019-05-03 17:29:39 +00:00
$(MAKE) clean
$(MAKE) test CC=$(CC) MOREFLAGS="-g -fsanitize=undefined -fno-sanitize-recover=all"
2015-05-05 00:01:10 +00:00
.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
2015-05-05 00:01:10 +00:00
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
2019-05-03 17:29:39 +00:00
namespaceTest: ## ensure XXH_NAMESPACE redefines all public symbols
2016-08-10 04:55:55 +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
MD2ROFF ?= ronn
MD2ROFF_FLAGS ?= --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)"
xxhsum.1: xxhsum.1.md
cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
.PHONY: man
man: xxhsum.1 ## generate man page from markdown source
2019-05-03 17:29:39 +00:00
.PHONY: clean-man
clean-man:
2016-08-10 04:55:55 +00:00
$(RM) xxhsum.1
2019-05-03 17:29:39 +00:00
.PHONY: preview-man
preview-man: man
man ./xxhsum.1
2019-05-03 17:29:39 +00:00
.PHONY: test
test: all namespaceTest check test-xxhsum-c c90test
2019-05-03 17:29:39 +00:00
.PHONY: test-all
test-all: CFLAGS += -Werror
test-all: test test32 clangtest cxxtest usan listL120 trailingWhitespace staticAnalyze
2017-10-09 20:22:16 +00:00
.PHONY: listL120
listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note : $$, for Makefile compatibility)
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:
! $(GREP) -E "`printf '[ \\t]$$'`" *.1 *.c *.h LICENSE Makefile cmake_unofficial/CMakeLists.txt
2016-08-23 09:42:53 +00:00
# =========================================================
# make install is validated only for the following targets
# =========================================================
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
DESTDIR ?=
# directory variables : GNU conventions prefer lowercase
# 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)
libdir ?= $(exec_prefix)/lib
LIBDIR ?= $(libdir)
includedir ?= $(PREFIX)/include
INCLUDEDIR ?= $(includedir)
bindir ?= $(exec_prefix)/bin
BINDIR ?= $(bindir)
datarootdir ?= $(PREFIX)/share
mandir ?= $(datarootdir)/man
man1dir ?= $(mandir)/man1
ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS))
MANDIR ?= $(PREFIX)/man/man1
else
MANDIR ?= $(man1dir)
endif
ifneq (,$(filter $(shell uname),SunOS))
INSTALL ?= ginstall
else
INSTALL ?= install
endif
INSTALL_PROGRAM ?= $(INSTALL)
INSTALL_DATA ?= $(INSTALL) -m 644
2016-08-23 09:42:53 +00:00
.PHONY: install
install: lib xxhsum ## install libraries, CLI, links and man page
@echo Installing libxxhash
@$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)
@$(INSTALL_DATA) libxxhash.a $(DESTDIR)$(LIBDIR)
@$(INSTALL_PROGRAM) $(LIBXXH) $(DESTDIR)$(LIBDIR)
@ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
@ln -sf $(LIBXXH) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
@$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR) # includes
@$(INSTALL_DATA) xxhash.h $(DESTDIR)$(INCLUDEDIR)
@echo Installing xxhsum
@$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
@$(INSTALL_PROGRAM) xxhsum $(DESTDIR)$(BINDIR)/xxhsum
2016-08-23 09:42:53 +00:00
@ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh32sum
@ln -sf xxhsum $(DESTDIR)$(BINDIR)/xxh64sum
@echo Installing man pages
@$(INSTALL_DATA) xxhsum.1 $(DESTDIR)$(MANDIR)/xxhsum.1
2017-07-29 19:17:40 +00:00
@ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh32sum.1
@ln -sf xxhsum.1 $(DESTDIR)$(MANDIR)/xxh64sum.1
@echo xxhash installation completed
2016-08-23 09:42:53 +00:00
.PHONY: uninstall
uninstall: ## uninstall libraries, CLI, links and man page
@$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.a
@$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT)
@$(RM) $(DESTDIR)$(LIBDIR)/libxxhash.$(SHARED_EXT_MAJOR)
@$(RM) $(DESTDIR)$(LIBDIR)/$(LIBXXH)
@$(RM) $(DESTDIR)$(INCLUDEDIR)/xxhash.h
@$(RM) $(DESTDIR)$(BINDIR)/xxh32sum
@$(RM) $(DESTDIR)$(BINDIR)/xxh64sum
@$(RM) $(DESTDIR)$(BINDIR)/xxhsum
@$(RM) $(DESTDIR)$(MANDIR)/xxh32sum.1
@$(RM) $(DESTDIR)$(MANDIR)/xxh64sum.1
@$(RM) $(DESTDIR)$(MANDIR)/xxhsum.1
2016-08-23 09:42:53 +00:00
@echo xxhsum successfully uninstalled
endif