2013-12-05 22:47:05 +00:00
# ################################################################
# xxHash Makefile
2015-05-04 22:56:53 +01:00
# Copyright (C) Yann Collet 2012-2015
#
2013-12-05 22:47:05 +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.
#
# You can contact the author at :
# - xxHash source repository : http://code.google.com/p/xxhash/
# ################################################################
2015-08-08 00:22:56 +01:00
# xxhsum : provides 32/64 bits hash of one or multiple files, or stdin
2013-12-05 22:47:05 +00:00
# ################################################################
2016-02-21 23:10:20 +09:00
# Version numbers
2017-09-14 09:44:34 -07:00
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) )
2016-02-21 23:10:20 +09:00
LIBVER := $( LIBVER_MAJOR) .$( LIBVER_MINOR) .$( LIBVER_PATCH)
2014-10-29 02:05:59 +01:00
CFLAGS ?= -O3
2016-08-11 00:53:10 +02:00
CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
2016-08-06 20:40:25 +02:00
-Wstrict-aliasing= 1 -Wswitch-enum -Wdeclaration-after-statement \
2016-08-11 00:53:10 +02:00
-Wstrict-prototypes -Wundef
2017-09-08 01:24:43 -07:00
FLAGS = $( CFLAGS) $( CPPFLAGS) $( LDFLAGS) $( MOREFLAGS)
2016-02-22 22:06:22 +09:00
XXHSUM_VERSION = $( LIBVER)
2016-08-06 20:40:25 +02:00
MD2ROFF = ronn
MD2ROFF_FLAGS = --roff --warnings --manual= "User Commands" --organization= " xxhsum $( XXHSUM_VERSION) "
2013-05-11 11:22:55 +00:00
2014-09-25 21:22:59 +01:00
# Define *.exe as extension for Windows systems
i f n e q ( , $( filter Windows %,$ ( OS ) ) )
2013-05-11 11:22:55 +00:00
EXT = .exe
2014-07-10 22:44:08 +02:00
e l s e
2014-09-25 21:22:59 +01:00
EXT =
2014-07-10 22:44:08 +02:00
e n d i f
2017-09-14 09:44:34 -07:00
# 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
i f e q ( $( shell uname ) , D a r w i n )
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)
e l s e
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)
e n d i f
LIBXXH = libxxhash.$( SHARED_EXT_VER)
2017-09-08 01:24:43 -07:00
.PHONY : default
2017-09-14 09:44:34 -07:00
default : lib xxhsum
2013-05-11 11:22:55 +00:00
2017-09-08 01:24:43 -07:00
.PHONY : all
2017-09-14 09:44:34 -07:00
all : lib xxhsum xxhsum 32 xxhsum_inlinedXXH
2013-05-11 11:22:55 +00:00
2017-09-08 01:24:43 -07:00
xxhsum32 : CFLAGS += -m 32
xxhsum xxhsum32 : xxhash .c xxhsum .c
2017-09-14 09:44:34 -07:00
$( CC) $( FLAGS) $^ -o $@ $( EXT)
2014-09-25 21:53:18 +01:00
ln -sf $@ xxh32sum
ln -sf $@ xxh64sum
2014-07-10 08:28:57 +01:00
2016-06-06 14:12:27 +02:00
xxhsum_inlinedXXH : xxhsum .c
2016-06-21 08:29:40 +02:00
$( CC) $( FLAGS) -DXXH_PRIVATE_API $^ -o $@ $( EXT)
2016-01-04 08:32:38 +01:00
2017-09-14 09:44:34 -07:00
# library
libxxhash.a : ARFLAGS = rcs
libxxhash.a : xxhash .o
@echo compiling static library
@$( AR) $( ARFLAGS) $@ $^
$(LIBXXH) : LDFLAGS += -shared -fPIC
$(LIBXXH) : xxhash .c
@echo compiling dynamic library $( LIBVER)
@$( CC) $( FLAGS) $^ $( LDFLAGS) $( SONAME_FLAGS) -o $@
@echo creating versioned links
@ln -sf $@ libxxhash.$( SHARED_EXT_MAJOR)
@ln -sf $@ libxxhash.$( SHARED_EXT)
libxxhash : $( LIBXXH )
lib : libxxhash .a libxxhash
# tests
2017-09-08 01:24:43 -07:00
.PHONY : test
test : xxhsum
2015-08-08 00:22:56 +01:00
# stdin
2014-10-29 14:02:50 +01:00
./xxhsum < xxhash.c
2015-08-08 00:22:56 +01:00
# multiple files
./xxhsum *
# internal bench
2015-05-07 13:30:27 +01:00
./xxhsum -bi1
2015-08-08 00:22:56 +01:00
# file bench
2015-05-05 01:01:10 +01:00
./xxhsum -bi1 xxhash.c
2017-09-08 01:24:43 -07:00
.PHONY : test -mem
test-mem : xxhsum
2017-09-08 01:37:59 -07:00
# memory tests
2015-05-04 22:56:53 +01:00
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
2014-07-10 22:44:08 +02:00
2017-09-08 01:24:43 -07:00
.PHONY : test 32
2015-05-05 01:01:10 +01:00
test32 : clean xxhsum 32
@echo ---- test 32-bits ----
./xxhsum32 -bi1 xxhash.c
2016-01-25 19:25:46 +09:00
test-xxhsum-c : xxhsum
# xxhsum to/from pipe
./xxhsum * | ./xxhsum -c -
./xxhsum -H0 * | ./xxhsum -c -
# xxhsum to/from file, shell redirection
./xxhsum * > .test.xxh64
./xxhsum -H0 * > .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
clean-xxhsum-c :
2016-08-10 06:55:55 +02:00
@$( RM) -f .test.xxh32 .test.xxh64
2016-01-25 19:25:46 +09:00
2015-06-28 03:20:23 -08:00
armtest : clean
2015-05-05 01:01:10 +01:00
@echo ---- test ARM compilation ----
2016-08-11 01:32:10 +02:00
$( MAKE) xxhsum CC = arm-linux-gnueabi-gcc MOREFLAGS = "-Werror -static"
2015-05-05 01:01:10 +01:00
2015-06-28 03:20:23 -08:00
clangtest : clean
2015-05-05 01:01:10 +01:00
@echo ---- test clang compilation ----
$( MAKE) all CC = clang MOREFLAGS = "-Werror -Wconversion -Wno-sign-conversion"
2015-06-28 03:20:23 -08:00
gpptest : clean
2015-05-05 01:01:10 +01:00
@echo ---- test g++ compilation ----
$( MAKE) all CC = g++ CFLAGS = "-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
2016-08-11 00:53:10 +02:00
c90test : clean
@echo ---- test strict C90 compilation [ xxh32 only] ----
$( CC) -std= c90 -Werror -pedantic -DXXH_NO_LONG_LONG -c xxhash.c
$( RM) xxhash.o
2016-08-11 19:41:20 +02:00
usan : clean
2015-05-05 01:01:10 +01:00
@echo ---- check undefined behavior - sanitize ----
2017-09-08 01:24:43 -07:00
$( MAKE) clean test CC = clang MOREFLAGS = "-g -fsanitize=undefined"
2015-05-05 01:01:10 +01:00
2015-06-28 03:20:23 -08:00
staticAnalyze : clean
2015-05-05 01:01:10 +01:00
@echo ---- static analyzer - scan-build ----
2016-01-10 17:06:34 +01:00
CFLAGS = "-g -Werror" scan-build --status-bugs -v $( MAKE) all
2015-05-05 01:01:10 +01:00
2016-08-10 06:55:55 +02:00
namespaceTest :
$( 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
2016-02-20 03:08:46 +09:00
xxhsum.1 : xxhsum .1.md
cat $^ | $( MD2ROFF) $( MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
man : xxhsum .1
clean-man :
2016-08-10 06:55:55 +02:00
$( RM) xxhsum.1
2016-02-20 03:08:46 +09:00
preview-man : clean -man man
man ./xxhsum.1
2016-08-11 19:41:20 +02:00
test-all : clean all namespaceTest test test 32 test -xxhsum -c clean -xxhsum -c \
2017-09-08 01:24:43 -07:00
armtest clangtest gpptest c90test test-mem usan staticAnalyze
2014-07-10 22:44:08 +02:00
2017-10-09 12:37:02 -07:00
.PHONY : checkL 120
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 : clean
2016-01-25 19:25:46 +09:00
clean : clean -xxhsum -c
2017-09-14 09:44:34 -07:00
@$( RM) core *.o libxxhash.*
@$( RM) xxhsum$( EXT) xxhsum32$( EXT) xxhsum_inlinedXXH$( EXT) xxh32sum xxh64sum
2014-09-25 21:22:59 +01:00
@echo cleaning completed
2016-08-23 11:42:53 +02:00
2017-09-08 00:31:30 -07:00
#-----------------------------------------------------------------------------
# make install is validated only for the following targets
#-----------------------------------------------------------------------------
i f n e q ( , $( 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)
2017-09-14 09:44:34 -07:00
libdir ?= $( exec_prefix) /lib
LIBDIR ?= $( libdir)
includedir ?= $( PREFIX) /include
INCLUDEDIR ?= $( includedir)
2017-09-08 00:31:30 -07:00
bindir ?= $( exec_prefix) /bin
BINDIR ?= $( bindir)
datarootdir ?= $( PREFIX) /share
mandir ?= $( datarootdir) /man
man1dir ?= $( mandir) /man1
i f n e q ( , $( filter $ ( shell uname ) ,OpenBSD FreeBSD NetBSD DragonFly SunOS ) )
MANDIR ?= $( PREFIX) /man/man1
e l s e
MANDIR ?= $( man1dir)
e n d i f
i f n e q ( , $( filter $ ( shell uname ) ,SunOS ) )
INSTALL ?= ginstall
e l s e
INSTALL ?= install
e n d i f
INSTALL_PROGRAM ?= $( INSTALL)
INSTALL_DATA ?= $( INSTALL) -m 644
2016-08-23 11:42:53 +02:00
2017-09-08 00:31:30 -07:00
.PHONY : install
2017-09-14 09:44:34 -07:00
install : lib xxhsum
@echo Installing libxxhash
@$( 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
2017-09-08 00:31:30 -07:00
@$( INSTALL) -d -m 755 $( DESTDIR) $( BINDIR) / $( DESTDIR) $( MANDIR) /
@$( INSTALL_PROGRAM) xxhsum $( DESTDIR) $( BINDIR) /xxhsum
2016-08-23 11:42:53 +02:00
@ln -sf xxhsum $( DESTDIR) $( BINDIR) /xxh32sum
@ln -sf xxhsum $( DESTDIR) $( BINDIR) /xxh64sum
@echo Installing man pages
2017-09-08 00:31:30 -07:00
@$( INSTALL_DATA) xxhsum.1 $( DESTDIR) $( MANDIR) /xxhsum.1
2017-07-29 20:17:40 +01:00
@ln -sf xxhsum.1 $( DESTDIR) $( MANDIR) /xxh32sum.1
@ln -sf xxhsum.1 $( DESTDIR) $( MANDIR) /xxh64sum.1
2017-09-14 09:44:34 -07:00
@echo xxhash installation completed
2016-08-23 11:42:53 +02:00
2017-09-08 00:31:30 -07:00
.PHONY : uninstall
2016-08-23 11:42:53 +02:00
uninstall :
2017-09-14 09:44:34 -07:00
@$( 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 11:42:53 +02:00
@echo xxhsum successfully uninstalled
e n d i f