Try to Fix Single File Library Combiner Script to Handle Relative Includes
This commit is contained in:
parent
7b75d772b1
commit
b48f6c7d26
@ -66,33 +66,43 @@ write_line() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Adds the contents of $1 with any of its includes inlined
|
# Find this file!
|
||||||
add_file() {
|
resolve_include() {
|
||||||
# Match the path
|
local srcdir=$1
|
||||||
local file=
|
local inc=$2
|
||||||
for root in $ROOTS; do
|
for root in $srcdir $ROOTS; do
|
||||||
if [ -f "$root/$1" ]; then
|
if [ -f "$root/$inc" ]; then
|
||||||
file="$root/$1"
|
echo "$(realpath --relative-to . "$root/$inc")"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
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 "$file" ]; then
|
||||||
if [ -n "$DESTN" ]; then
|
if [ -n "$DESTN" ]; then
|
||||||
# Log but only if not writing to stdout
|
# Log but only if not writing to stdout
|
||||||
echo "Processing: $file"
|
echo "Processing: $file"
|
||||||
fi
|
fi
|
||||||
|
# Get directory to resolve relative includes
|
||||||
|
local srcdir="$(dirname "$file")"
|
||||||
# Read the file
|
# Read the file
|
||||||
local line=
|
local line=
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
if echo "$line" | grep -Eq '^\s*#\s*include\s*".+"'; then
|
if echo "$line" | grep -Eq '^\s*#\s*include\s*".+"'; then
|
||||||
# We have an include directive so strip the (first) file
|
# 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
|
if list_has_item "$XINCS" "$inc"; then
|
||||||
# The file was excluded so error if the source attempts to use it
|
# The file was excluded so error if the source attempts to use it
|
||||||
write_line "#error Using excluded file: $inc"
|
write_line "#error Using excluded file: $inc"
|
||||||
else
|
else
|
||||||
if ! list_has_item "$FOUND" "$inc"; then
|
if ! list_has_item "$FOUND" "$res_inc"; then
|
||||||
# The file was not previously encountered
|
# The file was not previously encountered
|
||||||
FOUND="$FOUND $inc"
|
FOUND="$FOUND $res_inc"
|
||||||
if list_has_item "$KINCS" "$inc"; then
|
if list_has_item "$KINCS" "$inc"; then
|
||||||
# But the include was flagged to keep as included
|
# But the include was flagged to keep as included
|
||||||
write_line "/**** *NOT* inlining $inc ****/"
|
write_line "/**** *NOT* inlining $inc ****/"
|
||||||
@ -100,7 +110,7 @@ add_file() {
|
|||||||
else
|
else
|
||||||
# The file was neither excluded nor seen before so inline it
|
# The file was neither excluded nor seen before so inline it
|
||||||
write_line "/**** start inlining $inc ****/"
|
write_line "/**** start inlining $inc ****/"
|
||||||
add_file "$inc"
|
add_file "$res_inc"
|
||||||
write_line "/**** ended inlining $inc ****/"
|
write_line "/**** ended inlining $inc ****/"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
@ -122,6 +132,10 @@ add_file() {
|
|||||||
done < "$file"
|
done < "$file"
|
||||||
else
|
else
|
||||||
write_line "#error Unable to find \"$1\""
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +169,7 @@ if [ -n "$1" ]; then
|
|||||||
printf "" > "$DESTN"
|
printf "" > "$DESTN"
|
||||||
fi
|
fi
|
||||||
test_grep
|
test_grep
|
||||||
add_file $1
|
add_file "$1"
|
||||||
else
|
else
|
||||||
echo "Input file not found: \"$1\""
|
echo "Input file not found: \"$1\""
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -5,7 +5,7 @@ ZSTD_SRC_ROOT="../../lib"
|
|||||||
|
|
||||||
# Amalgamate the sources
|
# Amalgamate the sources
|
||||||
echo "Amalgamating files... this can take a while"
|
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?
|
# Did combining work?
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Combine script: FAILED"
|
echo "Combine script: FAILED"
|
||||||
|
@ -5,7 +5,7 @@ ZSTD_SRC_ROOT="../../lib"
|
|||||||
|
|
||||||
# Amalgamate the sources
|
# Amalgamate the sources
|
||||||
echo "Amalgamating files... this can take a while"
|
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?
|
# Did combining work?
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Combine script: FAILED"
|
echo "Combine script: FAILED"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Generate using:
|
* Generate using:
|
||||||
* \code
|
* \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
|
* \endcode
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@ -46,34 +46,31 @@
|
|||||||
#define ZSTD_MULTITHREAD
|
#define ZSTD_MULTITHREAD
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lib/common */
|
#include "common/debug.c"
|
||||||
#include "debug.c"
|
#include "common/entropy_common.c"
|
||||||
#include "entropy_common.c"
|
#include "common/error_private.c"
|
||||||
#include "error_private.c"
|
#include "common/fse_decompress.c"
|
||||||
#include "fse_decompress.c"
|
#include "common/threading.c"
|
||||||
#include "threading.c"
|
#include "common/pool.c"
|
||||||
#include "pool.c"
|
#include "common/zstd_common.c"
|
||||||
#include "zstd_common.c"
|
|
||||||
|
|
||||||
/* lib/compress */
|
#include "compress/fse_compress.c"
|
||||||
#include "fse_compress.c"
|
#include "compress/hist.c"
|
||||||
#include "hist.c"
|
#include "compress/huf_compress.c"
|
||||||
#include "huf_compress.c"
|
#include "compress/zstd_compress_literals.c"
|
||||||
#include "zstd_compress_literals.c"
|
#include "compress/zstd_compress_sequences.c"
|
||||||
#include "zstd_compress_sequences.c"
|
#include "compress/zstd_compress_superblock.c"
|
||||||
#include "zstd_compress_superblock.c"
|
#include "compress/zstd_compress.c"
|
||||||
#include "zstd_compress.c"
|
#include "compress/zstd_double_fast.c"
|
||||||
#include "zstd_double_fast.c"
|
#include "compress/zstd_fast.c"
|
||||||
#include "zstd_fast.c"
|
#include "compress/zstd_lazy.c"
|
||||||
#include "zstd_lazy.c"
|
#include "compress/zstd_ldm.c"
|
||||||
#include "zstd_ldm.c"
|
#include "compress/zstd_opt.c"
|
||||||
#include "zstd_opt.c"
|
|
||||||
#ifdef ZSTD_MULTITHREAD
|
#ifdef ZSTD_MULTITHREAD
|
||||||
#include "zstdmt_compress.c"
|
#include "compress/zstdmt_compress.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* lib/decompress */
|
#include "decompress/huf_decompress.c"
|
||||||
#include "huf_decompress.c"
|
#include "decompress/zstd_ddict.c"
|
||||||
#include "zstd_ddict.c"
|
#include "decompress/zstd_decompress.c"
|
||||||
#include "zstd_decompress.c"
|
#include "decompress/zstd_decompress_block.c"
|
||||||
#include "zstd_decompress_block.c"
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Generate using:
|
* Generate using:
|
||||||
* \code
|
* \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
|
* \endcode
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
@ -42,15 +42,13 @@
|
|||||||
#define ZSTD_NOBENCH
|
#define ZSTD_NOBENCH
|
||||||
#define ZSTD_STRIP_ERROR_STRINGS
|
#define ZSTD_STRIP_ERROR_STRINGS
|
||||||
|
|
||||||
/* lib/common */
|
#include "common/debug.c"
|
||||||
#include "debug.c"
|
#include "common/entropy_common.c"
|
||||||
#include "entropy_common.c"
|
#include "common/error_private.c"
|
||||||
#include "error_private.c"
|
#include "common/fse_decompress.c"
|
||||||
#include "fse_decompress.c"
|
#include "common/zstd_common.c"
|
||||||
#include "zstd_common.c"
|
|
||||||
|
|
||||||
/* lib/decompress */
|
#include "decompress/huf_decompress.c"
|
||||||
#include "huf_decompress.c"
|
#include "decompress/zstd_ddict.c"
|
||||||
#include "zstd_ddict.c"
|
#include "decompress/zstd_decompress.c"
|
||||||
#include "zstd_decompress.c"
|
#include "decompress/zstd_decompress_block.c"
|
||||||
#include "zstd_decompress_block.c"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user