Commit ac3a1f74 authored by multrus's avatar multrus
Browse files

initial version of script

parent adda5dd5
Loading
Loading
Loading
Loading
Loading
+295 −0
Original line number Diff line number Diff line
#!/bin/bash

#
#   (C) 2022-2023 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository. All Rights Reserved.
#
#   This software is protected by copyright law and by international treaties.
#   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
#   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
#   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
#   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
#   contributors to this repository retain full ownership rights in their respective contributions in
#   the software. This notice grants no license of any kind, including but not limited to patent
#   license, nor is any license granted by implication, estoppel or otherwise.
#
#   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
#   contributions.
#
#   This software is provided "AS IS", without any express or implied warranties. The software is in the
#   development stage. It is intended exclusively for experts who have experience with such software and
#   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
#   and fitness for a particular purpose are hereby disclaimed and excluded.
#
#   Any dispute, controversy or claim arising under or in relation to providing this software shall be
#   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
#   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
#   the United Nations Convention on Contracts on the International Sales of Goods.
#

REV=`git log -1 --pretty=format:"%H"`
DATE=`eval date +%Y_%m_%d`
OUTDIR=c-code
TMPCLEANDIR=clean-c-code
ROOT=$(dirname $0)/..


coan_exists () {
  type coan &> /dev/null ;
#  return false
}


##########################
#                        #
# Prepare dirs and copy  #
#                        #
##########################

rm -rf $OUTDIR
mkdir $OUTDIR

rm -rf $TMPCLEANDIR

# source code
cp -R ${ROOT}/lib_com $OUTDIR
cp -R ${ROOT}/lib_dec $OUTDIR
cp -R ${ROOT}/lib_enc $OUTDIR
cp -R ${ROOT}/lib_util $OUTDIR
cp -R ${ROOT}/lib_rend $OUTDIR
cp -R ${ROOT}/apps $OUTDIR
mkdir $OUTDIR/lib_debug
cp ${ROOT}/lib_debug/wmc_auto.[ch] $OUTDIR/lib_debug
cp ${ROOT}/.clang-format $OUTDIR

# MS VC Workspaces/Makefile
cp ${ROOT}/Makefile ${OUTDIR}
cp -R ${ROOT}/Workspace_msvc ${OUTDIR}
# remove debug files which will be stripped below
sed -i.bak -e '/lib_debug\\debug.[ch]/d' ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj
sed -i.bak -e '/lib_debug\\sba_debug.[ch]/d' ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj
sed -i.bak -e '/lib_debug\\snr.c/d' ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj
rm -f ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj.bak

# readme
cp ${ROOT}/readme.txt ${OUTDIR}
recode lat1..ibmpc ${OUTDIR}/readme.txt # unix2dos ...


##########################
#                        #
# Stripping              #
#                        #
##########################

# Switches in Start/End DEVELOPMENT switches
tmpfile=`mktemp`
rm -f $tmpfile
touch $tmpfile

cat $OUTDIR/lib_com/options.h  | sed -n '/Start DEVELOPMENT switches/,/End DEVELOPMENT switches/p' >> $tmpfile

if coan_exists; then

  COAN_LIST=coan_delivery.txt
  rm -f $COAN_LIST
  touch $COAN_LIST

  ${ROOT}/scripts/parse_options_h.sh -c $tmpfile >> $COAN_LIST

  # sanity check, whether any CR_ switches were parsed
  numCRs=`grep -c CR_ $COAN_LIST`
  if [ $numCRs -lt 0 ]; then
    echo "Warning: CR_-switches within DEVELOPMENT section!"
  fi

  # apply coan
  coan source --replace --no-transients -K --file $COAN_LIST $OUTDIR/lib_{com,dec,enc,util,rend}/*.[hc]
  coan source --replace --no-transients -K --file $COAN_LIST $OUTDIR/apps/*.[hc]

  # remove rejected switches from options.h
  while read line
  do    
    macro=`echo $line | grep '\-U' | sed -e "s/\-U//g"`
    if [[ ! $macro =~ [^[:space:]] ]] ; then
      continue
    fi
    sed -i.bak "/#define\ *$macro/d" $OUTDIR/lib_com/options.h
  done < $COAN_LIST

  rm -f $COAN_LIST

else

  echo "Coan required in path; Aborting. Available at https://coan2.sourceforge.net/"
  exit -1

fi

rm -f $tmpfile


# Manual Stripping of Debugging switches
if coan_exists; then

  COAN_LIST=coan_delivery.txt
  rm -f $COAN_LIST
  touch $COAN_LIST

  echo "-DRELEASE"                             >> $COAN_LIST
  echo "-UDEBUGGING"                           >> $COAN_LIST
  echo "-UDEBUG_MODE_INFO"                     >> $COAN_LIST
  echo "-UDEBUG_MODE_ACELP"                    >> $COAN_LIST
  echo "-UDEBUG_MODE_TCX"                      >> $COAN_LIST
  echo "-UDEBUG_MODE_DFT"                      >> $COAN_LIST
  echo "-UDEBUG_MODE_TD"                       >> $COAN_LIST
  echo "-UDEBUG_MODE_DIRAC"                    >> $COAN_LIST
  echo "-UDEBUG_MODE_MDCT"                     >> $COAN_LIST
  echo "-UDEBUG_MODE_PARAM_MC"                 >> $COAN_LIST
  echo "-UDEBUG_MODE_PARAM_ISM"                >> $COAN_LIST
  echo "-UDEBUG_MODE_INFO_TWEAK"               >> $COAN_LIST
  echo "-UDEBUG_MODE_INFO_PLC"                 >> $COAN_LIST
  echo "-UDEBUG_MODE_INFO_ALLRAD"              >> $COAN_LIST
  echo "-UDEBUG_MODE_LFE"                      >> $COAN_LIST
  echo "-UDEBUG_PLOT_BITS"                     >> $COAN_LIST
  echo "-UENABLE_BITRATE_VERIFICATION"         >> $COAN_LIST
  echo "-UDEBUG_PLOT"                          >> $COAN_LIST
  echo "-UALLOW_BYTE_EP"                       >> $COAN_LIST
  echo "-UWRAP_AS_EIDXOR"                      >> $COAN_LIST
  echo "-UDEBUG_FORCE_MDCT_STEREO_MODE"        >> $COAN_LIST
  echo "-UDEBUG_STEREO_DFT_NOCORE"             >> $COAN_LIST
  echo "-UDEBUG_STEREO_DFT_NOSTEREO"           >> $COAN_LIST
  echo "-UDEBUG_STEREO_DFT_NOQRES"             >> $COAN_LIST
  echo "-UDEBUG_STEREO_DFT_OUTRESPRED"         >> $COAN_LIST
  echo "-UDBG_STEREO_ICBWE2_TBE2K8"            >> $COAN_LIST
  echo "-UDEBUG_DISABLE_DIRAC_DELAY_COMP"      >> $COAN_LIST
  echo "-UDEBUG_BS_READ_WRITE"                 >> $COAN_LIST
  echo "-UDEBUG_MODE_DIRAC_NOCORE"             >> $COAN_LIST
  echo "-UDEBUG_MODE_QMETADATA"                >> $COAN_LIST
  echo "-UDEBUG_FORCE_MCT_CP"                  >> $COAN_LIST
  echo "-UDEBUG_SINGLE_CODE_OMNI"              >> $COAN_LIST
  echo "-UDEBUG_NO_TONAL_PLC"                  >> $COAN_LIST
  echo "-UDEBUG_NO_TD_TCX_PLC"                 >> $COAN_LIST
  echo "-UDEBUG_FORCE_TD_TCX_CONCEALMENT"      >> $COAN_LIST
  echo "-UDEBUG_PLC_INFO"                      >> $COAN_LIST
  echo "-UDEBUG_EFAP_POLY_TOFILE"              >> $COAN_LIST
  echo "-UTDREND_HRTF_TABLE_METHODS"           >> $COAN_LIST
  echo "-UTDREND_STANDALONE"                   >> $COAN_LIST
  echo "-UDEBUG_SBA"                           >> $COAN_LIST
  echo "-UDEBUG_LBR_SBA"                       >> $COAN_LIST
  echo "-UDEBUG_SBA_AUDIO_DUMP"                >> $COAN_LIST
  echo "-UDEBUG_SBA_MD_DUMP"                   >> $COAN_LIST
  echo "-UDEBUG_SPAR_MD_TARGET_TUNING"         >> $COAN_LIST
  echo "-UDEBUG_SPAR_BYPASS_EVS_CODEC"         >> $COAN_LIST
  echo "-UDEBUG_SPAR_WRITE_OUT_COV"            >> $COAN_LIST
  echo "-UDEBUG_SPAR_DIRAC_WRITE_OUT_PRED_PAR" >> $COAN_LIST
  echo "-UDEBUG_AGC"                           >> $COAN_LIST
  echo "-USPAR_HOA_DBG"                        >> $COAN_LIST
  echo "-UDEBUG_BINAURAL_FILTER_DESIGN"        >> $COAN_LIST
  echo "-UDEBUG_AGC_ENCODER_CMD_OPTION"        >> $COAN_LIST


  # apply coan
  coan source --replace --no-transients -K --file $COAN_LIST $OUTDIR/lib_{com,dec,enc,util,rend}/*.[hc]
  coan source --replace --no-transients -K --file $COAN_LIST $OUTDIR/apps/*.[hc]

  # remove rejected switches from options.h
  while read line
  do    
    macro=`echo $line | grep '\-U' | sed -e "s/\-U//g"`
    if [[ ! $macro =~ [^[:space:]] ]] ; then
      continue
    fi
    sed -i.bak "/#define\ *$macro/d" $OUTDIR/lib_com/options.h
  done < $COAN_LIST

  rm -f $COAN_LIST

else

  echo "Coan required in path; Aborting. Available at https://coan2.sourceforge.net/"
  exit -1

fi


##########################
#                        #
# Patch code             #
#                        #
##########################

# remove more debug-leftovers from code
find $OUTDIR -name "*.[ch]" -exec sed -i.bak "/#include\ *\"debug.h\"/d" \{\} \; 
#find $OUTDIR -name "*.[ch]" -exec sed -i.bak "/#include\ *\"wmc_auto.h\"/d" \{\} \; 


# TODO: needs to be reviewed!
if [ ]; then # START skip block

# remove unwanted comments
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.*TODO.*/?\*/$##sg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*\s*Variable not present in the floating point.*/?\*/##sg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* ERI.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* FHG.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* VE2FHG.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* HUA.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* HW.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* NOK.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* NTT.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* DOC.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* DCM.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* PAN.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* SAM.*/?\*/$##sg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* SAMSUNG.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* VA.*/?\*/$##sg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* ZTE.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* QC.*/?\*/$##sg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* QMM.*/?\*/$##isg' \{\} \;
find $OUTDIR/lib_com $OUTDIR/lib_dec $OUTDIR/lib_enc -name "*.[ch]" -exec perl -i.bak -pe 's#/\*.* ORA.*/?\*/$##isg' \{\} \;

# use ITU-T STL2009 instead of FhG WMOPS counters
#mv $OUTDIR/basic_op/count.c.stl $OUTDIR/basic_op/count.c
#mv $OUTDIR/basic_op/count.h.stl $OUTDIR/basic_op/count.h

# remove wmc_auto.h
rm -f ${OUTDIR}/lib_com/wmc_auto.h ${OUTDIR}/lib_dec/wmc_auto.h ${OUTDIR}/lib_enc/wmc_auto.h 

# remove comments after switches 
sed -i.bak "s/\(\/\*\ #define\ *\CR[a-zA-Z0-9_]*\ *\*\/\)\(.*\)/\1/g" $OUTDIR/lib_com/options.h
sed -i.bak "s/\(\#define\ *\CR[a-zA-Z0-9_]*\ *\)\(\/\*.*\)/\1/g" $OUTDIR/lib_com/options.h
sed -i.bak "s/\(\#define ACTIVATE_CR_SWITCHES\)\(.*\)/\1/g" $OUTDIR/lib_com/options.h
sed -i.bak "s/#define ACTIVATE_CR_SWITCHES.*/#define __CR                   \/* deactivate to build version w\/o CRs *\//g" $OUTDIR/lib_com/options.h 
sed -i.bak "/Start BE/,/End BE/d" $OUTDIR/lib_com/options.h
sed -i.bak "/Start CR/,/End CR/d" $OUTDIR/lib_com/options.h
sed -i.bak "/Start DEBUG/,/End DEBUG/d" $OUTDIR/lib_com/options.h
sed -i.bak "/Start DEVELOPMENT/,/End DEVELOPMENT/d" $OUTDIR/lib_com/options.h
sed -i.bak "/Start Auxiliary/,/End Auxiliary/d" $OUTDIR/lib_com/options.h
sed -i.bak "/delivery switches/d" $OUTDIR/lib_com/options.h
sed -i.bak '/^$/N;/^\n$/D' $OUTDIR/lib_com/options.h
rm -f $OUTDIR/lib_*/coan_*

fi

# clean-up *.bak-files
find $OUTDIR -name "*.bak" -exec rm \{\} \;


##########################
#                        #
# Zip                    #
#                        #
##########################

zip -r9 IVAS_Float_C__rev${REV}_${DATE}.zip $OUTDIR 


echo done

echo now build the Windows executable manually and insert it to the zip with the following commands:
echo zip -r9 IVAS_Float_C__rev${REV}_${DATE}.zip $OUTDIR c-code/IVAS_cod.exe c-code/IVAS_dec.exe c-code/IVAS_rend.exe