xref: /freebsd/sys/contrib/zstd/Makefile (revision 52f72944b8f5abb2386eae924357dee8aea17d5b)
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.PHONY: default
27default: lib-release zstd-release
28
29.PHONY: all
30all: | allmost examples manual
31
32.PHONY: allmost
33allmost: allzstd
34	$(MAKE) -C $(ZWRAPDIR) all
35
36#skip zwrapper, can't build that on alternate architectures without the proper zlib installed
37.PHONY: allzstd
38allzstd:
39	$(MAKE) -C $(ZSTDDIR) all
40	$(MAKE) -C $(PRGDIR) all
41	$(MAKE) -C $(TESTDIR) all
42
43.PHONY: all32
44all32:
45	$(MAKE) -C $(PRGDIR) zstd32
46	$(MAKE) -C $(TESTDIR) all32
47
48.PHONY: lib
49lib:
50	@$(MAKE) -C $(ZSTDDIR) $@
51
52.PHONY: lib-release
53lib-release:
54	@$(MAKE) -C $(ZSTDDIR)
55
56.PHONY: zstd
57zstd:
58	@$(MAKE) -C $(PRGDIR) $@
59	cp $(PRGDIR)/zstd$(EXT) .
60
61.PHONY: zstd-release
62zstd-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:
73	$(MAKE) -C $(ZWRAPDIR) test
74
75.PHONY: check
76check: shortest
77
78.PHONY: test shortest
79test shortest:
80	$(MAKE) -C $(PRGDIR) allVariants MOREFLAGS="-g -DZSTD_DEBUG=1"
81	$(MAKE) -C $(TESTDIR) $@
82
83.PHONY: examples
84examples:
85	CPPFLAGS=-I../lib LDFLAGS=-L../lib $(MAKE) -C examples/ all
86
87.PHONY: manual
88manual:
89	$(MAKE) -C contrib/gen_html $@
90
91.PHONY: cleanTabs
92cleanTabs:
93	cd contrib; ./cleanTabs
94
95.PHONY: clean
96clean:
97	@$(MAKE) -C $(ZSTDDIR) $@ > $(VOID)
98	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
99	@$(MAKE) -C $(TESTDIR) $@ > $(VOID)
100	@$(MAKE) -C $(ZWRAPDIR) $@ > $(VOID)
101	@$(MAKE) -C examples/ $@ > $(VOID)
102	@$(MAKE) -C contrib/gen_html $@ > $(VOID)
103	@$(RM) zstd$(EXT) zstdmt$(EXT) tmp*
104	@$(RM) -r lz4
105	@echo Cleaning completed
106
107#------------------------------------------------------------------------------
108# make install is validated only for Linux, OSX, Hurd and some BSD targets
109#------------------------------------------------------------------------------
110ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU FreeBSD DragonFly NetBSD MSYS_NT))
111
112HOST_OS = POSIX
113CMAKE_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
114
115.PHONY: list
116list:
117	@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
118
119.PHONY: install clangtest armtest usan asan uasan
120install:
121	@$(MAKE) -C $(ZSTDDIR) $@
122	@$(MAKE) -C $(PRGDIR) $@
123
124.PHONY: uninstall
125uninstall:
126	@$(MAKE) -C $(ZSTDDIR) $@
127	@$(MAKE) -C $(PRGDIR) $@
128
129.PHONY: travis-install
130travis-install:
131	$(MAKE) install PREFIX=~/install_test_dir
132
133.PHONY: gcc5build
134gcc5build: clean
135	gcc-5 -v
136	CC=gcc-5 $(MAKE) all MOREFLAGS="-Werror"
137
138.PHONY: gcc6build
139gcc6build: clean
140	gcc-6 -v
141	CC=gcc-6 $(MAKE) all MOREFLAGS="-Werror"
142
143.PHONY: gcc7build
144gcc7build: clean
145	gcc-7 -v
146	CC=gcc-7 $(MAKE) all MOREFLAGS="-Werror"
147
148.PHONY: clangbuild
149clangbuild: clean
150	clang -v
151	CXX=clang++ CC=clang $(MAKE) all MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation"
152
153m32build: clean
154	gcc -v
155	$(MAKE) all32
156
157armbuild: clean
158	CC=arm-linux-gnueabi-gcc CFLAGS="-Werror" $(MAKE) allzstd
159
160aarch64build: clean
161	CC=aarch64-linux-gnu-gcc CFLAGS="-Werror" $(MAKE) allzstd
162
163ppcbuild: clean
164	CC=powerpc-linux-gnu-gcc CFLAGS="-m32 -Wno-attributes -Werror" $(MAKE) allzstd
165
166ppc64build: clean
167	CC=powerpc-linux-gnu-gcc CFLAGS="-m64 -Werror" $(MAKE) allzstd
168
169armfuzz: clean
170	CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
171
172aarch64fuzz: clean
173	CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
174
175ppcfuzz: clean
176	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
177
178ppc64fuzz: clean
179	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
180
181.PHONY: cxxtest
182cxxtest: CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
183cxxtest: clean
184	$(MAKE) -C $(PRGDIR) all CC="$(CXX) -Wno-deprecated" CFLAGS="$(CXXFLAGS)"   # adding -Wno-deprecated to avoid clang++ warning on dealing with C files directly
185
186gcc5test: clean
187	gcc-5 -v
188	$(MAKE) all CC=gcc-5 MOREFLAGS="-Werror"
189
190gcc6test: clean
191	gcc-6 -v
192	$(MAKE) all CC=gcc-6 MOREFLAGS="-Werror"
193
194clangtest: clean
195	clang -v
196	$(MAKE) all CXX=clang-++ CC=clang MOREFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation"
197
198armtest: clean
199	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
200	$(MAKE) -C $(TESTDIR) test CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
201
202aarch64test:
203	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
204	$(MAKE) -C $(TESTDIR) test CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
205
206ppctest: clean
207	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
208	$(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
209
210ppc64test: clean
211	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
212	$(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests
213
214arm-ppc-compilation:
215	$(MAKE) -C $(PRGDIR) clean zstd CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
216	$(MAKE) -C $(PRGDIR) clean zstd CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
217	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
218	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
219
220regressiontest:
221	$(MAKE) -C $(FUZZDIR) regressiontest
222
223uasanregressiontest:
224	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
225
226msanregressiontest:
227	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
228
229# run UBsan with -fsanitize-recover=signed-integer-overflow
230# due to a bug in UBsan when doing pointer subtraction
231# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
232
233usan: clean
234	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=undefined"
235
236asan: clean
237	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address"
238
239asan-%: clean
240	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address" $(MAKE) -C $(TESTDIR) $*
241
242msan: clean
243	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=memory -fno-omit-frame-pointer" HAVE_LZMA=0   # datagen.c fails this test for no obvious reason
244
245msan-%: clean
246	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=memory -fno-omit-frame-pointer" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) HAVE_LZMA=0 $*
247
248asan32: clean
249	$(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address"
250
251uasan: clean
252	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined"
253
254uasan-%: clean
255	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined" $(MAKE) -C $(TESTDIR) $*
256
257tsan-%: clean
258	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS=--no-big-tests
259
260apt-install:
261	sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install $(APT_PACKAGES)
262
263apt-add-repo:
264	sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
265	sudo apt-get update -y -qq
266
267ppcinstall:
268	APT_PACKAGES="qemu-system-ppc qemu-user-static gcc-powerpc-linux-gnu" $(MAKE) apt-install
269
270arminstall:
271	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
272
273valgrindinstall:
274	APT_PACKAGES="valgrind" $(MAKE) apt-install
275
276libc6install:
277	APT_PACKAGES="libc6-dev-i386 gcc-multilib" $(MAKE) apt-install
278
279gcc6install: apt-add-repo
280	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-6 gcc-6-multilib" $(MAKE) apt-install
281
282gpp6install: apt-add-repo
283	APT_PACKAGES="libc6-dev-i386 g++-multilib gcc-6 g++-6 g++-6-multilib" $(MAKE) apt-install
284
285clang38install:
286	APT_PACKAGES="clang-3.8" $(MAKE) apt-install
287
288# Ubuntu 14.04 ships a too-old lz4
289lz4install:
290	[ -e lz4 ] || git clone https://github.com/lz4/lz4 && sudo $(MAKE) -C lz4 install
291
292endif
293
294
295ifneq (,$(filter MSYS%,$(shell uname)))
296HOST_OS = MSYS
297CMAKE_PARAMS = -G"MSYS Makefiles" -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
298endif
299
300
301#------------------------------------------------------------------------
302# target specific tests
303#------------------------------------------------------------------------
304ifneq (,$(filter $(HOST_OS),MSYS POSIX))
305cmakebuild:
306	cmake --version
307	$(RM) -r $(BUILDIR)/cmake/build
308	mkdir $(BUILDIR)/cmake/build
309	cd $(BUILDIR)/cmake/build ; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) .. ; $(MAKE) install ; $(MAKE) uninstall
310
311c90build: clean
312	$(CC) -v
313	CFLAGS="-std=c90" $(MAKE) allmost  # will fail, due to missing support for `long long`
314
315gnu90build: clean
316	$(CC) -v
317	CFLAGS="-std=gnu90" $(MAKE) allmost
318
319c99build: clean
320	$(CC) -v
321	CFLAGS="-std=c99" $(MAKE) allmost
322
323gnu99build: clean
324	$(CC) -v
325	CFLAGS="-std=gnu99" $(MAKE) allmost
326
327c11build: clean
328	$(CC) -v
329	CFLAGS="-std=c11" $(MAKE) allmost
330
331bmix64build: clean
332	$(CC) -v
333	CFLAGS="-O3 -mbmi -Werror" $(MAKE) -C $(TESTDIR) test
334
335bmix32build: clean
336	$(CC) -v
337	CFLAGS="-O3 -mbmi -mx32 -Werror" $(MAKE) -C $(TESTDIR) test
338
339bmi32build: clean
340	$(CC) -v
341	CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(TESTDIR) test
342
343staticAnalyze: clean
344	$(CC) -v
345	CPPFLAGS=-g scan-build --status-bugs -v $(MAKE) all
346endif
347