Skip to content

Commit 40ad5a0

Browse files
committed
feat: add lz4
1 parent d2d0b98 commit 40ad5a0

File tree

14 files changed

+11082
-0
lines changed

14 files changed

+11082
-0
lines changed

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ projects, including (but not limited to):
6363

6464
- lib/libfdt: (GPL-2.0-or-later OR BSD-2-Clause), used under BSD-2-Clause
6565
- lib/libufdt: Apache-2.0
66+
- lib/lz4: BSD-2-Clause
6667
- lib/openssl: OpenSSL
6768
- lib/zlib_inflate: Zlib
6869

lib/lz4/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
LZ4 Library
2+
Copyright (c) 2011-2020, Yann Collet
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without modification,
6+
are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright notice, this
9+
list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright notice, this
12+
list of conditions and the following disclaimer in the documentation and/or
13+
other materials provided with the distribution.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
19+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

lib/lz4/Makefile.lz4

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

0 commit comments

Comments
 (0)