LIBVER_MAJOR:=`sed -n '/define XXH_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
LIBVER_MINOR:=`sed -n '/define XXH_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
LIBVER_PATCH:=`sed -n '/define XXH_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < xxhash.h`
LIBVER := $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
CFLAGS ?= -O3
CFLAGS += -std=c99 -Wall -Wextra -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -Wstrict-aliasing=1 -Wswitch-enum -Wundef -pedantic
FLAGS := $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(MOREFLAGS)
XXHSUM_VERSION=$(LIBVER)
MD2ROFF =ronn
MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="xxhsum $(XXHSUM_VERSION)"
ifneq (,$(filter Windows%,$(OS)))
EXT =.exe
else
EXT =
endif
.PHONY: clean all
default: xxhsum
all: xxhsum xxhsum32 xxhsum_privateXXH
xxhsum: xxhash.c xxhsum.c
$(CC) $(FLAGS) $^ -o $@$(EXT)
ln -sf $@ xxh32sum
ln -sf $@ xxh64sum
xxhsum32: xxhash.c xxhsum.c
$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
xxhsum_privateXXH: xxhsum.c
$(CC) $(FLAGS) -DXXHSUM_INCLUDE_XXHC $^ -o $@$(EXT)
test: clean xxhsum
./xxhsum < xxhash.c
./xxhsum *
./xxhsum -bi1
./xxhsum -bi1 xxhash.c
valgrind --leak-check=yes --error-exitcode=1 ./xxhsum -bi1 xxhash.c
valgrind --leak-check=yes --error-exitcode=1 ./xxhsum -H0 xxhash.c
valgrind --leak-check=yes --error-exitcode=1 ./xxhsum -H1 xxhash.c
test32: clean xxhsum32
@echo ---- test 32-bits ----
./xxhsum32 -bi1 xxhash.c
test-xxhsum-c: xxhsum
./xxhsum * | ./xxhsum -c -
./xxhsum -H0 * | ./xxhsum -c -
./xxhsum * > .test.xxh64
./xxhsum -H0 * > .test.xxh32
./xxhsum -c .test.xxh64
./xxhsum -c .test.xxh32
./xxhsum -c < .test.xxh64
./xxhsum -c < .test.xxh32
cat .test.xxh64 .test.xxh32 | ./xxhsum -c -
cat .test.xxh32 .test.xxh64 | ./xxhsum -c -
echo "0000000000000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
echo "00000000 LICENSE" | ./xxhsum -c -; test $$? -eq 1
echo "0000000000000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
echo "00000000 test-expects-file-not-found" | ./xxhsum -c -; test $$? -eq 1
clean-xxhsum-c:
@rm -f .test.xxh32 .test.xxh64
armtest: clean
@echo ---- test ARM compilation ----
$(MAKE) xxhsum CC=arm-linux-gnueabi-gcc MOREFLAGS="-Werror"
clangtest: clean
@echo ---- test clang compilation ----
$(MAKE) all CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion"
gpptest: clean
@echo ---- test g++ compilation ----
$(MAKE) all CC=g++ CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
sanitize: clean
@echo ---- check undefined behavior - sanitize ----
$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=undefined"
staticAnalyze: clean
@echo ---- static analyzer - scan-build ----
CFLAGS="-g -Werror" scan-build --status-bugs -v $(MAKE) all
xxhsum.1: xxhsum.1.md
cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
man: xxhsum.1
clean-man:
rm xxhsum.1
preview-man: clean-man man
man ./xxhsum.1
test-all: clean all test test32 test-xxhsum-c clean-xxhsum-c armtest clangtest gpptest sanitize staticAnalyze
clean: clean-xxhsum-c
@rm -f core *.o xxhsum$(EXT) xxhsum32$(EXT) xxhsum_privateXXH$(EXT) xxh32sum xxh64sum
@echo cleaning completed