File indexing completed on 2022-09-20 15:08:37

0001 #!/usr/bin/env bash
0002 
0003 categories=(Data Networking IO Config)
0004 
0005 if [[ $# != 1 || $1 == "-h" || $1 == "--help" ]] ; then
0006         echo "Generate logging category headers and implementations."
0007         echo
0008         echo "One parameter is expected:"
0009         echo " 1. The absolute path to the the 'src/' directory inside"
0010         echo "    the build directory. If the directory does not yet"
0011         echo "    exist, it will be created."
0012         echo
0013         echo "Example:"
0014         echo "  ./generate-logging-categories.sh ~/git/build-bibsearch-SailfishOS_3_0_3_9_i486_in_Sailfish_OS_Build_Engine-Debug/src/"
0015         echo
0016         echo "The following logging category headers and implementations will be generated:"
0017         for category in "${categories[@]}" ; do echo "  ${category}" ; done
0018         exit 1
0019 fi
0020 
0021 destdir="$1"
0022 test -d "${destdir}" || { echo "Creating directory: '${destdir}'" >&2 ; mkdir -p "${destdir}" ; }
0023 
0024 for category in "${categories[@]}" ; do
0025         categoryUC="$(tr 'a-z' 'A-Z' <<<"${category}")"
0026         categoryLC="$(tr 'A-Z' 'a-z' <<<"${category}")"
0027 
0028         stem="${destdir}/${categoryLC}/logging_${categoryLC}"
0029         mkdir -p "$(dirname "${stem}")"
0030         cat <<EOF >"${stem}".h
0031 // This file was generated by generate-logging-categories.sh: DO NOT EDIT!
0032 #ifndef QLOGGINGCATEGORY_LOG_KBIBTEX_${categoryUC}_LOGGING_${categoryUC}_H
0033 #define QLOGGINGCATEGORY_LOG_KBIBTEX_${categoryUC}_LOGGING_${categoryUC}_H
0034 #include <QLoggingCategory>
0035 Q_DECLARE_LOGGING_CATEGORY(LOG_KBIBTEX_${categoryUC})
0036 #endif // QLOGGINGCATEGORY_LOG_KBIBTEX_${categoryUC}_LOGGING_${categoryUC}_H
0037 EOF
0038         cat <<EOF >"${stem}".cpp
0039 // This file was generated by generate-logging-categories.sh: DO NOT EDIT!
0040 #include "logging_${categoryLC}.h"
0041 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
0042 Q_LOGGING_CATEGORY(LOG_KBIBTEX_${categoryUC}, "kbibtex.${categoryLC}", QtInfoMsg)
0043 #else
0044 Q_LOGGING_CATEGORY(LOG_KBIBTEX_${categoryUC}, "kbibtex.${categoryLC}")
0045 #endif
0046 EOF
0047 done