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 34 LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 35 LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 36 LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 37 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 38 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 39 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 40 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 41 LIBVER := $(shell echo $(LIBVER_SCRIPT)) 42 43 BUILD_STATIC:= yes 44 45 CPPFLAGS+= -DXXH_NAMESPACE=LZ4_ 46 CFLAGS ?= -O3 47 DEBUGFLAGS:=-g -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 48 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef \ 49 -Wpointer-arith -Wstrict-aliasing=1 50 CFLAGS += $(MOREFLAGS) 51 FLAGS = $(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 57 ifeq ($(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) 62 else 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) 67 endif 68 69 LIBLZ4 = liblz4.$(SHARED_EXT_VER) 70 71 default: lib-release 72 73 lib-release: liblz4.a liblz4 74 75 lib: CFLAGS += $(DEBUGFLAGS) 76 lib: lib-release 77 78 all: lib 79 80 all32: CFLAGS+=-m32 81 all32: all 82 83 liblz4.a: *.c 84 ifeq ($(BUILD_STATIC),yes) 85 @echo compiling static library 86 @$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ 87 @$(AR) rcs $@ *.o 88 endif 89 90 $(LIBLZ4): *.c 91 @echo compiling dynamic library $(LIBVER) 92 ifneq (,$(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 95 else 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) 100 endif 101 102 liblz4: $(LIBLZ4) 103 104 clean: 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 #----------------------------------------------------------------------------- 113 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS)) 114 115 ifneq (,$(filter $(shell uname),SunOS)) 116 INSTALL ?= ginstall 117 else 118 INSTALL ?= install 119 endif 120 121 PREFIX ?= /usr/local 122 DESTDIR ?= 123 LIBDIR ?= $(PREFIX)/lib 124 INCLUDEDIR ?= $(PREFIX)/include 125 126 ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly)) 127 PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig 128 else 129 PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig 130 endif 131 132 INSTALL_LIB ?= $(INSTALL) -m 755 133 INSTALL_DATA ?= $(INSTALL) -m 644 134 135 liblz4.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 143 install: lib liblz4.pc 144 @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/ 145 @$(INSTALL_DATA) liblz4.pc $(DESTDIR)$(PKGCONFIGDIR)/ 146 @echo Installing libraries 147 ifeq ($(BUILD_STATIC),yes) 148 @$(INSTALL_LIB) liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a 149 endif 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 159 uninstall: 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 170 endif 171