File indexing completed on 2024-10-06 06:28:46

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 # We need to use --format-version 2 option for rcc to be retro-compatible with all our GCompris versions
0041 function generate_rcc {
0042     # Generate RCC 
0043     echo -n "$2 ... "
0044     mkdir -p ${2%/*}
0045     ${RCC} --format-version 2 --binary $1 -o $2
0046 
0047     echo "md5sum ... "
0048     cd ${2%/*}
0049     ${MD5SUM}  ${2##*/}>> ${CONTENTS_FILE}
0050 
0051     cd - &>/dev/null
0052 }
0053 
0054 function header_rcc {
0055 (cat <<EOHEADER
0056 <!DOCTYPE RCC><RCC version="1.0">
0057 <qresource prefix="/gcompris/data">
0058 EOHEADER
0059 ) > $1
0060 }
0061 
0062 function footer_rcc {
0063 (cat <<EOFOOTER
0064 </qresource>
0065 </RCC>
0066 EOFOOTER
0067 ) >> $1
0068 }
0069 
0070 echo "Generating binary resource files in ${RCC_DIR}/ folder:"
0071 
0072 [ -d ${RCC_DIR} ] && rm -rf ${RCC_DIR}
0073 mkdir  ${RCC_DIR}
0074 
0075 #header of the global qrc (all the langs)
0076 QRC_FULL_FILE="${QRC_DIR}/backgroundMusic-${CA}.qrc"
0077 RCC_FULL_FILE="${RCC_DIR}/backgroundMusic-${CA}-${LAST_UPDATE_DATE}.rcc"
0078 header_rcc $QRC_FULL_FILE
0079 
0080 for i in `find backgroundMusic -type f -name "*.$CA" | sort | cut -c 1-`
0081 do
0082         echo "    <file>${i#${MUSIC_DIR}}</file>" >> "${QRC_DIR}/backgroundMusic-${CA}.qrc"
0083 done
0084 footer_rcc $QRC_FULL_FILE
0085 echo -n "  full: ${QRC_FULL_FILE} ... "
0086 generate_rcc ${QRC_FULL_FILE} ${RCC_FULL_FILE}
0087 
0088 echo "Finished!"
0089 echo ""
0090 
0091 #EOF
0092 
0093