blob: c64cbe6b93a9d684abb5ec4eb80e01fc948170d7 [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 Collet5f9f9872015-12-30 19:52:08 +010033# Version numbers
34LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ../lib/zstd.h`
35LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ../lib/zstd.h`
36LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ../lib/zstd.h`
37LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
38LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
39LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
40LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
41LIBVER := $(shell echo $(LIBVER_SCRIPT))
Yann Collet722504c2015-12-31 18:32:15 +010042VERSION?= $(LIBVER)
Yann Collet4856a002015-01-24 01:58:16 +010043
44DESTDIR?=
Yann Colletbf504092015-08-26 00:19:06 +010045PREFIX ?= /usr/local
Yann Colletb096cbf2015-11-27 16:18:56 +010046CPPFLAGS= -I../lib -DZSTD_VERSION=\"$(VERSION)\"
Yann Collet91a97962015-11-26 09:59:49 +010047CFLAGS ?= -O3 # -falign-loops=32 # not always beneficial
Yann Collet977f1f32016-01-21 15:38:47 +010048CFLAGS += -std=c99 -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 -Wswitch-enum -Wstrict-prototypes -Wundef
Yann Collet17867ce2015-07-07 00:14:27 -080049FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS)
Yann Collet4856a002015-01-24 01:58:16 +010050
Yann Colletbf504092015-08-26 00:19:06 +010051BINDIR = $(PREFIX)/bin
52MANDIR = $(PREFIX)/share/man/man1
53ZSTDDIR = ../lib
Yann Collet4856a002015-01-24 01:58:16 +010054
Yann Collet00fd7a22015-11-28 16:03:22 +010055ZSTD_FILES := $(ZSTDDIR)/zstd_compress.c $(ZSTDDIR)/zstd_decompress.c $(ZSTDDIR)/fse.c $(ZSTDDIR)/huff0.c
56ZSTD_LEGACY:= $(ZSTDDIR)/legacy/zstd_v01.c $(ZSTDDIR)/legacy/zstd_v02.c $(ZSTDDIR)/legacy/zstd_v03.c
Yann Colletb096cbf2015-11-27 16:18:56 +010057
Yann Colletaead1bf2015-11-30 14:18:47 +010058ifeq ($(ZSTD_LEGACY_SUPPORT), 0)
Yann Colletb096cbf2015-11-27 16:18:56 +010059CPPFLAGS += -DZSTD_LEGACY_SUPPORT=0
60else
61ZSTD_FILES+= $(ZSTD_LEGACY)
62CPPFLAGS += -I../lib/legacy -I./legacy -DZSTD_LEGACY_SUPPORT=1
63ZSTD_FILEIO_LEGACY = legacy/fileio_legacy.c
64endif
65
Yann Collet4856a002015-01-24 01:58:16 +010066
67# Define *.exe as extension for Windows systems
68ifneq (,$(filter Windows%,$(OS)))
69EXT =.exe
70VOID = nul
71else
72EXT =
73VOID = /dev/null
74endif
75
Yann Collet7447ee92015-11-26 10:52:30 +010076ZBUFFTEST = -T2mn
Yann Collet1c2ddba2015-12-04 17:45:35 +010077FUZZERTEST= -T5mn
Yann Collet7447ee92015-11-26 10:52:30 +010078
Yann Collet5f2ec632015-11-26 10:32:17 +010079.PHONY: default all clean install uninstall test test32 test-all
Yann Collet4856a002015-01-24 01:58:16 +010080
81default: zstd
82
Yann Collet5f2ec632015-11-26 10:32:17 +010083all: zstd zstd32 fullbench fullbench32 fuzzer fuzzer32 zbufftest zbufftest32 paramgrill datagen
Yann Collet4856a002015-01-24 01:58:16 +010084
Yann Colletb096cbf2015-11-27 16:18:56 +010085zstd : $(ZSTD_FILES) $(ZSTDDIR)/zstd_buffered.c \
Yann Collet03386352015-12-01 01:28:32 +010086 zstdcli.c fileio.c $(ZSTD_FILEIO_LEGACY) bench.c xxhash.c datagen.c
Yann Collet4856a002015-01-24 01:58:16 +010087 $(CC) $(FLAGS) $^ -o $@$(EXT)
88
Yann Colletb096cbf2015-11-27 16:18:56 +010089zstd32: $(ZSTD_FILES) $(ZSTDDIR)/zstd_buffered.c \
Yann Collet03386352015-12-01 01:28:32 +010090 zstdcli.c fileio.c $(ZSTD_FILEIO_LEGACY) bench.c xxhash.c datagen.c
Yann Collet4856a002015-01-24 01:58:16 +010091 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
92
Yann Colleta85a8dd2015-11-30 11:53:11 +010093zstd_nolegacy :
Yann Colletaead1bf2015-11-30 14:18:47 +010094 $(MAKE) zstd ZSTD_LEGACY_SUPPORT=0
Yann Colleta85a8dd2015-11-30 11:53:11 +010095
Yann Collet03386352015-12-01 01:28:32 +010096zstd-pgo : MOREFLAGS = -fprofile-generate
97zstd-pgo : clean zstd
98 ./zstd -b $(PROFILE_WITH)
99 rm zstd
100 $(MAKE) zstd MOREFLAGS=-fprofile-use
101
Yann Collet28e7cef2015-12-03 12:11:30 +0100102zstd-noBench: $(ZSTD_FILES) $(ZSTDDIR)/zstd_buffered.c \
103 zstdcli.c fileio.c $(ZSTD_FILEIO_LEGACY)
104 $(CC) $(FLAGS) -DZSTD_NOBENCH $^ -o zstd$(EXT)
105
Yann Colletf6f3d752015-12-13 13:35:21 +0100106zstd-frugal: clean
107 $(MAKE) zstd-noBench ZSTD_LEGACY_SUPPORT=0
Yann Collet28e7cef2015-12-03 12:11:30 +0100108
Yann Colletb096cbf2015-11-27 16:18:56 +0100109fullbench : $(ZSTD_FILES) \
110 datagen.c fullbench.c
Yann Collet4856a002015-01-24 01:58:16 +0100111 $(CC) $(FLAGS) $^ -o $@$(EXT)
112
Yann Colletb096cbf2015-11-27 16:18:56 +0100113fullbench32: $(ZSTD_FILES) \
Yann Colletaa074052015-10-30 11:21:50 +0100114 datagen.c fullbench.c
Yann Collet4856a002015-01-24 01:58:16 +0100115 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
116
Yann Colletb096cbf2015-11-27 16:18:56 +0100117fuzzer : $(ZSTD_FILES) \
Yann Colletaa074052015-10-30 11:21:50 +0100118 datagen.c xxhash.c fuzzer.c
Yann Collet4856a002015-01-24 01:58:16 +0100119 $(CC) $(FLAGS) $^ -o $@$(EXT)
120
Yann Colletb096cbf2015-11-27 16:18:56 +0100121fuzzer32: $(ZSTD_FILES) \
Yann Colletaa074052015-10-30 11:21:50 +0100122 datagen.c xxhash.c fuzzer.c
Yann Collet4856a002015-01-24 01:58:16 +0100123 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
124
Yann Colletb096cbf2015-11-27 16:18:56 +0100125zbufftest : $(ZSTD_FILES) $(ZSTDDIR)/zstd_buffered.c \
Yann Collet91a97962015-11-26 09:59:49 +0100126 datagen.c xxhash.c zbufftest.c
127 $(CC) $(FLAGS) $^ -o $@$(EXT)
128
Yann Colletb096cbf2015-11-27 16:18:56 +0100129zbufftest32: $(ZSTD_FILES) $(ZSTDDIR)/zstd_buffered.c \
Yann Collet5f2ec632015-11-26 10:32:17 +0100130 datagen.c xxhash.c zbufftest.c
131 $(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
132
Yann Colletb096cbf2015-11-27 16:18:56 +0100133paramgrill : $(ZSTD_FILES) \
Yann Collet29a2c832015-11-26 16:02:04 +0100134 datagen.c xxhash.c paramgrill.c
Yann Collet1077bb82015-10-28 12:32:25 +0100135 $(CC) $(FLAGS) $^ -lm -o $@$(EXT)
Yann Collet78d0f392015-10-26 00:07:32 +0100136
Yann Collet6610cb32015-02-09 08:00:26 +0100137datagen : datagen.c datagencli.c
Yann Collet4856a002015-01-24 01:58:16 +0100138 $(CC) $(FLAGS) $^ -o $@$(EXT)
139
140clean:
Yann Collet03386352015-12-01 01:28:32 +0100141 @rm -f core *.o tmp* result* *.gcda \
Yann Collet4856a002015-01-24 01:58:16 +0100142 zstd$(EXT) zstd32$(EXT) \
143 fullbench$(EXT) fullbench32$(EXT) \
Yann Collet5f2ec632015-11-26 10:32:17 +0100144 fuzzer$(EXT) fuzzer32$(EXT) zbufftest$(EXT) zbufftest32$(EXT) \
Yann Collet0b879392015-10-26 00:11:16 +0100145 datagen$(EXT) paramgrill$(EXT)
Yann Collet4856a002015-01-24 01:58:16 +0100146 @echo Cleaning completed
147
148
149#------------------------------------------------------------------------
150#make install is validated only for Linux, OSX, kFreeBSD and Hurd targets
151ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU))
152
Yann Colletc620b482015-12-01 01:56:02 +0100153install: zstd
Yann Collet4856a002015-01-24 01:58:16 +0100154 @echo Installing binaries
155 @install -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
156 @install -m 755 zstd$(EXT) $(DESTDIR)$(BINDIR)/zstd$(EXT)
157 @ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdcat
Johan Förberg273d0492015-03-24 20:15:56 +0100158 @ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/unzstd
Yann Collet4856a002015-01-24 01:58:16 +0100159 @echo Installing man pages
160 @install -m 644 zstd.1 $(DESTDIR)$(MANDIR)/zstd.1
Yann Collet5abd8202015-08-27 03:16:04 +0100161 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/zstdcat.1
162 @ln -sf zstd.1 $(DESTDIR)$(MANDIR)/unzstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100163 @echo zstd installation completed
164
165uninstall:
166 rm -f $(DESTDIR)$(BINDIR)/zstdcat
Johan Förberg273d0492015-03-24 20:15:56 +0100167 rm -f $(DESTDIR)$(BINDIR)/unzstd
Yann Collet4856a002015-01-24 01:58:16 +0100168 [ -x $(DESTDIR)$(BINDIR)/zstd$(EXT) ] && rm -f $(DESTDIR)$(BINDIR)/zstd$(EXT)
Yann Collet5abd8202015-08-27 03:16:04 +0100169 rm -f $(DESTDIR)$(MANDIR)/zstdcat.1
170 rm -f $(DESTDIR)$(MANDIR)/unzstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100171 [ -f $(DESTDIR)$(MANDIR)/zstd.1 ] && rm -f $(DESTDIR)$(MANDIR)/zstd.1
Yann Collet4856a002015-01-24 01:58:16 +0100172 @echo zstd programs successfully uninstalled
173
Yann Collet5f2ec632015-11-26 10:32:17 +0100174test: test-zstd test-fullbench test-fuzzer test-zbuff
Yann Collet4856a002015-01-24 01:58:16 +0100175
Yann Collet5f2ec632015-11-26 10:32:17 +0100176test32: test-zstd32 test-fullbench32 test-fuzzer32 test-zbuff32
Yann Collet4856a002015-01-24 01:58:16 +0100177
Yann Collet83fae972015-10-23 15:21:53 +0100178test-all: test test32 valgrindTest
Yann Collet4856a002015-01-24 01:58:16 +0100179
Yann Collet00fd7a22015-11-28 16:03:22 +0100180zstd-playTests: datagen
Konstantin Tokarev0b570b52015-12-08 18:47:43 +0300181 ZSTD=$(ZSTD) ./playTests.sh --test-large-data
Yann Collet4856a002015-01-24 01:58:16 +0100182
Yann Collet00fd7a22015-11-28 16:03:22 +0100183test-zstd: ZSTD = ./zstd
184test-zstd: zstd zstd-playTests
185
186test-zstd32: ZSTD = ./zstd32
187test-zstd32: zstd32 zstd-playTests
Yann Collet4856a002015-01-24 01:58:16 +0100188
Yann Colleta85a8dd2015-11-30 11:53:11 +0100189test-zstd_nolegacy: ZSTD = ./zstd
190test-zstd_nolegacy: zstd_nolegacy zstd-playTests
191
Yann Collet759433d2015-01-24 13:31:55 +0100192test-fullbench: fullbench datagen
Yann Collet4856a002015-01-24 01:58:16 +0100193 ./fullbench -i1
Yann Colletf66d2ba2015-02-11 08:34:50 +0100194 ./fullbench -i1 -P0
Yann Collet4856a002015-01-24 01:58:16 +0100195
Yann Collet759433d2015-01-24 13:31:55 +0100196test-fullbench32: fullbench32 datagen
Yann Collet4856a002015-01-24 01:58:16 +0100197 ./fullbench32 -i1
Yann Colletf66d2ba2015-02-11 08:34:50 +0100198 ./fullbench32 -i1 -P0
Yann Collet4856a002015-01-24 01:58:16 +0100199
200test-fuzzer: fuzzer
Yann Collet1c2ddba2015-12-04 17:45:35 +0100201 ./fuzzer $(FUZZERTEST)
Yann Collet4856a002015-01-24 01:58:16 +0100202
203test-fuzzer32: fuzzer32
Yann Collet1c2ddba2015-12-04 17:45:35 +0100204 ./fuzzer32 $(FUZZERTEST)
Yann Collet4856a002015-01-24 01:58:16 +0100205
Yann Collet5f2ec632015-11-26 10:32:17 +0100206test-zbuff: zbufftest
Yann Collet7447ee92015-11-26 10:52:30 +0100207 ./zbufftest $(ZBUFFTEST)
Yann Collet5f2ec632015-11-26 10:32:17 +0100208
209test-zbuff32: zbufftest32
Yann Collet7447ee92015-11-26 10:52:30 +0100210 ./zbufftest32 $(ZBUFFTEST)
Yann Collet5f2ec632015-11-26 10:32:17 +0100211
Yann Collet26415d32015-11-26 12:43:28 +0100212valgrindTest: zstd datagen fuzzer fullbench zbufftest
Yann Collet078a9a22015-06-20 19:37:53 -0800213 @echo "\n ---- valgrind tests : memory analyzer ----"
Yann Colletbf504092015-08-26 00:19:06 +0100214 valgrind --leak-check=yes --error-exitcode=1 ./datagen -g50M > $(VOID)
Yann Collet4856a002015-01-24 01:58:16 +0100215 ./datagen -g16KB > tmp
Yann Colletbf504092015-08-26 00:19:06 +0100216 valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
Yann Colletfc04bcc2015-10-30 07:11:07 +0100217 ./datagen -g2930KB > tmp
Yann Collet26415d32015-11-26 12:43:28 +0100218 valgrind --leak-check=yes --error-exitcode=1 ./zstd -5 -vf tmp tmp2
219 valgrind --leak-check=yes --error-exitcode=1 ./zstd -vdf tmp2 $(VOID)
Yann Collet674d91b2015-07-07 00:36:49 -0800220 ./datagen -g64MB > tmp
Yann Colletbf504092015-08-26 00:19:06 +0100221 valgrind --leak-check=yes --error-exitcode=1 ./zstd -vf tmp $(VOID)
Yann Collet6434adc2015-01-29 07:00:43 +0100222 @rm tmp
Yann Collete47c4e52015-12-05 09:23:53 +0100223 valgrind --leak-check=yes --error-exitcode=1 ./fuzzer -T1mn -t1
Yann Collet078a9a22015-06-20 19:37:53 -0800224 valgrind --leak-check=yes --error-exitcode=1 ./fullbench -i1
Yann Collet26415d32015-11-26 12:43:28 +0100225 valgrind --leak-check=yes --error-exitcode=1 ./zbufftest -T1mn
Yann Collet4856a002015-01-24 01:58:16 +0100226
227endif