Move the implementation of programs/benchfn.c into rust/src/benchfn.rs and wire benchmark mode (-b/-e/-i) into the Rust CLI frontend, which previously rejected those options as not yet implemented. `zstd -b1 -i0 FILE` and range runs like `zstd -b5e6 -i0 FILE` work again, including the synthetic-sample benchmark when no file is given. benchfn.rs is a faithful port of the run/timing state machine: BMK_benchFunction keeps the exact loop accounting (first-loop blockResults and errorFn checks, dstSize summed on the first loop only, 0xE5 warm-up of result buffers, nbLoops minimum of 1) and BMK_benchTimedFn keeps the same convergence behavior (x10 workload growth for short runs, budget-based nbLoops estimation, runs below half the run budget re-tried rather than reported, best qualifying run returned). Arithmetic that C leaves to unsigned wrap-around uses wrapping operations so debug builds cannot panic where release C would wrap. ABI notes: BMK_runTime_t and BMK_runOutcome_t are returned by value across the C boundary and BMK_benchParams_t is passed by value, so all three are repr(C) mirrors of benchfn.h; their field offsets are pinned by const asserts in Rust and matching C static asserts in the benchfn.c shim, which is now declaration-only. BMK_timedFnState_t stays opaque, fits the 64-byte BMK_timedFnState_shell (compile-time checked), and is malloc/free-managed so creation and destruction remain interchangeable with C callers. The CLI parses -b (bench mode), -e (range end, digits attach directly, defaulting to 0 like readU32FromChar) and -i (duration in seconds), then dispatches through a new ZSTD_rust_cli_bench bridge in the zstdcli.c shim. The bridge exists because benchmark availability is a C preprocessor property (ZSTD_NOBENCH): orchestration and reporting stay in C benchzstd.c, stripped variants (zstd-small, zstd-compress, zstd-decompress) compile the stub branch and report "benchmark mode is not available in this build", and the Rust side never references benchmark symbols directly. Level clamping against ZSTD_maxCLevel() happens in the bridge, where the symbol is guaranteed to exist whenever benchmarking is compiled in. -T selects the worker count, defaulting to single-threaded like the C bench path; -S (separate files) and --priority=rt remain unimplemented. Makefile updates only extend the Rust source prerequisite lists with benchfn.rs; the helpers-archive plumbing from the timefn commit already links fullbench(-lib/-dll/32) and paramgrill, the benchfn consumers among the C tests. Original C test sources are untouched. Known pre-existing issues, unchanged by this commit: tests/fullbench-lib fails to link at the base commit too (libzstd.a precedes fullbench.c in its link line), and the cli-tests basic/help.sh, compression/levels.sh, compression/golden.sh, and decompression/pass-through.sh scripts fail identically with a base-commit binary because the Rust CLI frontend is still a partial reimplementation. Test Plan: - cd rust && cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test --all-targets && cargo build --release - cd rust/cli && cargo fmt --check && cargo clippy --all-targets -- -D warnings && cargo test --all-targets; repeat tests with --no-default-features plus features compression / decompression / (none) - make -C programs zstd; ./programs/zstd -b1 -i0 lib/common/xxhash.c; ./programs/zstd -b5e6 -i0 programs/fileio.c; ./programs/zstd -b1 -i0 (synthetic); echo roundtrip via zstd | zstd -d - make -C programs zstd-small zstd-compress zstd-decompress zstd-nolegacy zstd-dictBuilder; zstd-small -b reports benchmark unavailable; compress/ decompress roundtrip across the split binaries - make -C tests fullbench fuzzer zstreamtest paramgrill decodecorpus poolTests fullbench32 fuzzer32; ./tests/fullbench -i0 (exercises Rust BMK_benchTimedFn from C); ./tests/fullbench32 -i0; ./tests/fuzzer -i1 --no-big-tests; ./tests/poolTests; make -C tests test-rust-lib-smoke - cli-tests subset: basic/version.sh, compression/basic.sh, compression/multiple-files.sh pass; failing scripts match the base commit Refs: rust/README.md
608 lines
23 KiB
Makefile
608 lines
23 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.
|
|
# ##########################################################################
|
|
# zstd : Command Line Utility, supporting gzip-like arguments
|
|
# zstd32 : Same as zstd, but forced to compile in 32-bits mode
|
|
# zstd-nolegacy : zstd without support of decompression of legacy versions
|
|
# zstd-small : minimal zstd without dictionary builder and benchmark
|
|
# zstd-compress : compressor-only version of zstd
|
|
# zstd-decompress : decompressor-only version of zstd
|
|
# ##########################################################################
|
|
|
|
# default target (when running `make` with no argument)
|
|
zstd-release:
|
|
|
|
LIBZSTD_MK_DIR = ../lib
|
|
include $(LIBZSTD_MK_DIR)/libzstd.mk
|
|
|
|
# Link the in-progress Rust implementation after C objects whenever a program
|
|
# uses a migrated C shim. Source inputs are prerequisites so a changed Rust
|
|
# module rebuilds the archive and relinks the executable automatically.
|
|
CARGO ?= cargo
|
|
RUST_DIR := ../rust
|
|
RUST_MANIFEST := $(RUST_DIR)/Cargo.toml
|
|
RUST_CLI_DIR := $(RUST_DIR)/cli
|
|
RUST_CLI_MANIFEST := $(RUST_CLI_DIR)/Cargo.toml
|
|
RUST_SOURCES := $(RUST_MANIFEST) $(RUST_DIR)/Cargo.lock \
|
|
$(shell find $(RUST_DIR)/src -type f -name '*.rs' -print)
|
|
RUST_CLI_SOURCES := $(RUST_CLI_MANIFEST) $(RUST_CLI_DIR)/Cargo.lock \
|
|
$(RUST_CLI_DIR)/src/lib.rs $(RUST_DIR)/src/zstd_cli.rs \
|
|
$(RUST_DIR)/src/timefn.rs $(RUST_DIR)/src/benchfn.rs
|
|
|
|
# Keep Rust's HUF implementation in lockstep with libzstd.mk's C selection.
|
|
# Forced modes may arrive as libzstd.mk variables or as direct -D flags in
|
|
# MOREFLAGS/CFLAGS/CPPFLAGS, as used by the C-only build matrix.
|
|
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
|
|
|
|
# A separate target directory per mode prevents a forced build from reusing the
|
|
# default archive, and also gives link targets a configuration-specific input.
|
|
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
|
|
|
|
RUST_HUF_FEATURE :=
|
|
RUST_BUILD_CONFIG := default
|
|
ifneq ($(RUST_HUF_FORCE_X1),0)
|
|
RUST_HUF_FEATURE := huf-force-decompress-x1
|
|
RUST_BUILD_CONFIG := huf-force-decompress-x1
|
|
endif
|
|
ifneq ($(RUST_HUF_FORCE_X2),0)
|
|
RUST_HUF_FEATURE := huf-force-decompress-x2
|
|
RUST_BUILD_CONFIG := huf-force-decompress-x2
|
|
endif
|
|
|
|
RUST_TARGET_DIR := $(RUST_DIR)/target/$(RUST_BUILD_CONFIG)
|
|
RUST_STATICLIB := $(RUST_TARGET_DIR)/release/libzstd_rs.a
|
|
RUST_TARGET_32 ?= i686-unknown-linux-gnu
|
|
RUST_STATICLIB_32 := $(RUST_TARGET_DIR)/$(RUST_TARGET_32)/release/libzstd_rs.a
|
|
RUST_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
|
|
--target-dir $(RUST_TARGET_DIR) --no-default-features
|
|
RUST_CARGO_FLAGS += --features compression,decompression,dict-builder
|
|
ifneq ($(RUST_HUF_FEATURE),)
|
|
RUST_CARGO_FLAGS += --features $(RUST_HUF_FEATURE)
|
|
endif
|
|
|
|
$(RUST_STATICLIB): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_CARGO_FLAGS)
|
|
|
|
$(RUST_STATICLIB_32): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_CARGO_FLAGS) --target $(RUST_TARGET_32)
|
|
|
|
RUST_CLI_BUILD_CONFIG := cli-c1-d1-$(RUST_BUILD_CONFIG)
|
|
RUST_CLI_TARGET_DIR := $(RUST_DIR)/target/$(RUST_CLI_BUILD_CONFIG)
|
|
RUST_CLI_STATICLIB := $(RUST_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
|
|
RUST_CLI_STATICLIB_32 := $(RUST_CLI_TARGET_DIR)/$(RUST_TARGET_32)/release/libzstd_cli_rs.a
|
|
RUST_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
|
|
--target-dir $(RUST_CLI_TARGET_DIR) \
|
|
--no-default-features --features cli,compression,decompression
|
|
|
|
$(RUST_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
|
$(CARGO) build $(RUST_CLI_CARGO_FLAGS)
|
|
|
|
$(RUST_CLI_STATICLIB_32): $(RUST_CLI_SOURCES)
|
|
$(CARGO) build $(RUST_CLI_CARGO_FLAGS) --target $(RUST_TARGET_32)
|
|
|
|
RUST_DECOMPRESS_BUILD_CONFIG := lib-c0-d1-b0-$(RUST_BUILD_CONFIG)
|
|
RUST_DECOMPRESS_TARGET_DIR := $(RUST_DIR)/target/$(RUST_DECOMPRESS_BUILD_CONFIG)
|
|
RUST_DECOMPRESS_STATICLIB := $(RUST_DECOMPRESS_TARGET_DIR)/release/libzstd_rs.a
|
|
RUST_DECOMPRESS_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
|
|
--target-dir $(RUST_DECOMPRESS_TARGET_DIR) \
|
|
--no-default-features --features decompression
|
|
ifneq ($(RUST_HUF_FEATURE),)
|
|
RUST_DECOMPRESS_CARGO_FLAGS += --features $(RUST_HUF_FEATURE)
|
|
endif
|
|
|
|
$(RUST_DECOMPRESS_STATICLIB): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_DECOMPRESS_CARGO_FLAGS)
|
|
|
|
RUST_DECOMPRESS_CLI_BUILD_CONFIG := cli-c0-d1-$(RUST_BUILD_CONFIG)
|
|
RUST_DECOMPRESS_CLI_TARGET_DIR := $(RUST_DIR)/target/$(RUST_DECOMPRESS_CLI_BUILD_CONFIG)
|
|
RUST_DECOMPRESS_CLI_STATICLIB := $(RUST_DECOMPRESS_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
|
|
RUST_DECOMPRESS_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
|
|
--target-dir $(RUST_DECOMPRESS_CLI_TARGET_DIR) \
|
|
--no-default-features --features cli,decompression
|
|
|
|
$(RUST_DECOMPRESS_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
|
$(CARGO) build $(RUST_DECOMPRESS_CLI_CARGO_FLAGS)
|
|
|
|
RUST_COMPRESS_BUILD_CONFIG := lib-c1-d0-b0-$(RUST_BUILD_CONFIG)
|
|
RUST_COMPRESS_TARGET_DIR := $(RUST_DIR)/target/$(RUST_COMPRESS_BUILD_CONFIG)
|
|
RUST_COMPRESS_STATICLIB := $(RUST_COMPRESS_TARGET_DIR)/release/libzstd_rs.a
|
|
RUST_COMPRESS_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
|
|
--target-dir $(RUST_COMPRESS_TARGET_DIR) \
|
|
--no-default-features --features compression
|
|
|
|
$(RUST_COMPRESS_STATICLIB): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_COMPRESS_CARGO_FLAGS)
|
|
|
|
RUST_DICTBUILDER_BUILD_CONFIG := lib-c1-d0-b1-$(RUST_BUILD_CONFIG)
|
|
RUST_DICTBUILDER_TARGET_DIR := $(RUST_DIR)/target/$(RUST_DICTBUILDER_BUILD_CONFIG)
|
|
RUST_DICTBUILDER_STATICLIB := $(RUST_DICTBUILDER_TARGET_DIR)/release/libzstd_rs.a
|
|
RUST_DICTBUILDER_CARGO_FLAGS := --manifest-path $(RUST_MANIFEST) --release \
|
|
--target-dir $(RUST_DICTBUILDER_TARGET_DIR) \
|
|
--no-default-features \
|
|
--features compression,dict-builder
|
|
|
|
$(RUST_DICTBUILDER_STATICLIB): $(RUST_SOURCES)
|
|
$(CARGO) build $(RUST_DICTBUILDER_CARGO_FLAGS)
|
|
|
|
RUST_COMPRESS_CLI_BUILD_CONFIG := cli-c1-d0-$(RUST_BUILD_CONFIG)
|
|
RUST_COMPRESS_CLI_TARGET_DIR := $(RUST_DIR)/target/$(RUST_COMPRESS_CLI_BUILD_CONFIG)
|
|
RUST_COMPRESS_CLI_STATICLIB := $(RUST_COMPRESS_CLI_TARGET_DIR)/release/libzstd_cli_rs.a
|
|
RUST_COMPRESS_CLI_CARGO_FLAGS := --manifest-path $(RUST_CLI_MANIFEST) --release \
|
|
--target-dir $(RUST_COMPRESS_CLI_TARGET_DIR) \
|
|
--no-default-features --features cli,compression
|
|
|
|
$(RUST_COMPRESS_CLI_STATICLIB): $(RUST_CLI_SOURCES)
|
|
$(CARGO) build $(RUST_COMPRESS_CLI_CARGO_FLAGS)
|
|
|
|
# Most program objects use a configuration-hashed directory, but the compact
|
|
# direct-source variants below do not. Give their C outputs an independent
|
|
# mode stamp so they cannot outlive a different Rust HUF archive selection.
|
|
# The stamp is an empty archive, so normal linker `$^` recipes can consume it.
|
|
RUST_HUF_C_MODE_FILE := $(RUST_DIR)/target/.huf-c-mode-programs
|
|
RUST_HUF_C_MODE_STAMP := $(RUST_DIR)/target/.huf-c-mode-programs.a
|
|
.PHONY: FORCE_RUST_HUF_C_MODE
|
|
FORCE_RUST_HUF_C_MODE:
|
|
$(RUST_HUF_C_MODE_STAMP): FORCE_RUST_HUF_C_MODE
|
|
@mkdir -p $(@D)
|
|
@if test ! -r $(RUST_HUF_C_MODE_FILE) \
|
|
|| test "$$(cat $(RUST_HUF_C_MODE_FILE))" != "$(RUST_BUILD_CONFIG)" \
|
|
|| test ! -f $@; then \
|
|
printf '%s\n' "$(RUST_BUILD_CONFIG)" > $(RUST_HUF_C_MODE_FILE); \
|
|
$(AR) rcs $@; \
|
|
touch $@; \
|
|
fi
|
|
CLEAN += $(RUST_HUF_C_MODE_FILE) $(RUST_HUF_C_MODE_STAMP)
|
|
|
|
ifeq ($(shell $(CC) -v 2>&1 | $(GREP) -c "gcc version "), 1)
|
|
ALIGN_LOOP = -falign-loops=32
|
|
else
|
|
ALIGN_LOOP =
|
|
endif
|
|
|
|
ZSTDLIB_COMMON_SRC := $(sort $(ZSTD_COMMON_FILES))
|
|
ZSTDLIB_COMPRESS_SRC := $(sort $(ZSTD_COMPRESS_FILES))
|
|
ZSTDLIB_DECOMPRESS_SRC := $(sort $(ZSTD_DECOMPRESS_FILES))
|
|
ZSTDLIB_CORE_SRC := $(sort $(ZSTD_DECOMPRESS_FILES) $(ZSTD_COMMON_FILES) $(ZSTD_COMPRESS_FILES))
|
|
ZDICT_SRC := $(sort $(ZSTD_DICTBUILDER_FILES))
|
|
ZSTDLEGACY_SRC := $(sort $(ZSTD_LEGACY_FILES))
|
|
|
|
# Sort files in alphabetical order for reproducible builds
|
|
ZSTDLIB_FULL_SRC = $(sort $(ZSTDLIB_CORE_SRC) $(ZSTDLEGACY_SRC) $(ZDICT_SRC))
|
|
ZSTDLIB_LOCAL_SRC = $(notdir $(ZSTDLIB_FULL_SRC))
|
|
ZSTDLIB_LOCAL_OBJ0 := $(ZSTDLIB_LOCAL_SRC:.c=.o)
|
|
ZSTDLIB_LOCAL_OBJ := $(ZSTDLIB_LOCAL_OBJ0:.S=.o)
|
|
|
|
ZSTD_CLI_SRC := $(sort $(wildcard *.c))
|
|
ZSTD_CLI_OBJ := $(ZSTD_CLI_SRC:.c=.o)
|
|
|
|
ZSTD_ALL_SRC = $(ZSTDLIB_LOCAL_SRC) $(ZSTD_CLI_SRC)
|
|
ZSTD_ALL_OBJ0 := $(ZSTD_ALL_SRC:.c=.o)
|
|
ZSTD_ALL_OBJ := $(ZSTD_ALL_OBJ0:.S=.o)
|
|
|
|
# Define *.exe as extension for Windows systems
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
EXT =.exe
|
|
RES64_FILE = windres/zstd64.res
|
|
RES32_FILE = windres/zstd32.res
|
|
ifneq (,$(filter x86_64%,$(shell $(CC) -dumpmachine)))
|
|
RES_FILE = $(RES64_FILE)
|
|
else
|
|
RES_FILE = $(RES32_FILE)
|
|
endif
|
|
else
|
|
EXT =
|
|
endif
|
|
|
|
# thread detection
|
|
NO_THREAD_MSG := ==> no threads, building without multithreading support
|
|
HAVE_PTHREAD := $(shell printf '$(NUM_SYMBOL)include <pthread.h>\nint main(void) { return 0; }' > have_pthread.c && $(CC) $(FLAGS) -o have_pthread$(EXT) have_pthread.c -pthread 2> $(VOID) && rm have_pthread$(EXT) && echo 1 || echo 0; rm have_pthread.c)
|
|
HAVE_THREAD := $(shell [ "$(HAVE_PTHREAD)" -eq "1" -o -n "$(filter Windows%,$(OS))" ] && echo 1 || echo 0)
|
|
ifeq ($(HAVE_THREAD), 1)
|
|
THREAD_MSG := ==> building with threading support
|
|
THREAD_CPP := -DZSTD_MULTITHREAD
|
|
THREAD_LD := -pthread
|
|
else
|
|
THREAD_MSG := $(NO_THREAD_MSG)
|
|
endif
|
|
|
|
# zlib detection
|
|
NO_ZLIB_MSG := ==> no zlib, building zstd without .gz support
|
|
HAVE_ZLIB ?= $(shell printf '$(NUM_SYMBOL)include <zlib.h>\nint main(void) { return 0; }' > have_zlib.c && $(CC) $(FLAGS) -o have_zlib$(EXT) have_zlib.c -lz 2> $(VOID) && rm have_zlib$(EXT) && echo 1 || echo 0; rm have_zlib.c)
|
|
ifeq ($(HAVE_ZLIB), 1)
|
|
ZLIB_MSG := ==> building zstd with .gz compression support
|
|
ZLIBCPP = -DZSTD_GZCOMPRESS -DZSTD_GZDECOMPRESS
|
|
ZLIBLD = -lz
|
|
else
|
|
ZLIB_MSG := $(NO_ZLIB_MSG)
|
|
endif
|
|
|
|
# lzma detection
|
|
NO_LZMA_MSG := ==> no liblzma, building zstd without .xz/.lzma support
|
|
HAVE_LZMA ?= $(shell printf '$(NUM_SYMBOL)include <lzma.h>\nint main(void) { return 0; }' > have_lzma.c && $(CC) $(FLAGS) -o have_lzma$(EXT) have_lzma.c -llzma 2> $(VOID) && rm have_lzma$(EXT) && echo 1 || echo 0; rm have_lzma.c)
|
|
ifeq ($(HAVE_LZMA), 1)
|
|
LZMA_MSG := ==> building zstd with .xz/.lzma compression support
|
|
LZMACPP = -DZSTD_LZMACOMPRESS -DZSTD_LZMADECOMPRESS
|
|
LZMALD = -llzma
|
|
else
|
|
LZMA_MSG := $(NO_LZMA_MSG)
|
|
endif
|
|
|
|
# lz4 detection
|
|
NO_LZ4_MSG := ==> no liblz4, building zstd without .lz4 support
|
|
HAVE_LZ4 ?= $(shell printf '$(NUM_SYMBOL)include <lz4frame.h>\n$(NUM_SYMBOL)include <lz4.h>\nint main(void) { return 0; }' > have_lz4.c && $(CC) $(FLAGS) -o have_lz4$(EXT) have_lz4.c -llz4 2> $(VOID) && rm have_lz4$(EXT) && echo 1 || echo 0; rm have_lz4.c)
|
|
ifeq ($(HAVE_LZ4), 1)
|
|
LZ4_MSG := ==> building zstd with .lz4 compression support
|
|
LZ4CPP = -DZSTD_LZ4COMPRESS -DZSTD_LZ4DECOMPRESS
|
|
LZ4LD = -llz4
|
|
else
|
|
LZ4_MSG := $(NO_LZ4_MSG)
|
|
endif
|
|
|
|
# explicit backtrace enable/disable for Linux & Darwin
|
|
ifeq ($(BACKTRACE), 0)
|
|
DEBUGFLAGS += -DBACKTRACE_ENABLE=0
|
|
endif
|
|
ifeq (,$(filter Windows%, $(OS)))
|
|
ifeq ($(BACKTRACE), 1)
|
|
DEBUGFLAGS += -DBACKTRACE_ENABLE=1
|
|
DEBUGFLAGS_LD += -rdynamic
|
|
endif
|
|
endif
|
|
|
|
RUST_LIBRARY_LINK ?= $(RUST_STATICLIB)
|
|
RUST_CLI_LINK ?= $(RUST_CLI_STATICLIB)
|
|
|
|
SET_CACHE_DIRECTORY = \
|
|
+$(MAKE) --no-print-directory $@ \
|
|
BUILD_DIR=obj/$(HASH_DIR) \
|
|
CPPFLAGS="$(CPPFLAGS)" \
|
|
CFLAGS="$(CFLAGS)" \
|
|
LDFLAGS="$(LDFLAGS)" \
|
|
LDLIBS="$(LDLIBS)" \
|
|
RUST_LIBRARY_LINK="$(RUST_LIBRARY_LINK)" \
|
|
RUST_CLI_LINK="$(RUST_CLI_LINK)" \
|
|
ZSTD_ALL_SRC="$(ZSTD_ALL_SRC)"
|
|
|
|
|
|
.PHONY: all
|
|
all: zstd zstd-compress zstd-decompress zstd-small
|
|
|
|
.PHONY: allVariants
|
|
allVariants: all zstd-frugal zstd-nolegacy zstd-dictBuilder
|
|
|
|
.PHONY: zstd # must always be run
|
|
zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
|
|
zstd : LDFLAGS += $(THREAD_LD) $(DEBUGFLAGS_LD)
|
|
zstd : LDLIBS += $(ZLIBLD) $(LZMALD) $(LZ4LD)
|
|
zstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
zstd : $(RES_FILE)
|
|
endif
|
|
|
|
ifndef BUILD_DIR
|
|
# generate BUILD_DIR from flags
|
|
|
|
zstd:
|
|
$(SET_CACHE_DIRECTORY)
|
|
|
|
else
|
|
# BUILD_DIR is defined
|
|
|
|
ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
|
|
$(BUILD_DIR)/zstd : $(ZSTD_OBJ) $(RUST_LIBRARY_LINK) $(RUST_CLI_LINK)
|
|
@echo "$(THREAD_MSG)"
|
|
@echo "$(ZLIB_MSG)"
|
|
@echo "$(LZMA_MSG)"
|
|
@echo "$(LZ4_MSG)"
|
|
@echo LINK $@
|
|
$(CC) $(FLAGS) $^ $(LDLIBS) -o $@$(EXT)
|
|
|
|
ifeq ($(HAVE_HASH),1)
|
|
SRCBIN_HASH = $(shell cat $(BUILD_DIR)/zstd$(EXT) 2> $(VOID) | $(HASH) | cut -f 1 -d " ")
|
|
DSTBIN_HASH = $(shell cat zstd$(EXT) 2> $(VOID) | $(HASH) | cut -f 1 -d " ")
|
|
BIN_ISDIFFERENT = $(if $(filter $(SRCBIN_HASH),$(DSTBIN_HASH)),0,1)
|
|
else
|
|
BIN_ISDIFFERENT = 1
|
|
endif
|
|
|
|
zstd : $(BUILD_DIR)/zstd
|
|
if [ $(BIN_ISDIFFERENT) -eq 1 ]; then \
|
|
cp -f $<$(EXT) $@$(EXT); \
|
|
echo zstd build completed; \
|
|
else \
|
|
echo zstd already built; \
|
|
fi
|
|
|
|
endif # BUILD_DIR
|
|
|
|
|
|
CLEAN += zstd
|
|
.PHONY: zstd-release
|
|
zstd-release: DEBUGFLAGS := -DBACKTRACE_ENABLE=0
|
|
zstd-release: DEBUGFLAGS_LD :=
|
|
zstd-release: zstd
|
|
|
|
CLEAN += zstd32
|
|
zstd32 : CPPFLAGS += $(THREAD_CPP)
|
|
zstd32 : LDFLAGS += $(THREAD_LD)
|
|
zstd32 : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
zstd32 : $(RES32_FILE)
|
|
endif
|
|
zstd32 : $(ZSTDLIB_FULL_SRC) $(ZSTD_CLI_SRC) $(RUST_STATICLIB_32) $(RUST_CLI_STATICLIB_32)
|
|
$(CC) -m32 $(FLAGS) $^ -o $@$(EXT)
|
|
|
|
## zstd-nolegacy: same scope as zstd, with removed support of legacy formats
|
|
CLEAN += zstd-nolegacy
|
|
zstd-nolegacy : LDFLAGS += $(THREAD_LD) $(ZLIBLD) $(LZMALD) $(LZ4LD) $(DEBUGFLAGS_LD)
|
|
zstd-nolegacy : CPPFLAGS += -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0
|
|
zstd-nolegacy : $(ZSTDLIB_CORE_SRC) $(ZDICT_SRC) $(ZSTD_CLI_OBJ) $(RUST_STATICLIB) $(RUST_CLI_STATICLIB)
|
|
$(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)
|
|
|
|
.PHONY: zstd-nomt
|
|
zstd-nomt : THREAD_CPP :=
|
|
zstd-nomt : THREAD_LD :=
|
|
zstd-nomt : THREAD_MSG := - multi-threading disabled
|
|
zstd-nomt : zstd
|
|
|
|
.PHONY: zstd-nogz
|
|
zstd-nogz : ZLIBCPP :=
|
|
zstd-nogz : ZLIBLD :=
|
|
zstd-nogz : ZLIB_MSG := - gzip support is disabled
|
|
zstd-nogz : zstd
|
|
|
|
.PHONY: zstd-noxz
|
|
zstd-noxz : LZMACPP :=
|
|
zstd-noxz : LZMALD :=
|
|
zstd-noxz : LZMA_MSG := - xz/lzma support is disabled
|
|
zstd-noxz : zstd
|
|
|
|
## zstd-dll: zstd executable linked to dynamic library libzstd (must have same version)
|
|
.PHONY: zstd-dll
|
|
zstd-dll : LDFLAGS+= -L$(LIB_BINDIR)
|
|
zstd-dll : LDLIBS += -lzstd
|
|
zstd-dll : ZSTDLIB_LOCAL_SRC = xxhash.c pool.c threading.c
|
|
zstd-dll : RUST_LIBRARY_LINK =
|
|
zstd-dll : zstd
|
|
|
|
|
|
## zstd-pgo: zstd executable optimized with PGO.
|
|
.PHONY: zstd-pgo
|
|
zstd-pgo : LLVM_PROFDATA?=llvm-profdata
|
|
zstd-pgo : PROF_GENERATE_FLAGS=-fprofile-generate $(if $(findstring gcc,$(CC)),-fprofile-dir=.)
|
|
zstd-pgo : PROF_USE_FLAGS=-fprofile-use $(if $(findstring gcc,$(CC)),-fprofile-dir=. -Wno-error=missing-profile -Wno-error=coverage-mismatch)
|
|
zstd-pgo :
|
|
$(MAKE) clean HASH_DIR=$(HASH_DIR)
|
|
$(MAKE) zstd HASH_DIR=$(HASH_DIR) MOREFLAGS="$(PROF_GENERATE_FLAGS)"
|
|
./zstd -b19i1 $(PROFILE_WITH)
|
|
./zstd -b16i1 $(PROFILE_WITH)
|
|
./zstd -b9i2 $(PROFILE_WITH)
|
|
./zstd -b $(PROFILE_WITH)
|
|
./zstd -b7i2 $(PROFILE_WITH)
|
|
./zstd -b5 $(PROFILE_WITH)
|
|
ifndef BUILD_DIR
|
|
$(RM) zstd obj/$(HASH_DIR)/zstd obj/$(HASH_DIR)/*.o
|
|
else
|
|
$(RM) zstd $(BUILD_DIR)/zstd $(BUILD_DIR)/*.o
|
|
endif
|
|
case $(CC) in *clang*) if ! [ -e default.profdata ]; then $(LLVM_PROFDATA) merge -output=default.profdata default*.profraw; fi ;; esac
|
|
$(MAKE) zstd HASH_DIR=$(HASH_DIR) MOREFLAGS="$(PROF_USE_FLAGS)"
|
|
|
|
## zstd-small: minimal target, supporting only zstd compression and decompression. no bench. no legacy. no other format.
|
|
CLEAN += zstd-small zstd-frugal
|
|
# The target-specific CFLAGS assignment would otherwise hide an explicitly
|
|
# requested HUF decoder mode from the C sources while the Rust archive sees it.
|
|
ZSTD_SMALL_HUF_CFLAGS := $(filter -DHUF_FORCE_DECOMPRESS_X1% -DHUF_FORCE_DECOMPRESS_X2%,$(CFLAGS))
|
|
zstd-small: CFLAGS = -Os -Wl,-s $(ZSTD_SMALL_HUF_CFLAGS)
|
|
zstd-frugal zstd-small: $(ZSTDLIB_CORE_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c $(RUST_STATICLIB) $(RUST_CLI_STATICLIB)
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT)
|
|
|
|
CLEAN += zstd-decompress
|
|
zstd-decompress: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_DECOMPRESS_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c $(RUST_DECOMPRESS_STATICLIB) $(RUST_DECOMPRESS_CLI_STATICLIB)
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NOCOMPRESS -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT)
|
|
|
|
CLEAN += zstd-compress
|
|
zstd-compress: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c $(RUST_COMPRESS_STATICLIB) $(RUST_COMPRESS_CLI_STATICLIB)
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODICT -DZSTD_NODECOMPRESS -DZSTD_NOTRACE -UZSTD_LEGACY_SUPPORT -DZSTD_LEGACY_SUPPORT=0 $^ -o $@$(EXT)
|
|
|
|
## zstd-dictBuilder: executable supporting dictionary creation and compression (only)
|
|
CLEAN += zstd-dictBuilder
|
|
zstd-dictBuilder: $(ZSTDLIB_COMMON_SRC) $(ZSTDLIB_COMPRESS_SRC) $(ZDICT_SRC) zstdcli.c util.c timefn.c fileio.c fileio_asyncio.c dibio.c $(RUST_DICTBUILDER_STATICLIB) $(RUST_COMPRESS_CLI_STATICLIB)
|
|
$(CC) $(FLAGS) -DZSTD_NOBENCH -DZSTD_NODECOMPRESS -DZSTD_NOTRACE $^ -o $@$(EXT)
|
|
|
|
RUST_DIRECT_LINK_TARGETS := zstd32 zstd-nolegacy zstd-small zstd-frugal \
|
|
zstd-decompress zstd-compress zstd-dictBuilder
|
|
$(RUST_DIRECT_LINK_TARGETS): $(RUST_HUF_C_MODE_STAMP)
|
|
|
|
CLEAN += zstdmt
|
|
zstdmt: zstd
|
|
ln -sf zstd zstdmt
|
|
|
|
.PHONY: generate_res
|
|
generate_res: $(RES64_FILE) $(RES32_FILE)
|
|
|
|
ifneq (,$(filter Windows%,$(OS)))
|
|
RC ?= windres
|
|
# https://stackoverflow.com/questions/708238/how-do-i-add-an-icon-to-a-mingw-gcc-compiled-executable
|
|
$(RES64_FILE): windres/zstd.rc
|
|
$(RC) -o $@ -I ../lib -I windres -i $< -O coff -F pe-x86-64
|
|
$(RES32_FILE): windres/zstd.rc
|
|
$(RC) -o $@ -I ../lib -I windres -i $< -O coff -F pe-i386
|
|
endif
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(RM) $(CLEAN) core *.o tmp* result* dictionary *.zst \
|
|
*.gcda default*.profraw default.profdata have_zlib
|
|
$(RM) -r obj/*
|
|
@echo Cleaning completed
|
|
|
|
MD2ROFF = ronn
|
|
MD2ROFF_FLAGS = --roff --warnings --manual="User Commands" --organization="zstd $(ZSTD_VERSION)"
|
|
|
|
zstd.1: zstd.1.md ../lib/zstd.h
|
|
cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
|
|
|
|
zstdgrep.1: zstdgrep.1.md ../lib/zstd.h
|
|
cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
|
|
|
|
zstdless.1: zstdless.1.md ../lib/zstd.h
|
|
cat $< | $(MD2ROFF) $(MD2ROFF_FLAGS) | sed -n '/^\.\\\".*/!p' > $@
|
|
|
|
.PHONY: man
|
|
man: zstd.1 zstdgrep.1 zstdless.1
|
|
|
|
.PHONY: clean-man
|
|
clean-man:
|
|
$(RM) zstd.1
|
|
$(RM) zstdgrep.1
|
|
$(RM) zstdless.1
|
|
|
|
.PHONY: preview-man
|
|
preview-man: clean-man man
|
|
man ./zstd.1
|
|
man ./zstdgrep.1
|
|
man ./zstdless.1
|
|
|
|
|
|
# Generate .h dependencies automatically
|
|
|
|
DEPFLAGS = -MT $@ -MMD -MP -MF
|
|
|
|
$(BUILD_DIR)/%.o : %.c $(BUILD_DIR)/%.d | $(BUILD_DIR)
|
|
@echo CC $@
|
|
$(COMPILE.c) $(DEPFLAGS) $(BUILD_DIR)/$*.d $(OUTPUT_OPTION) $<
|
|
|
|
$(BUILD_DIR)/%.o : %.S | $(BUILD_DIR)
|
|
@echo AS $@
|
|
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
|
|
|
MKDIR ?= mkdir
|
|
$(BUILD_DIR): ; $(MKDIR) -p $@
|
|
|
|
DEPFILES := $(ZSTD_OBJ:.o=.d)
|
|
$(DEPFILES):
|
|
|
|
include $(wildcard $(DEPFILES))
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
|
|
#-----------------------------------------------------------------------------
|
|
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME)))
|
|
|
|
HAVE_COLORNEVER = $(shell echo a | egrep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
|
|
EGREP_OPTIONS ?=
|
|
ifeq ($(HAVE_COLORNEVER), 1)
|
|
EGREP_OPTIONS += --color=never
|
|
endif
|
|
EGREP = egrep $(EGREP_OPTIONS)
|
|
AWK = awk
|
|
|
|
# Print a two column output of targets and their description. To add a target description, put a
|
|
# comment in the Makefile with the format "## <TARGET>: <DESCRIPTION>". For example:
|
|
#
|
|
## list: Print all targets and their descriptions (if provided)
|
|
.PHONY: list
|
|
list:
|
|
TARGETS=$$($(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null \
|
|
| $(AWK) -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
|
|
| $(EGREP) -v -e '^[^[:alnum:]]' | sort); \
|
|
{ \
|
|
printf "Target Name\tDescription\n"; \
|
|
printf "%0.s-" {1..16}; printf "\t"; printf "%0.s-" {1..40}; printf "\n"; \
|
|
for target in $$TARGETS; do \
|
|
line=$$($(EGREP) "^##[[:space:]]+$$target:" $(lastword $(MAKEFILE_LIST))); \
|
|
description=$$(echo $$line | $(AWK) '{i=index($$0,":"); print substr($$0,i+1)}' | xargs); \
|
|
printf "$$target\t$$description\n"; \
|
|
done \
|
|
} | column -t -s $$'\t'
|
|
|
|
|
|
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)
|
|
bindir ?= $(exec_prefix)/bin
|
|
BINDIR ?= $(bindir)
|
|
datarootdir ?= $(PREFIX)/share
|
|
mandir ?= $(datarootdir)/man
|
|
man1dir ?= $(mandir)/man1
|
|
|
|
ifneq (,$(filter OpenBSD NetBSD DragonFly SunOS,$(UNAME)))
|
|
MANDIR ?= $(PREFIX)/man
|
|
MAN1DIR ?= $(MANDIR)/man1
|
|
else
|
|
MAN1DIR ?= $(man1dir)
|
|
endif
|
|
|
|
ifneq (,$(filter SunOS,$(UNAME)))
|
|
INSTALL ?= ginstall
|
|
else
|
|
INSTALL ?= install
|
|
endif
|
|
|
|
INSTALL_PROGRAM ?= $(INSTALL)
|
|
INSTALL_SCRIPT ?= $(INSTALL_PROGRAM)
|
|
INSTALL_DATA ?= $(INSTALL) -m 644
|
|
INSTALL_MAN ?= $(INSTALL_DATA)
|
|
|
|
.PHONY: install
|
|
install:
|
|
# generate zstd only if not already present
|
|
[ -e zstd ] || $(MAKE) zstd-release
|
|
[ -e $(DESTDIR)$(BINDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)/
|
|
[ -e $(DESTDIR)$(MAN1DIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(MAN1DIR)/
|
|
@echo Installing binaries
|
|
$(INSTALL_PROGRAM) zstd$(EXT) $(DESTDIR)$(BINDIR)/zstd$(EXT)
|
|
ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdcat$(EXT)
|
|
ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/unzstd$(EXT)
|
|
ln -sf zstd$(EXT) $(DESTDIR)$(BINDIR)/zstdmt$(EXT)
|
|
$(INSTALL_SCRIPT) zstdless $(DESTDIR)$(BINDIR)/zstdless
|
|
$(INSTALL_SCRIPT) zstdgrep $(DESTDIR)$(BINDIR)/zstdgrep
|
|
@echo Installing man pages
|
|
$(INSTALL_MAN) zstd.1 $(DESTDIR)$(MAN1DIR)/zstd.1
|
|
ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/zstdcat.1
|
|
ln -sf zstd.1 $(DESTDIR)$(MAN1DIR)/unzstd.1
|
|
$(INSTALL_MAN) zstdgrep.1 $(DESTDIR)$(MAN1DIR)/zstdgrep.1
|
|
$(INSTALL_MAN) zstdless.1 $(DESTDIR)$(MAN1DIR)/zstdless.1
|
|
@echo zstd installation completed
|
|
|
|
.PHONY: uninstall
|
|
uninstall:
|
|
$(RM) $(DESTDIR)$(BINDIR)/zstdgrep
|
|
$(RM) $(DESTDIR)$(BINDIR)/zstdless
|
|
$(RM) $(DESTDIR)$(BINDIR)/zstdcat
|
|
$(RM) $(DESTDIR)$(BINDIR)/unzstd
|
|
$(RM) $(DESTDIR)$(BINDIR)/zstdmt
|
|
$(RM) $(DESTDIR)$(BINDIR)/zstd
|
|
$(RM) $(DESTDIR)$(MAN1DIR)/zstdless.1
|
|
$(RM) $(DESTDIR)$(MAN1DIR)/zstdgrep.1
|
|
$(RM) $(DESTDIR)$(MAN1DIR)/zstdcat.1
|
|
$(RM) $(DESTDIR)$(MAN1DIR)/unzstd.1
|
|
$(RM) $(DESTDIR)$(MAN1DIR)/zstd.1
|
|
@echo zstd programs successfully uninstalled
|
|
|
|
endif
|