xref: /freebsd/sys/contrib/zstd/Makefile (revision 3c134670993bf525fcd6c4dfef84a3dfc3d4ed1b)
1# ################################################################
2# Copyright (c) 2015-2020, Yann Collet, Facebook, Inc.
3# All rights reserved.
4#
5# This source code is licensed under both the BSD-style license (found in the
6# LICENSE file in the root directory of this source tree) and the GPLv2 (found
7# in the COPYING file in the root directory of this source tree).
8# You may select, at your option, one of the above-listed licenses.
9# ################################################################
10
11PRGDIR   = programs
12ZSTDDIR  = lib
13BUILDIR  = build
14ZWRAPDIR = zlibWrapper
15TESTDIR  = tests
16FUZZDIR  = $(TESTDIR)/fuzz
17
18# Define nul output
19VOID = /dev/null
20
21# When cross-compiling from linux to windows, you might
22# need to specify this as "Windows." Fedora build fails
23# without it.
24#
25# Note: mingw-w64 build from linux to windows does not
26# fail on other tested distros (ubuntu, debian) even
27# without manually specifying the TARGET_SYSTEM.
28TARGET_SYSTEM ?= $(OS)
29
30ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
31EXT =.exe
32else
33EXT =
34endif
35
36## default: Build lib-release and zstd-release
37.PHONY: default
38default: lib-release zstd-release
39
40.PHONY: all
41all: allmost examples manual contrib
42
43.PHONY: allmost
44allmost: allzstd zlibwrapper
45
46# skip zwrapper, can't build that on alternate architectures without the proper zlib installed
47.PHONY: allzstd
48allzstd: lib-all
49	$(MAKE) -C $(PRGDIR) all
50	$(MAKE) -C $(TESTDIR) all
51
52.PHONY: all32
53all32:
54	$(MAKE) -C $(PRGDIR) zstd32
55	$(MAKE) -C $(TESTDIR) all32
56
57.PHONY: lib lib-release libzstd.a
58lib lib-release lib-all :
59	@$(MAKE) -C $(ZSTDDIR) $@
60
61.PHONY: zstd zstd-release
62zstd zstd-release:
63	@$(MAKE) -C $(PRGDIR) $@
64	cp $(PRGDIR)/zstd$(EXT) .
65
66.PHONY: zstdmt
67zstdmt:
68	@$(MAKE) -C $(PRGDIR) $@
69	cp $(PRGDIR)/zstd$(EXT) ./zstdmt$(EXT)
70
71.PHONY: zlibwrapper
72zlibwrapper: lib
73	$(MAKE) -C $(ZWRAPDIR) all
74
75## test: run long-duration tests
76.PHONY: test
77DEBUGLEVEL ?= 1
78test: MOREFLAGS += -g -DDEBUGLEVEL=$(DEBUGLEVEL) -Werror
79test:
80	MOREFLAGS="$(MOREFLAGS)" $(MAKE) -j -C $(PRGDIR) allVariants
81	$(MAKE) -C $(TESTDIR) $@
82	ZSTD=../../programs/zstd $(MAKE) -C doc/educational_decoder test
83
84## shortest: same as `make check`
85.PHONY: shortest
86shortest:
87	$(MAKE) -C $(TESTDIR) $@
88
89## check: run basic tests for `zstd` cli
90.PHONY: check
91check: shortest
92
93.PHONY: automated_benchmarking
94automated_benchmarking:
95	$(MAKE) -C $(TESTDIR) $@
96
97.PHONY: benchmarking
98benchmarking: automated_benchmarking
99
100## examples: build all examples in `/examples` directory
101.PHONY: examples
102examples: lib
103	CPPFLAGS=-I../lib LDFLAGS=-L../lib $(MAKE) -C examples/ all
104
105## manual: generate API documentation in html format
106.PHONY: manual
107manual:
108	$(MAKE) -C contrib/gen_html $@
109
110## man: generate man page
111.PHONY: man
112man:
113	$(MAKE) -C programs $@
114
115## contrib: build all supported projects in `/contrib` directory
116.PHONY: contrib
117contrib: lib
118	$(MAKE) -C contrib/pzstd all
119	$(MAKE) -C contrib/seekable_format/examples all
120	$(MAKE) -C contrib/largeNbDicts all
121	cd contrib/single_file_libs/ ; ./build_decoder_test.sh
122	cd contrib/single_file_libs/ ; ./build_library_test.sh
123
124.PHONY: cleanTabs
125cleanTabs:
126	cd contrib; ./cleanTabs
127
128.PHONY: clean
129clean:
130	@$(MAKE) -C $(ZSTDDIR) $@ > $(VOID)
131	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
132	@$(MAKE) -C $(TESTDIR) $@ > $(VOID)
133	@$(MAKE) -C $(ZWRAPDIR) $@ > $(VOID)
134	@$(MAKE) -C examples/ $@ > $(VOID)
135	@$(MAKE) -C contrib/gen_html $@ > $(VOID)
136	@$(MAKE) -C contrib/pzstd $@ > $(VOID)
137	@$(MAKE) -C contrib/seekable_format/examples $@ > $(VOID)
138	@$(MAKE) -C contrib/largeNbDicts $@ > $(VOID)
139	@$(RM) zstd$(EXT) zstdmt$(EXT) tmp*
140	@$(RM) -r lz4
141	@echo Cleaning completed
142
143#------------------------------------------------------------------------------
144# make install is validated only for Linux, macOS, Hurd and some BSD targets
145#------------------------------------------------------------------------------
146ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))
147
148HOST_OS = POSIX
149CMAKE_PARAMS = -DZSTD_BUILD_CONTRIB:BOOL=ON -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON -DZSTD_ZLIB_SUPPORT:BOOL=ON -DZSTD_LZMA_SUPPORT:BOOL=ON -DCMAKE_BUILD_TYPE=Release
150
151HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
152EGREP_OPTIONS ?=
153ifeq ($HAVE_COLORNEVER, 1)
154EGREP_OPTIONS += --color=never
155endif
156EGREP = egrep $(EGREP_OPTIONS)
157
158# Print a two column output of targets and their description. To add a target description, put a
159# comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>".  For example:
160#
161## list: Print all targets and their descriptions (if provided)
162.PHONY: list
163list:
164	@TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \
165		| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
166		| $(EGREP) -v  -e '^[^[:alnum:]]' | sort); \
167	{ \
168	    printf "Target Name\tDescription\n"; \
169	    printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \
170	    for target in $$TARGETS; do \
171	        line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \
172	        description=$$(echo $$line | awk '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \
173	        printf "$$target\t$$description\n"; \
174	    done \
175	} | column -t -s $$'\t'
176
177.PHONY: install armtest usan asan uasan
178install:
179	@$(MAKE) -C $(ZSTDDIR) $@
180	@$(MAKE) -C $(PRGDIR) $@
181
182.PHONY: uninstall
183uninstall:
184	@$(MAKE) -C $(ZSTDDIR) $@
185	@$(MAKE) -C $(PRGDIR) $@
186
187.PHONY: travis-install
188travis-install:
189	$(MAKE) install PREFIX=~/install_test_dir
190
191.PHONY: gcc5build
192gcc5build: clean
193	gcc-5 -v
194	CC=gcc-5 $(MAKE) all MOREFLAGS="-Werror"
195
196.PHONY: gcc6build
197gcc6build: clean
198	gcc-6 -v
199	CC=gcc-6 $(MAKE) all MOREFLAGS="-Werror"
200
201.PHONY: gcc7build
202gcc7build: clean
203	gcc-7 -v
204	CC=gcc-7 $(MAKE) all MOREFLAGS="-Werror"
205
206.PHONY: clangbuild
207clangbuild: clean
208	clang -v
209	CXX=clang++ CC=clang CFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation" $(MAKE) all
210
211m32build: clean
212	gcc -v
213	$(MAKE) all32
214
215armbuild: clean
216	CC=arm-linux-gnueabi-gcc CFLAGS="-Werror" $(MAKE) allzstd
217
218aarch64build: clean
219	CC=aarch64-linux-gnu-gcc CFLAGS="-Werror" $(MAKE) allzstd
220
221ppcbuild: clean
222	CC=powerpc-linux-gnu-gcc CFLAGS="-m32 -Wno-attributes -Werror" $(MAKE) allzstd
223
224ppc64build: clean
225	CC=powerpc-linux-gnu-gcc CFLAGS="-m64 -Werror" $(MAKE) allzstd
226
227armfuzz: clean
228	CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
229
230aarch64fuzz: clean
231	ld -v
232	CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
233
234ppcfuzz: clean
235	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
236
237ppc64fuzz: clean
238	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
239
240.PHONY: cxxtest
241cxxtest: CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
242cxxtest: clean
243	$(MAKE) -C $(PRGDIR) all CC="$(CXX) -Wno-deprecated" CFLAGS="$(CXXFLAGS)"   # adding -Wno-deprecated to avoid clang++ warning on dealing with C files directly
244
245gcc5test: clean
246	gcc-5 -v
247	$(MAKE) all CC=gcc-5 MOREFLAGS="-Werror"
248
249gcc6test: clean
250	gcc-6 -v
251	$(MAKE) all CC=gcc-6 MOREFLAGS="-Werror"
252
253armtest: clean
254	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
255	$(MAKE) -C $(TESTDIR) test CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
256
257aarch64test:
258	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
259	$(MAKE) -C $(TESTDIR) test CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
260
261ppctest: clean
262	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
263	$(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static" FUZZER_FLAGS=--no-big-tests
264
265ppc64test: clean
266	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
267	$(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests
268
269arm-ppc-compilation:
270	$(MAKE) -C $(PRGDIR) clean zstd CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
271	$(MAKE) -C $(PRGDIR) clean zstd CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
272	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
273	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
274
275regressiontest:
276	$(MAKE) -C $(FUZZDIR) regressiontest
277
278uasanregressiontest:
279	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
280
281msanregressiontest:
282	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
283
284# run UBsan with -fsanitize-recover=signed-integer-overflow
285# due to a bug in UBsan when doing pointer subtraction
286# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
287
288usan: clean
289	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=undefined -Werror"
290
291asan: clean
292	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address -Werror"
293
294asan-%: clean
295	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address -Werror" $(MAKE) -C $(TESTDIR) $*
296
297msan: clean
298	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=memory -fno-omit-frame-pointer -Werror" HAVE_LZMA=0   # datagen.c fails this test for no obvious reason
299
300msan-%: clean
301	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=memory -fno-omit-frame-pointer -Werror" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) HAVE_LZMA=0 $*
302
303asan32: clean
304	$(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address"
305
306uasan: clean
307	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror"
308
309uasan-%: clean
310	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror" $(MAKE) -C $(TESTDIR) $*
311
312tsan-%: clean
313	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread -Werror" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS=--no-big-tests
314
315apt-install:
316	sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install $(APT_PACKAGES)
317
318apt-add-repo:
319	sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
320	sudo apt-get update -y -qq
321
322ppcinstall:
323	APT_PACKAGES="qemu-system-ppc qemu-user-static gcc-powerpc-linux-gnu" $(MAKE) apt-install
324
325arminstall:
326	APT_PACKAGES="qemu-system-arm qemu-user-static gcc-arm-linux-gnueabi libc6-dev-armel-cross gcc-aarch64-linux-gnu libc6-dev-arm64-cross" $(MAKE) apt-install
327
328valgrindinstall:
329	APT_PACKAGES="valgrind" $(MAKE) apt-install
330
331libc6install:
332	APT_PACKAGES="libc6-dev-i386 gcc-multilib" $(MAKE) apt-install
333
334gcc6install: apt-add-repo
335	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-6 gcc-6-multilib" $(MAKE) apt-install
336
337gcc7install: apt-add-repo
338	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-7 gcc-7-multilib" $(MAKE) apt-install
339
340gcc8install: apt-add-repo
341	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-8 gcc-8-multilib" $(MAKE) apt-install
342
343gpp6install: apt-add-repo
344	APT_PACKAGES="libc6-dev-i386 g++-multilib gcc-6 g++-6 g++-6-multilib" $(MAKE) apt-install
345
346clang38install:
347	APT_PACKAGES="clang-3.8" $(MAKE) apt-install
348
349# Ubuntu 14.04 ships a too-old lz4
350lz4install:
351	[ -e lz4 ] || git clone https://github.com/lz4/lz4 && sudo $(MAKE) -C lz4 install
352
353endif
354
355
356ifneq (,$(filter MSYS%,$(shell uname)))
357HOST_OS = MSYS
358CMAKE_PARAMS = -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
359endif
360
361
362#------------------------------------------------------------------------
363# target specific tests
364#------------------------------------------------------------------------
365ifneq (,$(filter $(HOST_OS),MSYS POSIX))
366cmakebuild:
367	cmake --version
368	$(RM) -r $(BUILDIR)/cmake/build
369	mkdir $(BUILDIR)/cmake/build
370	cd $(BUILDIR)/cmake/build; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) ..
371	$(MAKE) -C $(BUILDIR)/cmake/build -j4;
372	$(MAKE) -C $(BUILDIR)/cmake/build install;
373	$(MAKE) -C $(BUILDIR)/cmake/build uninstall;
374	cd $(BUILDIR)/cmake/build; ctest -V -L Medium
375
376c89build: clean
377	$(CC) -v
378	CFLAGS="-std=c89 -Werror" $(MAKE) allmost  # will fail, due to missing support for `long long`
379
380gnu90build: clean
381	$(CC) -v
382	CFLAGS="-std=gnu90 -Werror" $(MAKE) allmost
383
384c99build: clean
385	$(CC) -v
386	CFLAGS="-std=c99 -Werror" $(MAKE) allmost
387
388gnu99build: clean
389	$(CC) -v
390	CFLAGS="-std=gnu99 -Werror" $(MAKE) allmost
391
392c11build: clean
393	$(CC) -v
394	CFLAGS="-std=c11 -Werror" $(MAKE) allmost
395
396bmix64build: clean
397	$(CC) -v
398	CFLAGS="-O3 -mbmi -Werror" $(MAKE) -C $(TESTDIR) test
399
400bmix32build: clean
401	$(CC) -v
402	CFLAGS="-O3 -mbmi -mx32 -Werror" $(MAKE) -C $(TESTDIR) test
403
404bmi32build: clean
405	$(CC) -v
406	CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(TESTDIR) test
407
408# static analyzer test uses clang's scan-build
409# does not analyze zlibWrapper, due to detected issues in zlib source code
410staticAnalyze: SCANBUILD ?= scan-build
411staticAnalyze:
412	$(CC) -v
413	CC=$(CC) CPPFLAGS=-g $(SCANBUILD) --status-bugs -v $(MAKE) allzstd examples contrib
414endif
415