1# ################################################################ 2# LZ4 library - Makefile 3# Copyright (C) Yann Collet 2011-2015 4# All rights reserved. 5# 6# BSD license 7# Redistribution and use in source and binary forms, with or without modification, 8# are permitted provided that the following conditions are met: 9# 10# * Redistributions of source code must retain the above copyright notice, this 11# list of conditions and the following disclaimer. 12# 13# * Redistributions in binary form must reproduce the above copyright notice, this 14# list of conditions and the following disclaimer in the documentation and/or 15# other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 21# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28# You can contact the author at : 29# - LZ4 source repository : http://code.google.com/p/lz4/ 30# - LZ4 source mirror : https://github.com/Cyan4973/lz4 31# - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c 32# ################################################################ 33 34# Version numbers 35VERSION ?= 126 36LIBVER_MAJOR=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` 37LIBVER_MINOR=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` 38LIBVER_PATCH=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < lz4.h` 39LIBVER=$(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH) 40 41DESTDIR?= 42PREFIX ?= /usr 43CFLAGS ?= -O3 44CFLAGS += -I. -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wstrict-prototypes -pedantic 45 46LIBDIR?= $(PREFIX)/lib 47INCLUDEDIR=$(PREFIX)/include 48 49 50# OS X linker doesn't support -soname, and use different extension 51# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 52ifeq ($(shell uname), Darwin) 53 SHARED_EXT = dylib 54 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 55 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 56 SONAME_FLAGS = -install_name $(PREFIX)/lib/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 57else 58 SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR) 59 SHARED_EXT = so 60 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 61 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 62endif 63 64default: liblz4 65 66all: liblz4 67 68liblz4: lz4.c lz4hc.c lz4frame.c xxhash.c 69 @echo compiling static library 70 @$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ 71 @$(AR) rcs liblz4.a lz4.o lz4hc.o lz4frame.o xxhash.o 72 @echo compiling dynamic library $(LIBVER) 73 @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -fPIC $(SONAME_FLAGS) -o $@.$(SHARED_EXT_VER) 74 @echo creating versioned links 75 @ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT_MAJOR) 76 @ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT) 77 78clean: 79 @rm -f core *.o *.a *.$(SHARED_EXT) *.$(SHARED_EXT).* liblz4.pc 80 @echo Cleaning library completed 81 82 83#------------------------------------------------------------------------ 84#make install is validated only for Linux, OSX, kFreeBSD and Hurd targets 85ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU)) 86 87liblz4.pc: liblz4.pc.in Makefile 88 @echo creating pkgconfig 89 @sed -e 's|@PREFIX@|$(PREFIX)|' \ 90 -e 's|@LIBDIR@|$(LIBDIR)|' \ 91 -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ 92 -e 's|@VERSION@|$(VERSION)|' \ 93 $< >$@ 94 95install: liblz4 liblz4.pc 96 @install -d -m 755 $(DESTDIR)$(LIBDIR)/pkgconfig/ $(DESTDIR)$(INCLUDEDIR)/ 97 @install -m 755 liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) 98 @cp -a liblz4.$(SHARED_EXT_MAJOR) $(DESTDIR)$(LIBDIR) 99 @cp -a liblz4.$(SHARED_EXT) $(DESTDIR)$(LIBDIR) 100 @cp -a liblz4.pc $(DESTDIR)$(LIBDIR)/pkgconfig/ 101 @install -m 644 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a 102 @install -m 644 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h 103 @install -m 644 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h 104 @install -m 644 lz4frame.h $(DESTDIR)$(INCLUDEDIR)/lz4frame.h 105 @echo lz4 static and shared library installed 106 107uninstall: 108 @rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT) 109 @rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR) 110 @rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/liblz4.pc 111 @[ -x $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) 112 @[ -f $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a 113 @[ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4.h 114 @[ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h 115 @echo lz4 libraries successfully uninstalled 116 117endif 118