xref: /freebsd/sys/contrib/zstd/Makefile (revision 8df8b2d3e51d1b816201d8a1fe8bc29fe192e562)
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 clangtest 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 $(MAKE) all MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation"
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
235clangtest: clean
236	clang -v
237	$(MAKE) all CXX=clang++ CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation"
238
239armtest: clean
240	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
241	$(MAKE) -C $(TESTDIR) test CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
242
243aarch64test:
244	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
245	$(MAKE) -C $(TESTDIR) test CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
246
247ppctest: clean
248	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
249	$(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
250
251ppc64test: clean
252	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
253	$(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests
254
255arm-ppc-compilation:
256	$(MAKE) -C $(PRGDIR) clean zstd CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
257	$(MAKE) -C $(PRGDIR) clean zstd CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
258	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
259	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
260
261regressiontest:
262	$(MAKE) -C $(FUZZDIR) regressiontest
263
264uasanregressiontest:
265	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
266
267msanregressiontest:
268	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
269
270# run UBsan with -fsanitize-recover=signed-integer-overflow
271# due to a bug in UBsan when doing pointer subtraction
272# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
273
274usan: clean
275	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=undefined -Werror"
276
277asan: clean
278	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address -Werror"
279
280asan-%: clean
281	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address -Werror" $(MAKE) -C $(TESTDIR) $*
282
283msan: clean
284	$(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
285
286msan-%: clean
287	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 $*
288
289asan32: clean
290	$(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address"
291
292uasan: clean
293	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror"
294
295uasan-%: clean
296	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror" $(MAKE) -C $(TESTDIR) $*
297
298tsan-%: clean
299	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread -Werror" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS=--no-big-tests
300
301apt-install:
302	sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install $(APT_PACKAGES)
303
304apt-add-repo:
305	sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
306	sudo apt-get update -y -qq
307
308ppcinstall:
309	APT_PACKAGES="qemu-system-ppc qemu-user-static gcc-powerpc-linux-gnu" $(MAKE) apt-install
310
311arminstall:
312	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
313
314valgrindinstall:
315	APT_PACKAGES="valgrind" $(MAKE) apt-install
316
317libc6install:
318	APT_PACKAGES="libc6-dev-i386 gcc-multilib" $(MAKE) apt-install
319
320gcc6install: apt-add-repo
321	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-6 gcc-6-multilib" $(MAKE) apt-install
322
323gcc7install: apt-add-repo
324	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-7 gcc-7-multilib" $(MAKE) apt-install
325
326gcc8install: apt-add-repo
327	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-8 gcc-8-multilib" $(MAKE) apt-install
328
329gpp6install: apt-add-repo
330	APT_PACKAGES="libc6-dev-i386 g++-multilib gcc-6 g++-6 g++-6-multilib" $(MAKE) apt-install
331
332clang38install:
333	APT_PACKAGES="clang-3.8" $(MAKE) apt-install
334
335# Ubuntu 14.04 ships a too-old lz4
336lz4install:
337	[ -e lz4 ] || git clone https://github.com/lz4/lz4 && sudo $(MAKE) -C lz4 install
338
339endif
340
341
342ifneq (,$(filter MSYS%,$(shell uname)))
343HOST_OS = MSYS
344CMAKE_PARAMS = -G"MSYS Makefiles" -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
345endif
346
347
348#------------------------------------------------------------------------
349# target specific tests
350#------------------------------------------------------------------------
351ifneq (,$(filter $(HOST_OS),MSYS POSIX))
352cmakebuild:
353	cmake --version
354	$(RM) -r $(BUILDIR)/cmake/build
355	mkdir $(BUILDIR)/cmake/build
356	cd $(BUILDIR)/cmake/build ; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) .. ; $(MAKE) install ; $(MAKE) uninstall
357
358c90build: clean
359	$(CC) -v
360	CFLAGS="-std=c90 -Werror" $(MAKE) allmost  # will fail, due to missing support for `long long`
361
362gnu90build: clean
363	$(CC) -v
364	CFLAGS="-std=gnu90 -Werror" $(MAKE) allmost
365
366c99build: clean
367	$(CC) -v
368	CFLAGS="-std=c99 -Werror" $(MAKE) allmost
369
370gnu99build: clean
371	$(CC) -v
372	CFLAGS="-std=gnu99 -Werror" $(MAKE) allmost
373
374c11build: clean
375	$(CC) -v
376	CFLAGS="-std=c11 -Werror" $(MAKE) allmost
377
378bmix64build: clean
379	$(CC) -v
380	CFLAGS="-O3 -mbmi -Werror" $(MAKE) -C $(TESTDIR) test
381
382bmix32build: clean
383	$(CC) -v
384	CFLAGS="-O3 -mbmi -mx32 -Werror" $(MAKE) -C $(TESTDIR) test
385
386bmi32build: clean
387	$(CC) -v
388	CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(TESTDIR) test
389
390# static analyzer test uses clang's scan-build
391# does not analyze zlibWrapper, due to detected issues in zlib source code
392staticAnalyze: SCANBUILD ?= scan-build
393staticAnalyze:
394	$(CC) -v
395	CC=$(CC) CPPFLAGS=-g $(SCANBUILD) --status-bugs -v $(MAKE) allzstd examples contrib
396endif
397