Makefile revision 28f98647e3349a4a0a9c8975199aa89f2a02f6b9
1d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# ################################################################
2d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# LZ4 library - Makefile
3daa320f3f7bd9cc121462ef7a201fad87f540bd6Yann Collet# Copyright (C) Yann Collet 2011-2015
4d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# All rights reserved.
54fcb2e17fb065f1d061a9c72066dd4dc1eb94a3fJulius Werner#
6d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# BSD license
7d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# Redistribution and use in source and binary forms, with or without modification,
8d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# are permitted provided that the following conditions are met:
94fcb2e17fb065f1d061a9c72066dd4dc1eb94a3fJulius Werner#
10d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# * Redistributions of source code must retain the above copyright notice, this
11d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet#   list of conditions and the following disclaimer.
124fcb2e17fb065f1d061a9c72066dd4dc1eb94a3fJulius Werner#
13d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# * Redistributions in binary form must reproduce the above copyright notice, this
14d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet#   list of conditions and the following disclaimer in the documentation and/or
15d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet#   other materials provided with the distribution.
164fcb2e17fb065f1d061a9c72066dd4dc1eb94a3fJulius Werner#
17d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274fcb2e17fb065f1d061a9c72066dd4dc1eb94a3fJulius Werner#
28d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# You can contact the author at :
292b55752a5c749e57bbd4c9b830ccf939510beec1Yann Collet#  - LZ4 source repository : https://github.com/Cyan4973/lz4
30d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet#  - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
31d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# ################################################################
32d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
33d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# Version numbers
3428f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_MAJOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
3528f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_MINOR_SCRIPT:=`sed -n '/define LZ4_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
3628f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_PATCH_SCRIPT:=`sed -n '/define LZ4_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./lz4.h`
3728f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
3828f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
3928f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
4028f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
4128f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletLIBVER := $(shell echo $(LIBVER_SCRIPT))
4228f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann Collet
43d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
44d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann ColletDESTDIR?=
452b55752a5c749e57bbd4c9b830ccf939510beec1Yann ColletPREFIX ?= /usr/local
46a3c6daba6e582094897e98c63ccc18ec8097ee5fYann ColletCPPFLAGS= -DXXH_NAMESPACE=LZ4_
47d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann ColletCFLAGS ?= -O3
4828f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann ColletCFLAGS += -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wcast-qual -Wstrict-prototypes
4960119e2585fd652a9c6dfd06aafa4c8f49208501Yann ColletFLAGS   = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS)
50d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
51d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann ColletLIBDIR?= $(PREFIX)/lib
52d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann ColletINCLUDEDIR=$(PREFIX)/include
53d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
54d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
55d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# OS X linker doesn't support -soname, and use different extension
56d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
57d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletifeq ($(shell uname), Darwin)
58d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT = dylib
59d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
60d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
61d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SONAME_FLAGS = -install_name $(PREFIX)/lib/liblz4.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
62d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletelse
63d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SONAME_FLAGS = -Wl,-soname=liblz4.$(SHARED_EXT).$(LIBVER_MAJOR)
64d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT = so
65d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
66d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
67d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletendif
68d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
69d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletdefault: liblz4
70d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
71d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletall: liblz4
72d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
7328f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann Colletliblz4: *.c
74d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo compiling static library
7528f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann Collet	@$(CC) $(FLAGS) -c $^
7628f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann Collet	@$(AR) rcs $@.a *.o
77d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo compiling dynamic library $(LIBVER)
78a3c6daba6e582094897e98c63ccc18ec8097ee5fYann Collet	@$(CC) $(FLAGS) -shared $^ -fPIC $(SONAME_FLAGS) -o $@.$(SHARED_EXT_VER)
79d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo creating versioned links
80d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT_MAJOR)
81d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@ln -sf $@.$(SHARED_EXT_VER) $@.$(SHARED_EXT)
82d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
83d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletclean:
84d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@rm -f core *.o *.a *.$(SHARED_EXT) *.$(SHARED_EXT).* liblz4.pc
85d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo Cleaning library completed
86d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
87d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
88d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet#------------------------------------------------------------------------
897bfbccb972d349b66f45c9791a12477bfee4c40eMartin Waschbüsch#make install is validated only for Linux, OSX, kFreeBSD, Hurd and
907bfbccb972d349b66f45c9791a12477bfee4c40eMartin Waschbüsch#FreeBSD targets
917bfbccb972d349b66f45c9791a12477bfee4c40eMartin Waschbüschifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU FreeBSD))
92d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
93d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletliblz4.pc: liblz4.pc.in Makefile
94d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo creating pkgconfig
95d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@sed -e 's|@PREFIX@|$(PREFIX)|' \
96d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet            -e 's|@LIBDIR@|$(LIBDIR)|' \
97d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet            -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
9828f98647e3349a4a0a9c8975199aa89f2a02f6b9Yann Collet            -e 's|@VERSION@|$(LIBVER)|' \
99d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet             $< >$@
100d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
101d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletinstall: liblz4 liblz4.pc
102d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@install -d -m 755 $(DESTDIR)$(LIBDIR)/pkgconfig/ $(DESTDIR)$(INCLUDEDIR)/
103cd18ed3086a3eaf5d6531412959bd875b74dc6c1Yann Collet	@install -m 755 liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
104cd18ed3086a3eaf5d6531412959bd875b74dc6c1Yann Collet	@ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR)
105cd18ed3086a3eaf5d6531412959bd875b74dc6c1Yann Collet	@ln -sf liblz4.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT)
106cd18ed3086a3eaf5d6531412959bd875b74dc6c1Yann Collet	@install -m 644 liblz4.pc $(DESTDIR)$(LIBDIR)/pkgconfig/
107d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@install -m 644 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
108d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@install -m 644 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
109d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@install -m 644 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
110daa320f3f7bd9cc121462ef7a201fad87f540bd6Yann Collet	@install -m 644 lz4frame.h $(DESTDIR)$(INCLUDEDIR)/lz4frame.h
111cd18ed3086a3eaf5d6531412959bd875b74dc6c1Yann Collet	@echo lz4 static and shared libraries installed
112d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
113d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletuninstall:
114d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT)
115d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_MAJOR)
116d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@rm -f $(DESTDIR)$(LIBDIR)/pkgconfig/liblz4.pc
117d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@[ -x $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER) ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.$(SHARED_EXT_VER)
118d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@[ -f $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
119d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4.h
120d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
1218f4e201a06109a4be4494aa5b024b3b4077e9d0dYann Collet	@[ -f $(DESTDIR)$(INCLUDEDIR)/lz4frame.h ] && rm -f $(DESTDIR)$(INCLUDEDIR)/lz4frame.h
122d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet	@echo lz4 libraries successfully uninstalled
123d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Collet
124d008c87151abf8c36a9f98d28461bf6f3dfdc6aeYann Colletendif
125