The legacy decoders (lib/legacy/zstd_v01.c .. zstd_v07.c) are next in the Rust migration. Each of those files is a frozen snapshot of the FSE/Huff0 entropy coders and frame logic of one historical release, so their ports must not reuse the modern Rust entropy modules and must not share code with each other: outputs and error codes have to stay byte-identical to the frozen C forever. This commit installs the build-system scaffolding so seven per-version ports can land independently, each adding only its own module file plus a one-line registration in rust/src/legacy/mod.rs. Cargo grows features legacy-v01 .. legacy-v07. They are never default features: the C build defaults differ per build system, so each build system passes the list explicitly, derived from its own legacy configuration: - lib/Makefile and programs/Makefile map ZSTD_LEGACY_SUPPORT=N to the features for versions N..7 (0 disables legacy), mirroring the ZSTD_LEGACY_FILES selection in lib/libzstd.mk. - tests/Makefile always enables all seven features because its ZSTDLEGACY_FILES wildcard compiles every lib/legacy/*.c regardless of the dispatch level. - build/meson maps legacy_level exactly like the makefiles; build/cmake enables all seven whenever ZSTD_LEGACY_SUPPORT is ON because it always compiles all seven C files (ZSTD_LEGACY_LEVEL only selects the C dispatch). Every build system also encodes the legacy selection in the Rust target directory name (e.g. c1-d1-default-legacy5), for the same reason the HUF mode is encoded there: a cached archive built for one configuration must never be linked into a build expecting another. In tests/Makefile the legacy level additionally flows into the existing HUF C-mode stamp, so the flat C test objects (which bake -DZSTD_LEGACY_SUPPORT into the dispatch) are rebuilt whenever the level changes. In programs/Makefile the compress-only, decompress-only, and CLI archives keep level-independent directories (RUST_HUF_MODE) because they are only linked into ZSTD_LEGACY_SUPPORT=0 program variants and carry no legacy features. A feature whose version has not been ported yet gates nothing: the module registration in rust/src/legacy/mod.rs is added by each port, so enabling e.g. legacy-v05 today simply leaves that decoder in C. This is what makes mixed C/Rust legacy levels link cleanly while the seven ports land in any order. Test plan: - cd rust && cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test --all-targets - cargo clippy with --no-default-features --features decompression,legacy-v01 and with all seven legacy features - make -C tests fuzzer && ./tests/fuzzer -i1 --no-big-tests - make -C tests test-rust-lib-smoke; make -C tests test-legacy - make -C lib libzstd.a with ZSTD_LEGACY_SUPPORT=0, 1 and default (5) - cmake configure and meson setup (including -Dlegacy_level=1) emit the expected --features lists and legacy-suffixed target directories
493 lines
16 KiB
Makefile
493 lines
16 KiB
Makefile
# ################################################################
|
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under both the BSD-style license (found in the
|
|
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
# in the COPYING file in the root directory of this source tree).
|
|
# You may select, at your option, one of the above-listed licenses.
|
|
# ################################################################
|
|
|
|
# default target (when running `make` with no argument)
|
|
lib-release:
|
|
|
|
# Modules
|
|
ZSTD_LIB_COMPRESSION ?= 1
|
|
ZSTD_LIB_DECOMPRESSION ?= 1
|
|
ZSTD_LIB_DICTBUILDER ?= 1
|
|
ZSTD_LIB_DEPRECATED ?= 0
|
|
|
|
# Input variables for libzstd.mk
|
|
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
|
|
ZSTD_LIB_DICTBUILDER = 0
|
|
ZSTD_LIB_DEPRECATED = 0
|
|
endif
|
|
|
|
ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
|
|
ZSTD_LEGACY_SUPPORT = 0
|
|
ZSTD_LIB_DEPRECATED = 0
|
|
endif
|
|
|
|
include libzstd.mk
|
|
|
|
ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
|
|
|
|
ifneq ($(ZSTD_LIB_COMPRESSION), 0)
|
|
ZSTD_FILES += $(ZSTD_COMPRESS_FILES)
|
|
endif
|
|
|
|
ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
|
|
ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES)
|
|
endif
|
|
|
|
ifneq ($(ZSTD_LIB_DEPRECATED), 0)
|
|
ZSTD_FILES += $(ZSTD_DEPRECATED_FILES)
|
|
endif
|
|
|
|
ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
|
|
ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES)
|
|
endif
|
|
|
|
# The migrated implementation is built as a Rust static archive. The archive
|
|
# is feature-specific so a build forced to use a particular HUF decoder never
|
|
# reuses the default decoder implementation. RUST_TARGET can be set for a
|
|
# cross build; -m32 selects the supported 32-bit Linux target automatically.
|
|
CARGO ?= cargo
|
|
RUST_DIR ?= ../rust
|
|
RUST_MANIFEST := $(RUST_DIR)/Cargo.toml
|
|
RUST_SOURCES := $(RUST_MANIFEST) $(RUST_DIR)/Cargo.lock \
|
|
$(shell find $(RUST_DIR)/src -type f -name '*.rs' -print)
|
|
|
|
RUST_HUF_FORCE_X1 := $(HUF_FORCE_DECOMPRESS_X1)
|
|
RUST_HUF_FORCE_X2 := $(HUF_FORCE_DECOMPRESS_X2)
|
|
ifneq ($(filter -DHUF_FORCE_DECOMPRESS_X1 -DHUF_FORCE_DECOMPRESS_X1=%,$(CPPFLAGS) $(CFLAGS) $(MOREFLAGS)),)
|
|
RUST_HUF_FORCE_X1 := 1
|
|
endif
|
|
ifneq ($(filter -DHUF_FORCE_DECOMPRESS_X2 -DHUF_FORCE_DECOMPRESS_X2=%,$(CPPFLAGS) $(CFLAGS) $(MOREFLAGS)),)
|
|
RUST_HUF_FORCE_X2 := 1
|
|
endif
|
|
|
|
ifneq ($(RUST_HUF_FORCE_X1),0)
|
|
ifneq ($(RUST_HUF_FORCE_X2),0)
|
|
$(error HUF_FORCE_DECOMPRESS_X1 and HUF_FORCE_DECOMPRESS_X2 are mutually exclusive)
|
|
endif
|
|
endif
|
|
|
|
empty :=
|
|
space := $(empty) $(empty)
|
|
comma := ,
|
|
|
|
RUST_CARGO_FEATURES :=
|
|
ifneq ($(ZSTD_LIB_COMPRESSION),0)
|
|
RUST_CARGO_FEATURES += compression
|
|
endif
|
|
ifneq ($(ZSTD_LIB_DECOMPRESSION),0)
|
|
RUST_CARGO_FEATURES += decompression
|
|
endif
|
|
|
|
RUST_HUF_FEATURE :=
|
|
RUST_BUILD_CONFIG := c$(ZSTD_LIB_COMPRESSION)-d$(ZSTD_LIB_DECOMPRESSION)-default
|
|
ifneq ($(RUST_HUF_FORCE_X1),0)
|
|
RUST_HUF_FEATURE := huf-force-decompress-x1
|
|
RUST_BUILD_CONFIG := c$(ZSTD_LIB_COMPRESSION)-d$(ZSTD_LIB_DECOMPRESSION)-huf-force-decompress-x1
|
|
endif
|
|
ifneq ($(RUST_HUF_FORCE_X2),0)
|
|
RUST_HUF_FEATURE := huf-force-decompress-x2
|
|
RUST_BUILD_CONFIG := c$(ZSTD_LIB_COMPRESSION)-d$(ZSTD_LIB_DECOMPRESSION)-huf-force-decompress-x2
|
|
endif
|
|
ifneq ($(RUST_HUF_FEATURE),)
|
|
ifneq ($(ZSTD_LIB_DECOMPRESSION),0)
|
|
RUST_CARGO_FEATURES += $(RUST_HUF_FEATURE)
|
|
endif
|
|
endif
|
|
|
|
# Legacy decoders follow the ZSTD_LEGACY_FILES selection exactly: level N
|
|
# enables versions v0.N .. v0.7 (0 disables legacy). The build directory
|
|
# also encodes the level, so archives for different legacy levels never mix.
|
|
RUST_LEGACY_FEATURES :=
|
|
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
|
|
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
|
|
RUST_LEGACY_FEATURES := $(addprefix legacy-v0,$(wordlist $(ZSTD_LEGACY_SUPPORT),7,1 2 3 4 5 6 7))
|
|
endif
|
|
endif
|
|
RUST_CARGO_FEATURES += $(RUST_LEGACY_FEATURES)
|
|
RUST_BUILD_CONFIG := $(RUST_BUILD_CONFIG)-legacy$(ZSTD_LEGACY_SUPPORT)
|
|
RUST_CARGO_FEATURES := $(subst $(space),$(comma),$(strip $(RUST_CARGO_FEATURES)))
|
|
|
|
RUST_TARGET ?=
|
|
ifeq ($(strip $(RUST_TARGET)),)
|
|
ifneq ($(filter -m32,$(CC) $(CPPFLAGS) $(CFLAGS) $(MOREFLAGS)),)
|
|
RUST_TARGET := i686-unknown-linux-gnu
|
|
endif
|
|
endif
|
|
|
|
RUST_TARGET_DIR := $(RUST_DIR)/target/$(RUST_BUILD_CONFIG)
|
|
RUST_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
|
|
--target-dir $(RUST_TARGET_DIR) --no-default-features
|
|
ifneq ($(RUST_CARGO_FEATURES),)
|
|
RUST_CARGO_FLAGS += --features $(RUST_CARGO_FEATURES)
|
|
endif
|
|
ifneq ($(strip $(RUST_TARGET)),)
|
|
RUST_CARGO_FLAGS += --target $(RUST_TARGET)
|
|
RUST_TARGET_COMPONENT := /$(RUST_TARGET)
|
|
endif
|
|
RUST_STATICLIB := $(RUST_TARGET_DIR)$(RUST_TARGET_COMPONENT)/release/libzstd_rs.a
|
|
|
|
$(RUST_STATICLIB): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_CARGO_FLAGS)
|
|
|
|
ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
|
|
ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o)
|
|
ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o)
|
|
|
|
VERSION := $(ZSTD_VERSION)
|
|
|
|
# Note: by default, the static library is built single-threaded and dynamic library is built
|
|
# multi-threaded. It is possible to force multi or single threaded builds by appending
|
|
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
|
|
|
|
|
|
CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
|
|
LDFLAGS_DYNLIB += -pthread
|
|
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
|
|
|
|
# pkg-config Libs.private points to LDFLAGS_DYNLIB
|
|
PCLIB := $(LDFLAGS_DYNLIB)
|
|
|
|
ifeq ($(findstring GCC,$(CCVER)),GCC)
|
|
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
|
|
endif
|
|
|
|
|
|
# macOS linker doesn't support -soname, and use different extension
|
|
# see : https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html
|
|
UNAME_TARGET_SYSTEM ?= $(UNAME)
|
|
|
|
ifeq ($(UNAME_TARGET_SYSTEM), Darwin)
|
|
SHARED_EXT = dylib
|
|
SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
|
|
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
|
|
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
|
|
else
|
|
ifeq ($(UNAME_TARGET_SYSTEM), AIX)
|
|
SONAME_FLAGS =
|
|
else
|
|
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
|
|
endif
|
|
SHARED_EXT = so
|
|
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
|
|
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
|
|
endif
|
|
|
|
# A dynamic library must retain every migrated public Rust export, including
|
|
# functions no C object calls directly. GNU-like linkers need an explicit
|
|
# whole-archive region for that; Darwin spells the same operation force_load.
|
|
ifeq ($(UNAME_TARGET_SYSTEM), Darwin)
|
|
RUST_DYNLIB_LINK = -Wl,-force_load,$(abspath $(RUST_STATICLIB))
|
|
else
|
|
RUST_DYNLIB_LINK = -Wl,--whole-archive $(RUST_STATICLIB) -Wl,--no-whole-archive
|
|
endif
|
|
|
|
|
|
.PHONY: all
|
|
all: lib
|
|
|
|
|
|
.PHONY: libzstd.a # must be run every time
|
|
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATICLIB)
|
|
|
|
SET_CACHE_DIRECTORY = \
|
|
+$(MAKE) --no-print-directory $@ \
|
|
BUILD_DIR=obj/$(HASH_DIR) \
|
|
CPPFLAGS="$(CPPFLAGS)" \
|
|
CFLAGS="$(CFLAGS)" \
|
|
LDFLAGS="$(LDFLAGS)"
|
|
|
|
ifndef BUILD_DIR
|
|
# determine BUILD_DIR from compilation flags
|
|
|
|
libzstd.a:
|
|
$(SET_CACHE_DIRECTORY)
|
|
|
|
else
|
|
# BUILD_DIR is defined
|
|
|
|
ZSTD_STATICLIB_DIR := $(BUILD_DIR)/static
|
|
ZSTD_STATICLIB := $(ZSTD_STATICLIB_DIR)/libzstd.a
|
|
ZSTD_STATICLIB_OBJ := $(addprefix $(ZSTD_STATICLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
|
|
ZSTD_STATICLIB_RUST_DIR := $(ZSTD_STATICLIB_DIR)/rust
|
|
$(ZSTD_STATICLIB): ARFLAGS = rcs
|
|
$(ZSTD_STATICLIB): | $(ZSTD_STATICLIB_DIR)
|
|
$(ZSTD_STATICLIB): $(ZSTD_STATICLIB_OBJ) $(RUST_STATICLIB)
|
|
# Check for multithread flag at target execution time
|
|
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
|
|
@echo compiling multi-threaded static library $(LIBVER),\
|
|
@echo compiling single-threaded static library $(LIBVER))
|
|
$(RM) -rf $(ZSTD_STATICLIB_RUST_DIR)
|
|
$(MKDIR) $(ZSTD_STATICLIB_RUST_DIR)
|
|
(cd $(ZSTD_STATICLIB_RUST_DIR) && $(AR) x $(abspath $(RUST_STATICLIB)))
|
|
$(RM) -f $@
|
|
$(AR) $(ARFLAGS) $@ $(ZSTD_STATICLIB_OBJ) $(ZSTD_STATICLIB_RUST_DIR)/*.o
|
|
$(RM) -rf $(ZSTD_STATICLIB_RUST_DIR)
|
|
|
|
libzstd.a: $(ZSTD_STATICLIB)
|
|
cp -f $< $@
|
|
|
|
endif
|
|
|
|
ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
|
|
|
|
LIBZSTD = dll/libzstd.dll
|
|
$(LIBZSTD): $(ZSTD_FILES) $(RUST_STATICLIB)
|
|
@echo compiling dynamic library $(LIBVER)
|
|
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll/libzstd.dll.a -shared $(ZSTD_FILES) $(RUST_DYNLIB_LINK) -o $@
|
|
|
|
else # not Windows
|
|
|
|
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
|
.PHONY: $(LIBZSTD) # must be run every time
|
|
$(LIBZSTD): CPPFLAGS += $(CPPFLAGS_DYNLIB)
|
|
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
|
|
$(LIBZSTD): LDFLAGS += -shared $(LDFLAGS_DYNLIB)
|
|
|
|
ifndef BUILD_DIR
|
|
# determine BUILD_DIR from compilation flags
|
|
|
|
$(LIBZSTD):
|
|
$(SET_CACHE_DIRECTORY)
|
|
|
|
else
|
|
# BUILD_DIR is defined
|
|
|
|
ZSTD_DYNLIB_DIR := $(BUILD_DIR)/dynamic
|
|
ZSTD_DYNLIB := $(ZSTD_DYNLIB_DIR)/$(LIBZSTD)
|
|
ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
|
|
|
|
$(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
|
|
$(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ) $(RUST_STATICLIB)
|
|
# Check for multithread flag at target execution time
|
|
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
|
|
@echo compiling multi-threaded dynamic library $(LIBVER),\
|
|
@echo compiling single-threaded dynamic library $(LIBVER))
|
|
$(CC) $(FLAGS) $(ZSTD_DYNLIB_OBJ) $(RUST_DYNLIB_LINK) $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
|
@echo creating versioned links
|
|
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
|
|
ln -sf $@ libzstd.$(SHARED_EXT)
|
|
|
|
$(LIBZSTD): $(ZSTD_DYNLIB)
|
|
cp -f $< $@
|
|
|
|
endif # ifndef BUILD_DIR
|
|
endif # if windows
|
|
|
|
.PHONY: libzstd
|
|
libzstd : $(LIBZSTD)
|
|
|
|
.PHONY: lib
|
|
lib : libzstd.a libzstd
|
|
|
|
|
|
# note : do not define lib-mt or lib-release as .PHONY
|
|
# make does not consider implicit pattern rule for .PHONY target
|
|
|
|
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
|
|
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
|
|
%-mt : LDFLAGS_DYNLIB := -pthread
|
|
%-mt : PCLIB :=
|
|
%-mt : PCMTLIB := $(LDFLAGS_DYNLIB)
|
|
%-mt : %
|
|
@echo multi-threaded build completed
|
|
|
|
%-nomt : CPPFLAGS_DYNLIB :=
|
|
%-nomt : LDFLAGS_DYNLIB :=
|
|
%-nomt : CPPFLAGS_STATICLIB :=
|
|
%-nomt : PCLIB :=
|
|
%-nomt : %
|
|
@echo single-threaded build completed
|
|
|
|
%-release : DEBUGFLAGS :=
|
|
%-release : %
|
|
@echo release build completed
|
|
|
|
|
|
# Generate .h dependencies automatically
|
|
|
|
# -MMD: compiler generates dependency information as a side-effect of compilation, without system headers
|
|
# -MP: adds phony target for each dependency other than main file.
|
|
DEPFLAGS = -MMD -MP
|
|
|
|
# ensure that ZSTD_DYNLIB_DIR exists prior to generating %.o
|
|
$(ZSTD_DYNLIB_DIR)/%.o : %.c | $(ZSTD_DYNLIB_DIR)
|
|
@echo CC $@
|
|
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
|
|
|
$(ZSTD_STATICLIB_DIR)/%.o : %.c | $(ZSTD_STATICLIB_DIR)
|
|
@echo CC $@
|
|
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
|
|
|
$(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
|
|
@echo AS $@
|
|
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
|
|
|
$(ZSTD_STATICLIB_DIR)/%.o : %.S | $(ZSTD_STATICLIB_DIR)
|
|
@echo AS $@
|
|
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
|
|
|
MKDIR ?= mkdir -p
|
|
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATICLIB_DIR):
|
|
$(MKDIR) $@
|
|
|
|
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATICLIB_OBJ:.o=.d)
|
|
$(DEPFILES):
|
|
|
|
# The leading '-' means: do not fail is include fails (ex: directory does not exist yet)
|
|
-include $(wildcard $(DEPFILES))
|
|
|
|
|
|
# Special case : build library in single-thread mode _and_ without zstdmt_compress.c
|
|
# Note : we still need threading.c and pool.c for the dictionary builder,
|
|
# but they will correctly behave single-threaded.
|
|
ZSTDMT_FILES = zstdmt_compress.c
|
|
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(notdir $(ZSTD_FILES)))
|
|
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
|
|
libzstd-nomt: LDFLAGS += -shared
|
|
libzstd-nomt: $(ZSTD_NOMT_FILES) $(RUST_STATICLIB)
|
|
@echo compiling single-thread dynamic library $(LIBVER)
|
|
@echo files : $(ZSTD_NOMT_FILES)
|
|
@if echo "$(ZSTD_NOMT_FILES)" | tr ' ' '\n' | $(GREP) -q zstdmt; then \
|
|
echo "Error: Found zstdmt in list."; \
|
|
exit 1; \
|
|
fi
|
|
$(CC) $(FLAGS) $(ZSTD_NOMT_FILES) $(RUST_DYNLIB_LINK) $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(RM) -r *.dSYM # macOS-specific
|
|
$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
|
|
$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
|
|
$(RM) -r obj/*
|
|
@echo Cleaning library completed
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# make install is validated only for below listed environments
|
|
#-----------------------------------------------------------------------------
|
|
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME)))
|
|
|
|
lib: libzstd.pc
|
|
|
|
HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
|
|
|
|
DESTDIR ?=
|
|
# directory variables : GNU conventions prefer lowercase
|
|
# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
|
|
# support both lower and uppercase (BSD), use uppercase in script
|
|
prefix ?= /usr/local
|
|
PREFIX ?= $(prefix)
|
|
exec_prefix ?= $(PREFIX)
|
|
EXEC_PREFIX ?= $(exec_prefix)
|
|
libdir ?= $(EXEC_PREFIX)/lib
|
|
LIBDIR ?= $(libdir)
|
|
includedir ?= $(PREFIX)/include
|
|
INCLUDEDIR ?= $(includedir)
|
|
|
|
PCINCDIR := $(patsubst $(PREFIX)%,%,$(INCLUDEDIR))
|
|
PCLIBDIR := $(patsubst $(EXEC_PREFIX)%,%,$(LIBDIR))
|
|
|
|
# If we successfully stripped off a prefix, we'll add a reference to the
|
|
# relevant pc variable.
|
|
PCINCPREFIX := $(if $(findstring $(INCLUDEDIR),$(PCINCDIR)),,$${prefix})
|
|
PCLIBPREFIX := $(if $(findstring $(LIBDIR),$(PCLIBDIR)),,$${exec_prefix})
|
|
|
|
# If no explicit EXEC_PREFIX was set by the caller, write it out as a reference
|
|
# to PREFIX, rather than as a resolved value.
|
|
PCEXEC_PREFIX := $(if $(HAS_EXPLICIT_EXEC_PREFIX),$(EXEC_PREFIX),$${prefix})
|
|
|
|
|
|
ifneq ($(MT),)
|
|
PCLIB :=
|
|
PCMTLIB := $(LDFLAGS_DYNLIB)
|
|
else
|
|
PCLIB := $(LDFLAGS_DYNLIB)
|
|
endif
|
|
|
|
ifneq (,$(filter FreeBSD NetBSD DragonFly,$(UNAME)))
|
|
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
|
|
else
|
|
PKGCONFIGDIR ?= $(LIBDIR)/pkgconfig
|
|
endif
|
|
|
|
ifneq (,$(filter SunOS,$(UNAME)))
|
|
INSTALL ?= ginstall
|
|
else
|
|
INSTALL ?= install
|
|
endif
|
|
|
|
INSTALL_PROGRAM ?= $(INSTALL)
|
|
INSTALL_DATA ?= $(INSTALL) -m 644
|
|
|
|
|
|
# pkg-config library define.
|
|
# For static single-threaded library declare -pthread in Libs.private
|
|
# For static multi-threaded library declare -pthread in Libs and Cflags
|
|
.PHONY: libzstd.pc
|
|
libzstd.pc: libzstd.pc.in
|
|
@echo creating pkgconfig
|
|
@sed \
|
|
-e 's|@PREFIX@|$(PREFIX)|' \
|
|
-e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
|
|
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
|
|
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
|
|
-e 's|@VERSION@|$(VERSION)|' \
|
|
-e 's|@LIBS_MT@|$(PCMTLIB)|' \
|
|
-e 's|@LIBS_PRIVATE@|$(PCLIB)|' \
|
|
$< >$@
|
|
|
|
.PHONY: install
|
|
install: install-pc install-static install-shared install-includes
|
|
@echo zstd static and shared library installed
|
|
|
|
.PHONY: install-pc
|
|
install-pc: libzstd.pc
|
|
[ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
|
|
$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
|
|
|
|
.PHONY: install-static
|
|
install-static:
|
|
# only generate libzstd.a if it's not already present
|
|
[ -e libzstd.a ] || $(MAKE) libzstd.a-release
|
|
[ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
|
|
@echo Installing static library
|
|
$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
|
|
|
|
.PHONY: install-shared
|
|
install-shared:
|
|
# only generate libzstd.so if it's not already present
|
|
[ -e $(LIBZSTD) ] || $(MAKE) libzstd-release
|
|
[ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
|
|
@echo Installing shared library
|
|
$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
|
|
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
|
|
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
|
|
|
|
.PHONY: install-includes
|
|
install-includes:
|
|
[ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
|
|
@echo Installing includes
|
|
$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
|
|
$(INSTALL_DATA) zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
|
|
$(INSTALL_DATA) zdict.h $(DESTDIR)$(INCLUDEDIR)
|
|
|
|
.PHONY: uninstall
|
|
uninstall:
|
|
$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
|
|
$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
|
|
$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
|
|
$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
|
|
$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
|
|
$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
|
|
$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
|
|
$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
|
|
@echo zstd libraries successfully uninstalled
|
|
|
|
endif
|