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