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