Script "flags_O2_to_O3.sh"
#!/bin/sh

# -----------------------------
# flags_O2_to_O3.sh
# version 1.1.4.5
# -----------------------------

# search for all '-O2' strings in files
printf ">> searching for -O2 strings..."
list_of_O2_strings=`find . -print0 | xargs -0 grep -H "\-O2"`
echo " ok"

# CFLAGS: [ -g ] -O2 --> -O3
list_of_files=`echo "${list_of_O2_strings}" | grep "CFLAGS" | cut -d':' -f1 | uniq | sort`
if [ ! -z "${list_of_files}" ]; then
  echo "** patching CFLAGS: [ -g ] -O2 --> -O3"
  echo "${list_of_files}" | while read the_file
  do
    printf "    patching %s..." "${the_file}"
    sed -i -e 's/-g -O2/-O3/g' -e 's/-O2 -g/-O3/g' -e 's/-O2/-O3/g' "${the_file}"
    echo " ok"
  done
  echo "++ CFLAGS are good now"
else
  echo "-- no CFLAGS with -O2 found"
fi

# CXXFLAGS: [ -g ] -O2 --> -O3
list_of_files=`echo "${list_of_O2_strings}" | grep "CXXFLAGS" | cut -d':' -f1 | uniq | sort`
if [ ! -z "${list_of_files}" ]; then
  echo "** patching CXXFLAGS: [ -g ] -O2 --> -O3"
  echo "${list_of_files}" | while read the_file
  do
    printf "    patching %s..." "${the_file}"
    sed -i -e 's/-g -O2/-O3/g' -e 's/-O2 -g/-O3/g' -e 's/-O2/-O3/g' "${the_file}"
    echo " ok"
  done
  echo "++ CXXFLAGS are good now"
else
  echo "-- no CXXFLAGS with -O2 found"
fi

# GCJFLAGS: [ -g ] -O2 --> -O3
list_of_files=`echo "${list_of_O2_strings}" | grep "GCJFLAGS" | cut -d':' -f1 | uniq | sort`
if [ ! -z "${list_of_files}" ]; then
  echo "** patching GCJFLAGS: [ -g ] -O2 --> -O3"
  echo "${list_of_files}" | while read the_file
  do
    printf "    patching %s..." "${the_file}"
    sed -i -e 's/-g -O2/-O3/g' -e 's/-O2 -g/-O3/g' -e 's/-O2/-O3/g' "${the_file}"
    echo " ok"
  done
  echo "++ GCJFLAGS are good now"
else
  echo "-- no GCJFLAGS with -O2 found"
fi

# AM_CPPFLAGS: [ -g ] -O2 --> -O3
list_of_files=`echo "${list_of_O2_strings}" | grep "AM_CPPFLAGS" | cut -d':' -f1 | uniq | sort`
if [ ! -z "${list_of_files}" ]; then
  echo "** patching AM_CPPFLAGS: [ -g ] -O2 --> -O3"
  echo "${list_of_files}" | while read the_file
  do
    printf "    patching %s..." "${the_file}"
    sed -i -e 's/-g -O2/-O3/g' -e 's/-O2 -g/-O3/g' -e 's/-O2/-O3/g' "${the_file}"
    echo " ok"
  done
  echo "++ AM_CPPFLAGS are good now"
else
  echo "-- no AM_CPPFLAGS with -O2 found"
fi

search_again="no"
if [ "${search_again}" = "yes" ]; then
  # are any of them left?
  printf ">> searching again for remaining -O2 strings..."
  list_of_O2_strings=`find . -print0 | xargs -0 grep -H "\-O2"`
  echo " ok"
  echo "================================================================"
  echo "${list_of_O2_strings}"
fi
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.