1# ########################################################################## 2# LZ4 programs - Makefile 3# Copyright (C) Yann Collet 2011-2016 4# 5# GPL v2 License 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License along 18# with this program; if not, write to the Free Software Foundation, Inc., 19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21# You can contact the author at : 22# - LZ4 homepage : http://www.lz4.org 23# - LZ4 source repository : https://github.com/Cyan4973/lz4 24# ########################################################################## 25# lz4 : Command Line Utility, supporting gzip-like arguments 26# lz4c : CLU, supporting also legacy lz4demo arguments 27# lz4c32: Same as lz4c, but forced to compile in 32-bits mode 28# ########################################################################## 29 30# Version numbers 31LIBVER_SRC := ../lib/lz4.h 32LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 33LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 34LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 35LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 36LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 37LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 38LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 39LIBVER := $(shell echo $(LIBVER_SCRIPT)) 40 41LZ4DIR := ../lib 42 43SRCFILES := $(wildcard $(LZ4DIR)/*.c) $(wildcard *.c) 44OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) 45 46CPPFLAGS+= -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ 47CFLAGS ?= -O3 48DEBUGFLAGS:=-g -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ 49 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 50 -Wpointer-arith -Wstrict-aliasing=1 51CFLAGS += $(MOREFLAGS) 52FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 53 54LZ4_VERSION=$(LIBVER) 55MD2ROFF =ronn 56MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)" 57 58 59# Define *.exe as extension for Windows systems 60ifneq (,$(filter Windows%,$(OS))) 61VOID := nul 62EXT :=.exe 63else 64VOID := /dev/null 65EXT := 66endif 67 68 69 70default: lz4-release 71 72all: lz4 lz4c 73 74all32: CFLAGS+=-m32 75all32: all 76 77lz4: CFLAGS += $(DEBUGFLAGS) 78lz4: $(OBJFILES) 79 $(CC) $(FLAGS) $^ -o $@$(EXT) 80 81lz4-release: DEBUGFLAGS= 82lz4-release: lz4 83 84lz4c : CFLAGS += $(DEBUGFLAGS) 85lz4c : $(SRCFILES) 86 $(CC) $(FLAGS) -DENABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT) 87 88lz4c32: CFLAGS += -m32 $(DEBUGFLAGS) 89lz4c32: $(SRCFILES) 90 $(CC) $(FLAGS) $^ -o $@$(EXT) 91 92clean: 93 @$(MAKE) -C $(LZ4DIR) $@ > $(VOID) 94 @$(RM) core *.o *.test tmp* \ 95 lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) unlz4 lz4cat 96 @echo Cleaning completed 97 98 99lz4.1: lz4.1.md 100 cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 101 102man: lz4.1 103 104clean-man: 105 rm lz4.1 106 107preview-man: clean-man man 108 man ./lz4.1 109 110 111#----------------------------------------------------------------------------- 112# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 113#----------------------------------------------------------------------------- 114ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 115 116unlz4: lz4 117 ln -s lz4 unlz4 118 119lz4cat: lz4 120 ln -s lz4 lz4cat 121 122 123ifneq (,$(filter $(shell uname),SunOS)) 124INSTALL ?= ginstall 125else 126INSTALL ?= install 127endif 128 129PREFIX ?= /usr/local 130DESTDIR ?= 131BINDIR ?= $(PREFIX)/bin 132 133ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS)) 134MANDIR ?= $(PREFIX)/man/man1 135else 136MANDIR ?= $(PREFIX)/share/man/man1 137endif 138 139INSTALL_PROGRAM ?= $(INSTALL) -m 755 140INSTALL_SCRIPT ?= $(INSTALL) -m 755 141INSTALL_MAN ?= $(INSTALL) -m 644 142 143 144install: lz4$(EXT) lz4c$(EXT) 145 @echo Installing binaries 146 @$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/ 147 @$(INSTALL_PROGRAM) lz4 $(DESTDIR)$(BINDIR)/lz4 148 @ln -sf lz4 $(DESTDIR)$(BINDIR)/lz4cat 149 @ln -sf lz4 $(DESTDIR)$(BINDIR)/unlz4 150 @$(INSTALL_PROGRAM) lz4c$(EXT) $(DESTDIR)$(BINDIR)/lz4c 151 @echo Installing man pages 152 @$(INSTALL_MAN) -m 644 lz4.1 $(DESTDIR)$(MANDIR)/lz4.1 153 @ln -sf lz4.1 $(DESTDIR)$(MANDIR)/lz4c.1 154 @ln -sf lz4.1 $(DESTDIR)$(MANDIR)/lz4cat.1 155 @ln -sf lz4.1 $(DESTDIR)$(MANDIR)/unlz4.1 156 @echo lz4 installation completed 157 158uninstall: 159 @$(RM) $(DESTDIR)$(BINDIR)/lz4cat 160 @$(RM) $(DESTDIR)$(BINDIR)/unlz4 161 @$(RM) $(DESTDIR)$(BINDIR)/lz4 162 @$(RM) $(DESTDIR)$(BINDIR)/lz4c 163 @$(RM) $(DESTDIR)$(MANDIR)/lz4.1 164 @$(RM) $(DESTDIR)$(MANDIR)/lz4c.1 165 @$(RM) $(DESTDIR)$(MANDIR)/lz4cat.1 166 @$(RM) $(DESTDIR)$(MANDIR)/unlz4.1 167 @echo lz4 programs successfully uninstalled 168 169endif 170