2022-08-29 14:23:38 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
UTARGET=$(uname)
|
|
|
|
|
|
|
|
# Determine platform
|
|
|
|
if [ "$UTARGET" = "Darwin" ]; then
|
|
|
|
export UPLATFORM="mac"
|
2023-02-04 15:53:10 +08:00
|
|
|
export UFIND="find -E"
|
|
|
|
export UFINDOPT=""
|
|
|
|
export USEDOPT="''"
|
2022-08-29 14:23:38 +08:00
|
|
|
elif [ "$UTARGET" = "Linux" ]; then
|
|
|
|
export UPLATFORM="linux_$(uname -m)"
|
2023-02-04 15:53:10 +08:00
|
|
|
export UFIND="find"
|
|
|
|
export UFINDOPT="-regextype posix-extended"
|
|
|
|
export USEDOPT=""
|
2022-08-29 14:23:38 +08:00
|
|
|
else
|
|
|
|
export UPLATFORM="$UTARGET"
|
2023-02-04 15:53:10 +08:00
|
|
|
echo "Please run this script on Linux or macOS"
|
2022-08-29 14:23:38 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate
|
|
|
|
echo "Attempting to to generate parsers from Kaitai KSY files on ${UPLATFORM}..."
|
2023-02-27 05:23:25 +08:00
|
|
|
kaitai-struct-compiler --target cpp_stl --cpp-standard 11 --outdir common/generated common/ksy/* || exit 1
|
2022-08-29 14:23:38 +08:00
|
|
|
|
|
|
|
# Show generated files
|
2023-02-04 15:53:10 +08:00
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
2022-08-29 14:23:38 +08:00
|
|
|
-regex '.*\.(cpp|h)' \
|
|
|
|
-print || exit 1
|
|
|
|
|
|
|
|
# Replace global includes for kaitai with local ones (<> -> "")
|
2023-02-04 15:53:10 +08:00
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
2022-08-29 14:23:38 +08:00
|
|
|
-regex '.*\.(cpp|h)' \
|
2023-02-04 15:53:10 +08:00
|
|
|
-exec sed -i ${USEDOPT} '/^#include <kaitai/s/[<>]/\"/g' {} + || exit 1
|
2022-08-29 14:23:38 +08:00
|
|
|
|
|
|
|
# Add .. to the include path for kaitai includes
|
2023-02-04 15:53:10 +08:00
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
2022-08-29 14:23:38 +08:00
|
|
|
-regex '.*\.(cpp|h)' \
|
2023-02-04 15:53:10 +08:00
|
|
|
-exec sed -i ${USEDOPT} '/^#include \"kaitai\//s/kaitai\//..\/kaitai\//g' {} + || exit 1
|
2022-08-29 14:23:38 +08:00
|
|
|
|
|
|
|
# Suppress "p__root - unused parameter" warning
|
2023-02-04 15:53:10 +08:00
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
2022-08-29 14:23:38 +08:00
|
|
|
-regex '.*\.(cpp)' \
|
2023-02-04 15:53:10 +08:00
|
|
|
-exec sed -i ${USEDOPT} '/^ m__root = this;/s/;/; (void)p__root;/g' {} + || exit 1
|
2022-08-29 14:23:38 +08:00
|
|
|
|
2023-02-04 15:53:10 +08:00
|
|
|
# Add uint64_t to enum structure_ids_t
|
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
|
|
|
-regex '.*\.(h)' \
|
|
|
|
-exec sed -i ${USEDOPT} '/^ enum structure_ids_t {/s/{/: uint64_t {/g' {} + || exit 1
|
2023-02-27 05:23:25 +08:00
|
|
|
|
|
|
|
# Suppress type downcast warning in ami_nvar.cpp
|
|
|
|
${UFIND} common/generated ${UFINDOPT} \
|
|
|
|
-name 'ami_nvar.cpp' \
|
|
|
|
-exec sed -i ${USEDOPT} 's/_offset = _io()->pos();/_offset = (int32_t)_io()->pos();/g' {} + || exit 1
|
|
|
|
|
2022-08-29 14:23:38 +08:00
|
|
|
exit 0
|