File indexing completed on 2023-05-30 10:40:33

0001 #!/bin/bash
0002 #
0003 # generate_backgroundMusic_rcc.sh
0004 
0005 # Copyright (C) 2014 Holger Kaelberer
0006 # Copyright (C) 2016 Divyam Madaan
0007 #
0008 # Generates Qt binary resource files (.rcc) for background music.
0009 #
0010 # Results will be written to $PWD/.rcc/ which is supposed be synced to the
0011 # upstream location.
0012 #
0013 
0014 # the path depends on the distribution
0015 #export RCC=/usr/lib64/qt5/bin/rcc
0016 export RCC=/usr/bin/rcc
0017 
0018 [ $# -ne 1 ] && {
0019     echo "Usage: generate_backgroundMusic_rcc.sh ogg|aac|ac3|mp3"
0020     exit 1
0021 }
0022 # Compressed Audio Format
0023 CA=$1
0024 
0025 QRC_DIR="."
0026 RCC_DIR=".rcc"
0027 #RCC_DEFAULT=`which rcc 2>/dev/null`   # default, better take /usr/bin/rcc?
0028 RCC_DEFAULT=$Qt5_DIR/bin/rcc
0029 CONTENTS_FILE=Contents
0030 MD5SUM=/usr/bin/md5sum
0031 
0032 [ -z "${RCC}" ] && RCC=${RCC_DEFAULT}
0033 
0034 [ -z "${RCC}" ] && {
0035     echo "No rcc command in PATH, can't continue. Try to set specify RCC in environment:"
0036     echo "RCC=/path/to/qt/bin/rcc $0"
0037     exit 1
0038 }
0039 
0040 function generate_rcc {
0041     # Generate RCC 
0042     echo -n "$2 ... "
0043     mkdir -p ${2%/*}
0044     ${RCC} -binary $1 -o $2
0045 
0046     echo "md5sum ... "
0047     cd ${2%/*}
0048     ${MD5SUM}  ${2##*/}>> ${CONTENTS_FILE}
0049     cd - &>/dev/null
0050 }
0051 
0052 function header_rcc {
0053 (cat <<EOHEADER
0054 <!DOCTYPE RCC><RCC version="1.0">
0055 <qresource prefix="/gcompris/data">
0056 EOHEADER
0057 ) > $1
0058 }
0059 
0060 function footer_rcc {
0061 (cat <<EOFOOTER
0062 </qresource>
0063 </RCC>
0064 EOFOOTER
0065 ) >> $1
0066 }
0067 
0068 echo "Generating binary resource files in ${RCC_DIR}/ folder:"
0069 
0070 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0071 mkdir  ${RCC_DIR}
0072 
0073 #header of the global qrc (all the langs)
0074 QRC_FULL_FILE="${QRC_DIR}/backgroundMusic-${CA}.qrc"
0075 RCC_FULL_FILE="${RCC_DIR}/backgroundMusic-${CA}.rcc"
0076 header_rcc $QRC_FULL_FILE
0077 
0078 for i in `find backgroundMusic -type f -name "*.$CA" | sort | cut -c 1-`
0079 do
0080         echo "    <file>${i#${MUSIC_DIR}}</file>" >> "${QRC_DIR}/backgroundMusic-${CA}.qrc"
0081 done
0082 footer_rcc $QRC_FULL_FILE
0083 echo -n "  full: ${QRC_FULL_FILE} ... "
0084 generate_rcc ${QRC_FULL_FILE} ${RCC_FULL_FILE}
0085 
0086 echo "Finished!"
0087 echo ""
0088 
0089 #EOF
0090 
0091