Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # ##########################################################################
  2. # LZ4 programs - Makefile
  3. # Copyright (C) Yann Collet 2011-2020
  4. #
  5. # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
  6. #
  7. # GPL v2 License
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. # You can contact the author at :
  24. # - LZ4 homepage : http://www.lz4.org
  25. # - LZ4 source repository : https://github.com/lz4/lz4
  26. # ##########################################################################
  27. # lz4 : Command Line Utility, supporting gzip-like arguments
  28. # lz4c : CLU, supporting also legacy lz4demo arguments
  29. # lz4c32: Same as lz4c, but forced to compile in 32-bits mode
  30. # ##########################################################################
  31. SED = sed
  32. # Version numbers
  33. LZ4DIR := ../lib
  34. LIBVER_SRC := $(LZ4DIR)/lz4.h
  35. LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
  36. LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
  37. LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)`
  38. LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
  39. LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
  40. LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
  41. LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
  42. LIBVER := $(shell echo $(LIBVER_SCRIPT))
  43. LIBFILES = $(wildcard $(LZ4DIR)/*.c)
  44. SRCFILES = $(sort $(LIBFILES) $(wildcard *.c))
  45. OBJFILES = $(SRCFILES:.c=.o)
  46. CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_
  47. CFLAGS ?= -O3
  48. DEBUGFLAGS= -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \
  49. -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \
  50. -Wpointer-arith -Wstrict-aliasing=1
  51. CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
  52. include ../Makefile.inc
  53. OS_VERSION ?= $(UNAME) -r
  54. ifeq ($(TARGET_OS)$(shell $(OS_VERSION)),SunOS5.10)
  55. LDFLAGS += -lrt
  56. endif
  57. FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
  58. LZ4_VERSION=$(LIBVER)
  59. MD2ROFF = ronn
  60. MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)"
  61. default: lz4-release
  62. # silent mode by default; verbose can be triggered by V=1 or VERBOSE=1
  63. $(V)$(VERBOSE).SILENT:
  64. all: lz4 lz4c
  65. all32: CFLAGS+=-m32
  66. all32: all
  67. ifeq ($(WINBASED),yes)
  68. lz4-exe.rc: lz4-exe.rc.in
  69. @echo creating executable resource
  70. $(SED) -e 's|@PROGNAME@|lz4|' \
  71. -e 's|@LIBVER_MAJOR@|$(LIBVER_MAJOR)|g' \
  72. -e 's|@LIBVER_MINOR@|$(LIBVER_MINOR)|g' \
  73. -e 's|@LIBVER_PATCH@|$(LIBVER_PATCH)|g' \
  74. -e 's|@EXT@|$(EXT)|g' \
  75. $< >$@
  76. lz4-exe.o: lz4-exe.rc
  77. $(WINDRES) -i lz4-exe.rc -o lz4-exe.o
  78. lz4: $(OBJFILES) lz4-exe.o
  79. $(CC) $(FLAGS) $^ -o $@$(EXT)
  80. else
  81. lz4: $(OBJFILES)
  82. $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
  83. endif
  84. .PHONY: lz4-release
  85. lz4-release: DEBUGFLAGS=
  86. lz4-release: lz4
  87. lz4-wlib: LIBFILES =
  88. lz4-wlib: SRCFILES+= $(LZ4DIR)/xxhash.c # benchmark unit needs XXH64()
  89. lz4-wlib: LDFLAGS += -L $(LZ4DIR)
  90. lz4-wlib: LDLIBS = -llz4
  91. lz4-wlib: liblz4 $(OBJFILES)
  92. @echo WARNING: $@ must link to an extended variant of the dynamic library which also exposes unstable symbols
  93. $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS)
  94. .PHONY:liblz4
  95. liblz4:
  96. CPPFLAGS="-DLZ4F_PUBLISH_STATIC_FUNCTIONS -DLZ4_PUBLISH_STATIC_FUNCTIONS" $(MAKE) -C $(LZ4DIR) liblz4
  97. lz4c: lz4
  98. $(LN_SF) lz4$(EXT) lz4c$(EXT)
  99. lz4c32: CFLAGS += -m32
  100. lz4c32 : $(SRCFILES)
  101. $(CC) $(FLAGS) $^ -o $@$(EXT)
  102. lz4.1: lz4.1.md $(LIBVER_SRC)
  103. cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | $(SED) -n '/^\.\\\".*/!p' > $@
  104. man: lz4.1
  105. clean-man:
  106. $(RM) lz4.1
  107. preview-man: clean-man man
  108. man ./lz4.1
  109. clean:
  110. ifeq ($(WINBASED),yes)
  111. $(RM) *.rc
  112. endif
  113. $(MAKE) -C $(LZ4DIR) $@ > $(VOID)
  114. $(RM) core *.o *.test tmp* \
  115. lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) lz4-wlib$(EXT) \
  116. unlz4$(EXT) lz4cat$(EXT)
  117. @echo Cleaning completed
  118. #-----------------------------------------------------------------------------
  119. # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
  120. #-----------------------------------------------------------------------------
  121. ifeq ($(POSIX_ENV),Yes)
  122. unlz4: lz4
  123. $(LN_SF) lz4$(EXT) unlz4$(EXT)
  124. lz4cat: lz4
  125. $(LN_SF) lz4$(EXT) lz4cat$(EXT)
  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 lowercase 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. DATAROOTDIR ?= $(prefix)/share
  137. datarootdir ?= $(DATAROOTDIR)
  138. MANDIR ?= $(datarootdir)/man
  139. mandir ?= $(MANDIR)
  140. MAN1DIR ?= $(mandir)/man1
  141. man1dir ?= $(MAN1DIR)
  142. install: lz4
  143. @echo Installing binaries in $(DESTDIR)$(bindir)
  144. $(INSTALL_DIR) $(DESTDIR)$(bindir)/ $(DESTDIR)$(man1dir)/
  145. $(INSTALL_PROGRAM) lz4$(EXT) $(DESTDIR)$(bindir)/lz4$(EXT)
  146. $(LN_SF) lz4$(EXT) $(DESTDIR)$(bindir)/lz4c$(EXT)
  147. $(LN_SF) lz4$(EXT) $(DESTDIR)$(bindir)/lz4cat$(EXT)
  148. $(LN_SF) lz4$(EXT) $(DESTDIR)$(bindir)/unlz4$(EXT)
  149. @echo Installing man pages in $(DESTDIR)$(man1dir)
  150. $(INSTALL_DATA) lz4.1 $(DESTDIR)$(man1dir)/lz4.1
  151. $(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4c.1
  152. $(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4cat.1
  153. $(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/unlz4.1
  154. @echo lz4 installation completed
  155. uninstall:
  156. $(RM) $(DESTDIR)$(bindir)/lz4cat$(EXT)
  157. $(RM) $(DESTDIR)$(bindir)/unlz4$(EXT)
  158. $(RM) $(DESTDIR)$(bindir)/lz4$(EXT)
  159. $(RM) $(DESTDIR)$(bindir)/lz4c$(EXT)
  160. $(RM) $(DESTDIR)$(man1dir)/lz4.1
  161. $(RM) $(DESTDIR)$(man1dir)/lz4c.1
  162. $(RM) $(DESTDIR)$(man1dir)/lz4cat.1
  163. $(RM) $(DESTDIR)$(man1dir)/unlz4.1
  164. @echo lz4 programs successfully uninstalled
  165. endif