Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. # ################################################################
  2. # LZ4 library - Makefile
  3. # Copyright (C) Yann Collet 2011-2020
  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. SED = sed
  35. # Version numbers
  36. LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
  37. LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
  38. LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
  39. LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
  40. LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
  41. LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
  42. LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
  43. LIBVER := $(shell echo $(LIBVER_SCRIPT))
  44. BUILD_SHARED:=yes
  45. BUILD_STATIC:=yes
  46. CPPFLAGS+= -DXXH_NAMESPACE=LZ4_
  47. CPPFLAGS+= $(MOREFLAGS)
  48. CFLAGS ?= -O3
  49. DEBUGFLAGS:= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
  50. -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
  51. -Wundef -Wpointer-arith -Wstrict-aliasing=1
  52. CFLAGS += $(DEBUGFLAGS)
  53. FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
  54. SRCFILES := $(sort $(wildcard *.c))
  55. include ../Makefile.inc
  56. # OS X linker doesn't support -soname, and use different extension
  57. # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
  58. ifeq ($(TARGET_OS), Darwin)
  59. SHARED_EXT = dylib
  60. SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
  61. SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
  62. SONAME_FLAGS = -install_name $(libdir)/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
  63. else
  64. SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR)
  65. SHARED_EXT = so
  66. SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
  67. SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
  68. endif
  69. .PHONY: default
  70. default: lib-release
  71. # silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
  72. $(V)$(VERBOSE).SILENT:
  73. lib-release: DEBUGFLAGS :=
  74. lib-release: lib
  75. .PHONY: lib
  76. lib: liblz4.a liblz4
  77. .PHONY: all
  78. all: lib
  79. .PHONY: all32
  80. all32: CFLAGS+=-m32
  81. all32: all
  82. liblz4.a: $(SRCFILES)
  83. ifeq ($(BUILD_STATIC),yes) # can be disabled on command line
  84. @echo compiling static library
  85. $(COMPILE.c) $^
  86. $(AR) rcs $@ *.o
  87. endif
  88. ifeq ($(WINBASED),yes)
  89. liblz4-dll.rc: liblz4-dll.rc.in
  90. @echo creating library resource
  91. $(SED) -e 's|@LIBLZ4@|$(LIBLZ4)|' \
  92. -e 's|@LIBVER_MAJOR@|$(LIBVER_MAJOR)|g' \
  93. -e 's|@LIBVER_MINOR@|$(LIBVER_MINOR)|g' \
  94. -e 's|@LIBVER_PATCH@|$(LIBVER_PATCH)|g' \
  95. $< >$@
  96. liblz4-dll.o: liblz4-dll.rc
  97. $(WINDRES) -i liblz4-dll.rc -o liblz4-dll.o
  98. $(LIBLZ4): $(SRCFILES) liblz4-dll.o
  99. @echo compiling dynamic library $(LIBVER)
  100. $(CC) $(FLAGS) -DLZ4_DLL_EXPORT=1 -shared $^ -o dll/$@.dll -Wl,--out-implib,dll/$(LIBLZ4_EXP)
  101. else # not windows
  102. $(LIBLZ4): $(SRCFILES)
  103. @echo compiling dynamic library $(LIBVER)
  104. $(CC) $(FLAGS) -shared $^ -fPIC -fvisibility=hidden $(SONAME_FLAGS) -o $@
  105. @echo creating versioned links
  106. $(LN_SF) $@ liblz4.$(SHARED_EXT_MAJOR)
  107. $(LN_SF) $@ liblz4.$(SHARED_EXT)
  108. endif
  109. .PHONY: liblz4
  110. liblz4: $(LIBLZ4)
  111. .PHONY: clean
  112. clean:
  113. ifeq ($(WINBASED),yes)
  114. $(RM) *.rc
  115. endif
  116. $(RM) core *.o liblz4.pc dll/$(LIBLZ4).dll dll/$(LIBLZ4_EXP)
  117. $(RM) *.a *.$(SHARED_EXT) *.$(SHARED_EXT_MAJOR) *.$(SHARED_EXT_VER)
  118. @echo Cleaning library completed
  119. #-----------------------------------------------------------------------------
  120. # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
  121. #-----------------------------------------------------------------------------
  122. ifeq ($(POSIX_ENV),Yes)
  123. .PHONY: listL120
  124. listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note : $$, for Makefile compatibility)
  125. find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done
  126. DESTDIR ?=
  127. # directory variables : GNU conventions prefer lowercase
  128. # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
  129. # support both lower and uppercase (BSD), use lower in script
  130. PREFIX ?= /usr/local
  131. prefix ?= $(PREFIX)
  132. EXEC_PREFIX ?= $(prefix)
  133. exec_prefix ?= $(EXEC_PREFIX)
  134. BINDIR ?= $(exec_prefix)/bin
  135. bindir ?= $(BINDIR)
  136. LIBDIR ?= $(exec_prefix)/lib
  137. libdir ?= $(LIBDIR)
  138. INCLUDEDIR ?= $(prefix)/include
  139. includedir ?= $(INCLUDEDIR)
  140. ifneq (,$(filter $(TARGET_OS),OpenBSD FreeBSD NetBSD DragonFly MidnightBSD))
  141. PKGCONFIGDIR ?= $(prefix)/libdata/pkgconfig
  142. else
  143. PKGCONFIGDIR ?= $(libdir)/pkgconfig
  144. endif
  145. pkgconfigdir ?= $(PKGCONFIGDIR)
  146. liblz4.pc: liblz4.pc.in Makefile
  147. @echo creating pkgconfig
  148. $(SED) -e 's|@PREFIX@|$(prefix)|' \
  149. -e 's|@LIBDIR@|$(libdir)|' \
  150. -e 's|@INCLUDEDIR@|$(includedir)|' \
  151. -e 's|@VERSION@|$(LIBVER)|' \
  152. -e 's|=${prefix}/|=$${prefix}/|' \
  153. $< >$@
  154. install: lib liblz4.pc
  155. $(INSTALL_DIR) $(DESTDIR)$(pkgconfigdir)/ $(DESTDIR)$(includedir)/ $(DESTDIR)$(libdir)/ $(DESTDIR)$(bindir)/
  156. $(INSTALL_DATA) liblz4.pc $(DESTDIR)$(pkgconfigdir)/
  157. @echo Installing libraries in $(DESTDIR)$(libdir)
  158. ifeq ($(BUILD_STATIC),yes)
  159. $(INSTALL_DATA) liblz4.a $(DESTDIR)$(libdir)/liblz4.a
  160. $(INSTALL_DATA) lz4frame_static.h $(DESTDIR)$(includedir)/lz4frame_static.h
  161. endif
  162. ifeq ($(BUILD_SHARED),yes)
  163. # Traditionally, one installs the DLLs in the bin directory as programs
  164. # search them first in their directory. This allows to not pollute system
  165. # directories (like c:/windows/system32), nor modify the PATH variable.
  166. ifeq ($(WINBASED),yes)
  167. $(INSTALL_PROGRAM) dll/$(LIBLZ4).dll $(DESTDIR)$(bindir)
  168. $(INSTALL_PROGRAM) dll/$(LIBLZ4_EXP) $(DESTDIR)$(libdir)
  169. else
  170. $(INSTALL_PROGRAM) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)
  171. $(LN_SF) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR)
  172. $(LN_SF) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT)
  173. endif
  174. endif
  175. @echo Installing headers in $(DESTDIR)$(includedir)
  176. $(INSTALL_DATA) lz4.h $(DESTDIR)$(includedir)/lz4.h
  177. $(INSTALL_DATA) lz4hc.h $(DESTDIR)$(includedir)/lz4hc.h
  178. $(INSTALL_DATA) lz4frame.h $(DESTDIR)$(includedir)/lz4frame.h
  179. @echo lz4 libraries installed
  180. uninstall:
  181. $(RM) $(DESTDIR)$(pkgconfigdir)/liblz4.pc
  182. ifeq (WINBASED,1)
  183. $(RM) $(DESTDIR)$(bindir)/$(LIBLZ4).dll
  184. $(RM) $(DESTDIR)$(libdir)/$(LIBLZ4_EXP)
  185. else
  186. $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT)
  187. $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR)
  188. $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_VER)
  189. endif
  190. $(RM) $(DESTDIR)$(libdir)/liblz4.a
  191. $(RM) $(DESTDIR)$(includedir)/lz4.h
  192. $(RM) $(DESTDIR)$(includedir)/lz4hc.h
  193. $(RM) $(DESTDIR)$(includedir)/lz4frame.h
  194. $(RM) $(DESTDIR)$(includedir)/lz4frame_static.h
  195. @echo lz4 libraries successfully uninstalled
  196. endif