1# ################################################################ 2# LZ4 library - Makefile 3# Copyright (C) Yann Collet 2011-2020 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/lz4/lz4 32# - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c 33# ################################################################ 34SED = sed 35 36# Version numbers 37LIBVER_MAJOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 38LIBVER_MINOR_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 39LIBVER_PATCH_SCRIPT:=`$(SED) -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h` 40LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT) 41LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT)) 42LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT)) 43LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT)) 44LIBVER := $(shell echo $(LIBVER_SCRIPT)) 45 46BUILD_SHARED:=yes 47BUILD_STATIC:=yes 48 49CPPFLAGS+= -DXXH_NAMESPACE=LZ4_ 50CPPFLAGS+= $(MOREFLAGS) 51CFLAGS ?= -O3 52DEBUGFLAGS:= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ 53 -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes \ 54 -Wundef -Wpointer-arith -Wstrict-aliasing=1 55CFLAGS += $(DEBUGFLAGS) 56FLAGS = $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) 57 58SRCFILES := $(sort $(wildcard *.c)) 59 60include ../Makefile.inc 61 62# OS X linker doesn't support -soname, and use different extension 63# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html 64ifeq ($(TARGET_OS), Darwin) 65 SHARED_EXT = dylib 66 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT) 67 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT) 68 SONAME_FLAGS = -install_name $(libdir)/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER) 69else 70 SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR) 71 SHARED_EXT = so 72 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR) 73 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER) 74endif 75 76.PHONY: default 77default: lib-release 78 79# silent mode by default; verbose can be triggered by V=1 or VERBOSE=1 80$(V)$(VERBOSE).SILENT: 81 82lib-release: DEBUGFLAGS := 83lib-release: lib 84 85.PHONY: lib 86lib: liblz4.a liblz4 87 88.PHONY: all 89all: lib 90 91.PHONY: all32 92all32: CFLAGS+=-m32 93all32: all 94 95liblz4.a: $(SRCFILES) 96ifeq ($(BUILD_STATIC),yes) # can be disabled on command line 97 @echo compiling static library 98 $(COMPILE.c) $^ 99 $(AR) rcs $@ *.o 100endif 101 102ifeq ($(WINBASED),yes) 103liblz4-dll.rc: liblz4-dll.rc.in 104 @echo creating library resource 105 $(SED) -e 's|@LIBLZ4@|$(LIBLZ4)|' \ 106 -e 's|@LIBVER_MAJOR@|$(LIBVER_MAJOR)|g' \ 107 -e 's|@LIBVER_MINOR@|$(LIBVER_MINOR)|g' \ 108 -e 's|@LIBVER_PATCH@|$(LIBVER_PATCH)|g' \ 109 $< >$@ 110 111liblz4-dll.o: liblz4-dll.rc 112 $(WINDRES) -i liblz4-dll.rc -o liblz4-dll.o 113 114$(LIBLZ4): $(SRCFILES) liblz4-dll.o 115 @echo compiling dynamic library $(LIBVER) 116 $(CC) $(FLAGS) -DLZ4_DLL_EXPORT=1 -shared $^ -o dll/$@.dll -Wl,--out-implib,dll/$(LIBLZ4_EXP) 117 118else # not windows 119 120$(LIBLZ4): $(SRCFILES) 121 @echo compiling dynamic library $(LIBVER) 122 $(CC) $(FLAGS) -shared $^ -fPIC -fvisibility=hidden $(SONAME_FLAGS) -o $@ 123 @echo creating versioned links 124 $(LN_SF) $@ liblz4.$(SHARED_EXT_MAJOR) 125 $(LN_SF) $@ liblz4.$(SHARED_EXT) 126 127endif 128 129.PHONY: liblz4 130liblz4: $(LIBLZ4) 131 132.PHONY: clean 133clean: 134ifeq ($(WINBASED),yes) 135 $(RM) *.rc 136endif 137 $(RM) core *.o liblz4.pc dll/$(LIBLZ4).dll dll/$(LIBLZ4_EXP) 138 $(RM) *.a *.$(SHARED_EXT) *.$(SHARED_EXT_MAJOR) *.$(SHARED_EXT_VER) 139 @echo Cleaning library completed 140 141#----------------------------------------------------------------------------- 142# make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets 143#----------------------------------------------------------------------------- 144ifeq ($(POSIX_ENV),Yes) 145 146.PHONY: listL120 147listL120: # extract lines >= 120 characters in *.{c,h}, by Takayuki Matsuoka (note : $$, for Makefile compatibility) 148 find . -type f -name '*.c' -o -name '*.h' | while read -r filename; do awk 'length > 120 {print FILENAME "(" FNR "): " $$0}' $$filename; done 149 150DESTDIR ?= 151# directory variables : GNU conventions prefer lowercase 152# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html 153# support both lower and uppercase (BSD), use lower in script 154PREFIX ?= /usr/local 155prefix ?= $(PREFIX) 156EXEC_PREFIX ?= $(prefix) 157exec_prefix ?= $(EXEC_PREFIX) 158BINDIR ?= $(exec_prefix)/bin 159bindir ?= $(BINDIR) 160LIBDIR ?= $(exec_prefix)/lib 161libdir ?= $(LIBDIR) 162INCLUDEDIR ?= $(prefix)/include 163includedir ?= $(INCLUDEDIR) 164 165 ifneq (,$(filter $(TARGET_OS),OpenBSD FreeBSD NetBSD DragonFly MidnightBSD)) 166PKGCONFIGDIR ?= $(prefix)/libdata/pkgconfig 167 else 168PKGCONFIGDIR ?= $(libdir)/pkgconfig 169 endif 170pkgconfigdir ?= $(PKGCONFIGDIR) 171 172liblz4.pc: liblz4.pc.in Makefile 173 @echo creating pkgconfig 174 $(SED) -e 's|@PREFIX@|$(prefix)|' \ 175 -e 's|@LIBDIR@|$(libdir)|' \ 176 -e 's|@INCLUDEDIR@|$(includedir)|' \ 177 -e 's|@VERSION@|$(LIBVER)|' \ 178 $< >$@ 179 180install: lib liblz4.pc 181 $(INSTALL_DIR) $(DESTDIR)$(pkgconfigdir)/ $(DESTDIR)$(includedir)/ $(DESTDIR)$(libdir)/ $(DESTDIR)$(bindir)/ 182 $(INSTALL_DATA) liblz4.pc $(DESTDIR)$(pkgconfigdir)/ 183 @echo Installing libraries 184 ifeq ($(BUILD_STATIC),yes) 185 $(INSTALL_DATA) liblz4.a $(DESTDIR)$(libdir)/liblz4.a 186 $(INSTALL_DATA) lz4frame_static.h $(DESTDIR)$(includedir)/lz4frame_static.h 187 endif 188 ifeq ($(BUILD_SHARED),yes) 189# Traditionnally, one installs the DLLs in the bin directory as programs 190# search them first in their directory. This allows to not pollute system 191# directories (like c:/windows/system32), nor modify the PATH variable. 192 ifeq ($(WINBASED),yes) 193 $(INSTALL_PROGRAM) dll/$(LIBLZ4).dll $(DESTDIR)$(bindir) 194 $(INSTALL_PROGRAM) dll/$(LIBLZ4_EXP) $(DESTDIR)$(libdir) 195 else 196 $(INSTALL_PROGRAM) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir) 197 $(LN_SF) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR) 198 $(LN_SF) liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT) 199 endif 200 endif 201 @echo Installing headers in $(includedir) 202 $(INSTALL_DATA) lz4.h $(DESTDIR)$(includedir)/lz4.h 203 $(INSTALL_DATA) lz4hc.h $(DESTDIR)$(includedir)/lz4hc.h 204 $(INSTALL_DATA) lz4frame.h $(DESTDIR)$(includedir)/lz4frame.h 205 @echo lz4 libraries installed 206 207uninstall: 208 $(RM) $(DESTDIR)$(pkgconfigdir)/liblz4.pc 209 ifeq (WINBASED,1) 210 $(RM) $(DESTDIR)$(bindir)/$(LIBLZ4).dll 211 $(RM) $(DESTDIR)$(libdir)/$(LIBLZ4_EXP) 212 else 213 $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT) 214 $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_MAJOR) 215 $(RM) $(DESTDIR)$(libdir)/liblz4.$(SHARED_EXT_VER) 216 endif 217 $(RM) $(DESTDIR)$(libdir)/liblz4.a 218 $(RM) $(DESTDIR)$(includedir)/lz4.h 219 $(RM) $(DESTDIR)$(includedir)/lz4hc.h 220 $(RM) $(DESTDIR)$(includedir)/lz4frame.h 221 $(RM) $(DESTDIR)$(includedir)/lz4frame_static.h 222 @echo lz4 libraries successfully uninstalled 223 224endif 225