127b27ec6Sopenharmony_ci# ################################################################
227b27ec6Sopenharmony_ci# LZ4 - Makefile
327b27ec6Sopenharmony_ci# Copyright (C) Yann Collet 2011-2020
427b27ec6Sopenharmony_ci# All rights reserved.
527b27ec6Sopenharmony_ci#
627b27ec6Sopenharmony_ci# BSD license
727b27ec6Sopenharmony_ci# Redistribution and use in source and binary forms, with or without modification,
827b27ec6Sopenharmony_ci# are permitted provided that the following conditions are met:
927b27ec6Sopenharmony_ci#
1027b27ec6Sopenharmony_ci# * Redistributions of source code must retain the above copyright notice, this
1127b27ec6Sopenharmony_ci#   list of conditions and the following disclaimer.
1227b27ec6Sopenharmony_ci#
1327b27ec6Sopenharmony_ci# * Redistributions in binary form must reproduce the above copyright notice, this
1427b27ec6Sopenharmony_ci#   list of conditions and the following disclaimer in the documentation and/or
1527b27ec6Sopenharmony_ci#   other materials provided with the distribution.
1627b27ec6Sopenharmony_ci#
1727b27ec6Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
1827b27ec6Sopenharmony_ci# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1927b27ec6Sopenharmony_ci# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2027b27ec6Sopenharmony_ci# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
2127b27ec6Sopenharmony_ci# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2227b27ec6Sopenharmony_ci# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2327b27ec6Sopenharmony_ci# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2427b27ec6Sopenharmony_ci# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2527b27ec6Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2627b27ec6Sopenharmony_ci# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2727b27ec6Sopenharmony_ci#
2827b27ec6Sopenharmony_ci# You can contact the author at :
2927b27ec6Sopenharmony_ci#  - LZ4 source repository : https://github.com/lz4/lz4
3027b27ec6Sopenharmony_ci#  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
3127b27ec6Sopenharmony_ci# ################################################################
3227b27ec6Sopenharmony_ci
3327b27ec6Sopenharmony_ciLZ4DIR  = lib
3427b27ec6Sopenharmony_ciPRGDIR  = programs
3527b27ec6Sopenharmony_ciTESTDIR = tests
3627b27ec6Sopenharmony_ciEXDIR   = examples
3727b27ec6Sopenharmony_ciFUZZDIR = ossfuzz
3827b27ec6Sopenharmony_ci
3927b27ec6Sopenharmony_ciinclude Makefile.inc
4027b27ec6Sopenharmony_ci
4127b27ec6Sopenharmony_ci
4227b27ec6Sopenharmony_ci.PHONY: default
4327b27ec6Sopenharmony_cidefault: lib-release lz4-release
4427b27ec6Sopenharmony_ci
4527b27ec6Sopenharmony_ci# silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
4627b27ec6Sopenharmony_ci$(V)$(VERBOSE).SILENT:
4727b27ec6Sopenharmony_ci
4827b27ec6Sopenharmony_ci.PHONY: all
4927b27ec6Sopenharmony_ciall: allmost examples manuals build_tests
5027b27ec6Sopenharmony_ci
5127b27ec6Sopenharmony_ci.PHONY: allmost
5227b27ec6Sopenharmony_ciallmost: lib lz4
5327b27ec6Sopenharmony_ci
5427b27ec6Sopenharmony_ci.PHONY: lib lib-release liblz4.a
5527b27ec6Sopenharmony_cilib: liblz4.a
5627b27ec6Sopenharmony_cilib lib-release liblz4.a:
5727b27ec6Sopenharmony_ci	$(MAKE) -C $(LZ4DIR) $@
5827b27ec6Sopenharmony_ci
5927b27ec6Sopenharmony_ci.PHONY: lz4 lz4-release
6027b27ec6Sopenharmony_cilz4 : liblz4.a
6127b27ec6Sopenharmony_cilz4-release : lib-release
6227b27ec6Sopenharmony_cilz4 lz4-release :
6327b27ec6Sopenharmony_ci	$(MAKE) -C $(PRGDIR) $@
6427b27ec6Sopenharmony_ci	cp $(PRGDIR)/lz4$(EXT) .
6527b27ec6Sopenharmony_ci
6627b27ec6Sopenharmony_ci.PHONY: examples
6727b27ec6Sopenharmony_ciexamples: liblz4.a
6827b27ec6Sopenharmony_ci	$(MAKE) -C $(EXDIR) all
6927b27ec6Sopenharmony_ci
7027b27ec6Sopenharmony_ci.PHONY: manuals
7127b27ec6Sopenharmony_cimanuals:
7227b27ec6Sopenharmony_ci	$(MAKE) -C contrib/gen_manual $@
7327b27ec6Sopenharmony_ci
7427b27ec6Sopenharmony_ci.PHONY: build_tests
7527b27ec6Sopenharmony_cibuild_tests:
7627b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) all
7727b27ec6Sopenharmony_ci
7827b27ec6Sopenharmony_ci.PHONY: clean
7927b27ec6Sopenharmony_ciclean:
8027b27ec6Sopenharmony_ci	$(MAKE) -C $(LZ4DIR) $@ > $(VOID)
8127b27ec6Sopenharmony_ci	$(MAKE) -C $(PRGDIR) $@ > $(VOID)
8227b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) $@ > $(VOID)
8327b27ec6Sopenharmony_ci	$(MAKE) -C $(EXDIR) $@ > $(VOID)
8427b27ec6Sopenharmony_ci	$(MAKE) -C $(FUZZDIR) $@ > $(VOID)
8527b27ec6Sopenharmony_ci	$(MAKE) -C contrib/gen_manual $@ > $(VOID)
8627b27ec6Sopenharmony_ci	$(RM) lz4$(EXT)
8727b27ec6Sopenharmony_ci	$(RM) -r $(CMAKE_BUILD_DIR)
8827b27ec6Sopenharmony_ci	@echo Cleaning completed
8927b27ec6Sopenharmony_ci
9027b27ec6Sopenharmony_ci
9127b27ec6Sopenharmony_ci#-----------------------------------------------------------------------------
9227b27ec6Sopenharmony_ci# make install is validated only for Posix environments
9327b27ec6Sopenharmony_ci#-----------------------------------------------------------------------------
9427b27ec6Sopenharmony_ciifeq ($(POSIX_ENV),Yes)
9527b27ec6Sopenharmony_ciHOST_OS = POSIX
9627b27ec6Sopenharmony_ci
9727b27ec6Sopenharmony_ci.PHONY: install uninstall
9827b27ec6Sopenharmony_ciinstall uninstall:
9927b27ec6Sopenharmony_ci	$(MAKE) -C $(LZ4DIR) $@
10027b27ec6Sopenharmony_ci	$(MAKE) -C $(PRGDIR) $@
10127b27ec6Sopenharmony_ci
10227b27ec6Sopenharmony_ci.PHONY: travis-install
10327b27ec6Sopenharmony_citravis-install:
10427b27ec6Sopenharmony_ci	$(MAKE) -j1 install DESTDIR=~/install_test_dir
10527b27ec6Sopenharmony_ci
10627b27ec6Sopenharmony_ciendif   # POSIX_ENV
10727b27ec6Sopenharmony_ci
10827b27ec6Sopenharmony_ci
10927b27ec6Sopenharmony_ciCMAKE ?= cmake
11027b27ec6Sopenharmony_ciCMAKE_BUILD_DIR ?= build/cmake/build
11127b27ec6Sopenharmony_ciifneq (,$(filter MSYS%,$(shell $(UNAME))))
11227b27ec6Sopenharmony_ciHOST_OS = MSYS
11327b27ec6Sopenharmony_ciCMAKE_PARAMS = -G"MSYS Makefiles"
11427b27ec6Sopenharmony_ciendif
11527b27ec6Sopenharmony_ci
11627b27ec6Sopenharmony_ci.PHONY: cmake
11727b27ec6Sopenharmony_cicmake:
11827b27ec6Sopenharmony_ci	mkdir -p $(CMAKE_BUILD_DIR)
11927b27ec6Sopenharmony_ci	cd $(CMAKE_BUILD_DIR); $(CMAKE) $(CMAKE_PARAMS) ..; $(CMAKE) --build .
12027b27ec6Sopenharmony_ci
12127b27ec6Sopenharmony_ci
12227b27ec6Sopenharmony_ci#------------------------------------------------------------------------
12327b27ec6Sopenharmony_ci# make tests validated only for MSYS and Posix environments
12427b27ec6Sopenharmony_ci#------------------------------------------------------------------------
12527b27ec6Sopenharmony_ciifneq (,$(filter $(HOST_OS),MSYS POSIX))
12627b27ec6Sopenharmony_ci
12727b27ec6Sopenharmony_ci.PHONY: list
12827b27ec6Sopenharmony_cilist:
12927b27ec6Sopenharmony_ci	$(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
13027b27ec6Sopenharmony_ci
13127b27ec6Sopenharmony_ci.PHONY: check
13227b27ec6Sopenharmony_cicheck:
13327b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) test-lz4-essentials
13427b27ec6Sopenharmony_ci
13527b27ec6Sopenharmony_ci.PHONY: test
13627b27ec6Sopenharmony_citest:
13727b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) $@
13827b27ec6Sopenharmony_ci	$(MAKE) -C $(EXDIR) $@
13927b27ec6Sopenharmony_ci
14027b27ec6Sopenharmony_ci.PHONY: clangtest
14127b27ec6Sopenharmony_ciclangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
14227b27ec6Sopenharmony_ciclangtest: CC = clang
14327b27ec6Sopenharmony_ciclangtest: clean
14427b27ec6Sopenharmony_ci	$(CC) -v
14527b27ec6Sopenharmony_ci	$(MAKE) -C $(LZ4DIR)  all CC=$(CC)
14627b27ec6Sopenharmony_ci	$(MAKE) -C $(PRGDIR)  all CC=$(CC)
14727b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) all CC=$(CC)
14827b27ec6Sopenharmony_ci
14927b27ec6Sopenharmony_ci.PHONY: clangtest-native
15027b27ec6Sopenharmony_ciclangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion
15127b27ec6Sopenharmony_ciclangtest-native: clean
15227b27ec6Sopenharmony_ci	clang -v
15327b27ec6Sopenharmony_ci	$(MAKE) -C $(LZ4DIR)  all    CC=clang
15427b27ec6Sopenharmony_ci	$(MAKE) -C $(PRGDIR)  native CC=clang
15527b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) native CC=clang
15627b27ec6Sopenharmony_ci
15727b27ec6Sopenharmony_ci.PHONY: usan
15827b27ec6Sopenharmony_ciusan: CC      = clang
15927b27ec6Sopenharmony_ciusan: CFLAGS  = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
16027b27ec6Sopenharmony_ciusan: LDFLAGS = $(CFLAGS)
16127b27ec6Sopenharmony_ciusan: clean
16227b27ec6Sopenharmony_ci	CC=$(CC) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
16327b27ec6Sopenharmony_ci
16427b27ec6Sopenharmony_ci.PHONY: usan32
16527b27ec6Sopenharmony_ciusan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined
16627b27ec6Sopenharmony_ciusan32: LDFLAGS = $(CFLAGS)
16727b27ec6Sopenharmony_ciusan32: clean
16827b27ec6Sopenharmony_ci	$(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
16927b27ec6Sopenharmony_ci
17027b27ec6Sopenharmony_ciSCANBUILD ?= scan-build
17127b27ec6Sopenharmony_ciSCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
17227b27ec6Sopenharmony_ci.PHONY: staticAnalyze
17327b27ec6Sopenharmony_cistaticAnalyze: clean
17427b27ec6Sopenharmony_ci	CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
17527b27ec6Sopenharmony_ci
17627b27ec6Sopenharmony_ci.PHONY: cppcheck
17727b27ec6Sopenharmony_cicppcheck:
17827b27ec6Sopenharmony_ci	cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
17927b27ec6Sopenharmony_ci
18027b27ec6Sopenharmony_ci.PHONY: platformTest
18127b27ec6Sopenharmony_ciplatformTest: clean
18227b27ec6Sopenharmony_ci	@echo "\n ---- test lz4 with $(CC) compiler ----"
18327b27ec6Sopenharmony_ci	$(CC) -v
18427b27ec6Sopenharmony_ci	CFLAGS="-O3 -Werror"         $(MAKE) -C $(LZ4DIR) all
18527b27ec6Sopenharmony_ci	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
18627b27ec6Sopenharmony_ci	CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
18727b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) test-platform
18827b27ec6Sopenharmony_ci
18927b27ec6Sopenharmony_ci.PHONY: versionsTest
19027b27ec6Sopenharmony_civersionsTest: clean
19127b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) $@
19227b27ec6Sopenharmony_ci
19327b27ec6Sopenharmony_ci.PHONY: test-freestanding
19427b27ec6Sopenharmony_citest-freestanding:
19527b27ec6Sopenharmony_ci	$(MAKE) -C $(TESTDIR) clean $@
19627b27ec6Sopenharmony_ci
19727b27ec6Sopenharmony_ci.PHONY: cxxtest cxx32test
19827b27ec6Sopenharmony_cicxxtest cxx32test: CC := "$(CXX) -Wno-deprecated"
19927b27ec6Sopenharmony_cicxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
20027b27ec6Sopenharmony_cicxx32test: CFLAGS += -m32
20127b27ec6Sopenharmony_cicxxtest cxx32test: clean
20227b27ec6Sopenharmony_ci	$(CXX) -v
20327b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
20427b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
20527b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
20627b27ec6Sopenharmony_ci
20727b27ec6Sopenharmony_ci.PHONY: cxx17build
20827b27ec6Sopenharmony_cicxx17build : CC = "$(CXX) -Wno-deprecated"
20927b27ec6Sopenharmony_cicxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
21027b27ec6Sopenharmony_cicxx17build : clean
21127b27ec6Sopenharmony_ci	$(CXX) -v
21227b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(LZ4DIR)  all CFLAGS="$(CFLAGS)"
21327b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(PRGDIR)  all CFLAGS="$(CFLAGS)"
21427b27ec6Sopenharmony_ci	CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
21527b27ec6Sopenharmony_ci
21627b27ec6Sopenharmony_ci.PHONY: ctocpptest
21727b27ec6Sopenharmony_cictocpptest: LIBCC="$(CC)"
21827b27ec6Sopenharmony_cictocpptest: TESTCC="$(CXX)"
21927b27ec6Sopenharmony_cictocpptest: CFLAGS=
22027b27ec6Sopenharmony_cictocpptest: clean
22127b27ec6Sopenharmony_ci	CC=$(LIBCC)  $(MAKE) -C $(LZ4DIR)  CFLAGS="$(CFLAGS)" all
22227b27ec6Sopenharmony_ci	CC=$(LIBCC)  $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" lz4.o lz4hc.o lz4frame.o
22327b27ec6Sopenharmony_ci	CC=$(TESTCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" all
22427b27ec6Sopenharmony_ci
22527b27ec6Sopenharmony_ci.PHONY: c_standards
22627b27ec6Sopenharmony_cic_standards: clean c_standards_c11 c_standards_c99 c_standards_c90
22727b27ec6Sopenharmony_ci
22827b27ec6Sopenharmony_ci.PHONY: c_standards_c90
22927b27ec6Sopenharmony_cic_standards_c90: clean
23027b27ec6Sopenharmony_ci	$(MAKE) clean; CFLAGS="-std=c90   -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
23127b27ec6Sopenharmony_ci	$(MAKE) clean; CFLAGS="-std=gnu90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
23227b27ec6Sopenharmony_ci
23327b27ec6Sopenharmony_ci.PHONY: c_standards_c99
23427b27ec6Sopenharmony_cic_standards_c99: clean
23527b27ec6Sopenharmony_ci	$(MAKE) clean; CFLAGS="-std=c99   -Werror -pedantic" $(MAKE) all
23627b27ec6Sopenharmony_ci	$(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
23727b27ec6Sopenharmony_ci
23827b27ec6Sopenharmony_ci.PHONY: c_standards_c11
23927b27ec6Sopenharmony_cic_standards_c11: clean
24027b27ec6Sopenharmony_ci	$(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all
24127b27ec6Sopenharmony_ci
24227b27ec6Sopenharmony_ci# The following test ensures that standard Makefile variables set through environment
24327b27ec6Sopenharmony_ci# are correctly transmitted at compilation stage.
24427b27ec6Sopenharmony_ci# This test is meant to detect issues like https://github.com/lz4/lz4/issues/958
24527b27ec6Sopenharmony_ci.PHONY: standard_variables
24627b27ec6Sopenharmony_cistandard_variables: clean
24727b27ec6Sopenharmony_ci	@echo =================
24827b27ec6Sopenharmony_ci	@echo Check support of Makefile Standard variables through environment
24927b27ec6Sopenharmony_ci	@echo note : this test requires V=1 to work properly
25027b27ec6Sopenharmony_ci	@echo =================
25127b27ec6Sopenharmony_ci	CC="cc -DCC_TEST" \
25227b27ec6Sopenharmony_ci	CFLAGS=-DCFLAGS_TEST \
25327b27ec6Sopenharmony_ci	CPPFLAGS=-DCPPFLAGS_TEST \
25427b27ec6Sopenharmony_ci	LDFLAGS=-DLDFLAGS_TEST \
25527b27ec6Sopenharmony_ci	LDLIBS=-DLDLIBS_TEST \
25627b27ec6Sopenharmony_ci	$(MAKE) V=1 > tmpsv
25727b27ec6Sopenharmony_ci	# Note: just checking the presence of custom flags
25827b27ec6Sopenharmony_ci	# would not detect situations where custom flags are
25927b27ec6Sopenharmony_ci	# supported in some part of the Makefile, and missed in others.
26027b27ec6Sopenharmony_ci	# So the test checks if they are present the _right nb of times_.
26127b27ec6Sopenharmony_ci	# However, checking static quantities makes this test brittle,
26227b27ec6Sopenharmony_ci	# because quantities (7, 2 and 1) can still evolve in future,
26327b27ec6Sopenharmony_ci	# for example when source directories or Makefile evolve.
26427b27ec6Sopenharmony_ci	if [ $$(grep CC_TEST tmpsv | wc -l) -ne 7 ]; then \
26527b27ec6Sopenharmony_ci		echo "CC environment variable missed" && False; fi
26627b27ec6Sopenharmony_ci	if [ $$(grep CFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
26727b27ec6Sopenharmony_ci		echo "CFLAGS environment variable missed" && False; fi
26827b27ec6Sopenharmony_ci	if [ $$(grep CPPFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
26927b27ec6Sopenharmony_ci		echo "CPPFLAGS environment variable missed" && False; fi
27027b27ec6Sopenharmony_ci	if [ $$(grep LDFLAGS_TEST tmpsv | wc -l) -ne 2 ]; then \
27127b27ec6Sopenharmony_ci		echo "LDFLAGS environment variable missed" && False; fi
27227b27ec6Sopenharmony_ci	if [ $$(grep LDLIBS_TEST tmpsv | wc -l) -ne 1 ]; then \
27327b27ec6Sopenharmony_ci		echo "LDLIBS environment variable missed" && False; fi
27427b27ec6Sopenharmony_ci	@echo =================
27527b27ec6Sopenharmony_ci	@echo all custom variables detected
27627b27ec6Sopenharmony_ci	@echo =================
27727b27ec6Sopenharmony_ci	$(RM) tmpsv
27827b27ec6Sopenharmony_ci
27927b27ec6Sopenharmony_ciendif   # MSYS POSIX
280