kusano 7d535a
# ################################################################
kusano 7d535a
# LZ4 library - Makefile
kusano 7d535a
# Copyright (C) Yann Collet 2011-2015
kusano 7d535a
# All rights reserved.
kusano 7d535a
# 
kusano 7d535a
# BSD license
kusano 7d535a
# Redistribution and use in source and binary forms, with or without modification,
kusano 7d535a
# are permitted provided that the following conditions are met:
kusano 7d535a
# 
kusano 7d535a
# * Redistributions of source code must retain the above copyright notice, this
kusano 7d535a
#   list of conditions and the following disclaimer.
kusano 7d535a
# 
kusano 7d535a
# * Redistributions in binary form must reproduce the above copyright notice, this
kusano 7d535a
#   list of conditions and the following disclaimer in the documentation and/or
kusano 7d535a
#   other materials provided with the distribution.
kusano 7d535a
# 
kusano 7d535a
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
kusano 7d535a
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
kusano 7d535a
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
kusano 7d535a
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
kusano 7d535a
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
kusano 7d535a
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
kusano 7d535a
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
kusano 7d535a
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
kusano 7d535a
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
kusano 7d535a
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kusano 7d535a
# 
kusano 7d535a
# You can contact the author at :
kusano 7d535a
#  - LZ4 source repository : https://github.com/Cyan4973/lz4
kusano 7d535a
#  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
kusano 7d535a
# ################################################################
kusano 7d535a
kusano 7d535a
# Version numbers
kusano 7d535a
VERSION ?= 129
kusano 7d535a
LIBVER_MAJOR=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h`
kusano 7d535a
LIBVER_MINOR=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h`
kusano 7d535a
LIBVER_PATCH=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h`
kusano 7d535a
LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH)
kusano 7d535a
kusano 7d535a
DESTDIR?=
kusano 7d535a
PREFIX ?= /usr/local
kusano 7d535a
CFLAGS ?= -O3
kusano 7d535a
CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual -Wstrict-prototypes -pedantic -DXXH_NAMESPACE=LZ4_
kusano 7d535a
kusano 7d535a
LIBDIR?= $(PREFIX)/lib
kusano 7d535a
INCLUDEDIR=$(PREFIX)/include
kusano 7d535a
kusano 7d535a
kusano 7d535a
# OS X linker doesn't support -soname, and use different extension
kusano 7d535a
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
kusano 7d535a
ifeq ($(shell uname), Darwin)
kusano 7d535a
	SHARED_EXT = dylib
kusano 7d535a
	SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
kusano 7d535a
	SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
kusano 7d535a
	SONAME_FLAGS = -install_name $(PREFIX)/lib/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
kusano 7d535a
else
kusano 7d535a
	SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR)
kusano 7d535a
	SHARED_EXT = so
kusano 7d535a
	SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
kusano 7d535a
	SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
kusano 7d535a
endif
kusano 7d535a
kusano 7d535a
default: liblz4
kusano 7d535a
kusano 7d535a
all: liblz4
kusano 7d535a
kusano 7d535a
liblz4: lz4.c lz4hc.c lz4frame.c xxhash.c
kusano 7d535a
	@echo compiling static library
kusano 7d535a
	@$(CC) $(CPPFLAGS) $(CFLAGS) -c $^
kusano 7d535a
	@$(AR) rcs liblz4.a lz4.o lz4hc.o lz4frame.o xxhash.o
kusano 7d535a
	@echo compiling dynamic library $(LIBVER)
kusano 7d535a
	@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -fPIC $(SONAME_FLAGS) -o $@.$(SHARED_EXT_VER)
kusano 7d535a
	@echo creating versioned links
kusano 7d535a
	@ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT_MAJOR)
kusano 7d535a
	@ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT)
kusano 7d535a
kusano 7d535a
clean:
kusano 7d535a
	@rm -f core *.o *.a *.$(SHARED_EXT) *.$(SHARED_EXT).* liblz4.pc
kusano 7d535a
	@echo Cleaning library completed
kusano 7d535a
kusano 7d535a
kusano 7d535a
#------------------------------------------------------------------------
kusano 7d535a
#make install is validated only for Linux, OSX, kFreeBSD and Hurd targets
kusano 7d535a
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU))
kusano 7d535a
kusano 7d535a
liblz4.pc: liblz4.pc.in Makefile
kusano 7d535a
	@echo creating pkgconfig
kusano 7d535a
	@sed -e 's|@PREFIX@|$(PREFIX)|' \
kusano 7d535a
            -e 's|@LIBDIR@|$(LIBDIR)|' \
kusano 7d535a
            -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
kusano 7d535a
            -e 's|@VERSION@|$(VERSION)|' \
kusano 7d535a
             $< >$@
kusano 7d535a
kusano 7d535a
install: liblz4 liblz4.pc
kusano 7d535a
	@install -d -m 755 $(DESTDIR)$(LIBDIR)/pkgconfig/ $(DESTDIR)$(INCLUDEDIR)/
kusano 7d535a
	@install -m 755 liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER)
kusano 7d535a
	@cp -a liblz4.$(SHARED_EXT_MAJOR) $(DESTDIR)$(LIBDIR)
kusano 7d535a
	@cp -a liblz4.$(SHARED_EXT) $(DESTDIR)$(LIBDIR)
kusano 7d535a
	@cp -a liblz4.pc $(DESTDIR)$(LIBDIR)/pkgconfig/
kusano 7d535a
	@install -m 644 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
kusano 7d535a
	@install -m 644 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
kusano 7d535a
	@install -m 644 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
kusano 7d535a
	@install -m 644 lz4frame.h $(DESTDIR)$(INCLUDEDIR)/lz4frame.h
kusano 7d535a
	@echo lz4 static and shared library installed
kusano 7d535a
kusano 7d535a
uninstall:
kusano 7d535a
	@rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT)
kusano 7d535a
	@rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR)
kusano 7d535a
	@rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/liblz4.pc
kusano 7d535a
	@[ -x $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER)
kusano 7d535a
	@[ -f $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
kusano 7d535a
	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4.h
kusano 7d535a
	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
kusano 7d535a
	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4frame.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4frame.h
kusano 7d535a
	@echo lz4 libraries successfully uninstalled
kusano 7d535a
kusano 7d535a
endif