Makefile revision e06fcd903909c96a72d1025a81ff8fb31ac572fb
1# ##########################################################################
2# LZ4 programs - Makefile
3# Copyright (C) Yann Collet 2011-2016
4#
5# GPL v2 License
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20#
21# You can contact the author at :
22#  - LZ4 homepage : http://www.lz4.org
23#  - LZ4 source repository : https://github.com/lz4/lz4
24# ##########################################################################
25# fuzzer  : Test tool, to check lz4 integrity on target platform
26# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
27# frametest  : Test tool, to check lz4frame integrity on target platform
28# frametest32: Same as frametest, but forced to compile in 32-bits mode
29# fullbench  : Precisely measure speed for each LZ4 function variant
30# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
31# datagen : generates synthetic data samples for tests & benchmarks
32# ##########################################################################
33
34DESTDIR ?=
35PREFIX  ?= /usr/local
36VOID    := /dev/null
37BINDIR  := $(PREFIX)/bin
38MANDIR  := $(PREFIX)/share/man/man1
39LZ4DIR  := ../lib
40PRGDIR  := ../programs
41TESTDIR := versionsTest
42PYTHON?= python3
43
44CFLAGS  ?= -O3   # can select custom flags. For example : CFLAGS="-O2 -g" make
45CFLAGS  += -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes
46CFLAGS  += $(MOREFLAGS)
47CPPFLAGS:= -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ -DLZ4_DLL_EXPORT=1
48FLAGS   := $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
49
50
51# Define *.exe as extension for Windows systems
52ifneq (,$(filter Windows%,$(OS)))
53EXT =.exe
54else
55EXT =
56endif
57
58
59# Default test parameters
60TEST_FILES   := COPYING
61FUZZER_TIME  := -T9mn
62
63
64default: bins
65
66m32: fullbench32 fuzzer32 frametest32
67
68bins: fullbench fuzzer frametest datagen
69
70all: bins m32
71
72
73lz4:
74	$(MAKE) -C $(PRGDIR) $@
75
76lz4c:
77	$(MAKE) -C $(PRGDIR) $@
78
79lz4c32:
80	$(MAKE) -C $(PRGDIR) $@ 
81
82fullbench  : $(LZ4DIR)/lz4.o $(LZ4DIR)/lz4hc.o $(LZ4DIR)/lz4frame.o $(LZ4DIR)/xxhash.o fullbench.c
83	$(CC) $(FLAGS) $^ -o $@$(EXT)
84
85fullbench32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/lz4frame.c $(LZ4DIR)/xxhash.c fullbench.c
86	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
87
88fuzzer  : $(LZ4DIR)/lz4.o $(LZ4DIR)/lz4hc.o $(LZ4DIR)/xxhash.o fuzzer.c
89	$(CC) $(FLAGS) $^ -o $@$(EXT)
90
91fuzzer32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c fuzzer.c
92	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
93
94frametest: $(LZ4DIR)/lz4frame.o $(LZ4DIR)/lz4.o $(LZ4DIR)/lz4hc.o $(LZ4DIR)/xxhash.o frametest.c
95	$(CC) $(FLAGS) $^ -o $@$(EXT)
96
97frametest32: $(LZ4DIR)/lz4frame.c $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c $(LZ4DIR)/xxhash.c frametest.c
98	$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
99
100datagen : $(PRGDIR)/datagen.c datagencli.c
101	$(CC) $(FLAGS) -I$(PRGDIR) $^ -o $@$(EXT)
102
103clean:
104	@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
105	@$(RM) core *.o *.test tmp* \
106        fullbench$(EXT) fullbench32$(EXT) \
107        fuzzer$(EXT) fuzzer32$(EXT) \
108        frametest$(EXT) frametest32$(EXT) \
109        datagen$(EXT)
110	@rm -fR $(TESTDIR)
111	@echo Cleaning completed
112
113versionsTest:
114	$(PYTHON) test-lz4-versions.py
115
116
117#------------------------------------------------------------------------
118#make install is validated only for Linux, OSX, kFreeBSD, Hurd and
119#FreeBSD targets
120ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU FreeBSD))
121
122test: test-lz4 test-lz4c test-frametest test-fullbench test-fuzzer test-mem
123
124test32: test-lz4c32 test-frametest32 test-fullbench32 test-fuzzer32 test-mem32
125
126test-all: test test32
127
128test-lz4-sparse: lz4 datagen
129	@echo "\n ---- test sparse file support ----"
130	./datagen -g5M  -P100 > tmpSrc
131	$(PRGDIR)/lz4 -B4D tmpSrc | $(PRGDIR)/lz4 -dv --sparse > tmpB4
132	diff -s tmpSrc tmpB4
133	$(PRGDIR)/lz4 -B5D tmpSrc | $(PRGDIR)/lz4 -dv --sparse > tmpB5
134	diff -s tmpSrc tmpB5
135	$(PRGDIR)/lz4 -B6D tmpSrc | $(PRGDIR)/lz4 -dv --sparse > tmpB6
136	diff -s tmpSrc tmpB6
137	$(PRGDIR)/lz4 -B7D tmpSrc | $(PRGDIR)/lz4 -dv --sparse > tmpB7
138	diff -s tmpSrc tmpB7
139	$(PRGDIR)/lz4 tmpSrc | $(PRGDIR)/lz4 -dv --no-sparse > tmpNoSparse
140	diff -s tmpSrc tmpNoSparse
141	ls -ls tmp*
142	./datagen -s1 -g1200007 -P100 | $(PRGDIR)/lz4 | $(PRGDIR)/lz4 -dv --sparse > tmpOdd   # Odd size file (to generate non-full last block)
143	./datagen -s1 -g1200007 -P100 | diff -s - tmpOdd
144	ls -ls tmpOdd
145	@$(RM) tmp*
146	@echo "\n Compatibility with Console :"
147	echo "Hello World 1 !" | $(PRGDIR)/lz4 | $(PRGDIR)/lz4 -d -c
148	echo "Hello World 2 !" | $(PRGDIR)/lz4 | $(PRGDIR)/lz4 -d | cat
149	echo "Hello World 3 !" | $(PRGDIR)/lz4 --no-frame-crc | $(PRGDIR)/lz4 -d -c
150	@echo "\n Compatibility with Append :"
151	./datagen -P100 -g1M > tmp1M
152	cat tmp1M tmp1M > tmp2M
153	$(PRGDIR)/lz4 -B5 -v tmp1M tmpC
154	$(PRGDIR)/lz4 -d -v tmpC tmpR
155	$(PRGDIR)/lz4 -d -v tmpC >> tmpR
156	ls -ls tmp*
157	diff tmp2M tmpR
158	@$(RM) tmp*
159
160test-lz4-contentSize: lz4 datagen
161	@echo "\n ---- test original size support ----"
162	./datagen -g15M > tmp
163	$(PRGDIR)/lz4 -v tmp | $(PRGDIR)/lz4 -t
164	$(PRGDIR)/lz4 -v --content-size tmp | $(PRGDIR)/lz4 -d > tmp2
165	diff -s tmp tmp2
166	# test large size [2-4] GB
167	@./datagen -g3G -P100 | $(PRGDIR)/lz4 | $(PRGDIR)/lz4 --decompress --force --sparse - tmp
168	@ls -ls tmp
169	$(PRGDIR)/lz4 --quiet --content-size tmp | $(PRGDIR)/lz4 --verbose --decompress --force --sparse - tmp2
170	@ls -ls tmp2
171	@$(RM) tmp*
172
173test-lz4-frame-concatenation: lz4 datagen
174	@echo "\n ---- test frame concatenation ----"
175	@echo -n > empty.test
176	@echo hi > nonempty.test
177	cat nonempty.test empty.test nonempty.test > orig.test
178	@$(PRGDIR)/lz4 -zq empty.test > empty.lz4.test
179	@$(PRGDIR)/lz4 -zq nonempty.test > nonempty.lz4.test
180	cat nonempty.lz4.test empty.lz4.test nonempty.lz4.test > concat.lz4.test
181	$(PRGDIR)/lz4 -d concat.lz4.test > result.test
182	sdiff orig.test result.test
183	@$(RM) *.test
184	@echo frame concatenation test completed
185
186test-lz4-multiple: lz4 datagen
187	@echo "\n ---- test multiple files ----"
188	@./datagen -s1        > tmp1 2> $(VOID)
189	@./datagen -s2 -g100K > tmp2 2> $(VOID)
190	@./datagen -s3 -g1M   > tmp3 2> $(VOID)
191	$(PRGDIR)/lz4 -f -m tmp*
192	ls -ls tmp*
193	@$(RM) tmp1 tmp2 tmp3
194	$(PRGDIR)/lz4 -df -m *.lz4
195	ls -ls tmp*
196	$(PRGDIR)/lz4 -f -m tmp1 notHere tmp2; echo $$?
197	@$(RM) tmp*
198
199test-lz4-basic: lz4 datagen
200	@echo "\n ---- test lz4 basic compression/decompression ----"
201	./datagen -g0     | $(PRGDIR)/lz4 -v     | $(PRGDIR)/lz4 -t
202	./datagen -g16KB  | $(PRGDIR)/lz4 -9     | $(PRGDIR)/lz4 -t
203	./datagen -g20KB > tmpSrc
204	$(PRGDIR)/lz4 < tmpSrc | $(PRGDIR)/lz4 -d > tmpRes
205	diff -q tmpSrc tmpRes
206	$(PRGDIR)/lz4 --no-frame-crc < tmpSrc | $(PRGDIR)/lz4 -d > tmpRes
207	diff -q tmpSrc tmpRes
208	./datagen         | $(PRGDIR)/lz4        | $(PRGDIR)/lz4 -t
209	./datagen -g6M -P99 | $(PRGDIR)/lz4 -9BD | $(PRGDIR)/lz4 -t
210	./datagen -g17M   | $(PRGDIR)/lz4 -9v    | $(PRGDIR)/lz4 -qt
211	./datagen -g33M   | $(PRGDIR)/lz4 --no-frame-crc | $(PRGDIR)/lz4 -t
212	./datagen -g256MB | $(PRGDIR)/lz4 -vqB4D | $(PRGDIR)/lz4 -t
213	./datagen -g6GB   | $(PRGDIR)/lz4 -vqB5D | $(PRGDIR)/lz4 -qt
214	./datagen -g6GB   | $(PRGDIR)/lz4 -vq9BD | $(PRGDIR)/lz4 -qt
215	@$(RM) tmp*
216
217test-lz4: lz4 datagen test-lz4-basic test-lz4-multiple test-lz4-sparse test-lz4-contentSize test-lz4-frame-concatenation
218	@echo "\n ---- test pass-through ----"
219	./datagen | $(PRGDIR)/lz4 -t             && false || true
220	./datagen | $(PRGDIR)/lz4 -tf            && false || true
221	./datagen | $(PRGDIR)/lz4 -d  > $(VOID)  && false || true
222	./datagen | $(PRGDIR)/lz4 -df > $(VOID)
223
224test-lz4c: lz4c datagen
225	@echo "\n ---- test lz4c version ----"
226	./datagen -g256MB | $(PRGDIR)/lz4c -l -v    | $(PRGDIR)/lz4c   -t
227
228test-interop-32-64: lz4 lz4c32 datagen
229	@echo "\n ---- test interoperability 32-bits -vs- 64 bits ----"
230	./datagen -g16KB  | $(PRGDIR)/lz4c32 -9     | $(PRGDIR)/lz4    -t
231	./datagen -P10    | $(PRGDIR)/lz4    -9B4   | $(PRGDIR)/lz4c32 -t
232	./datagen         | $(PRGDIR)/lz4c32        | $(PRGDIR)/lz4    -t
233	./datagen -g1M    | $(PRGDIR)/lz4    -3B5   | $(PRGDIR)/lz4c32 -t
234	./datagen -g256MB | $(PRGDIR)/lz4c32 -vqB4D | $(PRGDIR)/lz4    -qt
235	./datagen -g1G -P90 | $(PRGDIR)/lz4         | $(PRGDIR)/lz4c32 -t
236	./datagen -g6GB   | $(PRGDIR)/lz4c32 -vq9BD | $(PRGDIR)/lz4    -qt
237
238test-lz4c32-basic: lz4c32 datagen
239	@echo "\n ---- test lz4c32 32-bits version ----"
240	./datagen -g16KB  | $(PRGDIR)/lz4c32 -9     | $(PRGDIR)/lz4c32 -t
241	./datagen         | $(PRGDIR)/lz4c32        | $(PRGDIR)/lz4c32 -t
242	./datagen -g256MB | $(PRGDIR)/lz4c32 -vqB4D | $(PRGDIR)/lz4c32 -qt
243	./datagen -g6GB   | $(PRGDIR)/lz4c32 -vqB5D | $(PRGDIR)/lz4c32 -qt
244
245test-lz4c32: test-lz4c32-basic test-interop-32-64
246
247test-fullbench: fullbench
248	./fullbench --no-prompt $(NB_LOOPS) $(TEST_FILES)
249
250test-fullbench32: fullbench32
251	./fullbench32 --no-prompt $(NB_LOOPS) $(TEST_FILES)
252
253test-fuzzer: fuzzer
254	./fuzzer $(FUZZER_TIME)
255
256test-fuzzer32: fuzzer32
257	./fuzzer32 $(FUZZER_TIME)
258
259test-frametest: frametest
260	./frametest $(FUZZER_TIME)
261
262test-frametest32: frametest32
263	./frametest32 $(FUZZER_TIME)
264
265test-mem: lz4 datagen fuzzer frametest fullbench
266	@echo "\n ---- valgrind tests : memory analyzer ----"
267	valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
268	./datagen -g16KB > tmp
269	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 -9 -BD -f tmp $(VOID)
270	./datagen -g16KB -s2 > tmp2
271	./datagen -g16KB -s3 > tmp3
272	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 --force --multiple tmp tmp2 tmp3
273	./datagen -g16MB > tmp
274	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 -9 -B5D -f tmp tmp2
275	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 -t tmp2
276	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 -bi1 tmp
277	valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1 tmp tmp2
278	./datagen -g256MB > tmp
279	valgrind --leak-check=yes --error-exitcode=1 $(PRGDIR)/lz4 -B4D -f -vq tmp $(VOID)
280	$(RM) tmp*
281	valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i64 -t1
282	valgrind --leak-check=yes --error-exitcode=1 ./frametest -i256
283
284test-mem32: lz4c32 datagen
285# unfortunately, valgrind doesn't seem to work with non-native binary...
286
287endif
288