Commit 7a7d09ca authored by norvell's avatar norvell
Browse files

Add script prepare_delivery_keep_debug.sh that keeps debugging code

parent ccfb71e3
Loading
Loading
Loading
Loading
+331 −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)/..
STRIP_SPLITREND=0
PREPARE_ZIP=1

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


##########################
#                        #
# Start, Commandline     #
#                        #
##########################

ALL_OPTS=":h-:"
while getopts "$ALL_OPTS" OPTION; do
    case "${OPTION}" in
        -)
            case "${OPTARG}" in
                strip_sr)
                    STRIP_SPLITREND=1
                    ;;
                no_zip)
                    PREPARE_ZIP=0
                    ;;
               *)
                    if [ "$OPTERR" = 1 ] && [ "${ALL_OPTS:0:1}" != ":" ]; then
                        echo "Unknown option --${OPTARG}" >&2
                    fi
                    ;;
            esac;;
        h)
            echo "usage: $0 [--strip_sr] [--no_zip]" >&2
            exit -1
            ;;
        *)
            if [ "$OPTERR" != 1 ] || [ "${ALLOPTS:0:1}" = ":" ]; then
                echo "Unknown argument: '-${OPTARG}'" >&2
            fi
            ;;
    esac
done


##########################
#                        #
# 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_debug $OUTDIR
cp -R ${ROOT}/lib_enc $OUTDIR
cp -R ${ROOT}/lib_util $OUTDIR
cp -R ${ROOT}/lib_rend $OUTDIR
cp -R ${ROOT}/lib_lc3plus $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}
rm -f ${OUTDIR}/Workspace_msvc/lib_debug.vcxproj.bak
rm -f ${OUTDIR}/lib_util/tsm_scale_file_reader.[ch]
sed -i.bak -e "/lib_util\\\tsm_scale_file_reader.[ch]/d" ${OUTDIR}/Workspace_msvc/lib_util.vcxproj

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

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

# LICENSE.md
cp ${ROOT}/LICENSE.md ${OUTDIR}
recode lat1..ibmpc ${OUTDIR}/LICENSE.md # unix2dos ...

# include .clang_format, since this is a VS dependency
cp ${ROOT}/.clang-format ${OUTDIR}

# enable split rendering againg by default
# in case we strip it later, it will be explicitly disabled again belo
sed -i.bak -e "s/\/\*\ *\(#define\ *SPLIT_REND_WITH_HEAD_ROT\ *\)\*\//\1/g" ${OUTDIR}/lib_com/options.h


##########################
#                        #
# Strip Split Rendering  #
#                        #
##########################

if [ $STRIP_SPLITREND -ne 0 ]; then

  echo "Stripping Split Rendering"
  
  ${ROOT}/scripts/strip_split_rendering.sh ${OUTDIR}

  # strip macros
  declare -a sr_macros=(
      "SPLIT_REND_WITH_HEAD_ROT"
  )

  if coan_exists; then

    for macro in ${sr_macros[@]}; do
      coan source --replace --no-transients -K -U${macro} $OUTDIR/lib_{com,dec,enc,util,rend}/*.[hc]
      coan source --replace --no-transients -K -U${macro} $OUTDIR/apps/*.[hc]
      sed -i.bak "/#define\ *$macro/d" $OUTDIR/lib_com/options.h
    done

  else

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

  fi

  # patch Makefile
  patch ${OUTDIR}/Makefile < ${ROOT}/scripts/makefile_noSR.patch

  # delete readme_split_rendering
  rm ${OUTDIR}/readme_split_rendering.txt

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

else

  # patch Makefile so that split rendering sources are built by default
  patch ${OUTDIR}/Makefile < ${ROOT}/scripts/makefile_SR.patch  

fi


##########################
#                        #
# 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

  # 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

  # Remove current development switches from the code by parsing options.h
  tmpfile=`mktemp`
  rm -f $tmpfile
  touch $tmpfile  
  cat $OUTDIR/lib_com/options.h  | sed -n '/Start BE switches/,/End DEVELOPMENT switches/p' >> $tmpfile
  ${ROOT}/scripts/parse_options_h.sh -c $tmpfile >> $COAN_LIST
  rm -f $tmpfile

  # 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" \{\} \; 


# 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#/\*.* 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#/\*.* PAN.*/?\*/$##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' \{\} \;

# 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

fi # END skip block


# remove comments after switches 
sed -i.bak "/keep as part of options.h/d" $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\ *\CR[a-zA-Z0-9_]*\ *\)\(\/\*.*\)/\1/g" $OUTDIR/lib_com/options.h
sed -i.bak "/Start DEVELOPMENT switches/,/End DEVELOPMENT switches/d" $OUTDIR/lib_com/options.h

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


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

if [ $PREPARE_ZIP -eq 1 ]; then

    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
else
    echo done
fi