diff --git a/lib/Makefile b/lib/Makefile index c9bd4244927..a0fab3b0a81 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -60,6 +60,9 @@ CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL) ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting endif +ifdef ZSTD_PROGRAMS_LINK_SHARED + CPPFLAGS += -DZSTD_PROGRAMS_LINK_SHARED +endif DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \ -Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \ -Wstrict-prototypes -Wundef -Wpointer-arith \ diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index c04998b8b18..0a703245fdd 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -1198,6 +1198,9 @@ size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSe /** ZSTD_cycleLog() : * condition for correct operation : hashLog > 1 */ +#if defined(ZSTD_PROGRAMS_LINK_SHARED) +ZSTDLIB_API +#endif U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat); #endif /* ZSTD_COMPRESS_H */ diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 79c522ef367..aaf0b28863c 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -968,6 +968,9 @@ static size_t ZDICT_addEntropyTablesFromBuffer_advanced( } /* Hidden declaration for dbio.c */ +#if defined(ZSTD_PROGRAMS_LINK_SHARED) +ZSTDLIB_API +#endif size_t ZDICT_trainFromBuffer_unsafe_legacy( void* dictBuffer, size_t maxDictSize, const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples, diff --git a/programs/Makefile b/programs/Makefile index e66d182fece..e983e03e559 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -213,6 +213,10 @@ 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) +ifdef ZSTD_PROGRAMS_LINK_SHARED +zstd : LDFLAGS+= -L$(ZSTDDIR) -lzstd +zstd : ZSTDLIB_FULL_SRC = +endif ifneq (,$(filter Windows%,$(OS))) zstd : $(RES_FILE) endif @@ -226,7 +230,11 @@ zstd: else # BUILD_DIR is defined +ifndef ZSTD_PROGRAMS_LINK_SHARED ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ)) +else +ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_CLI_OBJ)) +endif $(BUILD_DIR)/zstd : $(ZSTD_OBJ) @echo "$(THREAD_MSG)" @echo "$(ZLIB_MSG)" @@ -288,20 +296,6 @@ 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 already exist) -# note : the following target doesn't link -# because zstd uses non-public symbols from libzstd -# such as XXH64 (for benchmark), -# ZDICT_trainFromBuffer_unsafe_legacy (for dictionary builder) -# and ZSTD_cycleLog (likely for --patch-from). -# It's unclear at this stage if this is a scenario that must be supported -.PHONY: zstd-dll -zstd-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd -zstd-dll : ZSTDLIB_FULL_SRC = -zstd-dll : $(ZSTD_CLI_OBJ) - $(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS) - - ## zstd-pgo: zstd executable optimized with PGO. zstd-pgo : $(MAKE) clean