• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ################################################################
2# Copyright (c) 2015-2020, 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# You may select, at your option, one of the above-listed licenses.
9# ################################################################
10
11# verbose mode (print commands) on V=1 or VERBOSE=1
12Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
13
14PRGDIR   = programs
15ZSTDDIR  = lib
16BUILDIR  = build
17ZWRAPDIR = zlibWrapper
18TESTDIR  = tests
19FUZZDIR  = $(TESTDIR)/fuzz
20
21# Define nul output
22VOID = /dev/null
23
24# When cross-compiling from linux to windows, you might
25# need to specify this as "Windows." Fedora build fails
26# without it.
27#
28# Note: mingw-w64 build from linux to windows does not
29# fail on other tested distros (ubuntu, debian) even
30# without manually specifying the TARGET_SYSTEM.
31TARGET_SYSTEM ?= $(OS)
32
33ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
34  EXT =.exe
35else
36  EXT =
37endif
38
39## default: Build lib-release and zstd-release
40.PHONY: default
41default: lib-release zstd-release
42
43.PHONY: all
44all: allmost examples manual contrib
45
46.PHONY: allmost
47allmost: allzstd zlibwrapper
48
49# skip zwrapper, can't build that on alternate architectures without the proper zlib installed
50.PHONY: allzstd
51allzstd: lib-all
52	$(Q)$(MAKE) -C $(PRGDIR) all
53	$(Q)$(MAKE) -C $(TESTDIR) all
54
55.PHONY: all32
56all32:
57	$(MAKE) -C $(PRGDIR) zstd32
58	$(MAKE) -C $(TESTDIR) all32
59
60.PHONY: lib lib-release libzstd.a
61lib-all : lib
62lib lib-release lib-all :
63	$(Q)$(MAKE) -C $(ZSTDDIR) $@
64
65.PHONY: zstd zstd-release
66zstd zstd-release:
67	$(Q)$(MAKE) -C $(PRGDIR) $@
68	$(Q)ln -sf $(PRGDIR)/zstd$(EXT) zstd$(EXT)
69
70.PHONY: zstdmt
71zstdmt:
72	$(Q)$(MAKE) -C $(PRGDIR) $@
73	$(Q)cp $(PRGDIR)/zstd$(EXT) ./zstdmt$(EXT)
74
75.PHONY: zlibwrapper
76zlibwrapper: lib
77	$(MAKE) -C $(ZWRAPDIR) all
78
79## test: run long-duration tests
80.PHONY: test
81DEBUGLEVEL ?= 1
82test: MOREFLAGS += -g -Werror
83test:
84	DEBUGLEVEL=$(DEBUGLEVEL) MOREFLAGS="$(MOREFLAGS)" $(MAKE) -j -C $(PRGDIR) allVariants
85	$(MAKE) -C $(TESTDIR) $@
86	ZSTD=../../programs/zstd $(MAKE) -C doc/educational_decoder $@
87
88## shortest: same as `make check`
89.PHONY: shortest
90shortest:
91	$(Q)$(MAKE) -C $(TESTDIR) $@
92
93## check: run basic tests for `zstd` cli
94.PHONY: check
95check: shortest
96
97.PHONY: automated_benchmarking
98automated_benchmarking:
99	$(MAKE) -C $(TESTDIR) $@
100
101.PHONY: benchmarking
102benchmarking: automated_benchmarking
103
104## examples: build all examples in `examples/` directory
105.PHONY: examples
106examples: lib
107	$(MAKE) -C examples all
108
109## manual: generate API documentation in html format
110.PHONY: manual
111manual:
112	$(MAKE) -C contrib/gen_html $@
113
114## man: generate man page
115.PHONY: man
116man:
117	$(MAKE) -C programs $@
118
119## contrib: build all supported projects in `/contrib` directory
120.PHONY: contrib
121contrib: lib
122	$(MAKE) -C contrib/pzstd all
123	$(MAKE) -C contrib/seekable_format/examples all
124	$(MAKE) -C contrib/seekable_format/tests test
125	$(MAKE) -C contrib/largeNbDicts all
126	cd contrib/single_file_libs/ ; ./build_decoder_test.sh
127	cd contrib/single_file_libs/ ; ./build_library_test.sh
128
129.PHONY: cleanTabs
130cleanTabs:
131	cd contrib; ./cleanTabs
132
133.PHONY: clean
134clean:
135	$(Q)$(MAKE) -C $(ZSTDDIR) $@ > $(VOID)
136	$(Q)$(MAKE) -C $(PRGDIR) $@ > $(VOID)
137	$(Q)$(MAKE) -C $(TESTDIR) $@ > $(VOID)
138	$(Q)$(MAKE) -C $(ZWRAPDIR) $@ > $(VOID)
139	$(Q)$(MAKE) -C examples/ $@ > $(VOID)
140	$(Q)$(MAKE) -C contrib/gen_html $@ > $(VOID)
141	$(Q)$(MAKE) -C contrib/pzstd $@ > $(VOID)
142	$(Q)$(MAKE) -C contrib/seekable_format/examples $@ > $(VOID)
143	$(Q)$(MAKE) -C contrib/seekable_format/tests $@ > $(VOID)
144	$(Q)$(MAKE) -C contrib/largeNbDicts $@ > $(VOID)
145	$(Q)$(RM) zstd$(EXT) zstdmt$(EXT) tmp*
146	$(Q)$(RM) -r lz4
147	@echo Cleaning completed
148
149#------------------------------------------------------------------------------
150# make install is validated only for Linux, macOS, Hurd and some BSD targets
151#------------------------------------------------------------------------------
152ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD DragonFly NetBSD MSYS_NT Haiku))
153
154HOST_OS = POSIX
155CMAKE_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
156
157HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
158EGREP_OPTIONS ?=
159ifeq ($HAVE_COLORNEVER, 1)
160EGREP_OPTIONS += --color=never
161endif
162EGREP = egrep $(EGREP_OPTIONS)
163
164# Print a two column output of targets and their description. To add a target description, put a
165# comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>".  For example:
166#
167## list: Print all targets and their descriptions (if provided)
168.PHONY: list
169list:
170	$(Q)TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \
171		| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
172		| $(EGREP) -v  -e '^[^[:alnum:]]' | sort); \
173	{ \
174	    printf "Target Name\tDescription\n"; \
175	    printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \
176	    for target in $$TARGETS; do \
177	        line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \
178	        description=$$(echo $$line | awk '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \
179	        printf "$$target\t$$description\n"; \
180	    done \
181	} | column -t -s $$'\t'
182
183.PHONY: install armtest usan asan uasan
184install:
185	$(Q)$(MAKE) -C $(ZSTDDIR) $@
186	$(Q)$(MAKE) -C $(PRGDIR) $@
187
188.PHONY: uninstall
189uninstall:
190	$(Q)$(MAKE) -C $(ZSTDDIR) $@
191	$(Q)$(MAKE) -C $(PRGDIR) $@
192
193.PHONY: travis-install
194travis-install:
195	$(MAKE) install PREFIX=~/install_test_dir
196
197.PHONY: gcc5build
198gcc5build: clean
199	gcc-5 -v
200	CC=gcc-5 $(MAKE) all MOREFLAGS="-Werror"
201
202.PHONY: gcc6build
203gcc6build: clean
204	gcc-6 -v
205	CC=gcc-6 $(MAKE) all MOREFLAGS="-Werror"
206
207.PHONY: gcc7build
208gcc7build: clean
209	gcc-7 -v
210	CC=gcc-7 $(MAKE) all MOREFLAGS="-Werror"
211
212.PHONY: clangbuild
213clangbuild: clean
214	clang -v
215	CXX=clang++ CC=clang CFLAGS="-Werror -Wconversion -Wno-sign-conversion -Wdocumentation" $(MAKE) all
216
217m32build: clean
218	gcc -v
219	$(MAKE) all32
220
221armbuild: clean
222	CC=arm-linux-gnueabi-gcc CFLAGS="-Werror" $(MAKE) allzstd
223
224aarch64build: clean
225	CC=aarch64-linux-gnu-gcc CFLAGS="-Werror" $(MAKE) allzstd
226
227ppcbuild: clean
228	CC=powerpc-linux-gnu-gcc CFLAGS="-m32 -Wno-attributes -Werror" $(MAKE) allzstd
229
230ppc64build: clean
231	CC=powerpc-linux-gnu-gcc CFLAGS="-m64 -Werror" $(MAKE) allzstd
232
233armfuzz: clean
234	CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
235
236aarch64fuzz: clean
237	ld -v
238	CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
239
240ppcfuzz: clean
241	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static MOREFLAGS="-static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
242
243ppc64fuzz: clean
244	CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests $(MAKE) -C $(TESTDIR) fuzztest
245
246.PHONY: cxxtest
247cxxtest: CXXFLAGS += -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
248cxxtest: clean
249	$(MAKE) -C $(PRGDIR) all CC="$(CXX) -Wno-deprecated" CFLAGS="$(CXXFLAGS)"   # adding -Wno-deprecated to avoid clang++ warning on dealing with C files directly
250
251gcc5test: clean
252	gcc-5 -v
253	$(MAKE) all CC=gcc-5 MOREFLAGS="-Werror"
254
255gcc6test: clean
256	gcc-6 -v
257	$(MAKE) all CC=gcc-6 MOREFLAGS="-Werror"
258
259armtest: clean
260	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
261	$(MAKE) -C $(TESTDIR) test CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
262
263aarch64test:
264	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
265	$(MAKE) -C $(TESTDIR) test CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static" FUZZER_FLAGS=--no-big-tests
266
267ppctest: clean
268	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
269	$(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
270
271ppc64test: clean
272	$(MAKE) -C $(TESTDIR) datagen   # use native, faster
273	$(MAKE) -C $(TESTDIR) test CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static" FUZZER_FLAGS=--no-big-tests
274
275arm-ppc-compilation:
276	$(MAKE) -C $(PRGDIR) clean zstd CC=arm-linux-gnueabi-gcc QEMU_SYS=qemu-arm-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
277	$(MAKE) -C $(PRGDIR) clean zstd CC=aarch64-linux-gnu-gcc QEMU_SYS=qemu-aarch64-static ZSTDRTTEST= MOREFLAGS="-Werror -static"
278	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc-static ZSTDRTTEST= MOREFLAGS="-Werror -Wno-attributes -static"
279	$(MAKE) -C $(PRGDIR) clean zstd CC=powerpc-linux-gnu-gcc QEMU_SYS=qemu-ppc64-static ZSTDRTTEST= MOREFLAGS="-m64 -static"
280
281regressiontest:
282	$(MAKE) -C $(FUZZDIR) regressiontest
283
284uasanregressiontest:
285	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=address,undefined" CXXFLAGS="-O3 -fsanitize=address,undefined"
286
287msanregressiontest:
288	$(MAKE) -C $(FUZZDIR) regressiontest CC=clang CXX=clang++ CFLAGS="-O3 -fsanitize=memory" CXXFLAGS="-O3 -fsanitize=memory"
289
290# run UBsan with -fsanitize-recover=signed-integer-overflow
291# due to a bug in UBsan when doing pointer subtraction
292# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303
293
294usan: clean
295	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=undefined -Werror"
296
297asan: clean
298	$(MAKE) test CC=clang MOREFLAGS="-g -fsanitize=address -Werror"
299
300asan-%: clean
301	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=address -Werror" $(MAKE) -C $(TESTDIR) $*
302
303msan: clean
304	$(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
305
306msan-%: clean
307	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 $*
308
309asan32: clean
310	$(MAKE) -C $(TESTDIR) test32 CC=clang MOREFLAGS="-g -fsanitize=address"
311
312uasan: clean
313	$(MAKE) test CC=clang MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror"
314
315uasan-%: clean
316	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize-recover=signed-integer-overflow -fsanitize=address,undefined -Werror" $(MAKE) -C $(TESTDIR) $*
317
318tsan-%: clean
319	LDFLAGS=-fuse-ld=gold MOREFLAGS="-g -fno-sanitize-recover=all -fsanitize=thread -Werror" $(MAKE) -C $(TESTDIR) $* FUZZER_FLAGS=--no-big-tests
320
321apt-install:
322	sudo apt-get -yq --no-install-suggests --no-install-recommends --force-yes install $(APT_PACKAGES)
323
324apt-add-repo:
325	sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
326	sudo apt-get update -y -qq
327
328ppcinstall:
329	APT_PACKAGES="qemu-system-ppc qemu-user-static gcc-powerpc-linux-gnu" $(MAKE) apt-install
330
331arminstall:
332	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
333
334valgrindinstall:
335	APT_PACKAGES="valgrind" $(MAKE) apt-install
336
337libc6install:
338	APT_PACKAGES="libc6-dev-i386 gcc-multilib" $(MAKE) apt-install
339
340gcc6install: apt-add-repo
341	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-6 gcc-6-multilib" $(MAKE) apt-install
342
343gcc7install: apt-add-repo
344	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-7 gcc-7-multilib" $(MAKE) apt-install
345
346gcc8install: apt-add-repo
347	APT_PACKAGES="libc6-dev-i386 gcc-multilib gcc-8 gcc-8-multilib" $(MAKE) apt-install
348
349gpp6install: apt-add-repo
350	APT_PACKAGES="libc6-dev-i386 g++-multilib gcc-6 g++-6 g++-6-multilib" $(MAKE) apt-install
351
352clang38install:
353	APT_PACKAGES="clang-3.8" $(MAKE) apt-install
354
355# Ubuntu 14.04 ships a too-old lz4
356lz4install:
357	[ -e lz4 ] || git clone https://github.com/lz4/lz4 && sudo $(MAKE) -C lz4 install
358
359endif
360
361
362ifneq (,$(filter MSYS%,$(shell uname)))
363HOST_OS = MSYS
364CMAKE_PARAMS = -G"MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DZSTD_MULTITHREAD_SUPPORT:BOOL=OFF -DZSTD_BUILD_STATIC:BOOL=ON -DZSTD_BUILD_TESTS:BOOL=ON
365endif
366
367
368#------------------------------------------------------------------------
369# target specific tests
370#------------------------------------------------------------------------
371ifneq (,$(filter $(HOST_OS),MSYS POSIX))
372cmakebuild:
373	cmake --version
374	$(RM) -r $(BUILDIR)/cmake/build
375	mkdir $(BUILDIR)/cmake/build
376	cd $(BUILDIR)/cmake/build; cmake -DCMAKE_INSTALL_PREFIX:PATH=~/install_test_dir $(CMAKE_PARAMS) ..
377	$(MAKE) -C $(BUILDIR)/cmake/build -j4;
378	$(MAKE) -C $(BUILDIR)/cmake/build install;
379	$(MAKE) -C $(BUILDIR)/cmake/build uninstall;
380	cd $(BUILDIR)/cmake/build; ctest -V -L Medium
381
382c89build: clean
383	$(CC) -v
384	CFLAGS="-std=c89 -Werror" $(MAKE) allmost  # will fail, due to missing support for `long long`
385
386gnu90build: clean
387	$(CC) -v
388	CFLAGS="-std=gnu90 -Werror" $(MAKE) allmost
389
390c99build: clean
391	$(CC) -v
392	CFLAGS="-std=c99 -Werror" $(MAKE) allmost
393
394gnu99build: clean
395	$(CC) -v
396	CFLAGS="-std=gnu99 -Werror" $(MAKE) allmost
397
398c11build: clean
399	$(CC) -v
400	CFLAGS="-std=c11 -Werror" $(MAKE) allmost
401
402bmix64build: clean
403	$(CC) -v
404	CFLAGS="-O3 -mbmi -Werror" $(MAKE) -C $(TESTDIR) test
405
406bmix32build: clean
407	$(CC) -v
408	CFLAGS="-O3 -mbmi -mx32 -Werror" $(MAKE) -C $(TESTDIR) test
409
410bmi32build: clean
411	$(CC) -v
412	CFLAGS="-O3 -mbmi -m32 -Werror" $(MAKE) -C $(TESTDIR) test
413
414# static analyzer test uses clang's scan-build
415# does not analyze zlibWrapper, due to detected issues in zlib source code
416staticAnalyze: SCANBUILD ?= scan-build
417staticAnalyze:
418	$(CC) -v
419	CC=$(CC) CPPFLAGS=-g $(SCANBUILD) --status-bugs -v $(MAKE) allzstd examples contrib
420endif
421