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"
+# Find this file!
+resolve_include() {
+ local srcdir=$1
+ local inc=$2
+ for root in $srcdir $ROOTS; do
+ if [ -f "$root/$inc" ]; then
+ echo "$(realpath --relative-to . "$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
+ # Get directory to 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 '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"
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 ****/"
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
done < "$file"
else
write_line "#error Unable to find \"$1\""
+ if [ -n "$DESTN" ]; then
+ # Log but only if not writing to stdout
+ echo "Error: Unable to find: \"$1\""
+ fi
fi
}
printf "" > "$DESTN"
fi
test_grep
- add_file $1
+ add_file "$1"
else
echo "Input file not found: \"$1\""
exit 1
# 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"
# 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"
*
* 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
*/
/*
#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"
*
* 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
*/
/*
#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"