Makefile 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. LZ4DIR = lib
  33. PRGDIR = programs
  34. TESTDIR = tests
  35. EXDIR = examples
  36. FUZZDIR = ossfuzz
  37. include Makefile.inc
  38. .PHONY: default
  39. default: lib-release lz4-release
  40. # silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
  41. $(V)$(VERBOSE).SILENT:
  42. .PHONY: all
  43. all: allmost examples manuals build_tests
  44. .PHONY: allmost
  45. allmost: lib lz4
  46. .PHONY: lib lib-release liblz4.a
  47. lib: liblz4.a
  48. lib lib-release liblz4.a:
  49. $(MAKE) -C $(LZ4DIR) $@
  50. .PHONY: lz4 lz4-release
  51. lz4 : liblz4.a
  52. lz4-release : lib-release
  53. lz4 lz4-release :
  54. $(MAKE) -C $(PRGDIR) $@
  55. cp $(PRGDIR)/lz4$(EXT) .
  56. .PHONY: examples
  57. examples: liblz4.a
  58. $(MAKE) -C $(EXDIR) all
  59. .PHONY: manuals
  60. manuals:
  61. $(MAKE) -C contrib/gen_manual $@
  62. .PHONY: build_tests
  63. build_tests:
  64. $(MAKE) -C $(TESTDIR) all
  65. .PHONY: clean
  66. clean:
  67. $(MAKE) -C $(LZ4DIR) $@ > $(VOID)
  68. $(MAKE) -C $(PRGDIR) $@ > $(VOID)
  69. $(MAKE) -C $(TESTDIR) $@ > $(VOID)
  70. $(MAKE) -C $(EXDIR) $@ > $(VOID)
  71. $(MAKE) -C $(FUZZDIR) $@ > $(VOID)
  72. $(MAKE) -C contrib/gen_manual $@ > $(VOID)
  73. $(RM) lz4$(EXT)
  74. $(RM) -r $(CMAKE_BUILD_DIR)
  75. @echo Cleaning completed
  76. #-----------------------------------------------------------------------------
  77. # make install is validated only for Posix environments
  78. #-----------------------------------------------------------------------------
  79. ifeq ($(POSIX_ENV),Yes)
  80. HOST_OS = POSIX
  81. .PHONY: install uninstall
  82. install uninstall:
  83. $(MAKE) -C $(LZ4DIR) $@
  84. $(MAKE) -C $(PRGDIR) $@
  85. .PHONY: travis-install
  86. travis-install:
  87. $(MAKE) -j1 install DESTDIR=~/install_test_dir
  88. endif # POSIX_ENV
  89. CMAKE ?= cmake
  90. CMAKE_BUILD_DIR ?= build/cmake/build
  91. ifneq (,$(filter MSYS%,$(shell $(UNAME))))
  92. HOST_OS = MSYS
  93. CMAKE_PARAMS = -G"MSYS Makefiles"
  94. endif
  95. .PHONY: cmake
  96. cmake:
  97. mkdir -p $(CMAKE_BUILD_DIR)
  98. cd $(CMAKE_BUILD_DIR); $(CMAKE) $(CMAKE_PARAMS) ..; $(CMAKE) --build .
  99. #------------------------------------------------------------------------
  100. # make tests validated only for MSYS and Posix environments
  101. #------------------------------------------------------------------------
  102. ifneq (,$(filter $(HOST_OS),MSYS POSIX))
  103. .PHONY: list
  104. list:
  105. $(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
  106. .PHONY: check
  107. check:
  108. $(MAKE) -C $(TESTDIR) test-lz4-essentials
  109. .PHONY: test
  110. test:
  111. $(MAKE) -C $(TESTDIR) $@
  112. $(MAKE) -C $(EXDIR) $@
  113. .PHONY: clangtest
  114. clangtest: CFLAGS += -Werror -Wconversion -Wno-sign-conversion
  115. clangtest: CC = clang
  116. clangtest: clean
  117. $(CC) -v
  118. $(MAKE) -C $(LZ4DIR) all CC=$(CC)
  119. $(MAKE) -C $(PRGDIR) all CC=$(CC)
  120. $(MAKE) -C $(TESTDIR) all CC=$(CC)
  121. .PHONY: clangtest-native
  122. clangtest-native: CFLAGS = -O3 -Werror -Wconversion -Wno-sign-conversion
  123. clangtest-native: clean
  124. clang -v
  125. $(MAKE) -C $(LZ4DIR) all CC=clang
  126. $(MAKE) -C $(PRGDIR) native CC=clang
  127. $(MAKE) -C $(TESTDIR) native CC=clang
  128. .PHONY: usan
  129. usan: CC = clang
  130. usan: CFLAGS = -O3 -g -fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=pointer-overflow
  131. usan: LDFLAGS = $(CFLAGS)
  132. usan: clean
  133. CC=$(CC) CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
  134. .PHONY: usan32
  135. usan32: CFLAGS = -m32 -O3 -g -fsanitize=undefined
  136. usan32: LDFLAGS = $(CFLAGS)
  137. usan32: clean
  138. $(MAKE) test FUZZER_TIME="-T30s" NB_LOOPS=-i1
  139. SCANBUILD ?= scan-build
  140. SCANBUILD_FLAGS += --status-bugs -v --force-analyze-debug-code
  141. .PHONY: staticAnalyze
  142. staticAnalyze: clean
  143. CPPFLAGS=-DLZ4_DEBUG=1 CFLAGS=-g $(SCANBUILD) $(SCANBUILD_FLAGS) $(MAKE) all V=1 DEBUGLEVEL=1
  144. .PHONY: cppcheck
  145. cppcheck:
  146. cppcheck . --force --enable=warning,portability,performance,style --error-exitcode=1 > /dev/null
  147. .PHONY: platformTest
  148. platformTest: clean
  149. @echo "\n ---- test lz4 with $(CC) compiler ----"
  150. $(CC) -v
  151. CFLAGS="-O3 -Werror" $(MAKE) -C $(LZ4DIR) all
  152. CFLAGS="-O3 -Werror -static" $(MAKE) -C $(PRGDIR) all
  153. CFLAGS="-O3 -Werror -static" $(MAKE) -C $(TESTDIR) all
  154. $(MAKE) -C $(TESTDIR) test-platform
  155. .PHONY: versionsTest
  156. versionsTest: clean
  157. $(MAKE) -C $(TESTDIR) $@
  158. .PHONY: test-freestanding
  159. test-freestanding:
  160. $(MAKE) -C $(TESTDIR) clean $@
  161. .PHONY: cxxtest cxx32test
  162. cxxtest cxx32test: CC := "$(CXX) -Wno-deprecated"
  163. cxxtest cxx32test: CFLAGS = -O3 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror
  164. cxx32test: CFLAGS += -m32
  165. cxxtest cxx32test: clean
  166. $(CXX) -v
  167. CC=$(CC) $(MAKE) -C $(LZ4DIR) all CFLAGS="$(CFLAGS)"
  168. CC=$(CC) $(MAKE) -C $(PRGDIR) all CFLAGS="$(CFLAGS)"
  169. CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
  170. .PHONY: cxx17build
  171. cxx17build : CC = "$(CXX) -Wno-deprecated"
  172. cxx17build : CFLAGS = -std=c++17 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Werror -pedantic
  173. cxx17build : clean
  174. $(CXX) -v
  175. CC=$(CC) $(MAKE) -C $(LZ4DIR) all CFLAGS="$(CFLAGS)"
  176. CC=$(CC) $(MAKE) -C $(PRGDIR) all CFLAGS="$(CFLAGS)"
  177. CC=$(CC) $(MAKE) -C $(TESTDIR) all CFLAGS="$(CFLAGS)"
  178. .PHONY: ctocpptest
  179. ctocpptest: LIBCC="$(CC)"
  180. ctocpptest: TESTCC="$(CXX)"
  181. ctocpptest: CFLAGS=
  182. ctocpptest: clean
  183. CC=$(LIBCC) $(MAKE) -C $(LZ4DIR) CFLAGS="$(CFLAGS)" all
  184. CC=$(LIBCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" lz4.o lz4hc.o lz4frame.o
  185. CC=$(TESTCC) $(MAKE) -C $(TESTDIR) CFLAGS="$(CFLAGS)" all
  186. .PHONY: c_standards
  187. c_standards: clean c_standards_c11 c_standards_c99 c_standards_c90
  188. .PHONY: c_standards_c90
  189. c_standards_c90: clean
  190. $(MAKE) clean; CFLAGS="-std=c90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
  191. $(MAKE) clean; CFLAGS="-std=gnu90 -Werror -pedantic -Wno-long-long -Wno-variadic-macros" $(MAKE) allmost
  192. .PHONY: c_standards_c99
  193. c_standards_c99: clean
  194. $(MAKE) clean; CFLAGS="-std=c99 -Werror -pedantic" $(MAKE) all
  195. $(MAKE) clean; CFLAGS="-std=gnu99 -Werror -pedantic" $(MAKE) all
  196. .PHONY: c_standards_c11
  197. c_standards_c11: clean
  198. $(MAKE) clean; CFLAGS="-std=c11 -Werror" $(MAKE) all
  199. # The following test ensures that standard Makefile variables set through environment
  200. # are correctly transmitted at compilation stage.
  201. # This test is meant to detect issues like https://github.com/lz4/lz4/issues/958
  202. .PHONY: standard_variables
  203. standard_variables: clean
  204. @echo =================
  205. @echo Check support of Makefile Standard variables through environment
  206. @echo note : this test requires V=1 to work properly
  207. @echo =================
  208. CC="cc -DCC_TEST" \
  209. CFLAGS=-DCFLAGS_TEST \
  210. CPPFLAGS=-DCPPFLAGS_TEST \
  211. LDFLAGS=-DLDFLAGS_TEST \
  212. LDLIBS=-DLDLIBS_TEST \
  213. $(MAKE) V=1 > tmpsv
  214. # Note: just checking the presence of custom flags
  215. # would not detect situations where custom flags are
  216. # supported in some part of the Makefile, and missed in others.
  217. # So the test checks if they are present the _right nb of times_.
  218. # However, checking static quantities makes this test brittle,
  219. # because quantities (7, 2 and 1) can still evolve in future,
  220. # for example when source directories or Makefile evolve.
  221. if [ $$(grep CC_TEST tmpsv | wc -l) -ne 7 ]; then \
  222. echo "CC environment variable missed" && False; fi
  223. if [ $$(grep CFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
  224. echo "CFLAGS environment variable missed" && False; fi
  225. if [ $$(grep CPPFLAGS_TEST tmpsv | wc -l) -ne 7 ]; then \
  226. echo "CPPFLAGS environment variable missed" && False; fi
  227. if [ $$(grep LDFLAGS_TEST tmpsv | wc -l) -ne 2 ]; then \
  228. echo "LDFLAGS environment variable missed" && False; fi
  229. if [ $$(grep LDLIBS_TEST tmpsv | wc -l) -ne 1 ]; then \
  230. echo "LDLIBS environment variable missed" && False; fi
  231. @echo =================
  232. @echo all custom variables detected
  233. @echo =================
  234. $(RM) tmpsv
  235. endif # MSYS POSIX