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