]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Makefile
Import Zstd 1.4.4
[FreeBSD/FreeBSD.git] / lib / Makefile
1 # ################################################################
2 # Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
3 # All rights reserved.
4 #
5 # This source code is licensed under both the BSD-style license (found in the
6 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 # in the COPYING file in the root directory of this source tree).
8 # ################################################################
9
10 # Version numbers
11 LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
12 LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
13 LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
14 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
15 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
16 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
17 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
18 LIBVER := $(shell echo $(LIBVER_SCRIPT))
19 VERSION?= $(LIBVER)
20 CCVER := $(shell $(CC) --version)
21
22 CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
23 ifeq ($(OS),Windows_NT)   # MinGW assumed
24 CPPFLAGS   += -D__USE_MINGW_ANSI_STDIO   # compatibility with %zu formatting
25 endif
26 CFLAGS  ?= -O3
27 DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
28             -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
29             -Wstrict-prototypes -Wundef -Wpointer-arith \
30             -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
31             -Wredundant-decls -Wmissing-prototypes -Wc++-compat
32 CFLAGS  += $(DEBUGFLAGS) $(MOREFLAGS)
33 FLAGS    = $(CPPFLAGS) $(CFLAGS)
34
35 HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
36 GREP_OPTIONS ?=
37 ifeq ($HAVE_COLORNEVER, 1)
38 GREP_OPTIONS += --color=never
39 endif
40 GREP = grep $(GREP_OPTIONS)
41
42 ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
43 ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
44 ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
45 ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
46 ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
47 ZSTD_FILES := $(ZSTDCOMMON_FILES)
48
49 ifeq ($(findstring GCC,$(CCVER)),GCC)
50 decompress/zstd_decompress_block.o :    CFLAGS+=-fno-tree-vectorize
51 endif
52
53 ZSTD_LEGACY_SUPPORT ?= 5
54 ZSTD_LIB_COMPRESSION ?= 1
55 ZSTD_LIB_DECOMPRESSION ?= 1
56 ZSTD_LIB_DICTBUILDER ?= 1
57 ZSTD_LIB_DEPRECATED ?= 1
58 HUF_FORCE_DECOMPRESS_X1 ?= 0
59 HUF_FORCE_DECOMPRESS_X2 ?= 0
60 ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
61 ZSTD_FORCE_DECOMPRESS_LONG ?= 0
62 ZSTD_NO_INLINE ?= 0
63 ZSTD_STRIP_ERROR_STRINGS ?= 0
64 ZSTD_LEGACY_MULTITHREADED_API ?= 0
65
66 ifeq ($(ZSTD_LIB_COMPRESSION), 0)
67         ZSTD_LIB_DICTBUILDER = 0
68         ZSTD_LIB_DEPRECATED = 0
69 endif
70
71 ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
72         ZSTD_LEGACY_SUPPORT = 0
73         ZSTD_LIB_DEPRECATED = 0
74 endif
75
76 ifneq ($(ZSTD_LIB_COMPRESSION), 0)
77         ZSTD_FILES += $(ZSTDCOMP_FILES)
78 endif
79
80 ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
81         ZSTD_FILES += $(ZSTDDECOMP_FILES)
82 endif
83
84 ifneq ($(ZSTD_LIB_DEPRECATED), 0)
85         ZSTD_FILES += $(ZDEPR_FILES)
86 endif
87
88 ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
89         ZSTD_FILES += $(ZDICT_FILES)
90 endif
91
92 ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
93         CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
94 endif
95
96 ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
97         CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
98 endif
99
100 ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
101         CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
102 endif
103
104 ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
105         CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
106 endif
107
108 ifneq ($(ZSTD_NO_INLINE), 0)
109         CFLAGS += -DZSTD_NO_INLINE
110 endif
111
112 ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
113         CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
114 endif
115
116 ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
117         CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
118 endif
119
120 ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
121 ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
122         ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
123 endif
124         CPPFLAGS += -I./legacy
125 endif
126 CPPFLAGS  += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
127
128 ZSTD_OBJ   := $(patsubst %.c,%.o,$(ZSTD_FILES))
129
130 # macOS linker doesn't support -soname, and use different extension
131 # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
132 ifeq ($(shell uname), Darwin)
133         SHARED_EXT = dylib
134         SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
135         SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
136         SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
137 else
138         SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
139         SHARED_EXT = so
140         SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
141         SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
142 endif
143
144
145 .PHONY: default all clean install uninstall
146
147 default: lib-release
148
149 all: lib
150
151 libzstd.a: ARFLAGS = rcs
152 libzstd.a: $(ZSTD_OBJ)
153         @echo compiling static library
154         @$(AR) $(ARFLAGS) $@ $^
155
156 libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
157 libzstd.a-mt: libzstd.a
158
159 ifneq (,$(filter Windows%,$(OS)))
160
161 LIBZSTD = dll\libzstd.dll
162 $(LIBZSTD): $(ZSTD_FILES)
163         @echo compiling dynamic library $(LIBVER)
164         $(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.lib -shared $^ -o $@
165
166 else
167
168 LIBZSTD = libzstd.$(SHARED_EXT_VER)
169 $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
170 $(LIBZSTD): $(ZSTD_FILES)
171         @echo compiling dynamic library $(LIBVER)
172         @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
173         @echo creating versioned links
174         @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
175         @ln -sf $@ libzstd.$(SHARED_EXT)
176
177 endif
178
179
180 libzstd : $(LIBZSTD)
181
182 libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
183 libzstd-mt : libzstd
184
185 lib: libzstd.a libzstd
186
187 lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD
188 lib-mt: lib
189
190 lib-release lib-release-mt: DEBUGFLAGS :=
191 lib-release: lib
192 lib-release-mt: lib-mt
193
194 # Special case : building library in single-thread mode _and_ without zstdmt_compress.c
195 ZSTDMT_FILES = compress/zstdmt_compress.c
196 ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
197 libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
198 libzstd-nomt: $(ZSTD_NOMT_FILES)
199         @echo compiling single-thread dynamic library $(LIBVER)
200         @echo files : $(ZSTD_NOMT_FILES)
201         @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
202
203 clean:
204         @$(RM) -r *.dSYM   # macOS-specific
205         @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
206         @$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
207         @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
208         @echo Cleaning library completed
209
210 #-----------------------------------------------------------------------------
211 # make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
212 #-----------------------------------------------------------------------------
213 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
214
215 DESTDIR     ?=
216 # directory variables : GNU conventions prefer lowercase
217 # see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
218 # support both lower and uppercase (BSD), use uppercase in script
219 prefix      ?= /usr/local
220 PREFIX      ?= $(prefix)
221 exec_prefix ?= $(PREFIX)
222 libdir      ?= $(exec_prefix)/lib
223 LIBDIR      ?= $(libdir)
224 includedir  ?= $(PREFIX)/include
225 INCLUDEDIR  ?= $(includedir)
226
227 ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
228 PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
229 else
230 PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
231 endif
232
233 ifneq (,$(filter $(shell uname),SunOS))
234 INSTALL ?= ginstall
235 else
236 INSTALL ?= install
237 endif
238
239 INSTALL_PROGRAM ?= $(INSTALL)
240 INSTALL_DATA    ?= $(INSTALL) -m 644
241
242
243 libzstd.pc:
244 libzstd.pc: libzstd.pc.in
245         @echo creating pkgconfig
246         @sed -e 's|@PREFIX@|$(PREFIX)|' \
247              -e 's|@VERSION@|$(VERSION)|' \
248              $< >$@
249
250 install: install-pc install-static install-shared install-includes
251         @echo zstd static and shared library installed
252
253 install-pc: libzstd.pc
254         @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
255         @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
256
257 install-static: libzstd.a
258         @echo Installing static library
259         @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
260         @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
261
262 install-shared: libzstd
263         @echo Installing shared library
264         @$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
265         @$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
266         @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
267         @ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
268
269 install-includes:
270         @echo Installing includes
271         @$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
272         @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
273         @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
274         @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR)     # prototypes generate deprecation warnings
275         @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
276
277 uninstall:
278         @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
279         @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
280         @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
281         @$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
282         @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
283         @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
284         @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
285         @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h   # Deprecated streaming functions
286         @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
287         @echo zstd libraries successfully uninstalled
288
289 endif