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