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