From e2d1f6b79ec7ccfa06aaa0d035720f8846b723d8 Mon Sep 17 00:00:00 2001 From: Carl Woffenden Date: Wed, 2 Oct 2019 12:32:34 +0200 Subject: [PATCH] Added combiner option to keep "#pragma once" directives Keeping the "#pragma once" directives in the combined headers but not in the combined source. --- contrib/single_file_transcoder/README.md | 4 ++-- contrib/single_file_transcoder/combine.sh | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/contrib/single_file_transcoder/README.md b/contrib/single_file_transcoder/README.md index c8af8da..d37788e 100644 --- a/contrib/single_file_transcoder/README.md +++ b/contrib/single_file_transcoder/README.md @@ -16,9 +16,9 @@ If certain features will _never__ be enabled, e.g. `BASISD_SUPPORT_BC7_MODE6_OPA ``` Excluding the BC7 mode 6 support reduces the generated source by 1.2MB, which is the choice taken in `basisu_transcoder-in.cpp` and used in the examples, with `create_transcoder.sh` running the above script, creating the final `basisu_transcoder.cpp`. -The combiner script can also generate separate amalgamated header and source files, using the `-k` option to keep the specified inline directive: +The combiner script can also generate separate amalgamated header and source files, using the `-k` option to keep the specified inline directive, and `-p` to keep the `#pragma once` directives in the header: ``` -./combine.sh -r ../../transcoder -o basisu_transcoder.h ../../transcoder/basisu_transcoder.h +./combine.sh -r ../../transcoder -o basisu_transcoder.h -p ../../transcoder/basisu_transcoder.h ./combine.sh -r ../../transcoder -x basisu_transcoder_tables_bc7_m6.inc -k basisu_transcoder.h -o basisu_transcoder.cpp basisu_transcoder-in.cpp diff --git a/contrib/single_file_transcoder/combine.sh b/contrib/single_file_transcoder/combine.sh index 0a59391..aedae92 100755 --- a/contrib/single_file_transcoder/combine.sh +++ b/contrib/single_file_transcoder/combine.sh @@ -5,7 +5,8 @@ # Note: this POSIX-compliant script is many times slower than the original bash # implementation (due to the grep calls) but it runs and works everywhere. # -# TODO: ROOTS and FOUND as arrays (since they fail on paths with spaces) +# TODO: ROOTS, FOUND, etc., as arrays (since they fail on paths with spaces) +# TODO: revert to Bash-only regex (the grep ones being too slow) # # Script released under a CC0 license. @@ -24,12 +25,16 @@ FOUND="" # Optional destination file (empty string to write to stdout) DESTN="" +# Whether the "#pragma once" directives should be written to the output +PONCE=0 + # Prints the script usage then exits usage() { echo "Usage: $0 [-r ] [-x
] [-k
] [-o ] infile" echo " -r file root search path" echo " -x file to completely exclude from inlining" echo " -k file to exclude from inlining but keep the include directive" + echo " -p keep any '#pragma once' directives (removed by default)" echo " -o output file (otherwise stdout)" echo "Example: $0 -r ../my/path - r ../other/path -o out.c in.c" exit 1 @@ -104,7 +109,13 @@ add_file() { fi else # Skip any 'pragma once' directives, otherwise write the source line - if echo "$line" | grep -Eqv '^\s*#\s*pragma\s*once\s*'; then + local write=$PONCE + if [ $write -eq 0 ]; then + if echo "$line" | grep -Eqv '^\s*#\s*pragma\s*once\s*'; then + write=1 + fi + fi + if [ $write -ne 0 ]; then write_line "$line" fi fi @@ -114,7 +125,7 @@ add_file() { fi } -while getopts ":r:x:k:o:" opts; do +while getopts ":r:x:k:po:" opts; do case $opts in r) ROOTS="$ROOTS $OPTARG" @@ -125,6 +136,9 @@ while getopts ":r:x:k:o:" opts; do k) KINCS="$KINCS $OPTARG" ;; + p) + PONCE=1 + ;; o) DESTN="$OPTARG" ;;