1# ################################################################
2# LZ4 - Makefile
3# Copyright (C) Yann Collet 2011-2016
4# All rights reserved.
5#
6# This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
7#
8# BSD license
9# Redistribution and use in source and binary forms, with or without modification,
10# are permitted provided that the following conditions are met:
11#
12# * Redistributions of source code must retain the above copyright notice, this
13#   list of conditions and the following disclaimer.
14#
15# * Redistributions in binary form must reproduce the above copyright notice, this
16#   list of conditions and the following disclaimer in the documentation and/or
17#   other materials provided with the distribution.
18#
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29#
30# You can contact the author at :
31#  - LZ4 source repository : https://github.com/lz4/lz4
32#  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
33# ################################################################
34
35LZ4DIR  = lib
36PRGDIR  = programs
37TESTDIR = tests
38EXDIR   = examples
39
40
41# Define nul output
42ifneq (,$(filter Windows%,$(OS)))
43EXT  = .exe
44VOID = nul
45else
46EXT  =
47VOID = /dev/null
48endif
49
50
51.PHONY: default
52default: lib-release lz4-release
53
54.PHONY: all
55all: allmost manuals
56
57.PHONY: allmost
58allmost: lib lz4 examples
59
60.PHONY: lib lib-release
61lib lib-release:
62	@$(MAKE) -C $(LZ4DIR) $@
63
64.PHONY: lz4 lz4-release
65lz4 : lib
66lz4-release : lib-release
67lz4 lz4-release :
68	@$(MAKE) -C $(PRGDIR) $@
69	@cp $(PRGDIR)/lz4$(EXT) .
70
71.PHONY: examples
72examples: lib lz4
73	$(MAKE) -C $(EXDIR) test
74
75.PHONY: manuals
76manuals:
77	@$(MAKE) -C contrib/gen_manual $@
78
79.PHONY: clean
80clean:
81	@$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
82	@$(MAKE) -C $(PRGDIR) $@ > $(VOID)
83	@$(MAKE) -C $(TESTDIR) $@ > $(VOID)
84	@$(MAKE) -C $(EXDIR) $@ > $(VOID)
85	@$(MAKE) -C contrib/gen_manual $@
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#-----------------------------------------------------------------------------
93ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
94HOST_OS = POSIX
95
96.PHONY: install uninstall
97install uninstall:
98	@$(MAKE) -C $(LZ4DIR) $@
99	@$(MAKE) -C $(PRGDIR) $@
100
101travis-install:
102	$(MAKE) -j1 install DESTDIR=~/install_test_dir
103
104cmake:
105	@cd contrib/cmake_unofficial; cmake $(CMAKE_PARAMS) CMakeLists.txt; $(MAKE)
106
107endif
108
109
110ifneq (,$(filter MSYS%,$(shell uname)))
111HOST_OS = MSYS
112CMAKE_PARAMS = -G"MSYS Makefiles"
113endif
114
115
116#------------------------------------------------------------------------
117#make tests validated only for MSYS, Linux, OSX, kFreeBSD and Hurd targets
118#------------------------------------------------------------------------
119ifneq (,$(filter $(HOST_OS),MSYS POSIX))
120
121.PHONY: list
122list:
123	@$(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
124
125.PHONY: test
126test:
127	$(MAKE) -C $(TESTDIR) $@
128
129clangtest: clean
130	clang -v
131	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(LZ4DIR)  all CC=clang
132	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(PRGDIR)  all CC=clang
133	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(TESTDIR) all CC=clang
134
135clangtest-native: clean
136	clang -v
137	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(LZ4DIR)  all    CC=clang
138	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(PRGDIR)  native CC=clang
139	@CFLAGS="-O3 -Werror -Wconversion -Wno-sign-conversion" $(MAKE) -C $(TESTDIR) native CC=clang
140
141usan: clean
142	CC=clang CFLAGS="-O3 -g -fsanitize=undefined" $(MAKE) test FUZZER_TIME="-T1mn" NB_LOOPS=-i1
143
144usan32: clean
145	CFLAGS="-m32 -O3 -g -fsanitize=undefined" $(MAKE) test FUZZER_TIME="-T1mn" NB_LOOPS=-i1
146
147staticAnalyze: clean
148	CFLAGS=-g scan-build --status-bugs -v $(MAKE) all
149
150platformTest: clean
151	@echo "\n ---- test lz4 with $(CC) compiler ----"
152	@$(CC) -v
153	CFLAGS="-O3 -Werror"         $(MAKE) -C $(LZ4DIR) all
154	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
155	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
156	$(MAKE) -C $(TESTDIR) test-platform
157
158.PHONY: versionsTest
159versionsTest: clean
160	$(MAKE) -C $(TESTDIR) $@
161
162gpptest: clean
163	g++ -v
164	CC=g++ $(MAKE) -C $(LZ4DIR)  all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
165	CC=g++ $(MAKE) -C $(PRGDIR)  all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
166	CC=g++ $(MAKE) -C $(TESTDIR) all CFLAGS="-O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
167
168gpptest32: clean
169	g++ -v
170	CC=g++ $(MAKE) -C $(LZ4DIR)  all    CFLAGS="-m32 -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
171	CC=g++ $(MAKE) -C $(PRGDIR)  native CFLAGS="-m32 -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
172	CC=g++ $(MAKE) -C $(TESTDIR) native CFLAGS="-m32 -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror"
173
174c_standards: clean
175	# note : lz4 is not C90 compatible, because it requires long long support
176	CFLAGS="-std=gnu90 -Werror" $(MAKE) clean allmost
177	CFLAGS="-std=c99   -Werror" $(MAKE) clean allmost
178	CFLAGS="-std=gnu99 -Werror" $(MAKE) clean allmost
179	CFLAGS="-std=c11   -Werror" $(MAKE) clean allmost
180
181endif
182