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