• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	$(RM) -r $(CMAKE_BUILD_DIR)
88	@echo Cleaning completed
89
90
91#-----------------------------------------------------------------------------
92# make install is validated only for Posix environments
93#-----------------------------------------------------------------------------
94ifeq ($(POSIX_ENV),Yes)
95HOST_OS = POSIX
96
97.PHONY: install uninstall
98install uninstall:
99	$(MAKE) -C $(LZ4DIR) $@
100	$(MAKE) -C $(PRGDIR) $@
101
102.PHONY: travis-install
103travis-install:
104	$(MAKE) -j1 install DESTDIR=~/install_test_dir
105
106endif   # POSIX_ENV
107
108
109CMAKE ?= cmake
110CMAKE_BUILD_DIR ?= build/cmake/build
111ifneq (,$(filter MSYS%,$(shell $(UNAME))))
112HOST_OS = MSYS
113CMAKE_PARAMS = -G"MSYS Makefiles"
114endif
115
116.PHONY: cmake
117cmake:
118	mkdir -p $(CMAKE_BUILD_DIR)
119	cd $(CMAKE_BUILD_DIR); $(CMAKE) $(CMAKE_PARAMS) ..; $(CMAKE) --build .
120
121
122#------------------------------------------------------------------------
123# make tests validated only for MSYS and Posix environments
124#------------------------------------------------------------------------
125ifneq (,$(filter $(HOST_OS),MSYS POSIX))
126
127.PHONY: list
128list:
129	$(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
130
131.PHONY: check
132check:
133	$(MAKE) -C $(TESTDIR) test-lz4-essentials
134
135.PHONY: test
136test:
137	$(MAKE) -C $(TESTDIR) $@
138	$(MAKE) -C $(EXDIR) $@
139
140.PHONY: clangtest
141clangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
142clangtest: CC = clang
143clangtest: clean
144	$(CC) -v
145	$(MAKE) -C $(LZ4DIR)  all CC=$(CC)
146	$(MAKE) -C $(PRGDIR)  all CC=$(CC)
147	$(MAKE) -C $(TESTDIR) all CC=$(CC)
148
149.PHONY: clangtest-native
150clangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion
151clangtest-native: clean
152	clang -v
153	$(MAKE) -C $(LZ4DIR)  all    CC=clang
154	$(MAKE) -C $(PRGDIR)  native CC=clang
155	$(MAKE) -C $(TESTDIR) native CC=clang
156
157.PHONY: usan
158usan: CC      = clang
159usan: CFLAGS  = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
160usan: LDFLAGS = $(CFLAGS)
161usan: clean
162	CC=$(CC) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
163
164.PHONY: usan32
165usan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined
166usan32: LDFLAGS = $(CFLAGS)
167usan32: clean
168	$(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
169
170SCANBUILD ?= scan-build
171SCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
172.PHONY: staticAnalyze
173staticAnalyze: clean
174	CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
175
176.PHONY: cppcheck
177cppcheck:
178	cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
179
180.PHONY: platformTest
181platformTest: clean
182	@echo "\n ---- test lz4 with $(CC) compiler ----"
183	$(CC) -v
184	CFLAGS="-O3 -Werror"         $(MAKE) -C $(LZ4DIR) all
185	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
186	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
187	$(MAKE) -C $(TESTDIR) test-platform
188
189.PHONY: versionsTest
190versionsTest: clean
191	$(MAKE) -C $(TESTDIR) $@
192
193.PHONY: test-freestanding
194test-freestanding:
195	$(MAKE) -C $(TESTDIR) clean $@
196
197.PHONY: cxxtest cxx32test
198cxxtest cxx32test: CC := "$(CXX) -Wno-deprecated"
199cxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
200cxx32test: CFLAGS += -m32
201cxxtest cxx32test: clean
202	$(CXX) -v
203	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
204	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
205	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
206
207.PHONY: cxx17build
208cxx17build : CC = "$(CXX) -Wno-deprecated"
209cxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
210cxx17build : clean
211	$(CXX) -v
212	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
213	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
214	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
215
216.PHONY: ctocpptest
217ctocpptest: LIBCC="$(CC)"
218ctocpptest: TESTCC="$(CXX)"
219ctocpptest: CFLAGS=
220ctocpptest: clean
221	CC=$(LIBCC)  $(MAKE) -C $(LZ4DIR)  CFLAGS="$(CFLAGS)" all
222	CC=$(LIBCC)  $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" lz4.o lz4hc.o lz4frame.o
223	CC=$(TESTCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" all
224
225.PHONY: c_standards
226c_standards: clean c_standards_c11 c_standards_c99 c_standards_c90
227
228.PHONY: c_standards_c90
229c_standards_c90: clean
230	$(MAKE) clean; CFLAGS="-std=c90   -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
231	$(MAKE) clean; CFLAGS="-std=gnu90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
232
233.PHONY: c_standards_c99
234c_standards_c99: clean
235	$(MAKE) clean; CFLAGS="-std=c99   -Werror -pedantic" $(MAKE) all
236	$(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
237
238.PHONY: c_standards_c11
239c_standards_c11: clean
240	$(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all
241
242# The following test ensures that standard Makefile variables set through environment
243# are correctly transmitted at compilation stage.
244# This test is meant to detect issues like https://github.com/lz4/lz4/issues/958
245.PHONY: standard_variables
246standard_variables: clean
247	@echo =================
248	@echo Check support of Makefile Standard variables through environment
249	@echo note : this test requires V=1 to work properly
250	@echo =================
251	CC="cc -DCC_TEST" \
252	CFLAGS=-DCFLAGS_TEST \
253	CPPFLAGS=-DCPPFLAGS_TEST \
254	LDFLAGS=-DLDFLAGS_TEST \
255	LDLIBS=-DLDLIBS_TEST \
256	$(MAKE) V=1 > tmpsv
257	# Note: just checking the presence of custom flags
258	# would not detect situations where custom flags are
259	# supported in some part of the Makefile, and missed in others.
260	# So the test checks if they are present the _right nb of times_.
261	# However, checking static quantities makes this test brittle,
262	# because quantities (7, 2 and 1) can still evolve in future,
263	# for example when source directories or Makefile evolve.
264	if [ $$(grep CC_TEST tmpsv | wc -l) -ne 7 ]; then \
265		echo "CC environment variable missed" && False; fi
266	if [ $$(grep CFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
267		echo "CFLAGS environment variable missed" && False; fi
268	if [ $$(grep CPPFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
269		echo "CPPFLAGS environment variable missed" && False; fi
270	if [ $$(grep LDFLAGS_TEST tmpsv | wc -l) -ne 2 ]; then \
271		echo "LDFLAGS environment variable missed" && False; fi
272	if [ $$(grep LDLIBS_TEST tmpsv | wc -l) -ne 1 ]; then \
273		echo "LDLIBS environment variable missed" && False; fi
274	@echo =================
275	@echo all custom variables detected
276	@echo =================
277	$(RM) tmpsv
278
279endif   # MSYS POSIX
280