kusano 7d535a
# ##########################################################################
kusano 7d535a
# LZ4 programs - Makefile
kusano 7d535a
# Copyright (C) Yann Collet 2011-2015
kusano 7d535a
#
kusano 7d535a
# GPL v2 License
kusano 7d535a
#
kusano 7d535a
# This program is free software; you can redistribute it and/or modify
kusano 7d535a
# it under the terms of the GNU General Public License as published by
kusano 7d535a
# the Free Software Foundation; either version 2 of the License, or
kusano 7d535a
# (at your option) any later version.
kusano 7d535a
#
kusano 7d535a
# This program is distributed in the hope that it will be useful,
kusano 7d535a
# but WITHOUT ANY WARRANTY; without even the implied warranty of
kusano 7d535a
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
kusano 7d535a
# GNU General Public License for more details.
kusano 7d535a
#
kusano 7d535a
# You should have received a copy of the GNU General Public License along
kusano 7d535a
# with this program; if not, write to the Free Software Foundation, Inc.,
kusano 7d535a
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
kusano 7d535a
#
kusano 7d535a
# You can contact the author at :
kusano 7d535a
#  - LZ4 source repository : https://github.com/Cyan4973/lz4
kusano 7d535a
#  - LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
kusano 7d535a
# ##########################################################################
kusano 7d535a
# lz4 : Command Line Utility, supporting gzip-like arguments
kusano 7d535a
# lz4c  : CLU, supporting also legacy lz4demo arguments
kusano 7d535a
# lz4c32: Same as lz4c, but forced to compile in 32-bits mode
kusano 7d535a
# fuzzer  : Test tool, to check lz4 integrity on target platform
kusano 7d535a
# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
kusano 7d535a
# frametest  : Test tool, to check lz4frame integrity on target platform
kusano 7d535a
# frametest32: Same as frametest, but forced to compile in 32-bits mode
kusano 7d535a
# fullbench  : Precisely measure speed for each LZ4 function variant
kusano 7d535a
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
kusano 7d535a
# datagen : generates synthetic data samples for tests & benchmarks
kusano 7d535a
# ##########################################################################
kusano 7d535a
kusano 7d535a
RELEASE?= r131
kusano 7d535a
kusano 7d535a
DESTDIR?=
kusano 7d535a
PREFIX ?= /usr/local
kusano 7d535a
CFLAGS ?= -O3
kusano 7d535a
CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -pedantic -DLZ4_VERSION=\"$(RELEASE)\"
kusano 7d535a
FLAGS  := -I../lib $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
kusano 7d535a
kusano 7d535a
BINDIR := $(PREFIX)/bin
kusano 7d535a
MANDIR := $(PREFIX)/share/man/man1
kusano 7d535a
LZ4DIR := ../lib
kusano 7d535a
kusano 7d535a
kusano 7d535a
# Define *.exe as extension for Windows systems
kusano 7d535a
ifneq (,$(filter Windows%,$(OS)))
kusano 7d535a
EXT =.exe
kusano 7d535a
VOID = nul
kusano 7d535a
else
kusano 7d535a
EXT =
kusano 7d535a
VOID = /dev/null
kusano 7d535a
endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
# Select test target for Travis CI's Build Matrix
kusano 7d535a
TRAVIS_TARGET:= $(LZ4_TRAVIS_CI_ENV)
kusano 7d535a
TEST_FILES   := COPYING
kusano 7d535a
TEST_TARGETS := test-native
kusano 7d535a
FUZZER_TIME  := -T9mn
kusano 7d535a
kusano 7d535a
kusano 7d535a
default: lz4
kusano 7d535a
kusano 7d535a
m32: lz4c32 fullbench32 fuzzer32 frametest32
kusano 7d535a
kusano 7d535a
bins: lz4 lz4c fullbench fuzzer frametest datagen
kusano 7d535a
kusano 7d535a
all: bins m32
kusano 7d535a
kusano 7d535a
lz4: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c bench.c lz4io.c lz4cli.c
kusano 7d535a
	$(CC)      $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
lz4c  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c bench.c lz4io.c lz4cli.c
kusano 7d535a
	$(CC)      $(FLAGS) -DENABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
lz4c32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c bench.c lz4io.c lz4cli.c
kusano 7d535a
	$(CC) -m32 $(FLAGS) -DENABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
fullbench  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c fullbench.c
kusano 7d535a
	$(CC)      $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
fullbench32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c fullbench.c
kusano 7d535a
	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
fuzzer  : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c fuzzer.c
kusano 7d535a
	$(CC)      $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
fuzzer32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c fuzzer.c
kusano 7d535a
	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
frametest: $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c frametest.c
kusano 7d535a
	$(CC)      $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
frametest32: $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c frametest.c
kusano 7d535a
	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
datagen : datagen.c datagencli.c
kusano 7d535a
	$(CC)      $(FLAGS) $^ -o $@$(EXT)
kusano 7d535a
kusano 7d535a
clean:
kusano 7d535a
	@rm -f core *.o *.test tmp* \
kusano 7d535a
        lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) \
kusano 7d535a
        fullbench$(EXT) fullbench32$(EXT) \
kusano 7d535a
        fuzzer$(EXT) fuzzer32$(EXT) \
kusano 7d535a
        frametest$(EXT) frametest32$(EXT) \
kusano 7d535a
        datagen$(EXT)
kusano 7d535a
	@echo Cleaning completed
kusano 7d535a
kusano 7d535a
kusano 7d535a
#------------------------------------------------------------------------
kusano 7d535a
#make install is validated only for Linux, OSX, kFreeBSD and Hurd targets
kusano 7d535a
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU))
kusano 7d535a
kusano 7d535a
install: lz4 lz4c
kusano 7d535a
	@echo Installing binaries
kusano 7d535a
	@install -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
kusano 7d535a
	@install -m 755 lz4 $(DESTDIR)$(BINDIR)/lz4
kusano 7d535a
	@ln -sf lz4 $(DESTDIR)$(BINDIR)/lz4cat
kusano 7d535a
	@ln -sf lz4 $(DESTDIR)$(BINDIR)/unlz4
kusano 7d535a
	@install -m 755 lz4c $(DESTDIR)$(BINDIR)/lz4c
kusano 7d535a
	@echo Installing man pages
kusano 7d535a
	@install -m 644 lz4.1 $(DESTDIR)$(MANDIR)/lz4.1
kusano 7d535a
	@ln -sf lz4.1 $(DESTDIR)$(MANDIR)/lz4c.1
kusano 7d535a
	@ln -sf lz4.1 $(DESTDIR)$(MANDIR)/lz4cat.1
kusano 7d535a
	@ln -sf lz4.1 $(DESTDIR)$(MANDIR)/unlz4.1
kusano 7d535a
	@echo lz4 installation completed
kusano 7d535a
kusano 7d535a
uninstall:
kusano 7d535a
	rm -f $(DESTDIR)$(BINDIR)/lz4cat
kusano 7d535a
	rm -f $(DESTDIR)$(BINDIR)/unlz4
kusano 7d535a
	[ -x $(DESTDIR)$(BINDIR)/lz4 ] && rm -f $(DESTDIR)$(BINDIR)/lz4
kusano 7d535a
	[ -x $(DESTDIR)$(BINDIR)/lz4c ] && rm -f $(DESTDIR)$(BINDIR)/lz4c
kusano 7d535a
	[ -f $(DESTDIR)$(MANDIR)/lz4.1 ] && rm -f $(DESTDIR)$(MANDIR)/lz4.1
kusano 7d535a
	rm -f $(DESTDIR)$(MANDIR)/lz4c.1
kusano 7d535a
	rm -f $(DESTDIR)$(MANDIR)/lz4cat.1
kusano 7d535a
	rm -f $(DESTDIR)$(MANDIR)/unlz4.1
kusano 7d535a
	@echo lz4 programs successfully uninstalled
kusano 7d535a
kusano 7d535a
test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-mem
kusano 7d535a
kusano 7d535a
test32: test-lz4c32 test-frametest32 test-fullbench32 test-fuzzer32 test-mem32
kusano 7d535a
kusano 7d535a
test-all: test test32
kusano 7d535a
kusano 7d535a
test-travis: $(TRAVIS_TARGET)
kusano 7d535a
kusano 7d535a
test-lz4-sparse: lz4 datagen
kusano 7d535a
	@echo "\n ---- test sparse file support ----"
kusano 7d535a
	./datagen -g5M  -P100 > tmpSrc
kusano 7d535a
	./lz4 -B4D tmpSrc | ./lz4 -dv --sparse > tmpB4
kusano 7d535a
	diff -s tmpSrc tmpB4
kusano 7d535a
	./lz4 -B5D tmpSrc | ./lz4 -dv --sparse > tmpB5
kusano 7d535a
	diff -s tmpSrc tmpB5
kusano 7d535a
	./lz4 -B6D tmpSrc | ./lz4 -dv --sparse > tmpB6
kusano 7d535a
	diff -s tmpSrc tmpB6
kusano 7d535a
	./lz4 -B7D tmpSrc | ./lz4 -dv --sparse > tmpB7
kusano 7d535a
	diff -s tmpSrc tmpB7
kusano 7d535a
	./lz4 tmpSrc | ./lz4 -dv --no-sparse > tmpNoSparse
kusano 7d535a
	diff -s tmpSrc tmpNoSparse
kusano 7d535a
	ls -ls tmp*
kusano 7d535a
	./datagen -s1 -g1200007 -P100 | ./lz4 | ./lz4 -dv --sparse > tmpOdd   # Odd size file (to not finish on an exact nb of blocks)
kusano 7d535a
	./datagen -s1 -g1200007 -P100 | diff -s - tmpOdd
kusano 7d535a
	ls -ls tmpOdd
kusano 7d535a
	@rm tmp*
kusano 7d535a
	@echo "\n Compatibility with Console :"
kusano 7d535a
	echo "Hello World 1 !" | ./lz4 | ./lz4 -d -c
kusano 7d535a
	echo "Hello World 2 !" | ./lz4 | ./lz4 -d | cat
kusano 7d535a
	echo "Hello World 3 !" | ./lz4 --no-frame-crc | ./lz4 -d -c
kusano 7d535a
	@echo "\n Compatibility with Append :"
kusano 7d535a
	./datagen -P100 -g1M > tmp1M
kusano 7d535a
	cat tmp1M tmp1M > tmp2M
kusano 7d535a
	./lz4 -B5 -v tmp1M tmpC
kusano 7d535a
	./lz4 -d -v tmpC tmpR
kusano 7d535a
	./lz4 -d -v tmpC >> tmpR
kusano 7d535a
	ls -ls tmp*
kusano 7d535a
	diff tmp2M tmpR
kusano 7d535a
	@rm tmp*
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
test-lz4-contentSize: lz4 datagen
kusano 7d535a
	@echo "\n ---- test original size support ----"
kusano 7d535a
	./datagen -g15M > tmp
kusano 7d535a
	./lz4 -v tmp | ./lz4 -t
kusano 7d535a
	./lz4 -v --content-size tmp | ./lz4 -d > tmp2
kusano 7d535a
	diff -s tmp tmp2
kusano 7d535a
	# test large size [2-4] GB
kusano 7d535a
	@./datagen -g3G -P100 | ./lz4 | ./lz4 --decompress --force --sparse - tmp
kusano 7d535a
	@ls -ls tmp
kusano 7d535a
	./lz4 --quiet --content-size tmp | ./lz4 --verbose --decompress --force --sparse - tmp2
kusano 7d535a
	@ls -ls tmp2
kusano 7d535a
	@rm tmp*
kusano 7d535a
kusano 7d535a
test-lz4-frame-concatenation: lz4 datagen
kusano 7d535a
	@echo "\n ---- test frame concatenation ----"
kusano 7d535a
	@echo -n > empty.test
kusano 7d535a
	@echo hi > nonempty.test
kusano 7d535a
	cat nonempty.test empty.test nonempty.test > orig.test
kusano 7d535a
	@./lz4 -zq empty.test > empty.lz4.test
kusano 7d535a
	@./lz4 -zq nonempty.test > nonempty.lz4.test
kusano 7d535a
	cat nonempty.lz4.test empty.lz4.test nonempty.lz4.test > concat.lz4.test
kusano 7d535a
	./lz4 -d concat.lz4.test > result.test
kusano 7d535a
	sdiff orig.test result.test
kusano 7d535a
	@rm *.test
kusano 7d535a
	@echo frame concatenation test completed
kusano 7d535a
kusano 7d535a
test-lz4-multiple: lz4 datagen
kusano 7d535a
	@echo "\n ---- test multiple files ----"
kusano 7d535a
	@./datagen -s1        > tmp1 2> $(VOID)
kusano 7d535a
	@./datagen -s2 -g100K > tmp2 2> $(VOID)
kusano 7d535a
	@./datagen -s3 -g1M   > tmp3 2> $(VOID)
kusano 7d535a
	./lz4 -f -m tmp*
kusano 7d535a
	ls -ls tmp*
kusano 7d535a
	rm tmp1 tmp2 tmp3
kusano 7d535a
	./lz4 -df -m *.lz4
kusano 7d535a
	ls -ls tmp*
kusano 7d535a
	./lz4 -f -m tmp1 notHere tmp2; echo $$?
kusano 7d535a
	@rm tmp*
kusano 7d535a
kusano 7d535a
test-lz4-basic: lz4 datagen
kusano 7d535a
	@echo "\n ---- test lz4 basic compression/decompression ----"
kusano 7d535a
	./datagen -g0     | ./lz4 -v     | ./lz4 -t
kusano 7d535a
	./datagen -g16KB  | ./lz4 -9     | ./lz4 -t
kusano 7d535a
	./datagen -g20KB > tmpSrc
kusano 7d535a
	./lz4 < tmpSrc | ./lz4 -d > tmpRes
kusano 7d535a
	diff -q tmpSrc tmpRes
kusano 7d535a
	./lz4 --no-frame-crc < tmpSrc | ./lz4 -d > tmpRes
kusano 7d535a
	diff -q tmpSrc tmpRes
kusano 7d535a
	./datagen         | ./lz4        | ./lz4 -t
kusano 7d535a
	./datagen -g6M -P99 | ./lz4 -9BD | ./lz4 -t
kusano 7d535a
	./datagen -g17M   | ./lz4 -9v    | ./lz4 -qt
kusano 7d535a
	./datagen -g33M   | ./lz4 --no-frame-crc | ./lz4 -t
kusano 7d535a
	./datagen -g256MB | ./lz4 -vqB4D | ./lz4 -t
kusano 7d535a
	./datagen -g6GB   | ./lz4 -vqB5D | ./lz4 -qt
kusano 7d535a
	./datagen -g6GB   | ./lz4 -vq9BD | ./lz4 -qt
kusano 7d535a
	@rm tmp*
kusano 7d535a
kusano 7d535a
test-lz4: lz4 datagen test-lz4-basic test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation
kusano 7d535a
	@echo "\n ---- test pass-through ----"
kusano 7d535a
	./datagen | ./lz4 -tf
kusano 7d535a
kusano 7d535a
test-lz4c: lz4c datagen
kusano 7d535a
	@echo "\n ---- test lz4c version ----"
kusano 7d535a
	./datagen -g256MB | ./lz4c -l -v    | ./lz4c   -t
kusano 7d535a
kusano 7d535a
test-interop-32-64: lz4 lz4c32 datagen
kusano 7d535a
	@echo "\n ---- test interoperability 32-bits -vs- 64 bits ----"
kusano 7d535a
	./datagen -g16KB  | ./lz4c32 -9     | ./lz4    -t
kusano 7d535a
	./datagen -P10    | ./lz4    -9B4   | ./lz4c32 -t
kusano 7d535a
	./datagen         | ./lz4c32        | ./lz4    -t
kusano 7d535a
	./datagen -g1M    | ./lz4    -3B5   | ./lz4c32 -t
kusano 7d535a
	./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4    -qt
kusano 7d535a
	./datagen -g1G -P90 | ./lz4         | ./lz4c32 -t
kusano 7d535a
	./datagen -g6GB   | ./lz4c32 -vq9BD | ./lz4    -qt
kusano 7d535a
kusano 7d535a
test-lz4c32-basic: lz4c32 datagen
kusano 7d535a
	@echo "\n ---- test lz4c32 32-bits version ----"
kusano 7d535a
	./datagen -g16KB  | ./lz4c32 -9     | ./lz4c32 -t
kusano 7d535a
	./datagen         | ./lz4c32        | ./lz4c32 -t
kusano 7d535a
	./datagen -g256MB | ./lz4c32 -vqB4D | ./lz4c32 -qt
kusano 7d535a
	./datagen -g6GB   | ./lz4c32 -vqB5D | ./lz4c32 -qt
kusano 7d535a
kusano 7d535a
test-lz4c32: test-lz4c32-basic test-interop-32-64
kusano 7d535a
kusano 7d535a
test-fullbench: fullbench
kusano 7d535a
	./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES)
kusano 7d535a
kusano 7d535a
test-fullbench32: fullbench32
kusano 7d535a
	./fullbench32 --no-prompt $(NB_LOOPS) $(TEST_FILES)
kusano 7d535a
kusano 7d535a
test-fuzzer: fuzzer
kusano 7d535a
	./fuzzer $(FUZZER_TIME)
kusano 7d535a
kusano 7d535a
test-fuzzer32: fuzzer32
kusano 7d535a
	./fuzzer32 $(FUZZER_TIME)
kusano 7d535a
kusano 7d535a
test-frametest: frametest
kusano 7d535a
	./frametest $(FUZZER_TIME)
kusano 7d535a
kusano 7d535a
test-frametest32: frametest32
kusano 7d535a
	./frametest32 $(FUZZER_TIME)
kusano 7d535a
kusano 7d535a
test-mem: lz4 datagen fuzzer frametest fullbench
kusano 7d535a
	@echo "\n ---- valgrind tests : memory analyzer ----"
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
kusano 7d535a
	./datagen -g16KB > tmp
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 -9 -BD -f tmp $(VOID)
kusano 7d535a
	./datagen -g16KB -s2 > tmp2
kusano 7d535a
	./datagen -g16KB -s3 > tmp3
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 --force --multiple tmp tmp2 tmp3
kusano 7d535a
	./datagen -g16MB > tmp
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 -9 -B5D -f tmp tmp2
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 -t tmp2
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 -bi1 tmp
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1 tmp tmp2
kusano 7d535a
	./datagen -g256MB > tmp
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./lz4 -B4D -f -vq tmp $(VOID)
kusano 7d535a
	rm tmp*
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i64 -t1
kusano 7d535a
	valgrind --leak-check=yes --error-exitcode=1 ./frametest -i256
kusano 7d535a
kusano 7d535a
test-mem32: lz4c32 datagen
kusano 7d535a
# unfortunately, valgrind doesn't seem to work with non-native binary. If someone knows how to do a valgrind-test on a 32-bits exe with a 64-bits system...
kusano 7d535a
kusano 7d535a
endif