blob: ea51bbf7fe3d27e48c7864ea328c46fe75071174 [file] [log] [blame]
Yann Collet4856a002015-01-24 01:58:16 +01001# ##########################################################################
2# ZSTD programs - Makefile
3# Copyright (C) Yann Collet 2015
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# - ZSTD source repository : http://code.google.com/p/zstd/
23# - Public forum : https://groups.google.com/forum/#!forum/lz4c
24# ##########################################################################
25# zstd : Command Line Utility, supporting gzip-like arguments
26# datagen : Synthetic and parametrable data generator, for tests
27# fuzzer : Test tool, to check zstd integrity on target platform
28# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
29# fullbench : Precisely measure speed for each zstd inner function
30# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
31# ##########################################################################
32
Yann Colletf48e35c2015-11-07 01:13:31 +010033VERSION?= 0.3.5
Yann Collet4856a002015-01-24 01:58:16 +010034
35DESTDIR?=
Yann Colletbf504092015-08-26 00:19:06 +010036PREFIX ?= /usr/local
Yann Colletaa074052015-10-30 11:21:50 +010037CPPFLAGS= -I../lib -I../lib/legacy -I./legacy -DZSTD_VERSION=\"$(VERSION)\" -DZSTD_LEGACY_SUPPORT=1
Yann Collet1c00dc32015-10-21 08:22:25 +010038CFLAGS ?= -O3 # -falign-loops=32 # not always positive
Yann Colletb1f3f4b2015-10-18 22:18:32 +010039CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes
Yann Collet17867ce2015-07-07 00:14:27 -080040FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS)
Yann Collet4856a002015-01-24 01:58:16 +010041
Yann Colletbf504092015-08-26 00:19:06 +010042BINDIR = $(PREFIX)/bin
43MANDIR = $(PREFIX)/share/man/man1
44ZSTDDIR = ../lib
Yann Collet4856a002015-01-24 01:58:16 +010045
46
47# Define *.exe as extension for Windows systems
48ifneq (,$(filter Windows%,$(OS)))
49EXT =.exe
50VOID = nul
51else
52EXT =
53VOID = /dev/null
54endif
55
56
57default: zstd
58
Yann Collet78d0f392015-10-26 00:07:32 +010059all: zstd zstd32 fullbench fullbench32 fuzzer fuzzer32 paramgrill datagen
Yann Collet4856a002015-01-24 01:58:16 +010060
Yann Colletaa074052015-10-30 11:21:50 +010061zstd: $(ZSTDDIR)/zstd.c $(ZSTDDIR)/zstdhc.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
62 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
63 xxhash.c bench.c fileio.c zstdcli.c legacy/fileio_legacy.c
Yann Collet4856a002015-01-24 01:58:16 +010064 $(CC) $(FLAGS) $^ -o $@$(EXT)
65
Yann Colletaa074052015-10-30 11:21:50 +010066zstd32: $(ZSTDDIR)/zstd.c $(ZSTDDIR)/zstdhc.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
67 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
68 xxhash.c bench.c fileio.c zstdcli.c legacy/fileio_legacy.c
Yann Collet4856a002015-01-24 01:58:16 +010069 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
70
Yann Colletaa074052015-10-30 11:21:50 +010071fullbench : $(ZSTDDIR)/zstd.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
72 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
73 datagen.c fullbench.c
Yann Collet4856a002015-01-24 01:58:16 +010074 $(CC) $(FLAGS) $^ -o $@$(EXT)
75
Yann Colletaa074052015-10-30 11:21:50 +010076fullbench32: $(ZSTDDIR)/zstd.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
77 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
78 datagen.c fullbench.c
Yann Collet4856a002015-01-24 01:58:16 +010079 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
80
Yann Colletaa074052015-10-30 11:21:50 +010081fuzzer : $(ZSTDDIR)/zstd.c $(ZSTDDIR)/zstdhc.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
82 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
83 datagen.c xxhash.c fuzzer.c
Yann Collet4856a002015-01-24 01:58:16 +010084 $(CC) $(FLAGS) $^ -o $@$(EXT)
85
Yann Colletaa074052015-10-30 11:21:50 +010086fuzzer32: $(ZSTDDIR)/zstd.c $(ZSTDDIR)/zstdhc.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
87 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
88 datagen.c xxhash.c fuzzer.c
Yann Collet4856a002015-01-24 01:58:16 +010089 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
90
Yann Colletaa074052015-10-30 11:21:50 +010091paramgrill : $(ZSTDDIR)/zstdhc.c $(ZSTDDIR)/zstd.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c \
92 $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c \
93 datagen.c xxhash.c paramgrill.c
Yann Collet1077bb82015-10-28 12:32:25 +010094 $(CC) $(FLAGS) $^ -lm -o $@$(EXT)
Yann Collet78d0f392015-10-26 00:07:32 +010095
Yann Collet6610cb32015-02-09 08:00:26 +010096datagen : datagen.c datagencli.c
Yann Collet4856a002015-01-24 01:58:16 +010097 $(CC) $(FLAGS) $^ -o $@$(EXT)
98
99clean:
100 @rm -f core *.o tmp \
101 zstd$(EXT) zstd32$(EXT) \
102 fullbench$(EXT) fullbench32$(EXT) \
103 fuzzer$(EXT) fuzzer32$(EXT) \
Yann Collet0b879392015-10-26 00:11:16 +0100104 datagen$(EXT) paramgrill$(EXT)
Yann Collet4856a002015-01-24 01:58:16 +0100105 @echo Cleaning completed
106
107
108#------------------------------------------------------------------------
109#make install is validated only for Linux, OSX, kFreeBSD and Hurd targets
110ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU))
111
112install: zstd
113 @echo Installing binaries
114 @install -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
115 @install -m 755 zstd$(EXT) $(DESTDIR)$(BINDIR)/zstd$(EXT)
116 @ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdcat
Johan Förberg273d0492015-03-24 20:15:56 +0100117 @ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/unzstd
Yann Collet4856a002015-01-24 01:58:16 +0100118 @echo Installing man pages
119 @install -m 644 zstd.1 $(DESTDIR)$(MANDIR)/zstd.1
Yann Collet5abd8202015-08-27 03:16:04 +0100120 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/zstdcat.1
121 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/unzstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100122 @echo zstd installation completed
123
124uninstall:
125 rm -f $(DESTDIR)$(BINDIR)/zstdcat
Johan Förberg273d0492015-03-24 20:15:56 +0100126 rm -f $(DESTDIR)$(BINDIR)/unzstd
Yann Collet4856a002015-01-24 01:58:16 +0100127 [ -x $(DESTDIR)$(BINDIR)/zstd$(EXT) ] && rm -f $(DESTDIR)$(BINDIR)/zstd$(EXT)
Yann Collet5abd8202015-08-27 03:16:04 +0100128 rm -f $(DESTDIR)$(MANDIR)/zstdcat.1
129 rm -f $(DESTDIR)$(MANDIR)/unzstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100130 [ -f $(DESTDIR)$(MANDIR)/zstd.1 ] && rm -f $(DESTDIR)$(MANDIR)/zstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100131 @echo zstd programs successfully uninstalled
132
Yann Collet674d91b2015-07-07 00:36:49 -0800133test: test-zstd test-fullbench test-fuzzer
Yann Collet4856a002015-01-24 01:58:16 +0100134
135test32: test-zstd32 test-fullbench32 test-fuzzer32
136
Yann Collet83fae972015-10-23 15:21:53 +0100137test-all: test test32 valgrindTest
Yann Collet4856a002015-01-24 01:58:16 +0100138
139test-zstd: zstd datagen
Yann Colletbe50aaa2015-09-10 23:26:09 +0100140 @echo "\n**** frame concatenation **** "
141 @echo "hello " > hello.tmp
142 @echo "world!" > world.tmp
143 @cat hello.tmp world.tmp > helloworld.tmp
144 ./zstd hello.tmp > hello.zstd
145 ./zstd world.tmp > world.zstd
146 @cat hello.zstd world.zstd > helloworld.zstd
147 ./zstd -d helloworld.zstd > result.tmp
148 cat result.tmp
149 sdiff helloworld.tmp result.tmp
150 @rm *.tmp *.zstd
151 @echo frame concatenation test completed
152 @echo "**** flush write error test **** "
Yann Collet5b147602015-08-25 17:41:46 +0100153 echo foo | ./zstd > /dev/full; if [ $$? -eq 0 ] ; then echo "write error not detected!"; false; fi
Yann Collet5abd8202015-08-27 03:16:04 +0100154 echo foo | ./zstd | ./zstd -d > /dev/full; if [ $$? -eq 0 ] ; then echo "write error not detected!"; false; fi
Yann Colletbe50aaa2015-09-10 23:26:09 +0100155 @echo "**** zstd round-trip tests **** "
Yann Collet7083b8a2015-07-06 23:58:59 -0800156 ./datagen | ./zstd -v | ./zstd -d > $(VOID)
Yann Colletf8eaf0e2015-10-30 05:59:18 +0100157 ./datagen | ./zstd -6 -v | ./zstd -d > $(VOID)
Yann Collet7083b8a2015-07-06 23:58:59 -0800158 ./datagen -g256MB | ./zstd -v | ./zstd -d > $(VOID)
Yann Colletf8eaf0e2015-10-30 05:59:18 +0100159 ./datagen -g256MB | ./zstd -3 -v | ./zstd -d > $(VOID)
Yann Collet7083b8a2015-07-06 23:58:59 -0800160 ./datagen -g6GB -P99 | ./zstd -vq | ./zstd -d > $(VOID)
Yann Collet4856a002015-01-24 01:58:16 +0100161
162test-zstd32: zstd32 datagen
Yann Collet7083b8a2015-07-06 23:58:59 -0800163 ./datagen | ./zstd32 -v | ./zstd32 -d > $(VOID)
164 ./datagen -g256MB | ./zstd32 -v | ./zstd32 -d > $(VOID)
165 ./datagen -g6GB -P99 | ./zstd32 -vq | ./zstd32 -d > $(VOID)
Yann Collet4856a002015-01-24 01:58:16 +0100166
Yann Collet759433d2015-01-24 13:31:55 +0100167test-fullbench: fullbench datagen
Yann Collet4856a002015-01-24 01:58:16 +0100168 ./fullbench -i1
Yann Colletf66d2ba2015-02-11 08:34:50 +0100169 ./fullbench -i1 -P0
Yann Collet4856a002015-01-24 01:58:16 +0100170
Yann Collet759433d2015-01-24 13:31:55 +0100171test-fullbench32: fullbench32 datagen
Yann Collet4856a002015-01-24 01:58:16 +0100172 ./fullbench32 -i1
Yann Colletf66d2ba2015-02-11 08:34:50 +0100173 ./fullbench32 -i1 -P0
Yann Collet4856a002015-01-24 01:58:16 +0100174
175test-fuzzer: fuzzer
176 ./fuzzer
177
178test-fuzzer32: fuzzer32
179 ./fuzzer32
180
Yann Collet83fae972015-10-23 15:21:53 +0100181valgrindTest: zstd datagen fuzzer fullbench
Yann Collet078a9a22015-06-20 19:37:53 -0800182 @echo "\n ---- valgrind tests : memory analyzer ----"
Yann Colletbf504092015-08-26 00:19:06 +0100183 valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
Yann Collet4856a002015-01-24 01:58:16 +0100184 ./datagen -g16KB > tmp
Yann Colletbf504092015-08-26 00:19:06 +0100185 valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
Yann Colletfc04bcc2015-10-30 07:11:07 +0100186 ./datagen -g2930KB > tmp
187 valgrind --leak-check=yes --error-exitcode=1 ./zstd -4 -vf tmp $(VOID)
Yann Collet674d91b2015-07-07 00:36:49 -0800188 ./datagen -g64MB > tmp
Yann Colletbf504092015-08-26 00:19:06 +0100189 valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
Yann Collet6434adc2015-01-29 07:00:43 +0100190 @rm tmp
Yann Colletbf504092015-08-26 00:19:06 +0100191 valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -i1000 -t1
Yann Collet078a9a22015-06-20 19:37:53 -0800192 valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1
Yann Collet4856a002015-01-24 01:58:16 +0100193
194endif