1# ########################################################################## 2# LZ4 programs - Makefile 3# Copyright (C) Yann Collet 2011-2017 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 32# Version numbers 33LZ4DIR := ../lib 34LIBVER_SRC := $(LZ4DIR)/lz4.h 35LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 36LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 37LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 38LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 39LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 40LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 41LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 42LIBVER := $(shell echo $(LIBVER_SCRIPT)) 43 44LIBFILES = $(wildcard $(LZ4DIR)/*.c) 45SRCFILES = $(sort $(LIBFILES) $(wildcard *.c)) 46OBJFILES = $(SRCFILES:.c=.o) 47 48CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ 49CFLAGS ?= -O3 50DEBUGFLAGS= -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ 51 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 52 -Wpointer-arith -Wstrict-aliasing=1 53CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 54FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 55 56LZ4_VERSION=$(LIBVER) 57MD2ROFF = ronn 58MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)" 59 60include ../Makefile.inc 61 62default: lz4-release 63 64all: lz4 lz4c 65 66all32: CFLAGS+=-m32 67all32: all 68 69ifeq ($(WINBASED),yes) 70lz4-exe.rc: lz4-exe.rc.in 71 @echo creating executable resource 72 $(Q)sed -e 's|@PROGNAME@|lz4|' \ 73 -e 's|@LIBVER_MAJOR@|$(LIBVER_MAJOR)|g' \ 74 -e 's|@LIBVER_MINOR@|$(LIBVER_MINOR)|g' \ 75 -e 's|@LIBVER_PATCH@|$(LIBVER_PATCH)|g' \ 76 -e 's|@EXT@|$(EXT)|g' \ 77 $< >$@ 78 79lz4-exe.o: lz4-exe.rc 80 $(WINDRES) -i lz4-exe.rc -o lz4-exe.o 81 82lz4: $(OBJFILES) lz4-exe.o 83 $(CC) $(FLAGS) $^ -o $@$(EXT) 84else 85lz4: $(OBJFILES) 86 $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS) 87endif 88 89.PHONY: lz4-release 90lz4-release: DEBUGFLAGS= 91lz4-release: lz4 92 93lz4-wlib: LIBFILES = 94lz4-wlib: SRCFILES+= $(LZ4DIR)/xxhash.c # benchmark unit needs XXH64() 95lz4-wlib: LDFLAGS += -L $(LZ4DIR) 96lz4-wlib: LDLIBS = -llz4 97lz4-wlib: liblz4 $(OBJFILES) 98 @echo WARNING: $@ must link to an extended variant of the dynamic library which also exposes unstable symbols 99 $(CC) $(FLAGS) $(OBJFILES) -o $@$(EXT) $(LDLIBS) 100 101.PHONY:liblz4 102liblz4: 103 CPPFLAGS="-DLZ4F_PUBLISH_STATIC_FUNCTIONS -DLZ4_PUBLISH_STATIC_FUNCTIONS" $(MAKE) -C $(LZ4DIR) liblz4 104 105lz4c: lz4 106 $(LN_SF) lz4$(EXT) lz4c$(EXT) 107 108lz4c32: CFLAGS += -m32 109lz4c32 : $(SRCFILES) 110 $(CC) $(FLAGS) $^ -o $@$(EXT) 111 112lz4.1: lz4.1.md $(LIBVER_SRC) 113 cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 114 115man: lz4.1 116 117clean-man: 118 $(RM) lz4.1 119 120preview-man: clean-man man 121 man ./lz4.1 122 123clean: 124ifeq ($(WINBASED),yes) 125 $(Q)$(RM) *.rc 126endif 127 @$(MAKE) -C $(LZ4DIR) $@ > $(VOID) 128 @$(RM) core *.o *.test tmp* \ 129 lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) lz4-wlib$(EXT) \ 130 unlz4$(EXT) lz4cat$(EXT) 131 @echo Cleaning completed 132 133 134#----------------------------------------------------------------------------- 135# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 136#----------------------------------------------------------------------------- 137ifeq ($(POSIX_ENV),Yes) 138 139unlz4: lz4 140 $(LN_SF) lz4$(EXT) unlz4$(EXT) 141 142lz4cat: lz4 143 $(LN_SF) lz4$(EXT) lz4cat$(EXT) 144 145DESTDIR ?= 146# directory variables : GNU conventions prefer lowercase 147# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 148# support both lower and uppercase (BSD), use lowercase in script 149PREFIX ?= /usr/local 150prefix ?= $(PREFIX) 151EXEC_PREFIX ?= $(prefix) 152exec_prefix ?= $(EXEC_PREFIX) 153BINDIR ?= $(exec_prefix)/bin 154bindir ?= $(BINDIR) 155DATAROOTDIR ?= $(prefix)/share 156datarootdir ?= $(DATAROOTDIR) 157MANDIR ?= $(datarootdir)/man 158mandir ?= $(MANDIR) 159MAN1DIR ?= $(mandir)/man1 160man1dir ?= $(MAN1DIR) 161 162install: lz4 163 @echo Installing binaries 164 @$(INSTALL_DIR) $(DESTDIR)$(bindir)/ $(DESTDIR)$(man1dir)/ 165 @$(INSTALL_PROGRAM) lz4$(EXT) $(DESTDIR)$(bindir)/lz4$(EXT) 166 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/lz4c$(EXT) 167 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/lz4cat$(EXT) 168 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/unlz4$(EXT) 169 @echo Installing man pages 170 @$(INSTALL_DATA) lz4.1 $(DESTDIR)$(man1dir)/lz4.1 171 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4c.1 172 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4cat.1 173 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/unlz4.1 174 @echo lz4 installation completed 175 176uninstall: 177 @$(RM) $(DESTDIR)$(bindir)/lz4cat$(EXT) 178 @$(RM) $(DESTDIR)$(bindir)/unlz4$(EXT) 179 @$(RM) $(DESTDIR)$(bindir)/lz4$(EXT) 180 @$(RM) $(DESTDIR)$(bindir)/lz4c$(EXT) 181 @$(RM) $(DESTDIR)$(man1dir)/lz4.1 182 @$(RM) $(DESTDIR)$(man1dir)/lz4c.1 183 @$(RM) $(DESTDIR)$(man1dir)/lz4cat.1 184 @$(RM) $(DESTDIR)$(man1dir)/unlz4.1 185 @echo lz4 programs successfully uninstalled 186 187endif 188