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 31 LIBVER_SRC := ../lib/lz4.h 32 LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 33 LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 34 LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < $(LIBVER_SRC)` 35 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 36 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 37 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 38 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 39 LIBVER := $(shell echo $(LIBVER_SCRIPT)) 40 41 LZ4DIR := ../lib 42 43 SRCFILES := $(wildcard $(LZ4DIR)/*.c) $(wildcard *.c) 44 OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) 45 46 CPPFLAGS+= -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ 47 CFLAGS ?= -O3 48 DEBUGFLAGS:=-g -Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ 49 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 50 -Wpointer-arith -Wstrict-aliasing=1 51 CFLAGS += $(MOREFLAGS) 52 FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 53 54 LZ4_VERSION=$(LIBVER) 55 MD2ROFF =ronn 56 MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)" 57 58 59 # Define *.exe as extension for Windows systems 60 ifneq (,$(filter Windows%,$(OS))) 61 VOID := nul 62 EXT :=.exe 63 else 64 VOID := /dev/null 65 EXT := 66 endif 67 68 69 70 default: lz4-release 71 72 all: lz4 lz4c 73 74 all32: CFLAGS+=-m32 75 all32: all 76 77 lz4: CFLAGS += $(DEBUGFLAGS) 78 lz4: $(OBJFILES) 79 $(CC) $(FLAGS) $^ -o $@$(EXT) 80 81 lz4-release: DEBUGFLAGS= 82 lz4-release: lz4 83 84 lz4c : CFLAGS += $(DEBUGFLAGS) 85 lz4c : $(SRCFILES) 86 $(CC) $(FLAGS) -DENABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT) 87 88 lz4c32: CFLAGS += -m32 $(DEBUGFLAGS) 89 lz4c32: $(SRCFILES) 90 $(CC) $(FLAGS) $^ -o $@$(EXT) 91 92 clean: 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 99 lz4.1: lz4.1.md 100 cat $^ | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@ 101 102 man: lz4.1 103 104 clean-man: 105 rm lz4.1 106 107 preview-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 #----------------------------------------------------------------------------- 114 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 115 116 unlz4: lz4 117 ln -s lz4 unlz4 118 119 lz4cat: lz4 120 ln -s lz4 lz4cat 121 122 123 ifneq (,$(filter $(shell uname),SunOS)) 124 INSTALL ?= ginstall 125 else 126 INSTALL ?= install 127 endif 128 129 PREFIX ?= /usr/local 130 DESTDIR ?= 131 BINDIR ?= $(PREFIX)/bin 132 133 ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly SunOS)) 134 MANDIR ?= $(PREFIX)/man/man1 135 else 136 MANDIR ?= $(PREFIX)/share/man/man1 137 endif 138 139 INSTALL_PROGRAM ?= $(INSTALL) -m 755 140 INSTALL_SCRIPT ?= $(INSTALL) -m 755 141 INSTALL_MAN ?= $(INSTALL) -m 644 142 143 144 install: 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 158 uninstall: 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 169 endif 170