diff --git a/contrib/single_file_libs/combine.sh b/contrib/single_file_libs/combine.sh index ea99717f8..05c7bce8e 100755 --- a/contrib/single_file_libs/combine.sh +++ b/contrib/single_file_libs/combine.sh @@ -41,11 +41,15 @@ usage() { } # Tests that the grep implementation works as expected (older OSX grep fails) -test_grep() { +test_deps() { if ! echo '#include "foo"' | grep -Eq '^\s*#\s*include\s*".+"'; then echo "Aborting: the grep implementation fails to parse include lines" exit 1 fi + if ! echo '"foo.h"' | sed -E 's/"([^"]+)"/\1/' | grep -Eq '^foo\.h$'; then + echo "Aborting: sed is unavailable or non-functional" + exit 1 + fi } # Tests if list $1 has item $2 (returning zero on a match) @@ -66,41 +70,75 @@ write_line() { fi } -# Adds the contents of $1 with any of its includes inlined -add_file() { - # Match the path - local file= - for root in $ROOTS; do - if [ -f "$root/$1" ]; then - file="$root/$1" +log_line() { + echo $@ >&2 +} + +# Find this file! +resolve_include() { + local srcdir=$1 + local inc=$2 + for root in $srcdir $ROOTS; do + if [ -f "$root/$inc" ]; then + # Try to reduce the file path into a canonical form (so that multiple) + # includes of the same file are successfully deduplicated, even if they + # are expressed differently. + local relpath="$(realpath --relative-to . "$root/$inc" 2>/dev/null)" + if [ "$relpath" != "" ]; then # not all realpaths support --relative-to + echo "$relpath" + return 0 + fi + local relpath="$(realpath "$root/$inc" 2>/dev/null)" + if [ "$relpath" != "" ]; then # not all distros have realpath... + echo "$relpath" + return 0 + fi + # Worst case, fall back to just the root + relative include path. The + # problem with this is that it is possible to emit multiple different + # resolved paths to the same file, depending on exactly how its included. + # Since the main loop below keeps a list of the resolved paths it's + # already included, in order to avoid repeated includes, this failure to + # produce a canonical/reduced path can lead to multiple inclusions of the + # same file. But it seems like the resulting single file library still + # works (hurray include guards!), so I guess it's ok. + echo "$root/$inc" + return 0 fi done + return 1 +} + +# Adds the contents of $1 with any of its includes inlined +add_file() { + local file=$1 if [ -n "$file" ]; then - if [ -n "$DESTN" ]; then - # Log but only if not writing to stdout - echo "Processing: $file" - fi + log_line "Processing: $file" + # Get directory of the current so we can resolve relative includes + local srcdir="$(dirname "$file")" # Read the file local line= while IFS= read -r line; do if echo "$line" | grep -Eq '^\s*#\s*include\s*".+"'; then # We have an include directive so strip the (first) file - local inc=$(echo "$line" | grep -Eo '".*"' | grep -Eo '\w*(\.?\w+)+' | head -1) + local inc=$(echo "$line" | grep -Eo '".*"' | sed -E 's/"([^"]+)"/\1/' | head -1) + local res_inc="$(resolve_include "$srcdir" "$inc")" if list_has_item "$XINCS" "$inc"; then # The file was excluded so error if the source attempts to use it write_line "#error Using excluded file: $inc" + log_line "Excluding: $inc" else - if ! list_has_item "$FOUND" "$inc"; then + if ! list_has_item "$FOUND" "$res_inc"; then # The file was not previously encountered - FOUND="$FOUND $inc" + FOUND="$FOUND $res_inc" if list_has_item "$KINCS" "$inc"; then # But the include was flagged to keep as included write_line "/**** *NOT* inlining $inc ****/" write_line "$line" + log_line "Not Inlining: $inc" else # The file was neither excluded nor seen before so inline it write_line "/**** start inlining $inc ****/" - add_file "$inc" + add_file "$res_inc" write_line "/**** ended inlining $inc ****/" fi else @@ -122,6 +160,7 @@ add_file() { done < "$file" else write_line "#error Unable to find \"$1\"" + log_line "Error: Unable to find: \"$1\"" fi } @@ -154,8 +193,8 @@ if [ -n "$1" ]; then if [ -n "$DESTN" ]; then printf "" > "$DESTN" fi - test_grep - add_file $1 + test_deps + add_file "$1" else echo "Input file not found: \"$1\"" exit 1 diff --git a/contrib/single_file_libs/create_single_file_decoder.sh b/contrib/single_file_libs/create_single_file_decoder.sh index ad249ccd7..b5f5613ae 100755 --- a/contrib/single_file_libs/create_single_file_decoder.sh +++ b/contrib/single_file_libs/create_single_file_decoder.sh @@ -5,7 +5,7 @@ ZSTD_SRC_ROOT="../../lib" # Amalgamate the sources echo "Amalgamating files... this can take a while" -./combine.sh -r "$ZSTD_SRC_ROOT" -r "$ZSTD_SRC_ROOT/common" -r "$ZSTD_SRC_ROOT/decompress" -o zstddeclib.c zstddeclib-in.c +./combine.sh -r "$ZSTD_SRC_ROOT" -o zstddeclib.c zstddeclib-in.c # Did combining work? if [ $? -ne 0 ]; then echo "Combine script: FAILED" diff --git a/contrib/single_file_libs/create_single_file_library.sh b/contrib/single_file_libs/create_single_file_library.sh index 68bbfbd27..6cbff4595 100755 --- a/contrib/single_file_libs/create_single_file_library.sh +++ b/contrib/single_file_libs/create_single_file_library.sh @@ -5,7 +5,7 @@ ZSTD_SRC_ROOT="../../lib" # Amalgamate the sources echo "Amalgamating files... this can take a while" -./combine.sh -r "$ZSTD_SRC_ROOT" -r "$ZSTD_SRC_ROOT/common" -r "$ZSTD_SRC_ROOT/compress" -r "$ZSTD_SRC_ROOT/decompress" -k zstd.h -o zstd.c zstd-in.c +./combine.sh -r "$ZSTD_SRC_ROOT" -k zstd.h -o zstd.c zstd-in.c # Did combining work? if [ $? -ne 0 ]; then echo "Combine script: FAILED" diff --git a/contrib/single_file_libs/zstd-in.c b/contrib/single_file_libs/zstd-in.c index c35512264..aa197a682 100644 --- a/contrib/single_file_libs/zstd-in.c +++ b/contrib/single_file_libs/zstd-in.c @@ -4,7 +4,7 @@ * * Generate using: * \code - * combine.sh -r ../../lib -r ../../lib/common -r ../../lib/compress -r ../../lib/decompress -k zstd.h -o zstd.c zstd-in.c + * combine.sh -r ../../lib -k zstd.h -o zstd.c zstd-in.c * \endcode */ /* @@ -46,34 +46,31 @@ #define ZSTD_MULTITHREAD #endif -/* lib/common */ -#include "debug.c" -#include "entropy_common.c" -#include "error_private.c" -#include "fse_decompress.c" -#include "threading.c" -#include "pool.c" -#include "zstd_common.c" +#include "common/debug.c" +#include "common/entropy_common.c" +#include "common/error_private.c" +#include "common/fse_decompress.c" +#include "common/threading.c" +#include "common/pool.c" +#include "common/zstd_common.c" -/* lib/compress */ -#include "fse_compress.c" -#include "hist.c" -#include "huf_compress.c" -#include "zstd_compress_literals.c" -#include "zstd_compress_sequences.c" -#include "zstd_compress_superblock.c" -#include "zstd_compress.c" -#include "zstd_double_fast.c" -#include "zstd_fast.c" -#include "zstd_lazy.c" -#include "zstd_ldm.c" -#include "zstd_opt.c" +#include "compress/fse_compress.c" +#include "compress/hist.c" +#include "compress/huf_compress.c" +#include "compress/zstd_compress_literals.c" +#include "compress/zstd_compress_sequences.c" +#include "compress/zstd_compress_superblock.c" +#include "compress/zstd_compress.c" +#include "compress/zstd_double_fast.c" +#include "compress/zstd_fast.c" +#include "compress/zstd_lazy.c" +#include "compress/zstd_ldm.c" +#include "compress/zstd_opt.c" #ifdef ZSTD_MULTITHREAD -#include "zstdmt_compress.c" +#include "compress/zstdmt_compress.c" #endif -/* lib/decompress */ -#include "huf_decompress.c" -#include "zstd_ddict.c" -#include "zstd_decompress.c" -#include "zstd_decompress_block.c" +#include "decompress/huf_decompress.c" +#include "decompress/zstd_ddict.c" +#include "decompress/zstd_decompress.c" +#include "decompress/zstd_decompress_block.c" diff --git a/contrib/single_file_libs/zstddeclib-in.c b/contrib/single_file_libs/zstddeclib-in.c old mode 100755 new mode 100644 index c447bc25c..a9083dd34 --- a/contrib/single_file_libs/zstddeclib-in.c +++ b/contrib/single_file_libs/zstddeclib-in.c @@ -4,7 +4,7 @@ * * Generate using: * \code - * combine.sh -r ../../lib -r ../../lib/common -r ../../lib/decompress -o zstddeclib.c zstddeclib-in.c + * combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c * \endcode */ /* @@ -42,15 +42,13 @@ #define ZSTD_NOBENCH #define ZSTD_STRIP_ERROR_STRINGS -/* lib/common */ -#include "debug.c" -#include "entropy_common.c" -#include "error_private.c" -#include "fse_decompress.c" -#include "zstd_common.c" +#include "common/debug.c" +#include "common/entropy_common.c" +#include "common/error_private.c" +#include "common/fse_decompress.c" +#include "common/zstd_common.c" -/* lib/decompress */ -#include "huf_decompress.c" -#include "zstd_ddict.c" -#include "zstd_decompress.c" -#include "zstd_decompress_block.c" +#include "decompress/huf_decompress.c" +#include "decompress/zstd_ddict.c" +#include "decompress/zstd_decompress.c" +#include "decompress/zstd_decompress_block.c" diff --git a/lib/Makefile b/lib/Makefile index 025de8e54..4e3598acc 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT)) VERSION?= $(LIBVER) CCVER := $(shell $(CC) --version) -CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_ +CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_ ifeq ($(OS),Windows_NT) # MinGW assumed CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting endif @@ -149,7 +149,6 @@ ifneq ($(ZSTD_LEGACY_SUPPORT), 0) ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]') endif - CPPFLAGS += -I./legacy endif CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT) diff --git a/lib/common/pool.h b/lib/common/pool.h index 8503e2d23..259bafc97 100644 --- a/lib/common/pool.h +++ b/lib/common/pool.h @@ -18,7 +18,7 @@ extern "C" { #include /* size_t */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */ -#include "zstd.h" +#include "../zstd.h" typedef struct POOL_ctx_s POOL_ctx; diff --git a/lib/common/zstd_internal.h b/lib/common/zstd_internal.h index 57a6137e1..bd08de821 100644 --- a/lib/common/zstd_internal.h +++ b/lib/common/zstd_internal.h @@ -24,7 +24,7 @@ #include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */ #include "error_private.h" #define ZSTD_STATIC_LINKING_ONLY -#include "zstd.h" +#include "../zstd.h" #define FSE_STATIC_LINKING_ONLY #include "fse.h" #define HUF_STATIC_LINKING_ONLY diff --git a/lib/compress/fse_compress.c b/lib/compress/fse_compress.c index e09b646df..a42759814 100644 --- a/lib/compress/fse_compress.c +++ b/lib/compress/fse_compress.c @@ -17,14 +17,14 @@ ****************************************************************/ #include /* malloc, free, qsort */ #include /* memcpy, memset */ -#include "compiler.h" -#include "mem.h" /* U32, U16, etc. */ -#include "debug.h" /* assert, DEBUGLOG */ +#include "../common/compiler.h" +#include "../common/mem.h" /* U32, U16, etc. */ +#include "../common/debug.h" /* assert, DEBUGLOG */ #include "hist.h" /* HIST_count_wksp */ -#include "bitstream.h" +#include "../common/bitstream.h" #define FSE_STATIC_LINKING_ONLY -#include "fse.h" -#include "error_private.h" +#include "../common/fse.h" +#include "../common/error_private.h" /* ************************************************************** diff --git a/lib/compress/hist.c b/lib/compress/hist.c index c17b9725f..61e08c796 100644 --- a/lib/compress/hist.c +++ b/lib/compress/hist.c @@ -14,9 +14,9 @@ ****************************************************************** */ /* --- dependencies --- */ -#include "mem.h" /* U32, BYTE, etc. */ -#include "debug.h" /* assert, DEBUGLOG */ -#include "error_private.h" /* ERROR */ +#include "../common/mem.h" /* U32, BYTE, etc. */ +#include "../common/debug.h" /* assert, DEBUGLOG */ +#include "../common/error_private.h" /* ERROR */ #include "hist.h" diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index 4efffbb54..546879868 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -25,14 +25,14 @@ ****************************************************************/ #include /* memcpy, memset */ #include /* printf (debug) */ -#include "compiler.h" -#include "bitstream.h" +#include "../common/compiler.h" +#include "../common/bitstream.h" #include "hist.h" #define FSE_STATIC_LINKING_ONLY /* FSE_optimalTableLog_internal */ -#include "fse.h" /* header compression */ +#include "../common/fse.h" /* header compression */ #define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "error_private.h" +#include "../common/huf.h" +#include "../common/error_private.h" /* ************************************************************** diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 22f5542eb..ff8a00e6b 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -13,13 +13,13 @@ ***************************************/ #include /* INT_MAX */ #include /* memset */ -#include "cpu.h" -#include "mem.h" -#include "hist.h" /* HIST_countFast_wksp */ +#include "../common/cpu.h" +#include "../common/mem.h" +#include "hist.h" /* HIST_countFast_wksp */ #define FSE_STATIC_LINKING_ONLY /* FSE_encodeSymbol */ -#include "fse.h" +#include "../common/fse.h" #define HUF_STATIC_LINKING_ONLY -#include "huf.h" +#include "../common/huf.h" #include "zstd_compress_internal.h" #include "zstd_compress_sequences.h" #include "zstd_compress_literals.h" diff --git a/lib/compress/zstd_compress_internal.h b/lib/compress/zstd_compress_internal.h index d95eb1bf9..8a16c371a 100644 --- a/lib/compress/zstd_compress_internal.h +++ b/lib/compress/zstd_compress_internal.h @@ -18,7 +18,7 @@ /*-************************************* * Dependencies ***************************************/ -#include "zstd_internal.h" +#include "../common/zstd_internal.h" #include "zstd_cwksp.h" #ifdef ZSTD_MULTITHREAD # include "zstdmt_compress.h" diff --git a/lib/compress/zstd_compress_sequences.h b/lib/compress/zstd_compress_sequences.h index b884e45b4..68c6f9a5a 100644 --- a/lib/compress/zstd_compress_sequences.h +++ b/lib/compress/zstd_compress_sequences.h @@ -11,8 +11,8 @@ #ifndef ZSTD_COMPRESS_SEQUENCES_H #define ZSTD_COMPRESS_SEQUENCES_H -#include "fse.h" /* FSE_repeat, FSE_CTable */ -#include "zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */ +#include "../common/fse.h" /* FSE_repeat, FSE_CTable */ +#include "../common/zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */ typedef enum { ZSTD_defaultDisallowed = 0, diff --git a/lib/compress/zstd_compress_superblock.c b/lib/compress/zstd_compress_superblock.c index e44a14b62..b693866c0 100644 --- a/lib/compress/zstd_compress_superblock.c +++ b/lib/compress/zstd_compress_superblock.c @@ -11,12 +11,13 @@ /*-************************************* * Dependencies ***************************************/ -#include "hist.h" /* HIST_countFast_wksp */ +#include "zstd_compress_superblock.h" + +#include "../common/zstd_internal.h" /* ZSTD_getSequenceLength */ +#include "hist.h" /* HIST_countFast_wksp */ #include "zstd_compress_internal.h" #include "zstd_compress_sequences.h" #include "zstd_compress_literals.h" -#include "zstd_compress_superblock.h" -#include "zstd_internal.h" /* ZSTD_getSequenceLength */ /*-************************************* * Superblock entropy buffer structs diff --git a/lib/compress/zstd_compress_superblock.h b/lib/compress/zstd_compress_superblock.h index 35d207299..07f4cb1dc 100644 --- a/lib/compress/zstd_compress_superblock.h +++ b/lib/compress/zstd_compress_superblock.h @@ -15,7 +15,7 @@ * Dependencies ***************************************/ -#include "zstd.h" /* ZSTD_CCtx */ +#include "../zstd.h" /* ZSTD_CCtx */ /*-************************************* * Target Compressed Block Size diff --git a/lib/compress/zstd_cwksp.h b/lib/compress/zstd_cwksp.h index 91f812fa3..a25c9263b 100644 --- a/lib/compress/zstd_cwksp.h +++ b/lib/compress/zstd_cwksp.h @@ -14,7 +14,7 @@ /*-************************************* * Dependencies ***************************************/ -#include "zstd_internal.h" +#include "../common/zstd_internal.h" #if defined (__cplusplus) extern "C" { diff --git a/lib/compress/zstd_double_fast.h b/lib/compress/zstd_double_fast.h index 73a2002f3..14d944d69 100644 --- a/lib/compress/zstd_double_fast.h +++ b/lib/compress/zstd_double_fast.h @@ -15,7 +15,7 @@ extern "C" { #endif -#include "mem.h" /* U32 */ +#include "../common/mem.h" /* U32 */ #include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms, diff --git a/lib/compress/zstd_fast.h b/lib/compress/zstd_fast.h index 3e15cc85c..cf6aaa8e6 100644 --- a/lib/compress/zstd_fast.h +++ b/lib/compress/zstd_fast.h @@ -15,7 +15,7 @@ extern "C" { #endif -#include "mem.h" /* U32 */ +#include "../common/mem.h" /* U32 */ #include "zstd_compress_internal.h" void ZSTD_fillHashTable(ZSTD_matchState_t* ms, diff --git a/lib/compress/zstd_ldm.c b/lib/compress/zstd_ldm.c index 0e72c0b59..2a1c2cd62 100644 --- a/lib/compress/zstd_ldm.c +++ b/lib/compress/zstd_ldm.c @@ -10,7 +10,7 @@ #include "zstd_ldm.h" -#include "debug.h" +#include "../common/debug.h" #include "zstd_fast.h" /* ZSTD_fillHashTable() */ #include "zstd_double_fast.h" /* ZSTD_fillDoubleHashTable() */ diff --git a/lib/compress/zstd_ldm.h b/lib/compress/zstd_ldm.h index aa2b6c52e..229ea05a9 100644 --- a/lib/compress/zstd_ldm.h +++ b/lib/compress/zstd_ldm.h @@ -16,7 +16,7 @@ extern "C" { #endif #include "zstd_compress_internal.h" /* ldmParams_t, U32 */ -#include "zstd.h" /* ZSTD_CCtx, size_t */ +#include "../zstd.h" /* ZSTD_CCtx, size_t */ /*-************************************* * Long distance matching diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 56186f506..f6b26a757 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -22,9 +22,9 @@ /* ====== Dependencies ====== */ #include /* memcpy, memset */ #include /* INT_MAX, UINT_MAX */ -#include "mem.h" /* MEM_STATIC */ -#include "pool.h" /* threadpool */ -#include "threading.h" /* mutex */ +#include "../common/mem.h" /* MEM_STATIC */ +#include "../common/pool.h" /* threadpool */ +#include "../common/threading.h" /* mutex */ #include "zstd_compress_internal.h" /* MIN, ERROR, ZSTD_*, ZSTD_highbit32 */ #include "zstd_ldm.h" #include "zstdmt_compress.h" diff --git a/lib/compress/zstdmt_compress.h b/lib/compress/zstdmt_compress.h index b90fd389a..89914eb7f 100644 --- a/lib/compress/zstdmt_compress.h +++ b/lib/compress/zstdmt_compress.h @@ -40,7 +40,7 @@ /* === Dependencies === */ #include /* size_t */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */ -#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */ +#include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */ /* === Constants === */ diff --git a/lib/decompress/huf_decompress.c b/lib/decompress/huf_decompress.c index ab5db481c..68293a130 100644 --- a/lib/decompress/huf_decompress.c +++ b/lib/decompress/huf_decompress.c @@ -16,12 +16,12 @@ * Dependencies ****************************************************************/ #include /* memcpy, memset */ -#include "compiler.h" -#include "bitstream.h" /* BIT_* */ -#include "fse.h" /* to compress headers */ +#include "../common/compiler.h" +#include "../common/bitstream.h" /* BIT_* */ +#include "../common/fse.h" /* to compress headers */ #define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "error_private.h" +#include "../common/huf.h" +#include "../common/error_private.h" /* ************************************************************** * Macros diff --git a/lib/decompress/zstd_ddict.c b/lib/decompress/zstd_ddict.c index 70477ca7d..042a7bc85 100644 --- a/lib/decompress/zstd_ddict.c +++ b/lib/decompress/zstd_ddict.c @@ -15,17 +15,17 @@ * Dependencies *********************************************************/ #include /* memcpy, memmove, memset */ -#include "cpu.h" /* bmi2 */ -#include "mem.h" /* low level memory routines */ +#include "../common/cpu.h" /* bmi2 */ +#include "../common/mem.h" /* low level memory routines */ #define FSE_STATIC_LINKING_ONLY -#include "fse.h" +#include "../common/fse.h" #define HUF_STATIC_LINKING_ONLY -#include "huf.h" +#include "../common/huf.h" #include "zstd_decompress_internal.h" #include "zstd_ddict.h" #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) -# include "zstd_legacy.h" +# include "../legacy/zstd_legacy.h" #endif diff --git a/lib/decompress/zstd_ddict.h b/lib/decompress/zstd_ddict.h index 3ab7532ee..af307efd3 100644 --- a/lib/decompress/zstd_ddict.h +++ b/lib/decompress/zstd_ddict.h @@ -16,7 +16,7 @@ * Dependencies *********************************************************/ #include /* size_t */ -#include "zstd.h" /* ZSTD_DDict, and several public functions */ +#include "../zstd.h" /* ZSTD_DDict, and several public functions */ /*-******************************************************* diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 91adb8a6e..90ddeaabe 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -56,19 +56,19 @@ * Dependencies *********************************************************/ #include /* memcpy, memmove, memset */ -#include "cpu.h" /* bmi2 */ -#include "mem.h" /* low level memory routines */ +#include "../common/cpu.h" /* bmi2 */ +#include "../common/mem.h" /* low level memory routines */ #define FSE_STATIC_LINKING_ONLY -#include "fse.h" +#include "../common/fse.h" #define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "zstd_internal.h" /* blockProperties_t */ +#include "../common/huf.h" +#include "../common/zstd_internal.h" /* blockProperties_t */ #include "zstd_decompress_internal.h" /* ZSTD_DCtx */ #include "zstd_ddict.h" /* ZSTD_DDictDictContent */ #include "zstd_decompress_block.h" /* ZSTD_decompressBlock_internal */ #if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1) -# include "zstd_legacy.h" +# include "../legacy/zstd_legacy.h" #endif diff --git a/lib/decompress/zstd_decompress_block.c b/lib/decompress/zstd_decompress_block.c index 5a1226eba..6eb7462cd 100644 --- a/lib/decompress/zstd_decompress_block.c +++ b/lib/decompress/zstd_decompress_block.c @@ -15,14 +15,14 @@ * Dependencies *********************************************************/ #include /* memcpy, memmove, memset */ -#include "compiler.h" /* prefetch */ -#include "cpu.h" /* bmi2 */ -#include "mem.h" /* low level memory routines */ +#include "../common/compiler.h" /* prefetch */ +#include "../common/cpu.h" /* bmi2 */ +#include "../common/mem.h" /* low level memory routines */ #define FSE_STATIC_LINKING_ONLY -#include "fse.h" +#include "../common/fse.h" #define HUF_STATIC_LINKING_ONLY -#include "huf.h" -#include "zstd_internal.h" +#include "../common/huf.h" +#include "../common/zstd_internal.h" #include "zstd_decompress_internal.h" /* ZSTD_DCtx */ #include "zstd_ddict.h" /* ZSTD_DDictDictContent */ #include "zstd_decompress_block.h" diff --git a/lib/decompress/zstd_decompress_block.h b/lib/decompress/zstd_decompress_block.h index a065f8d93..bf39b7350 100644 --- a/lib/decompress/zstd_decompress_block.h +++ b/lib/decompress/zstd_decompress_block.h @@ -16,8 +16,8 @@ * Dependencies *********************************************************/ #include /* size_t */ -#include "zstd.h" /* DCtx, and some public functions */ -#include "zstd_internal.h" /* blockProperties_t, and some public functions */ +#include "../zstd.h" /* DCtx, and some public functions */ +#include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */ #include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */ diff --git a/lib/decompress/zstd_decompress_internal.h b/lib/decompress/zstd_decompress_internal.h index f1c2585a6..8c4f79f46 100644 --- a/lib/decompress/zstd_decompress_internal.h +++ b/lib/decompress/zstd_decompress_internal.h @@ -19,8 +19,8 @@ /*-******************************************************* * Dependencies *********************************************************/ -#include "mem.h" /* BYTE, U16, U32 */ -#include "zstd_internal.h" /* ZSTD_seqSymbol */ +#include "../common/mem.h" /* BYTE, U16, U32 */ +#include "../common/zstd_internal.h" /* ZSTD_seqSymbol */ diff --git a/lib/deprecated/zbuff.h b/lib/deprecated/zbuff.h index 7686f76a4..03cb14a03 100644 --- a/lib/deprecated/zbuff.h +++ b/lib/deprecated/zbuff.h @@ -28,7 +28,7 @@ extern "C" { * Dependencies ***************************************/ #include /* size_t */ -#include "zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ +#include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */ /* *************************************************************** @@ -186,7 +186,7 @@ ZBUFF_DEPRECATED("use ZSTD_DStreamOutSize") size_t ZBUFF_recommendedDOutSize(voi /*--- Dependency ---*/ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */ -#include "zstd.h" +#include "../zstd.h" /*--- Custom memory allocator ---*/ diff --git a/lib/deprecated/zbuff_common.c b/lib/deprecated/zbuff_common.c index e2b9613f0..579bc4df1 100644 --- a/lib/deprecated/zbuff_common.c +++ b/lib/deprecated/zbuff_common.c @@ -11,7 +11,7 @@ /*-************************************* * Dependencies ***************************************/ -#include "error_private.h" +#include "../common/error_private.h" #include "zbuff.h" /*-**************************************** diff --git a/lib/dictBuilder/cover.c b/lib/dictBuilder/cover.c index b57981c52..da54ef15f 100644 --- a/lib/dictBuilder/cover.c +++ b/lib/dictBuilder/cover.c @@ -26,11 +26,11 @@ #include /* memset */ #include /* clock */ -#include "mem.h" /* read */ -#include "pool.h" -#include "threading.h" +#include "../common/mem.h" /* read */ +#include "../common/pool.h" +#include "../common/threading.h" #include "cover.h" -#include "zstd_internal.h" /* includes zstd.h */ +#include "../common/zstd_internal.h" /* includes zstd.h */ #ifndef ZDICT_STATIC_LINKING_ONLY #define ZDICT_STATIC_LINKING_ONLY #endif diff --git a/lib/dictBuilder/cover.h b/lib/dictBuilder/cover.h index 77943f0a7..f2aa0e35e 100644 --- a/lib/dictBuilder/cover.h +++ b/lib/dictBuilder/cover.h @@ -12,10 +12,10 @@ #include /* malloc, free, qsort */ #include /* memset */ #include /* clock */ -#include "mem.h" /* read */ -#include "pool.h" -#include "threading.h" -#include "zstd_internal.h" /* includes zstd.h */ +#include "../common/mem.h" /* read */ +#include "../common/pool.h" +#include "../common/threading.h" +#include "../common/zstd_internal.h" /* includes zstd.h */ #ifndef ZDICT_STATIC_LINKING_ONLY #define ZDICT_STATIC_LINKING_ONLY #endif diff --git a/lib/dictBuilder/fastcover.c b/lib/dictBuilder/fastcover.c index 5bc9ca50f..485c333b5 100644 --- a/lib/dictBuilder/fastcover.c +++ b/lib/dictBuilder/fastcover.c @@ -16,11 +16,11 @@ #include /* memset */ #include /* clock */ -#include "mem.h" /* read */ -#include "pool.h" -#include "threading.h" +#include "../common/mem.h" /* read */ +#include "../common/pool.h" +#include "../common/threading.h" #include "cover.h" -#include "zstd_internal.h" /* includes zstd.h */ +#include "../common/zstd_internal.h" /* includes zstd.h */ #ifndef ZDICT_STATIC_LINKING_ONLY #define ZDICT_STATIC_LINKING_ONLY #endif diff --git a/lib/dictBuilder/zdict.c b/lib/dictBuilder/zdict.c index 6fa1ca699..6d0b04231 100644 --- a/lib/dictBuilder/zdict.c +++ b/lib/dictBuilder/zdict.c @@ -37,18 +37,18 @@ #include /* fprintf, fopen, ftello64 */ #include /* clock */ -#include "mem.h" /* read */ -#include "fse.h" /* FSE_normalizeCount, FSE_writeNCount */ +#include "../common/mem.h" /* read */ +#include "../common/fse.h" /* FSE_normalizeCount, FSE_writeNCount */ #define HUF_STATIC_LINKING_ONLY -#include "huf.h" /* HUF_buildCTable, HUF_writeCTable */ -#include "zstd_internal.h" /* includes zstd.h */ -#include "xxhash.h" /* XXH64 */ +#include "../common/huf.h" /* HUF_buildCTable, HUF_writeCTable */ +#include "../common/zstd_internal.h" /* includes zstd.h */ +#include "../common/xxhash.h" /* XXH64 */ #include "divsufsort.h" #ifndef ZDICT_STATIC_LINKING_ONLY # define ZDICT_STATIC_LINKING_ONLY #endif #include "zdict.h" -#include "compress/zstd_compress_internal.h" /* ZSTD_loadCEntropy() */ +#include "../compress/zstd_compress_internal.h" /* ZSTD_loadCEntropy() */ /*-************************************* diff --git a/lib/legacy/zstd_legacy.h b/lib/legacy/zstd_legacy.h index ecd968212..6bea6a519 100644 --- a/lib/legacy/zstd_legacy.h +++ b/lib/legacy/zstd_legacy.h @@ -18,9 +18,9 @@ extern "C" { /* ************************************* * Includes ***************************************/ -#include "mem.h" /* MEM_STATIC */ -#include "error_private.h" /* ERROR */ -#include "zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */ +#include "../common/mem.h" /* MEM_STATIC */ +#include "../common/error_private.h" /* ERROR */ +#include "../common/zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */ #if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0) # undef ZSTD_LEGACY_SUPPORT diff --git a/lib/legacy/zstd_v01.c b/lib/legacy/zstd_v01.c index 4d5ecf7d3..0517222ca 100644 --- a/lib/legacy/zstd_v01.c +++ b/lib/legacy/zstd_v01.c @@ -14,7 +14,7 @@ ******************************************/ #include /* size_t, ptrdiff_t */ #include "zstd_v01.h" -#include "error_private.h" +#include "../common/error_private.h" /****************************************** diff --git a/lib/legacy/zstd_v02.c b/lib/legacy/zstd_v02.c index 7105aa49a..a7aa27cdf 100644 --- a/lib/legacy/zstd_v02.c +++ b/lib/legacy/zstd_v02.c @@ -11,7 +11,7 @@ #include /* size_t, ptrdiff_t */ #include "zstd_v02.h" -#include "error_private.h" +#include "../common/error_private.h" /****************************************** diff --git a/lib/legacy/zstd_v03.c b/lib/legacy/zstd_v03.c index 980cf02f1..1b00c98bf 100644 --- a/lib/legacy/zstd_v03.c +++ b/lib/legacy/zstd_v03.c @@ -11,7 +11,7 @@ #include /* size_t, ptrdiff_t */ #include "zstd_v03.h" -#include "error_private.h" +#include "../common/error_private.h" /****************************************** diff --git a/lib/legacy/zstd_v04.c b/lib/legacy/zstd_v04.c index e5b51f782..1a3d49cf6 100644 --- a/lib/legacy/zstd_v04.c +++ b/lib/legacy/zstd_v04.c @@ -16,7 +16,7 @@ #include /* memcpy */ #include "zstd_v04.h" -#include "error_private.h" +#include "../common/error_private.h" /* ****************************************************************** diff --git a/lib/legacy/zstd_v05.c b/lib/legacy/zstd_v05.c index 649144d04..79ea59a1b 100644 --- a/lib/legacy/zstd_v05.c +++ b/lib/legacy/zstd_v05.c @@ -11,7 +11,7 @@ /*- Dependencies -*/ #include "zstd_v05.h" -#include "error_private.h" +#include "../common/error_private.h" /* ****************************************************************** diff --git a/lib/legacy/zstd_v05.h b/lib/legacy/zstd_v05.h index 6c46e8f23..167d892e6 100644 --- a/lib/legacy/zstd_v05.h +++ b/lib/legacy/zstd_v05.h @@ -19,7 +19,7 @@ extern "C" { * Dependencies ***************************************/ #include /* size_t */ -#include "mem.h" /* U64, U32 */ +#include "../common/mem.h" /* U64, U32 */ /* ************************************* diff --git a/lib/legacy/zstd_v06.c b/lib/legacy/zstd_v06.c index 288eebe81..1a670fad0 100644 --- a/lib/legacy/zstd_v06.c +++ b/lib/legacy/zstd_v06.c @@ -14,7 +14,7 @@ #include /* size_t, ptrdiff_t */ #include /* memcpy */ #include /* malloc, free, qsort */ -#include "error_private.h" +#include "../common/error_private.h" diff --git a/lib/legacy/zstd_v07.c b/lib/legacy/zstd_v07.c index 36593d38b..5393475da 100644 --- a/lib/legacy/zstd_v07.c +++ b/lib/legacy/zstd_v07.c @@ -17,14 +17,14 @@ #ifndef XXH_STATIC_LINKING_ONLY # define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */ #endif -#include "xxhash.h" /* XXH64_* */ +#include "../common/xxhash.h" /* XXH64_* */ #include "zstd_v07.h" #define FSEv07_STATIC_LINKING_ONLY /* FSEv07_MIN_TABLELOG */ #define HUFv07_STATIC_LINKING_ONLY /* HUFv07_TABLELOG_ABSOLUTEMAX */ #define ZSTDv07_STATIC_LINKING_ONLY -#include "error_private.h" +#include "../common/error_private.h" #ifdef ZSTDv07_STATIC_LINKING_ONLY diff --git a/programs/Makefile b/programs/Makefile index abad6da6b..1a85f185e 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -43,9 +43,7 @@ else ALIGN_LOOP = endif -CPPFLAGS+= -I$(ZSTDDIR) -I$(ZSTDDIR)/common -I$(ZSTDDIR)/compress \ - -I$(ZSTDDIR)/dictBuilder \ - -DXXH_NAMESPACE=ZSTD_ +CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_ ifeq ($(OS),Windows_NT) # MinGW assumed CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting endif @@ -72,7 +70,6 @@ ifneq ($(ZSTD_LEGACY_SUPPORT), 0) ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0) ZSTDLEGACY_FILES += $(shell ls $(ZSTDDIR)/legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]') endif - CPPFLAGS += -I$(ZSTDDIR)/legacy else endif diff --git a/programs/benchzstd.c b/programs/benchzstd.c index 80e98050c..77056203d 100644 --- a/programs/benchzstd.c +++ b/programs/benchzstd.c @@ -30,13 +30,13 @@ #include "timefn.h" /* UTIL_time_t */ #include "benchfn.h" -#include "mem.h" +#include "../lib/common/mem.h" #define ZSTD_STATIC_LINKING_ONLY -#include "zstd.h" +#include "../lib/zstd.h" #include "datagen.h" /* RDG_genBuffer */ -#include "xxhash.h" +#include "../lib/common/xxhash.h" #include "benchzstd.h" -#include "zstd_errors.h" +#include "../lib/common/zstd_errors.h" /* ************************************* diff --git a/programs/benchzstd.h b/programs/benchzstd.h index 99fae56a0..8c55b3c4f 100644 --- a/programs/benchzstd.h +++ b/programs/benchzstd.h @@ -24,7 +24,7 @@ extern "C" { /* === Dependencies === */ #include /* size_t */ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ -#include "zstd.h" /* ZSTD_compressionParameters */ +#include "../lib/zstd.h" /* ZSTD_compressionParameters */ /* === Constants === */ diff --git a/programs/datagen.c b/programs/datagen.c index 7cf83bdaa..4353b7ff9 100644 --- a/programs/datagen.c +++ b/programs/datagen.c @@ -18,7 +18,7 @@ #include /* malloc, free */ #include /* FILE, fwrite, fprintf */ #include /* memcpy */ -#include "mem.h" /* U32 */ +#include "../lib/common/mem.h" /* U32 */ /*-************************************ diff --git a/programs/dibio.c b/programs/dibio.c index 2b322b639..463095a8e 100644 --- a/programs/dibio.c +++ b/programs/dibio.c @@ -30,8 +30,8 @@ #include #include "timefn.h" /* UTIL_time_t, UTIL_clockSpanMicro, UTIL_getTime */ -#include "mem.h" /* read */ -#include "error_private.h" +#include "../lib/common/mem.h" /* read */ +#include "../lib/common/error_private.h" #include "dibio.h" diff --git a/programs/dibio.h b/programs/dibio.h index 436bddbb5..682723d6a 100644 --- a/programs/dibio.h +++ b/programs/dibio.h @@ -19,7 +19,7 @@ * Dependencies ***************************************/ #define ZDICT_STATIC_LINKING_ONLY -#include "zdict.h" /* ZDICT_params_t */ +#include "../lib/dictBuilder/zdict.h" /* ZDICT_params_t */ /*-************************************* diff --git a/programs/fileio.c b/programs/fileio.c index 802e6fb61..d72879d64 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -39,13 +39,13 @@ # include #endif -#include "mem.h" /* U32, U64 */ +#include "../lib/common/mem.h" /* U32, U64 */ #include "fileio.h" #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_magicNumber, ZSTD_frameHeaderSize_max */ -#include "zstd.h" -#include "zstd_errors.h" /* ZSTD_error_frameParameter_windowTooLarge */ -#include "zstd_compress_internal.h" +#include "../lib/zstd.h" +#include "../lib/common/zstd_errors.h" /* ZSTD_error_frameParameter_windowTooLarge */ +#include "../lib/compress/zstd_compress_internal.h" #if defined(ZSTD_GZCOMPRESS) || defined(ZSTD_GZDECOMPRESS) # include diff --git a/programs/fileio.h b/programs/fileio.h index 565cbae11..2fbf01f82 100644 --- a/programs/fileio.h +++ b/programs/fileio.h @@ -13,7 +13,7 @@ #define FILEIO_H_23981798732 #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */ -#include "zstd.h" /* ZSTD_* */ +#include "../lib/zstd.h" /* ZSTD_* */ #if defined (__cplusplus) extern "C" { diff --git a/programs/util.h b/programs/util.h index 40200729a..8e187e4f2 100644 --- a/programs/util.h +++ b/programs/util.h @@ -23,7 +23,7 @@ extern "C" { #include /* size_t, ptrdiff_t */ #include /* stat, utime */ #include /* stat, chmod */ -#include "mem.h" /* U64 */ +#include "../lib/common/mem.h" /* U64 */ /*-************************************************************ diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 3e293c57b..81f1910c2 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -40,7 +40,7 @@ #ifndef ZSTD_NODICT # include "dibio.h" /* ZDICT_cover_params_t, DiB_trainFromFiles() */ #endif -#include "zstd.h" /* ZSTD_VERSION_STRING, ZSTD_minCLevel, ZSTD_maxCLevel */ +#include "../lib/zstd.h" /* ZSTD_VERSION_STRING, ZSTD_minCLevel, ZSTD_maxCLevel */ /*-************************************