1 # ##########################################################################
2 # Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
5 # This Makefile is validated for Linux, macOS, *BSD, Hurd, Solaris, MSYS2 targets
7 # This source code is licensed under the BSD-style license found in the
8 # LICENSE file in the root directory of this source tree. An additional grant
9 # of patent rights can be found in the PATENTS file in the same directory.
10 # ##########################################################################
13 LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
14 LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
15 LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
16 LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
17 LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
18 LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
19 LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
20 LIBVER := $(shell echo $(LIBVER_SCRIPT))
23 CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
25 DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
26 -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
27 -Wstrict-prototypes -Wundef -Wpointer-arith -Wformat-security \
28 -Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
30 CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
31 FLAGS = $(CPPFLAGS) $(CFLAGS)
34 ZSTD_FILES := $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)
36 ZSTD_LEGACY_SUPPORT ?= 4
38 ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
39 ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
40 ZSTD_FILES += $(shell ls legacy/*.c | grep 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
42 CPPFLAGS += -I./legacy
44 CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
46 ZSTD_OBJ := $(patsubst %.c,%.o,$(ZSTD_FILES))
48 # OS X linker doesn't support -soname, and use different extension
49 # see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
50 ifeq ($(shell uname), Darwin)
52 SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
53 SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
54 SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
56 SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
58 SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
59 SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
62 LIBZSTD = libzstd.$(SHARED_EXT_VER)
65 .PHONY: default all clean install uninstall
71 libzstd.a: ARFLAGS = rcs
72 libzstd.a: $(ZSTD_OBJ)
73 @echo compiling static library
74 @$(AR) $(ARFLAGS) $@ $^
76 libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
77 libzstd.a-mt: libzstd.a
79 $(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
80 $(LIBZSTD): $(ZSTD_FILES)
81 @echo compiling dynamic library $(LIBVER)
82 ifneq (,$(filter Windows%,$(OS)))
83 @$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -shared $^ -o dll\libzstd.dll
84 dlltool -D dll\libzstd.dll -d dll\libzstd.def -l dll\libzstd.lib
86 @$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
87 @echo creating versioned links
88 @ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
89 @ln -sf $@ libzstd.$(SHARED_EXT)
94 libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
97 lib: libzstd.a libzstd
99 lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD
102 lib-release lib-release-mt: DEBUGFLAGS :=
104 lib-release-mt: lib-mt
107 @$(RM) -r *.dSYM # Mac OS-X specific
108 @$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
109 @$(RM) dll/libzstd.dll dll/libzstd.lib
110 @$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
111 @echo Cleaning library completed
113 #-----------------------------------------------------------------------------
114 # make install is validated only for Linux, OSX, BSD, Hurd and Solaris targets
115 #-----------------------------------------------------------------------------
116 ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS))
118 ifneq (,$(filter $(shell uname),SunOS))
126 LIBDIR ?= $(PREFIX)/lib
127 INCLUDEDIR ?= $(PREFIX)/include
129 ifneq (,$(filter $(shell uname),OpenBSD FreeBSD NetBSD DragonFly))
130 PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
132 PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
135 INSTALL_LIB ?= $(INSTALL) -m 755
136 INSTALL_DATA ?= $(INSTALL) -m 644
140 libzstd.pc: libzstd.pc.in
141 @echo creating pkgconfig
142 @sed -e 's|@PREFIX@|$(PREFIX)|' \
143 -e 's|@LIBDIR@|$(LIBDIR)|' \
144 -e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
145 -e 's|@VERSION@|$(VERSION)|' \
148 install: libzstd.a libzstd libzstd.pc
149 @$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/ $(DESTDIR)$(INCLUDEDIR)/
150 @$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
151 @echo Installing libraries
152 @$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
153 @$(INSTALL_LIB) libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)
154 @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
155 @ln -sf libzstd.$(SHARED_EXT_VER) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
156 @echo Installing includes
157 @$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
158 @$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
159 @$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
160 @$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
161 @echo zstd static and shared library installed
164 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
165 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
166 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
167 @$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_VER)
168 @$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
169 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
170 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
171 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
172 @$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
173 @echo zstd libraries successfully uninstalled