1 # ################################################################ 2 # LZ4 library - Makefile 3 # Copyright (C) Yann Collet 2011-2016 4 # All rights reserved. 5 # 6 # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets 7 # 8 # BSD license 9 # Redistribution and use in source and binary forms, with or without modification, 10 # are permitted provided that the following conditions are met: 11 # 12 # * Redistributions of source code must retain the above copyright notice, this 13 # list of conditions and the following disclaimer. 14 # 15 # * Redistributions in binary form must reproduce the above copyright notice, this 16 # list of conditions and the following disclaimer in the documentation and/or 17 # other materials provided with the distribution. 18 # 19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 # 30 # You can contact the author at : 31 # - LZ4 source repository : https://github.com/Cyan4973/lz4 32 # - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c 33 # ################################################################ 34 35 # Version numbers 36 LIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 37 LIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 38 LIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 39 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 40 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 41 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 42 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 43 LIBVER := $(shell echo $(LIBVER_SCRIPT)) 44 45 BUILD_SHARED:=yes 46 BUILD_STATIC:=yes 47 48 OS ?= $(shell uname) 49 CPPFLAGS+= -DXXH_NAMESPACE=LZ4_ 50 CFLAGS ?= -O3 51 DEBUGFLAGS:= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 52 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 53 -Wundef -Wpointer-arith -Wstrict-aliasing=1 54 CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) 55 FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) 56 57 SRCFILES := $(sort $(wildcard *.c)) 58 59 60 # OS X linker doesn't support -soname, and use different extension 61 # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 62 ifeq ($(OS), Darwin) 63 SHARED_EXT = dylib 64 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 65 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 66 SONAME_FLAGS = -install_name $(libdir)/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 67 else 68 SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR) 69 SHARED_EXT = so 70 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 71 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 72 endif 73 74 LIBLZ4 = liblz4.$(SHARED_EXT_VER) 75 76 .PHONY: default 77 default: lib-release 78 79 lib-release: DEBUGFLAGS := 80 lib-release: lib 81 82 lib: liblz4.a liblz4 83 84 all: lib 85 86 all32: CFLAGS+=-m32 87 all32: all 88 89 ifeq ($(V), 1) 90 Q = 91 else 92 Q = @ 93 endif 94 95 liblz4.a: $(SRCFILES) 96 ifeq ($(BUILD_STATIC),yes) # can be disabled on command line 97 @echo compiling static library 98 $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c $^ 99 $(Q)$(AR) rcs $@ *.o 100 endif 101 102 $(LIBLZ4): $(SRCFILES) 103 ifeq ($(BUILD_SHARED),yes) # can be disabled on command line 104 @echo compiling dynamic library $(LIBVER) 105 ifneq (,$(filter Windows%,$(OS))) 106 $(Q)$(CC) $(FLAGS) -DLZ4_DLL_EXPORT=1 -shared $^ -o dll\$@.dll 107 dlltool -D dll\liblz4.dll -d dll\liblz4.def -l dll\liblz4.lib 108 else 109 $(Q)$(CC) $(FLAGS) -shared $^ -fPIC -fvisibility=hidden $(SONAME_FLAGS) -o $@ 110 @echo creating versioned links 111 $(Q)ln -sf $@ liblz4.$(SHARED_EXT_MAJOR) 112 $(Q)ln -sf $@ liblz4.$(SHARED_EXT) 113 endif 114 endif 115 116 liblz4: $(LIBLZ4) 117 118 clean: 119 $(Q)$(RM) core *.o liblz4.pc dll/liblz4.dll dll/liblz4.lib 120 $(Q)$(RM) *.a *.$(SHARED_EXT) *.$(SHARED_EXT_MAJOR) *.$(SHARED_EXT_VER) 121 @echo Cleaning library completed 122 123 124 #----------------------------------------------------------------------------- 125 # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 126 #----------------------------------------------------------------------------- 127 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku MidnightBSD)) 128 129 .PHONY: listL120 130 listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note : $$, for Makefile compatibility) 131 find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done 132 133 DESTDIR ?= 134 # directory variables : GNU conventions prefer lowercase 135 # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 136 # support both lower and uppercase (BSD), use lower in script 137 PREFIX ?= /usr/local 138 prefix ?= $(PREFIX) 139 EXEC_PREFIX ?= $(prefix) 140 exec_prefix ?= $(EXEC_PREFIX) 141 LIBDIR ?= $(exec_prefix)/lib 142 libdir ?= $(LIBDIR) 143 INCLUDEDIR ?= $(prefix)/include 144 includedir ?= $(INCLUDEDIR) 145 146 ifneq (,$(filter $(OS),OpenBSD FreeBSD NetBSD DragonFly)) 147 PKGCONFIGDIR ?= $(prefix)/libdata/pkgconfig 148 else 149 PKGCONFIGDIR ?= $(libdir)/pkgconfig 150 endif 151 pkgconfigdir ?= $(PKGCONFIGDIR) 152 153 ifneq (,$(filter $(OS),SunOS)) 154 INSTALL ?= ginstall 155 else 156 INSTALL ?= install 157 endif 158 159 INSTALL_PROGRAM ?= $(INSTALL) 160 INSTALL_DATA ?= $(INSTALL) -m 644 161 162 liblz4.pc: liblz4.pc.in Makefile 163 @echo creating pkgconfig 164 $(Q)sed -e 's|@PREFIX@|$(prefix)|' \ 165 -e 's|@LIBDIR@|$(libdir)|' \ 166 -e 's|@INCLUDEDIR@|$(includedir)|' \ 167 -e 's|@VERSION@|$(LIBVER)|' \ 168 $< >$@ 169 170 install: lib liblz4.pc 171 $(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(pkgconfigdir)/ $(DESTDIR)$(includedir)/ $(DESTDIR)$(libdir)/ 172 $(Q)$(INSTALL_DATA) liblz4.pc $(DESTDIR)$(pkgconfigdir)/ 173 @echo Installing libraries 174 ifeq ($(BUILD_STATIC),yes) 175 $(Q)$(INSTALL_DATA) liblz4.a $(DESTDIR)$(libdir)/liblz4.a 176 $(Q)$(INSTALL_DATA) lz4frame_static.h $(DESTDIR)$(includedir)/lz4frame_static.h 177 endif 178 ifeq ($(BUILD_SHARED),yes) 179 $(Q)$(INSTALL_PROGRAM) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir) 180 $(Q)ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR) 181 $(Q)ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT) 182 endif 183 @echo Installing headers in $(includedir) 184 $(Q)$(INSTALL_DATA) lz4.h $(DESTDIR)$(includedir)/lz4.h 185 $(Q)$(INSTALL_DATA) lz4hc.h $(DESTDIR)$(includedir)/lz4hc.h 186 $(Q)$(INSTALL_DATA) lz4frame.h $(DESTDIR)$(includedir)/lz4frame.h 187 @echo lz4 libraries installed 188 189 uninstall: 190 $(Q)$(RM) $(DESTDIR)$(pkgconfigdir)/liblz4.pc 191 $(Q)$(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT) 192 $(Q)$(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR) 193 $(Q)$(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_VER) 194 $(Q)$(RM) $(DESTDIR)$(libdir)/liblz4.a 195 $(Q)$(RM) $(DESTDIR)$(includedir)/lz4.h 196 $(Q)$(RM) $(DESTDIR)$(includedir)/lz4hc.h 197 $(Q)$(RM) $(DESTDIR)$(includedir)/lz4frame.h 198 $(Q)$(RM) $(DESTDIR)$(includedir)/lz4frame_static.h 199 @echo lz4 libraries successfully uninstalled 200 201 endif 202