Makefile : added capability to install libraries

Modified Directory tree, to better separate libraries from programs.


git-svn-id: https://lz4.googlecode.com/svn/trunk@111 650e7d94-2a16-8b24-b05c-7c0b3f6821cd
This commit is contained in:
yann.collet.73@gmail.com 2014-01-07 18:47:50 +00:00
parent fb38ddaacb
commit 648678788c
17 changed files with 401 additions and 375 deletions

24
LICENSE Normal file
View File

@ -0,0 +1,24 @@
LZ4 Library
Copyright (c) 2013, Yann Collet
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

144
Makefile
View File

@ -1,110 +1,110 @@
# ################################################################ # ################################################################
# LZ4 Makefile # LZ4 library - Makefile
# Copyright (C) Yann Collet 2011-2013 # Copyright (C) Yann Collet 2011-2014
# GPL v2 License # All rights reserved.
# #
# This program is free software; you can redistribute it and/or modify # BSD license
# it under the terms of the GNU General Public License as published by # Redistribution and use in source and binary forms, with or without modification,
# the Free Software Foundation; either version 2 of the License, or # are permitted provided that the following conditions are met:
# (at your option) any later version. #
# # * Redistributions of source code must retain the above copyright notice, this
# This program is distributed in the hope that it will be useful, # list of conditions and the following disclaimer.
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # * Redistributions in binary form must reproduce the above copyright notice, this
# GNU General Public License for more details. # list of conditions and the following disclaimer in the documentation and/or
# # other materials provided with the distribution.
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# You can contact the author at : # You can contact the author at :
# - LZ4 source repository : http://code.google.com/p/lz4/ # - LZ4 source repository : http://code.google.com/p/lz4/
# - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c # - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
# ################################################################ # ################################################################
# lz4 : Command Line Utility, supporting gzip-like arguments
# lz4c : CLU, supporting also legacy lz4demo arguments
# lz4c32: Same as lz4c, but forced to compile in 32-bits mode
# fuzzer : Test tool, to check lz4 integrity on target platform
# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
# fullbench : Precisely measure speed for each LZ4 function variant
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
# ################################################################
RELEASE=r110 RELEASE=r111
DESTDIR= DESTDIR=
PREFIX=${DESTDIR}/usr PREFIX=/usr
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/share/man/man1
DISTRIBNAME=lz4-$(RELEASE).tar.gz
CC=gcc CC=gcc
CFLAGS=-I. -std=c99 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\" CFLAGS+= -I. -std=c99 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
LIBDIR=$(PREFIX)/lib
INCLUDEDIR=$(PREFIX)/include
PRGDIR=programs
DISTRIBNAME=lz4-$(RELEASE).tar.gz
# Define *.exe as extension for Windows systems # Define *.exe as extension for Windows systems
# ifeq ($(OS),Windows_NT)
ifneq (,$(filter Windows%,$(OS))) ifneq (,$(filter Windows%,$(OS)))
EXT =.exe EXT =.exe
else else
EXT = EXT =
endif endif
TEXT = bench.c bench.h fullbench.c fuzzer.c lz4.1 lz4.c lz4cli.c \ TEXT = lz4.c lz4.h lz4hc.c lz4hc.h \
lz4_format_description.txt lz4.h lz4hc.c lz4hc.h \ lz4_format_description.txt Makefile NEWS LICENSE \
Makefile xxhash.c xxhash.h \ cmake_unofficial/CMakeLists.txt \
NEWS COPYING \ $(PRGDIR)/fullbench.c $(PRGDIR)/fuzzer.c $(PRGDIR)/lz4cli.c \
cmake/CMakeLists.txt cmake/pack/release_COPYING.txt \ $(PRGDIR)/bench.c $(PRGDIR)/bench.h \
cmake/pack/CMakeLists.txt $(PRGDIR)/xxhash.c $(PRGDIR)/xxhash.h \
$(PRGDIR)/lz4.1 $(PRGDIR)/Makefile $(PRGDIR)/COPYING
NONTEXT = LZ4_Streaming_Format.odt NONTEXT = LZ4_Streaming_Format.odt
SOURCES = $(TEXT) $(NONTEXT) SOURCES = $(TEXT) $(NONTEXT)
default: lz4 lz4c default: liblz4
all: lz4 lz4c lz4c32 fuzzer fuzzer32 fullbench fullbench32 all: liblz4 lz4programs
lz4: lz4.c lz4hc.c bench.c xxhash.c lz4cli.c liblz4: liblz4.a liblz4.so
$(CC) -O3 $(CFLAGS) -DDISABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
lz4c : lz4.c lz4hc.c bench.c xxhash.c lz4cli.c lz4programs: lz4.c lz4hc.c
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT) @cd $(PRGDIR); make all
lz4c32: lz4.c lz4hc.c bench.c xxhash.c lz4cli.c liblz4.a: lz4.c lz4hc.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT) $(CC) -O3 -c $(CFLAGS) $^
ar rcs liblz4.a lz4.o lz4hc.o
fuzzer : lz4.c lz4hc.c fuzzer.c liblz4.so: lz4.c lz4hc.c lz4.h
@echo fuzzer is a test tool to check lz4 integrity on target platform $(CC) -shared -fPIC -Wl,--soname=liblz4.so.1 $(CFLAGS) -o $@
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT)
fuzzer32: lz4.c lz4hc.c fuzzer.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
fullbench : lz4.c lz4hc.c xxhash.c fullbench.c
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT)
fullbench32: lz4.c lz4hc.c xxhash.c fullbench.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
clean: clean:
@rm -f core *.o lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) \ @rm -f core *.o *.a *.so $(DISTRIBNAME)
fuzzer$(EXT) fuzzer32$(EXT) fullbench$(EXT) fullbench32$(EXT) \ @cd $(PRGDIR); make clean
$(DISTRIBNAME)
@echo Cleaning completed @echo Cleaning completed
ifeq ($(shell uname),Linux) #ifeq ($(shell uname),Linux)
ifneq (,$(filter $(shell uname),Linux Darwin))
install: lz4 lz4c install: liblz4
@install -d -m 755 $(BINDIR)/ $(MANDIR)/ @install -d -m 755 $(DESTDIR)$(LIBDIR)/ $(DESTDIR)$(INCLUDEDIR)/
@install -m 755 lz4 $(BINDIR)/lz4 @install -m 755 liblz4.a $(DESTDIR)$(LIBDIR)/liblz4.a
@install -m 755 lz4c $(BINDIR)/lz4c @install -m 755 liblz4.so $(DESTDIR)$(LIBDIR)/liblz4.so
@install -m 644 lz4.1 $(MANDIR)/lz4.1 @install -m 755 lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
@install -m 755 lz4hc.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
@echo lz4 static and shared library installed
@cd $(PRGDIR); make install
uninstall: uninstall:
[ -x $(BINDIR)/lz4 ] && rm -f $(BINDIR)/lz4 [ -x $(DESTDIR)$(LIBDIR)/liblz4.a ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.a
[ -x $(BINDIR)/lz4c ] && rm -f $(BINDIR)/lz4c [ -x $(DESTDIR)$(LIBDIR)/liblz4.so ] && rm -f $(DESTDIR)$(LIBDIR)/liblz4.so
[ -f $(MANDIR)/lz4.1 ] && rm -f $(MANDIR)/lz4.1 [ -f $(DESTDIR)$(INCLUDEDIR)/lz4.h ] && rm -f lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4.h
[ -f $(DESTDIR)$(INCLUDEDIR)/lz4hc.h ] && rm -f lz4.h $(DESTDIR)$(INCLUDEDIR)/lz4hc.h
@echo lz4 libraries successfully uninstalled
@cd $(PRGDIR); make uninstall
dist: clean dist: clean
@install -dD -m 700 lz4-$(RELEASE)/cmake/pack/ @install -dD -m 700 lz4-$(RELEASE)/programs/
@install -dD -m 700 lz4-$(RELEASE)/cmake_unofficial/
@for f in $(TEXT); do \ @for f in $(TEXT); do \
tr -d '\r' < $$f > .tmp; \ tr -d '\r' < $$f > .tmp; \
install -m 600 .tmp lz4-$(RELEASE)/$$f; \ install -m 600 .tmp lz4-$(RELEASE)/$$f; \

4
NEWS
View File

@ -1,3 +1,7 @@
r111 :
Makefile : added capability to install libraries
Modified Directory tree, to better separate libraries from programs.
r110 : r110 :
lz4 & lz4hc : added capability to allocate state & stream state with custom allocator (issue 99) lz4 & lz4hc : added capability to allocate state & stream state with custom allocator (issue 99)
fuzzer & fullbench : updated to test new functions fuzzer & fullbench : updated to test new functions

View File

@ -1,82 +0,0 @@
cmake_minimum_required (VERSION 2.8)
PROJECT(LZ4)
############################## CPACK
set(SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 Packer")
set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH r107)
#set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL)
##############################
FIND_PACKAGE(Subversion)
IF(SUBVERSION_FOUND)
Subversion_WC_INFO(${SRC_DIR} revision)
set(revision_MY_WC_STATUS "LZ4 has revision ${revision_WC_REVISION} at ${revision_WC_LAST_CHANGED_DATE}")
message(STATUS ${revision_MY_WC_STATUS})
if(NOT ${revision_WC_REVISION})
else(NOT ${revision_WC_REVISION})
set(CPACK_PACKAGE_VERSION_PATCH "r${revision_WC_REVISION}")
endif(NOT ${revision_WC_REVISION})
ELSE(SUBVERSION_FOUND)
message(WARNING "NO Subversion FOUND!!!")
ENDIF(SUBVERSION_FOUND)
set(VERSION_STRING " \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ")
##############################
INCLUDE (CheckTypeSize)
check_type_size("void *" SIZEOF_VOID_P)
IF( ${SIZEOF_VOID_P} STREQUAL "8" )
set (CMAKE_SYSTEM_PROCESSOR "64bit")
MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P})
ENDIF()
############################### warnings
ADD_DEFINITIONS("-Wall")
ADD_DEFINITIONS("-W")
ADD_DEFINITIONS("-Wundef")
ADD_DEFINITIONS("-Wcast-align")
ADD_DEFINITIONS("-Wno-implicit-function-declaration")
ADD_DEFINITIONS("-O3 -march=native -std=c99")
INCLUDE_DIRECTORIES (${SRC_DIR})
set(LZ4_SRCS_LIB ${SRC_DIR}lz4.c ${SRC_DIR}lz4hc.c ${SRC_DIR}lz4.h ${SRC_DIR}lz4_format_description.txt)
set(LZ4_SRCS ${LZ4_SRCS_LIB} ${SRC_DIR}xxhash.c ${SRC_DIR}bench.c ${SRC_DIR}lz4cli.c )
set(FUZZER_SRCS ${SRC_DIR}lz4.c ${SRC_DIR}lz4hc.c ${SRC_DIR}lz4.h ${SRC_DIR}fuzzer.c)
# EXECUTABLES FOR 32 Bit and 64 versions
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "64bit")
add_executable(lz4c32 ${LZ4_SRCS})
install(TARGETS lz4c32 RUNTIME DESTINATION "bin/")
SET_TARGET_PROPERTIES(lz4c32 PROPERTIES
COMPILE_FLAGS PROPERTIES COMPILE_FLAGS "-m32 -Os" LINK_FLAGS "-m32")
endif()
add_executable(lz4c ${LZ4_SRCS})
install(TARGETS lz4c RUNTIME DESTINATION "bin/")
add_executable(fuzzer ${FUZZER_SRCS})
install(TARGETS fuzzer RUNTIME DESTINATION "bin/")
#target_link_libraries(lz4 ${LZ4_SRCS_LIB})
####################### CPACK PACKAGING ###################
install(FILES ${SRC_DIR}lz4_format_description.txt DESTINATION "./")
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/release_COPYING.txt")
set(CPACK_PACKAGE_VENDOR "Yann Collet")
set(CPACK_WWW_SITE "http://fastcompression.blogspot.com/p/lz4.html")
set(CPACK_NSIS_URL_INFO_ABOUT "${CPACK_WWW_SITE}")
set(CPACK_NSIS_HELP_LINK "${CPACK_WWW_SITE}")
set(CPACK_NSIS_DISPLAY_NAME ${CPACK_PACKAGE_NAME})
set(CPACK_NSIS_COMPRESSOR "/SOLID lzma \r\n SetCompressorDictSize 32")
set(CPACK_NSIS_MENU_LINKS
"${CPACK_WWW_SITE}" "${CPACK_PACKAGE_NAME} homepage"
"/lz4_format_description.txt " "lz4 format description"
"/" "LZ4 directory "
)
include (CPack)

View File

@ -1,21 +0,0 @@
lz4demo and fuzzer is an open-source demo compression algorithm LZ4 programs
Copyright (C) Yann Collet 2012
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
You can contact the author at :
- LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
- LZ4 source repository : http://code.google.com/p/lz4/

View File

@ -1,80 +1,81 @@
PROJECT(LZ4 C) PROJECT(LZ4 C)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 compression library") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "LZ4 compression library")
set(CPACK_PACKAGE_VERSION_MAJOR 0) set(CPACK_PACKAGE_VERSION_MAJOR 0)
set(CPACK_PACKAGE_VERSION_MINOR 0) set(CPACK_PACKAGE_VERSION_MINOR 0)
set(CPACK_PACKAGE_VERSION_PATCH r110) set(CPACK_PACKAGE_VERSION_PATCH r111)
#set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL) #set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_BINARY_DIR}/COPYING_LGPL)
set(VERSION_STRING " \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ") set(VERSION_STRING " \"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}\" ")
include(CPack) include(CPack)
cmake_minimum_required (VERSION 2.6) cmake_minimum_required (VERSION 2.6)
INCLUDE (CheckTypeSize) INCLUDE (CheckTypeSize)
check_type_size("void *" SIZEOF_VOID_P) check_type_size("void *" SIZEOF_VOID_P)
IF( ${SIZEOF_VOID_P} STREQUAL "8" ) IF( ${SIZEOF_VOID_P} STREQUAL "8" )
set (CMAKE_SYSTEM_PROCESSOR "64bit") set (CMAKE_SYSTEM_PROCESSOR "64bit")
MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P}) MESSAGE( STATUS "64 bit architecture detected size of void * is " ${SIZEOF_VOID_P})
ENDIF() ENDIF()
option(BUILD_TOOLS "Build the command line tools" ON) option(BUILD_TOOLS "Build the command line tools" ON)
option(BUILD_LIBS "Build the libraries in addition to the tools" OFF) option(BUILD_LIBS "Build the libraries in addition to the tools" OFF)
if(UNIX AND BUILD_LIBS) if(UNIX AND BUILD_LIBS)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
add_definitions(-fPIC) add_definitions(-fPIC)
endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") endif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
endif() endif()
set(SRC_DIR ../) set(LZ4_DIR ../)
set(LZ4_SRCS_LIB ${SRC_DIR}lz4.c ${SRC_DIR}lz4hc.c ${SRC_DIR}lz4.h ) set(PRG_DIR ../programs/)
set(LZ4_SRCS ${SRC_DIR}xxhash.c ${SRC_DIR}bench.c ${SRC_DIR}lz4cli.c) set(LZ4_SRCS_LIB ${LZ4_DIR}lz4.c ${LZ4_DIR}lz4hc.c ${LZ4_DIR}lz4.h ${LZ4_DIR}lz4hc.h)
set(LZ4_SRCS ${PRG_DIR}xxhash.c ${PRG_DIR}bench.c ${PRG_DIR}lz4cli.c)
if(BUILD_TOOLS AND NOT BUILD_LIBS)
set(LZ4_SRCS ${LZ4_SRCS} ${LZ4_SRCS_LIB}) if(BUILD_TOOLS AND NOT BUILD_LIBS)
endif() set(LZ4_SRCS ${LZ4_SRCS} ${LZ4_SRCS_LIB})
endif()
if(BUILD_TOOLS)
add_executable(lz4 ${LZ4_SRCS}) if(BUILD_TOOLS)
set_target_properties(lz4 PROPERTIES COMPILE_DEFINITIONS DISABLE_LZ4C_LEGACY_OPTIONS) add_executable(lz4 ${LZ4_SRCS})
install(TARGETS lz4 RUNTIME DESTINATION "bin/") set_target_properties(lz4 PROPERTIES COMPILE_DEFINITIONS DISABLE_LZ4C_LEGACY_OPTIONS)
add_executable(lz4c ${LZ4_SRCS}) install(TARGETS lz4 RUNTIME DESTINATION "bin/")
install(TARGETS lz4c RUNTIME DESTINATION "bin/") add_executable(lz4c ${LZ4_SRCS})
endif() install(TARGETS lz4c RUNTIME DESTINATION "bin/")
endif()
if(BUILD_LIBS)
add_library(liblz4 ${LZ4_SRCS_LIB}) if(BUILD_LIBS)
add_library(liblz4 ${LZ4_SRCS_LIB})
set_target_properties(liblz4 PROPERTIES
OUTPUT_NAME lz4 set_target_properties(liblz4 PROPERTIES
SOVERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}" OUTPUT_NAME lz4
) SOVERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
)
install(TARGETS liblz4
LIBRARY DESTINATION lib install(TARGETS liblz4
ARCHIVE DESTINATION lib LIBRARY DESTINATION lib
) ARCHIVE DESTINATION lib
)
install(FILES
${SRC_DIR}/lz4.h install(FILES
${SRC_DIR}/lz4hc.h ${LZ4_DIR}/lz4.h
DESTINATION include ${LZ4_DIR}/lz4hc.h
) DESTINATION include
)
if(BUILD_TOOLS)
target_link_libraries(lz4 liblz4) if(BUILD_TOOLS)
target_link_libraries(lz4c liblz4) target_link_libraries(lz4 liblz4)
endif() target_link_libraries(lz4c liblz4)
endif() endif()
endif()
#warnings
#warnings
ADD_DEFINITIONS("-Wall")
ADD_DEFINITIONS("-W") ADD_DEFINITIONS("-Wall")
ADD_DEFINITIONS("-Wundef") ADD_DEFINITIONS("-W")
ADD_DEFINITIONS("-Wcast-align") ADD_DEFINITIONS("-Wundef")
ADD_DEFINITIONS("-std=c99") ADD_DEFINITIONS("-Wcast-align")
ADD_DEFINITIONS("-DLZ4_VERSION=\"${CPACK_PACKAGE_VERSION_PATCH}\"") ADD_DEFINITIONS("-std=c99")
INCLUDE_DIRECTORIES (${SRC_DIR}) ADD_DEFINITIONS("-DLZ4_VERSION=\"${CPACK_PACKAGE_VERSION_PATCH}\"")
INCLUDE_DIRECTORIES (${LZ4_DIR})

View File

@ -1,120 +1,120 @@
LZ4 Format Description LZ4 Format Description
Last revised: 2012-02-27 Last revised: 2012-02-27
Author : Y. Collet Author : Y. Collet
This small specification intents to provide enough information This small specification intents to provide enough information
to anyone willing to produce LZ4-compatible compressed data blocks to anyone willing to produce LZ4-compatible compressed data blocks
using any programming language. using any programming language.
LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding. LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.
The most important design principle behind LZ4 is simplicity. The most important design principle behind LZ4 is simplicity.
It helps to create an easy to read and maintain source code. It helps to create an easy to read and maintain source code.
It also helps later on for optimisations, compactness, and speed. It also helps later on for optimisations, compactness, and speed.
There is no entropy encoder backend nor framing layer. There is no entropy encoder backend nor framing layer.
The latter is assumed to be handled by other parts of the system. The latter is assumed to be handled by other parts of the system.
This document only describes the format, This document only describes the format,
not how the LZ4 compressor nor decompressor actually work. not how the LZ4 compressor nor decompressor actually work.
The correctness of the decompressor should not depend The correctness of the decompressor should not depend
on implementation details of the compressor, and vice versa. on implementation details of the compressor, and vice versa.
-- Compressed block format -- -- Compressed block format --
An LZ4 compressed block is composed of sequences. An LZ4 compressed block is composed of sequences.
Schematically, a sequence is a suite of literals, followed by a match copy. Schematically, a sequence is a suite of literals, followed by a match copy.
Each sequence starts with a token. Each sequence starts with a token.
The token is a one byte value, separated into two 4-bits fields. The token is a one byte value, separated into two 4-bits fields.
Therefore each field ranges from 0 to 15. Therefore each field ranges from 0 to 15.
The first field uses the 4 high-bits of the token. The first field uses the 4 high-bits of the token.
It provides the length of literals to follow. It provides the length of literals to follow.
(Note : a literal is a not-compressed byte). (Note : a literal is a not-compressed byte).
If the field value is 0, then there is no literal. If the field value is 0, then there is no literal.
If it is 15, then we need to add some more bytes to indicate the full length. If it is 15, then we need to add some more bytes to indicate the full length.
Each additionnal byte then represent a value from 0 to 255, Each additionnal byte then represent a value from 0 to 255,
which is added to the previous value to produce a total length. which is added to the previous value to produce a total length.
When the byte value is 255, another byte is output. When the byte value is 255, another byte is output.
There can be any number of bytes following the token. There is no "size limit". There can be any number of bytes following the token. There is no "size limit".
(Sidenote this is why a not-compressible input block is expanded by 0.4%). (Sidenote this is why a not-compressible input block is expanded by 0.4%).
Example 1 : A length of 48 will be represented as : Example 1 : A length of 48 will be represented as :
- 15 : value for the 4-bits High field - 15 : value for the 4-bits High field
- 33 : (=48-15) remaining length to reach 48 - 33 : (=48-15) remaining length to reach 48
Example 2 : A length of 280 will be represented as : Example 2 : A length of 280 will be represented as :
- 15 : value for the 4-bits High field - 15 : value for the 4-bits High field
- 255 : following byte is maxed, since 280-15 >= 255 - 255 : following byte is maxed, since 280-15 >= 255
- 10 : (=280 - 15 - 255) ) remaining length to reach 280 - 10 : (=280 - 15 - 255) ) remaining length to reach 280
Example 3 : A length of 15 will be represented as : Example 3 : A length of 15 will be represented as :
- 15 : value for the 4-bits High field - 15 : value for the 4-bits High field
- 0 : (=15-15) yes, the zero must be output - 0 : (=15-15) yes, the zero must be output
Following the token and optional length bytes, are the literals themselves. Following the token and optional length bytes, are the literals themselves.
They are exactly as numerous as previously decoded (length of literals). They are exactly as numerous as previously decoded (length of literals).
It's possible that there are zero literal. It's possible that there are zero literal.
Following the literals is the match copy operation. Following the literals is the match copy operation.
It starts by the offset. It starts by the offset.
This is a 2 bytes value, in little endian format. This is a 2 bytes value, in little endian format.
The offset represents the position of the match to be copied from. The offset represents the position of the match to be copied from.
1 means "current position - 1 byte". 1 means "current position - 1 byte".
The maximum offset value is 65535, 65536 cannot be coded. The maximum offset value is 65535, 65536 cannot be coded.
Note that 0 is an invalid value, not used. Note that 0 is an invalid value, not used.
Then we need to extract the match length. Then we need to extract the match length.
For this, we use the second token field, the low 4-bits. For this, we use the second token field, the low 4-bits.
Value, obviously, ranges from 0 to 15. Value, obviously, ranges from 0 to 15.
However here, 0 means that the copy operation will be minimal. However here, 0 means that the copy operation will be minimal.
The minimum length of a match, called minmatch, is 4. The minimum length of a match, called minmatch, is 4.
As a consequence, a 0 value means 4 bytes, and a value of 15 means 19+ bytes. As a consequence, a 0 value means 4 bytes, and a value of 15 means 19+ bytes.
Similar to literal length, on reaching the highest possible value (15), Similar to literal length, on reaching the highest possible value (15),
we output additional bytes, one at a time, with values ranging from 0 to 255. we output additional bytes, one at a time, with values ranging from 0 to 255.
They are added to total to provide the final match length. They are added to total to provide the final match length.
A 255 value means there is another byte to read and add. A 255 value means there is another byte to read and add.
There is no limit to the number of optional bytes that can be output this way. There is no limit to the number of optional bytes that can be output this way.
(This points towards a maximum achievable compression ratio of ~250). (This points towards a maximum achievable compression ratio of ~250).
With the offset and the matchlength, With the offset and the matchlength,
the decoder can now proceed to copy the data from the already decoded buffer. the decoder can now proceed to copy the data from the already decoded buffer.
On decoding the matchlength, we reach the end of the compressed sequence, On decoding the matchlength, we reach the end of the compressed sequence,
and therefore start another one. and therefore start another one.
-- Parsing restrictions -- -- Parsing restrictions --
There are specific parsing rules to respect in order to remain compatible There are specific parsing rules to respect in order to remain compatible
with assumptions made by the decoder : with assumptions made by the decoder :
1) The last 5 bytes are always literals 1) The last 5 bytes are always literals
2) The last match must start at least 12 bytes before end of block 2) The last match must start at least 12 bytes before end of block
Consequently, a block with less than 13 bytes cannot be compressed. Consequently, a block with less than 13 bytes cannot be compressed.
These rules are in place to ensure that the decoder These rules are in place to ensure that the decoder
will never read beyond the input buffer, nor write beyond the output buffer. will never read beyond the input buffer, nor write beyond the output buffer.
Note that the last sequence is also incomplete, Note that the last sequence is also incomplete,
and stops right after literals. and stops right after literals.
-- Additional notes -- -- Additional notes --
There is no assumption nor limits to the way the compressor There is no assumption nor limits to the way the compressor
searches and selects matches within the source data block. searches and selects matches within the source data block.
It could be a fast scan, a multi-probe, a full search using BST, It could be a fast scan, a multi-probe, a full search using BST,
standard hash chains or MMC, well whatever. standard hash chains or MMC, well whatever.
Advanced parsing strategies can also be implemented, such as lazy match, Advanced parsing strategies can also be implemented, such as lazy match,
or full optimal parsing. or full optimal parsing.
All these trade-off offer distinctive speed/memory/compression advantages. All these trade-off offer distinctive speed/memory/compression advantages.
Whatever the method used by the compressor, its result will be decodable Whatever the method used by the compressor, its result will be decodable
by any LZ4 decoder if it follows the format specification described above. by any LZ4 decoder if it follows the format specification described above.

100
programs/Makefile Normal file
View File

@ -0,0 +1,100 @@
# ################################################################
# LZ4 programs - Makefile
# Copyright (C) Yann Collet 2011-2014
# GPL v2 License
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# You can contact the author at :
# - LZ4 source repository : http://code.google.com/p/lz4/
# - LZ4 forum froup : https://groups.google.com/forum/#!forum/lz4c
# ################################################################
# lz4 : Command Line Utility, supporting gzip-like arguments
# lz4c : CLU, supporting also legacy lz4demo arguments
# lz4c32: Same as lz4c, but forced to compile in 32-bits mode
# fuzzer : Test tool, to check lz4 integrity on target platform
# fuzzer32: Same as fuzzer, but forced to compile in 32-bits mode
# fullbench : Precisely measure speed for each LZ4 function variant
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode
# ################################################################
RELEASE=r111
DESTDIR=
PREFIX=/usr
CC=gcc
CFLAGS+= -I. -std=c99 -Wall -W -Wundef -DLZ4_VERSION=\"$(RELEASE)\"
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/share/man/man1
LZ4DIR=..
# Define *.exe as extension for Windows systems
ifneq (,$(filter Windows%,$(OS)))
EXT =.exe
else
EXT =
endif
default: lz4 lz4c
all: lz4 lz4c lz4c32 fuzzer fuzzer32 fullbench fullbench32
lz4: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4cli.c
$(CC) -O3 $(CFLAGS) -DDISABLE_LZ4C_LEGACY_OPTIONS $^ -o $@$(EXT)
lz4c : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4cli.c
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT)
lz4c32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c bench.c xxhash.c lz4cli.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
fuzzer : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c fuzzer.c
@echo fuzzer is a test tool to check lz4 integrity on target platform
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT)
fuzzer32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c fuzzer.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
fullbench : $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c xxhash.c fullbench.c
$(CC) -O3 $(CFLAGS) $^ -o $@$(EXT)
fullbench32: $(LZ4DIR)/lz4.c $(LZ4DIR)/lz4hc.c xxhash.c fullbench.c
$(CC) -m32 -O3 $(CFLAGS) $^ -o $@$(EXT)
clean:
@rm -f core *.o \
lz4$(EXT) lz4c$(EXT) lz4c32$(EXT) \
fuzzer$(EXT) fuzzer32$(EXT) fullbench$(EXT) fullbench32$(EXT)
@echo Cleaning completed
ifneq (,$(filter $(shell uname),Linux Darwin))
install: lz4 lz4c
@install -d -m 755 $(DESTDIR)$(BINDIR)/ $(DESTDIR)$(MANDIR)/
@install -m 755 lz4 $(DESTDIR)$(BINDIR)/lz4
@install -m 755 lz4c $(DESTDIR)$(BINDIR)/lz4c
@install -m 644 lz4.1 $(DESTDIR)$(MANDIR)/lz4.1
@echo lz4 installation completed
uninstall:
[ -x $(DESTDIR)$(BINDIR)/lz4 ] && rm -f $(DESTDIR)$(BINDIR)/lz4
[ -x $(DESTDIR)$(BINDIR)/lz4c ] && rm -f $(DESTDIR)$(BINDIR)/lz4c
[ -f $(DESTDIR)$(MANDIR)/lz4.1 ] && rm -f $(DESTDIR)$(MANDIR)/lz4.1
@echo lz4 successfully uninstalled
endif