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/Cyan4973/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 44SRCFILES := $(sort $(wildcard $(LZ4DIR)/*.c) $(wildcard *.c)) 45OBJFILES := $(SRCFILES:.c=.o) 46 47CPPFLAGS += -I$(LZ4DIR) -DXXH_NAMESPACE=LZ4_ 48CFLAGS ?= -O3 49DEBUGFLAGS:=-Wall -Wextra -Wundef -Wcast-qual -Wcast-align -Wshadow \ 50 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 51 -Wpointer-arith -Wstrict-aliasing=1 52CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 53FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 54 55LZ4_VERSION=$(LIBVER) 56MD2ROFF = ronn 57MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="lz4 $(LZ4_VERSION)" 58 59include ../Makefile.inc 60 61default: lz4-release 62 63all: lz4 lz4c 64 65all32: CFLAGS+=-m32 66all32: all 67 68ifeq ($(WINBASED),yes) 69lz4-exe.rc: lz4-exe.rc.in 70 @echo creating executable resource 71 $(Q)sed -e 's|@PROGNAME@|lz4|' \ 72 -e 's|@LIBVER_MAJOR@|$(LIBVER_MAJOR)|g' \ 73 -e 's|@LIBVER_MINOR@|$(LIBVER_MINOR)|g' \ 74 -e 's|@LIBVER_PATCH@|$(LIBVER_PATCH)|g' \ 75 -e 's|@EXT@|$(EXT)|g' \ 76 $< >$@ 77 78lz4-exe.o: lz4-exe.rc 79 $(WINDRES) -i lz4-exe.rc -o lz4-exe.o 80 81lz4: $(OBJFILES) lz4-exe.o 82 $(CC) $(FLAGS) $^ -o $@$(EXT) 83else 84lz4: $(OBJFILES) 85 $(CC) $(FLAGS) $^ -o $@$(EXT) 86endif 87 88 89lz4-release: DEBUGFLAGS= 90lz4-release: lz4 91 92lz4c: lz4 93 $(LN_SF) lz4$(EXT) lz4c$(EXT) 94 95lz4c32: CFLAGS += -m32 96lz4c32 : $(SRCFILES) 97 $(CC) $(FLAGS) $^ -o $@$(EXT) 98 99lz4.1: lz4.1.md $(LIBVER_SRC) 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 110clean: 111ifeq ($(WINBASED),yes) 112 $(Q)$(RM) *.rc 113endif 114 @$(MAKE) -C $(LZ4DIR) $@ > $(VOID) 115 @$(RM) core *.o *.test tmp* \ 116 lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) unlz4$(EXT) lz4cat$(EXT) 117 @echo Cleaning completed 118 119 120#----------------------------------------------------------------------------- 121# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 122#----------------------------------------------------------------------------- 123ifeq ($(POSIX_ENV),Yes) 124 125unlz4: lz4 126 $(LN_SF) lz4$(EXT) unlz4$(EXT) 127 128lz4cat: lz4 129 $(LN_SF) lz4$(EXT) lz4cat$(EXT) 130 131DESTDIR ?= 132# directory variables : GNU conventions prefer lowercase 133# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 134# support both lower and uppercase (BSD), use lowercase in script 135PREFIX ?= /usr/local 136prefix ?= $(PREFIX) 137EXEC_PREFIX ?= $(prefix) 138exec_prefix ?= $(EXEC_PREFIX) 139BINDIR ?= $(exec_prefix)/bin 140bindir ?= $(BINDIR) 141DATAROOTDIR ?= $(prefix)/share 142datarootdir ?= $(DATAROOTDIR) 143MANDIR ?= $(datarootdir)/man 144mandir ?= $(MANDIR) 145MAN1DIR ?= $(mandir)/man1 146man1dir ?= $(MAN1DIR) 147 148install: lz4 149 @echo Installing binaries 150 @$(INSTALL_DIR) $(DESTDIR)$(bindir)/ $(DESTDIR)$(man1dir)/ 151 @$(INSTALL_PROGRAM) lz4$(EXT) $(DESTDIR)$(bindir)/lz4$(EXT) 152 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/lz4c$(EXT) 153 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/lz4cat$(EXT) 154 @$(LN_S) lz4$(EXT) $(DESTDIR)$(bindir)/unlz4$(EXT) 155 @echo Installing man pages 156 @$(INSTALL_DATA) lz4.1 $(DESTDIR)$(man1dir)/lz4.1 157 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4c.1 158 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/lz4cat.1 159 @$(LN_SF) lz4.1 $(DESTDIR)$(man1dir)/unlz4.1 160 @echo lz4 installation completed 161 162uninstall: 163 @$(RM) $(DESTDIR)$(bindir)/lz4cat$(EXT) 164 @$(RM) $(DESTDIR)$(bindir)/unlz4$(EXT) 165 @$(RM) $(DESTDIR)$(bindir)/lz4$(EXT) 166 @$(RM) $(DESTDIR)$(bindir)/lz4c$(EXT) 167 @$(RM) $(DESTDIR)$(man1dir)/lz4.1 168 @$(RM) $(DESTDIR)$(man1dir)/lz4c.1 169 @$(RM) $(DESTDIR)$(man1dir)/lz4cat.1 170 @$(RM) $(DESTDIR)$(man1dir)/unlz4.1 171 @echo lz4 programs successfully uninstalled 172 173endif 174