• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ################################################################
2# LZ4 - Makefile
3# Copyright (C) Yann Collet 2011-present
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.PHONY: default
42default: lib-release lz4-release
43
44.PHONY: all
45all: allmost examples manuals build_tests
46
47.PHONY: allmost
48allmost: lib lz4
49
50.PHONY: lib lib-release liblz4.a
51lib: liblz4.a
52lib lib-release liblz4.a:
53	@$(MAKE) -C $(LZ4DIR) $@
54
55.PHONY: lz4 lz4-release
56lz4 : liblz4.a
57lz4-release : lib-release
58lz4 lz4-release :
59	@$(MAKE) -C $(PRGDIR) $@
60	@cp $(PRGDIR)/lz4$(EXT) .
61
62.PHONY: examples
63examples: liblz4.a
64	$(MAKE) -C $(EXDIR) all
65
66.PHONY: manuals
67manuals:
68	@$(MAKE) -C contrib/gen_manual $@
69
70.PHONY: build_tests
71build_tests:
72	@$(MAKE) -C $(TESTDIR) all
73
74.PHONY: clean
75clean:
76	@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
77	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
78	@$(MAKE) -C $(TESTDIR) $@ > $(VOID)
79	@$(MAKE) -C $(EXDIR) $@ > $(VOID)
80	@$(MAKE) -C $(FUZZDIR) $@ > $(VOID)
81	@$(MAKE) -C contrib/gen_manual $@ > $(VOID)
82	@$(RM) lz4$(EXT)
83	@echo Cleaning completed
84
85
86#-----------------------------------------------------------------------------
87# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
88#-----------------------------------------------------------------------------
89ifeq ($(POSIX_ENV),Yes)
90HOST_OS = POSIX
91
92.PHONY: install uninstall
93install uninstall:
94	@$(MAKE) -C $(LZ4DIR) $@
95	@$(MAKE) -C $(PRGDIR) $@
96
97travis-install:
98	$(MAKE) -j1 install DESTDIR=~/install_test_dir
99
100cmake:
101	@cd build/cmake; cmake $(CMAKE_PARAMS) CMakeLists.txt; $(MAKE)
102
103endif
104
105
106ifneq (,$(filter MSYS%,$(shell uname)))
107HOST_OS = MSYS
108CMAKE_PARAMS = -G"MSYS Makefiles"
109endif
110
111
112#------------------------------------------------------------------------
113#make tests validated only for MSYS, Linux, OSX, kFreeBSD and Hurd targets
114#------------------------------------------------------------------------
115ifneq (,$(filter $(HOST_OS),MSYS POSIX))
116
117.PHONY: list
118list:
119	@$(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
120
121.PHONY: check
122check:
123	$(MAKE) -C $(TESTDIR) test-lz4-essentials
124
125.PHONY: test
126test:
127	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) -C $(TESTDIR) $@
128	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) -C $(EXDIR) $@
129
130clangtest: CFLAGS ?= -O3
131clangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
132clangtest: CC = clang
133clangtest: clean
134	$(CC) -v
135	@CFLAGS="$(CFLAGS)" $(MAKE) -C $(LZ4DIR)  all CC=$(CC)
136	@CFLAGS="$(CFLAGS)" $(MAKE) -C $(PRGDIR)  all CC=$(CC)
137	@CFLAGS="$(CFLAGS)" $(MAKE) -C $(TESTDIR) all CC=$(CC)
138
139clangtest-native: clean
140	clang -v
141	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(LZ4DIR)  all    CC=clang
142	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(PRGDIR)  native CC=clang
143	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(TESTDIR) native CC=clang
144
145usan: CC      = clang
146usan: CFLAGS  = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
147usan: LDFLAGS = $(CFLAGS)
148usan: clean
149	CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
150
151usan32: clean
152	CFLAGS="-m32 -O3 -g -fsanitize=undefined" $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
153
154SCANBUILD ?= scan-build
155SCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
156.PHONY: staticAnalyze
157staticAnalyze: clean
158	CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
159
160.PHONY: cppcheck
161cppcheck:
162	cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
163
164platformTest: clean
165	@echo "\n ---- test lz4 with $(CC) compiler ----"
166	@$(CC) -v
167	CFLAGS="-O3 -Werror"         $(MAKE) -C $(LZ4DIR) all
168	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
169	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
170	$(MAKE) -C $(TESTDIR) test-platform
171
172.PHONY: versionsTest
173versionsTest: clean
174	$(MAKE) -C $(TESTDIR) $@
175
176gpptest gpptest32: CC = "$(CXX) -Wno-deprecated"
177gpptest gpptest32: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
178gpptest32: CFLAGS += -m32
179gpptest gpptest32: clean
180	$(CXX) -v
181	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
182	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
183	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
184
185cxx17build : CC = "$(CXX) -Wno-deprecated"
186cxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
187cxx17build : clean
188	$(CXX) -v
189	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
190	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
191	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
192
193ctocpptest: LIBCC="$(CC)"
194ctocpptest: TESTCC="$(CXX)"
195ctocpptest: CFLAGS=""
196ctocpptest: clean
197	CC=$(LIBCC)  $(MAKE) -C $(LZ4DIR)  CFLAGS="$(CFLAGS)" all
198	CC=$(LIBCC)  $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" lz4.o lz4hc.o lz4frame.o
199	CC=$(TESTCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" all
200
201c_standards: clean
202	$(MAKE) clean; CFLAGS="-std=c90   -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
203	$(MAKE) clean; CFLAGS="-std=gnu90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
204	$(MAKE) clean; CFLAGS="-std=c99   -Werror -pedantic" $(MAKE) all
205	$(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
206	$(MAKE) clean; CFLAGS="-std=c11   -Werror" $(MAKE) all
207
208endif
209