1# ################################################################ 2# LZ4 library - Makefile 3# Copyright (C) Yann Collet 2011-2016 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 : https://github.com/Cyan4973/lz4 30# - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c 31# ################################################################ 32 33# Version numbers 34LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 35LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 36LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 37LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 38LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 39LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 40LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 41LIBVER := $(shell echo $(LIBVER_SCRIPT)) 42 43BUILD_STATIC:= yes 44 45CPPFLAGS+= -DXXH_NAMESPACE=LZ4_ 46CFLAGS ?= -O3 47DEBUGFLAGS:=-g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 48 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef \ 49 -Wpointer-arith -Wstrict-aliasing=1 50CFLAGS += $(MOREFLAGS) 51FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) 52 53 54 55# OS X linker doesn't support -soname, and use different extension 56# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 57ifeq ($(shell uname), Darwin) 58 SHARED_EXT = dylib 59 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 60 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 61 SONAME_FLAGS = -install_name $(PREFIX)/lib/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 62else 63 SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR) 64 SHARED_EXT = so 65 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 66 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 67endif 68 69LIBLZ4 = liblz4.$(SHARED_EXT_VER) 70 71default: lib-release 72 73lib-release: liblz4.a liblz4 74 75lib: CFLAGS += $(DEBUGFLAGS) 76lib: lib-release 77 78all: lib 79 80all32: CFLAGS+=-m32 81all32: all 82 83liblz4.a: *.c 84ifeq ($(BUILD_STATIC),yes) 85 @echo compiling static library 86 @$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ 87 @$(AR) rcs $@ *.o 88endif 89 90$(LIBLZ4): *.c 91 @echo compiling dynamic library $(LIBVER) 92ifneq (,$(filter Windows%,$(OS))) 93 @$(CC) $(FLAGS) -DLZ4_DLL_EXPORT=1 -shared $^ -o dll\$@.dll 94 dlltool -D dll\liblz4.dll -d dll\liblz4.def -l dll\liblz4.lib 95else 96 @$(CC) $(FLAGS) -shared $^ -fPIC $(SONAME_FLAGS) -o $@ 97 @echo creating versioned links 98 @ln -sf $@ liblz4.$(SHARED_EXT_MAJOR) 99 @ln -sf $@ liblz4.$(SHARED_EXT) 100endif 101 102liblz4: $(LIBLZ4) 103 104clean: 105 @$(RM) core *.o liblz4.pc dll/liblz4.dll dll/liblz4.lib 106 @$(RM) *.a *.$(SHARED_EXT) *.$(SHARED_EXT_MAJOR) *.$(SHARED_EXT_VER) 107 @echo Cleaning library completed 108 109 110#----------------------------------------------------------------------------- 111# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 112#----------------------------------------------------------------------------- 113ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 114 115ifneq (,$(filter $(shell uname),SunOS)) 116INSTALL ?= ginstall 117else 118INSTALL ?= install 119endif 120 121PREFIX ?= /usr/local 122DESTDIR ?= 123LIBDIR ?= $(PREFIX)/lib 124INCLUDEDIR ?= $(PREFIX)/include 125 126ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly)) 127PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig 128else 129PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig 130endif 131 132INSTALL_LIB ?= $(INSTALL) -m 755 133INSTALL_DATA ?= $(INSTALL) -m 644 134 135liblz4.pc: liblz4.pc.in Makefile 136 @echo creating pkgconfig 137 @sed -e 's|@PREFIX@|$(PREFIX)|' \ 138 -e 's|@LIBDIR@|$(LIBDIR)|' \ 139 -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \ 140 -e 's|@VERSION@|$(LIBVER)|' \ 141 $< >$@ 142 143install: lib liblz4.pc 144 @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/ 145 @$(INSTALL_DATA) liblz4.pc $(DESTDIR)$(PKGCONFIGDIR)/ 146 @echo Installing libraries 147ifeq ($(BUILD_STATIC),yes) 148 @$(INSTALL_LIB) liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a 149endif 150 @$(INSTALL_LIB) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR) 151 @ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR) 152 @ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT) 153 @echo Installing includes 154 @$(INSTALL_DATA) lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h 155 @$(INSTALL_DATA) lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h 156 @$(INSTALL_DATA) lz4frame.h $(DESTDIR)$(INCLUDEDIR)/lz4frame.h 157 @echo lz4 static and shared libraries installed 158 159uninstall: 160 @$(RM) $(DESTDIR)$(LIBDIR)/pkgconfig/liblz4.pc 161 @$(RM) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT) 162 @$(RM) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR) 163 @$(RM) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) 164 @$(RM) $(DESTDIR)$(LIBDIR)/liblz4.a 165 @$(RM) $(DESTDIR)$(INCLUDEDIR)/lz4.h 166 @$(RM) $(DESTDIR)$(INCLUDEDIR)/lz4hc.h 167 @$(RM) $(DESTDIR)$(INCLUDEDIR)/lz4frame.h 168 @echo lz4 libraries successfully uninstalled 169 170endif 171