diff --git a/.travis.yml b/.travis.yml index 4959e97fb..eb84aa782 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,7 @@ matrix: - env: Cmd='make lz4install && make -C tests test-lz4' + - env: Cmd='bash tests/libzstd_partial_builds.sh' # tag-specific test - if: tag =~ ^v[0-9]\.[0-9] env: Cmd='make -C tests checkTag && tests/checkTag $TRAVIS_BRANCH' diff --git a/lib/Makefile b/lib/Makefile index 3a160f88c..701cf7e9f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -28,10 +28,44 @@ DEBUGFLAGS = -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS) FLAGS = $(CPPFLAGS) $(CFLAGS) - -ZSTD_FILES := $(sort $(wildcard common/*.c compress/*.c decompress/*.c dictBuilder/*.c deprecated/*.c)) +ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c)) +ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c)) +ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c)) +ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c)) +ZDEPR_FILES := $(sort $(wildcard deprecated/*.c)) +ZSTD_FILES := $(ZSTDCOMMON_FILES) ZSTD_LEGACY_SUPPORT ?= 4 +ZSTD_LIB_COMPRESSION ?= 1 +ZSTD_LIB_DECOMPRESSION ?= 1 +ZSTD_LIB_DICTBUILDER ?= 1 +ZSTD_LIB_DEPRECATED ?= 1 + +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 + +ifneq ($(ZSTD_LIB_COMPRESSION), 0) + ZSTD_FILES += $(ZSTDCOMP_FILES) +endif + +ifneq ($(ZSTD_LIB_DECOMPRESSION), 0) + ZSTD_FILES += $(ZSTDDECOMP_FILES) +endif + +ifneq ($(ZSTD_LIB_DEPRECATED), 0) + ZSTD_FILES += $(ZDEPR_FILES) +endif + +ifneq ($(ZSTD_LIB_DICTBUILDER), 0) + ZSTD_FILES += $(ZDICT_FILES) +endif ifneq ($(ZSTD_LEGACY_SUPPORT), 0) ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) diff --git a/lib/README.md b/lib/README.md index 95196e467..75debe872 100644 --- a/lib/README.md +++ b/lib/README.md @@ -61,6 +61,10 @@ It's possible to compile only a limited set of features. Each version also provides an additional dedicated set of advanced API. For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` . Note : `lib/legacy` only supports _decoding_ legacy formats. +- Similarly, you can define `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`, + and `ZSTD_LIB_DEPRECATED` as 0 to forgo compilation of the corresponding features. This will + also disable compilation of all dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable + dictBuilder). #### Multithreading support diff --git a/tests/libzstd_partial_builds.sh b/tests/libzstd_partial_builds.sh new file mode 100755 index 000000000..34d8ea552 --- /dev/null +++ b/tests/libzstd_partial_builds.sh @@ -0,0 +1,36 @@ +#!/bin/sh -e + +die() { + $ECHO "$@" 1>&2 + exit 1 +} + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +INTOVOID="/dev/null" +case "$OS" in + Windows*) + INTOVOID="NUL" + ;; +esac + +ZSTD_LIB_COMPRESSION=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID +nm $DIR/../lib/libzstd.a | grep ".*\.o:" > tmplog +! grep -q "zstd_compress" tmplog && grep -q "zstd_decompress" tmplog && ! grep -q "dict" tmplog && grep -q "zstd_v" tmplog && ! grep -q "zbuff" tmplog && make clean && rm -f tmplog || die "Compression macro failed" + + +ZSTD_LIB_DECOMPRESSION=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID +nm $DIR/../lib/libzstd.a | grep ".*\.o:" > tmplog +grep -q "zstd_compress" tmplog && ! grep -q "zstd_decompress" tmplog && grep -q "dict" tmplog && ! grep -q "zstd_v" tmplog && ! grep -q "zbuff" tmplog && make clean && rm -f tmplog || die "Decompression macro failed" + +ZSTD_LIB_DEPRECATED=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID +nm $DIR/../lib/libzstd.a | grep ".*\.o:" > tmplog +grep -q "zstd_compress" tmplog && grep -q "zstd_decompress" tmplog && grep -q "dict" tmplog && grep -q "zstd_v" tmplog && ! grep -q "zbuff" tmplog && make clean && rm -f tmplog || die "Deprecated macro failed" + +ZSTD_LIB_DICTBUILDER=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID +nm $DIR/../lib/libzstd.a | grep ".*\.o:" > tmplog +grep -q "zstd_compress" tmplog && grep -q "zstd_decompress" tmplog && ! grep -q "dict" tmplog && grep -q "zstd_v" tmplog && grep -q "zbuff" tmplog && make clean && rm -f tmplog || die "Dictbuilder macro failed" + +ZSTD_LIB_DECOMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 CFLAGS= make -C $DIR/../lib libzstd.a > $INTOVOID +nm $DIR/../lib/libzstd.a | grep ".*\.o:" > tmplog +grep -q "zstd_compress" tmplog && ! grep -q "zstd_decompress" tmplog && ! grep -q "dict" tmplog && ! grep -q "zstd_v" tmplog && ! grep -q "zbuff" tmplog && make clean && rm -f tmplog || die "Multi-macro failed" \ No newline at end of file