1# ################################################################
2# LZ4 - Makefile
3# Copyright (C) Yann Collet 2011-2020
4# All rights reserved.
5#
6# BSD license
7# Redistribution and use in source and binary forms, with or without modification,
8# are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice, this
11#   list of conditions and the following disclaimer.
12#
13# * Redistributions in binary form must reproduce the above copyright notice, this
14#   list of conditions and the following disclaimer in the documentation and/or
15#   other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27#
28# You can contact the author at :
29#  - LZ4 source repository : https://github.com/lz4/lz4
30#  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
31# ################################################################
32
33LZ4DIR  = lib
34PRGDIR  = programs
35TESTDIR = tests
36EXDIR   = examples
37FUZZDIR = ossfuzz
38
39include Makefile.inc
40
41
42.PHONY: default
43default: lib-release lz4-release
44
45# silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
46$(V)$(VERBOSE).SILENT:
47
48.PHONY: all
49all: allmost examples manuals build_tests
50
51.PHONY: allmost
52allmost: lib lz4
53
54.PHONY: lib lib-release liblz4.a
55lib: liblz4.a
56lib lib-release liblz4.a:
57	$(MAKE) -C $(LZ4DIR) $@
58
59.PHONY: lz4 lz4-release
60lz4 : liblz4.a
61lz4-release : lib-release
62lz4 lz4-release :
63	$(MAKE) -C $(PRGDIR) $@
64	cp $(PRGDIR)/lz4$(EXT) .
65
66.PHONY: examples
67examples: liblz4.a
68	$(MAKE) -C $(EXDIR) all
69
70.PHONY: manuals
71manuals:
72	$(MAKE) -C contrib/gen_manual $@
73
74.PHONY: build_tests
75build_tests:
76	$(MAKE) -C $(TESTDIR) all
77
78.PHONY: clean
79clean:
80	$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
81	$(MAKE) -C $(PRGDIR) $@ > $(VOID)
82	$(MAKE) -C $(TESTDIR) $@ > $(VOID)
83	$(MAKE) -C $(EXDIR) $@ > $(VOID)
84	$(MAKE) -C $(FUZZDIR) $@ > $(VOID)
85	$(MAKE) -C contrib/gen_manual $@ > $(VOID)
86	$(RM) lz4$(EXT)
87	@echo Cleaning completed
88
89
90#-----------------------------------------------------------------------------
91# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
92#-----------------------------------------------------------------------------
93ifeq ($(POSIX_ENV),Yes)
94HOST_OS = POSIX
95
96.PHONY: install uninstall
97install uninstall:
98	$(MAKE) -C $(LZ4DIR) $@
99	$(MAKE) -C $(PRGDIR) $@
100
101.PHONY: travis-install
102travis-install:
103	$(MAKE) -j1 install DESTDIR=~/install_test_dir
104
105.PHONY: cmake
106cmake:
107	cd build/cmake; cmake $(CMAKE_PARAMS) CMakeLists.txt; $(MAKE)
108
109endif   # POSIX_ENV
110
111
112ifneq (,$(filter MSYS%,$(shell uname)))
113HOST_OS = MSYS
114CMAKE_PARAMS = -G"MSYS Makefiles"
115endif
116
117
118#------------------------------------------------------------------------
119#make tests validated only for MSYS, Linux, OSX, kFreeBSD and Hurd targets
120#------------------------------------------------------------------------
121ifneq (,$(filter $(HOST_OS),MSYS POSIX))
122
123.PHONY: list
124list:
125	$(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
126
127.PHONY: check
128check:
129	$(MAKE) -C $(TESTDIR) test-lz4-essentials
130
131.PHONY: test
132test:
133	$(MAKE) -C $(TESTDIR) $@
134	$(MAKE) -C $(EXDIR) $@
135
136.PHONY: clangtest
137clangtest: CFLAGS ?= -O3  # make's bug (http://savannah.gnu.org/bugs/?func=detailitem&item_id=59230)
138# this line has the hidden side effect of `unexport CFLAGS`
139export CFLAGS   # fix the side effect by issuing export command
140clangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
141clangtest: CC = clang
142clangtest: clean
143	$(CC) -v
144	$(MAKE) -C $(LZ4DIR)  all CC=$(CC)
145	$(MAKE) -C $(PRGDIR)  all CC=$(CC)
146	$(MAKE) -C $(TESTDIR) all CC=$(CC)
147
148.PHONY: clangtest-native
149clangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion
150clangtest-native: clean
151	clang -v
152	$(MAKE) -C $(LZ4DIR)  all    CC=clang
153	$(MAKE) -C $(PRGDIR)  native CC=clang
154	$(MAKE) -C $(TESTDIR) native CC=clang
155
156.PHONY: usan
157usan: CC      = clang
158usan: CFLAGS  = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
159usan: LDFLAGS = $(CFLAGS)
160usan: clean
161	$(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
162
163.PHONY: usan32
164usan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined
165usan32: LDFLAGS = $(CFLAGS)
166usan32: clean
167	$(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
168
169SCANBUILD ?= scan-build
170SCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
171.PHONY: staticAnalyze
172staticAnalyze: clean
173	CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
174
175.PHONY: cppcheck
176cppcheck:
177	cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
178
179.PHONY: platformTest
180platformTest: clean
181	@echo "\n ---- test lz4 with $(CC) compiler ----"
182	$(CC) -v
183	CFLAGS="-O3 -Werror"         $(MAKE) -C $(LZ4DIR) all
184	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
185	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
186	$(MAKE) -C $(TESTDIR) test-platform
187
188.PHONY: versionsTest
189versionsTest: clean
190	$(MAKE) -C $(TESTDIR) $@
191
192.PHONY: cxxtest cxx32test
193cxxtest cxx32test: CC := "$(CXX) -Wno-deprecated"
194cxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
195cxx32test: CFLAGS += -m32
196cxxtest cxx32test: clean
197	$(CXX) -v
198	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
199	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
200	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
201
202.PHONY: cxx17build
203cxx17build : CC = "$(CXX) -Wno-deprecated"
204cxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
205cxx17build : clean
206	$(CXX) -v
207	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
208	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
209	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
210
211.PHONY: ctocpptest
212ctocpptest: LIBCC="$(CC)"
213ctocpptest: TESTCC="$(CXX)"
214ctocpptest: CFLAGS=
215ctocpptest: clean
216	CC=$(LIBCC)  $(MAKE) -C $(LZ4DIR)  CFLAGS="$(CFLAGS)" all
217	CC=$(LIBCC)  $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" lz4.o lz4hc.o lz4frame.o
218	CC=$(TESTCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" all
219
220.PHONY: c_standards
221c_standards: clean
222	$(MAKE) clean; CFLAGS="-std=c90   -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
223	$(MAKE) clean; CFLAGS="-std=gnu90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
224	$(MAKE) clean; CFLAGS="-std=c99   -Werror -pedantic" $(MAKE) all
225	$(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
226	$(MAKE) clean; CFLAGS="-std=c11   -Werror" $(MAKE) all
227
228endif   # MSYS POSIX
229