1
# ################################################################
3
# Copyright (C) Yann Collet 2011-2020
7
# Redistribution and use in source and binary forms, with or without modification,
8
# are permitted provided that the following conditions are met:
10
# * Redistributions of source code must retain the above copyright notice, this
11
# list of conditions and the following disclaimer.
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.
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.
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
# ################################################################
43
default: lib-release lz4-release
45
# silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
46
$(V)$(VERBOSE).SILENT:
49
all: allmost examples manuals build_tests
54
.PHONY: lib lib-release liblz4.a
56
lib lib-release liblz4.a:
57
$(MAKE) -C $(LZ4DIR) $@
59
.PHONY: lz4 lz4-release
61
lz4-release : lib-release
63
$(MAKE) -C $(PRGDIR) $@
64
cp $(PRGDIR)/lz4$(EXT) .
68
$(MAKE) -C $(EXDIR) all
72
$(MAKE) -C contrib/gen_manual $@
76
$(MAKE) -C $(TESTDIR) all
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)
87
$(RM) -r $(CMAKE_BUILD_DIR)
88
@echo Cleaning completed
91
#-----------------------------------------------------------------------------
92
# make install is validated only for Posix environments
93
#-----------------------------------------------------------------------------
94
ifeq ($(POSIX_ENV),Yes)
97
.PHONY: install uninstall
99
$(MAKE) -C $(LZ4DIR) $@
100
$(MAKE) -C $(PRGDIR) $@
102
.PHONY: travis-install
104
$(MAKE) -j1 install DESTDIR=~/install_test_dir
110
CMAKE_BUILD_DIR ?= build/cmake/build
111
ifneq (,$(filter MSYS%,$(shell $(UNAME))))
113
CMAKE_PARAMS = -G"MSYS Makefiles"
118
mkdir -p $(CMAKE_BUILD_DIR)
119
cd $(CMAKE_BUILD_DIR); $(CMAKE) $(CMAKE_PARAMS) ..; $(CMAKE) --build .
122
#------------------------------------------------------------------------
123
# make tests validated only for MSYS and Posix environments
124
#------------------------------------------------------------------------
125
ifneq (,$(filter $(HOST_OS),MSYS POSIX))
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
133
$(MAKE) -C $(TESTDIR) test-lz4-essentials
137
$(MAKE) -C $(TESTDIR) $@
138
$(MAKE) -C $(EXDIR) $@
141
clangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
142
clangtest: CC = clang
145
$(MAKE) -C $(LZ4DIR) all CC=$(CC)
146
$(MAKE) -C $(PRGDIR) all CC=$(CC)
147
$(MAKE) -C $(TESTDIR) all CC=$(CC)
149
.PHONY: clangtest-native
150
clangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion
151
clangtest-native: clean
153
$(MAKE) -C $(LZ4DIR) all CC=clang
154
$(MAKE) -C $(PRGDIR) native CC=clang
155
$(MAKE) -C $(TESTDIR) native CC=clang
159
usan: CFLAGS = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
160
usan: LDFLAGS = $(CFLAGS)
162
CC=$(CC) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
165
usan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined
166
usan32: LDFLAGS = $(CFLAGS)
168
$(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
170
SCANBUILD ?= scan-build
171
SCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
172
.PHONY: staticAnalyze
174
CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
178
cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
182
@echo "\n ---- test lz4 with $(CC) compiler ----"
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
191
$(MAKE) -C $(TESTDIR) $@
193
.PHONY: test-freestanding
195
$(MAKE) -C $(TESTDIR) clean $@
197
.PHONY: cxxtest cxx32test
198
cxxtest cxx32test: CC := "$(CXX) -Wno-deprecated"
199
cxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
200
cxx32test: CFLAGS += -m32
201
cxxtest cxx32test: clean
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)"
208
cxx17build : CC = "$(CXX) -Wno-deprecated"
209
cxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
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)"
217
ctocpptest: LIBCC="$(CC)"
218
ctocpptest: TESTCC="$(CXX)"
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
226
c_standards: clean c_standards_c11 c_standards_c99 c_standards_c90
228
.PHONY: c_standards_c90
229
c_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
233
.PHONY: c_standards_c99
234
c_standards_c99: clean
235
$(MAKE) clean; CFLAGS="-std=c99 -Werror -pedantic" $(MAKE) all
236
$(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
238
.PHONY: c_standards_c11
239
c_standards_c11: clean
240
$(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all
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
246
standard_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 =================
252
CFLAGS=-DCFLAGS_TEST \
253
CPPFLAGS=-DCPPFLAGS_TEST \
254
LDFLAGS=-DLDFLAGS_TEST \
255
LDLIBS=-DLDLIBS_TEST \
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 =================