if [ "$OPTIMIZATIONS" = normal ];then
  GCC_OPTIM="-O2"
  LD_OPTIM=""
fi

if [ "$OPTIMIZATIONS" = size ];then
  GCC_OPTIM="-Os -fexcess-precision=fast"
  LD_OPTIM="-Wl,--as-needed"
fi

if [ "$LTO_SUPPORT" = yes ];then
  GCC_OPTIM_LTO="-flto -ffat-lto-objects"
  LD_OPTIM_LTO="-fuse-linker-plugin -flto"
fi

if [ "$GOLD_SUPPORT" = yes ];then
  LD_OPTIM_GOLD="-fuse-ld=gold"
fi

if [ "$DEBUG" = yes ]; then
  TARGET_CFLAGS="$TARGET_CFLAGS -ggdb"
  TARGET_CXXFLAGS="$TARGET_CXXFLAGS -ggdb"
  TARGET_LDFLAGS="$TARGET_LDFLAGS -ggdb"
else
  TARGET_CFLAGS="$TARGET_CFLAGS -fomit-frame-pointer"
  TARGET_CXXFLAGS="$TARGET_CXXFLAGS -fomit-frame-pointer"
  TARGET_LDFLAGS="$TARGET_LDFLAGS"
fi

TARGET_CPPFLAGS=
TARGET_CFLAGS="$TARGET_CFLAGS -Wall -pipe $GCC_OPTIM $GCC_OPTIM_LTO $PROJECT_CFLAGS"
TARGET_CXXFLAGS="$TARGET_CFLAGS"
TARGET_LDFLAGS="$TARGET_LDFLAGS $LD_OPTIM $LD_OPTIM_GOLD $LD_OPTIM_LTO"
TARGET_LIBDIR="$SYSROOT_PREFIX/lib $SYSROOT_PREFIX/usr/lib"
TARGET_INCDIR="$SYSROOT_PREFIX/include $SYSROOT_PREFIX/usr/include"

HOST_CPPFLAGS=""
HOST_CFLAGS="-O2 -Wall -pipe -I$ROOT/$TOOLCHAIN/include"
HOST_CXXFLAGS="$HOST_CFLAGS"
HOST_LDFLAGS="-Wl,-rpath,$ROOT/$TOOLCHAIN/lib -L$ROOT/$TOOLCHAIN/lib"
HOST_LIBDIR="$ROOT/$TOOLCHAIN/lib"

# work around Ubuntu default C*FLAGS 
# see https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-Wformat_-Wformat-security
HOST_CFLAGS="$HOST_CFLAGS -Wno-format-security"
HOST_CXXFLAGS="$HOST_CXXFLAGS -Wno-format-security" 

# add distro specific library dirs
  # ubuntu/debian specific "multiarch support"
    FAMILY_TRIPLET=$(echo $HOST_NAME | sed -e "s,$(uname -m),$(uname -i),")
    if [ -d /lib/$FAMILY_TRIPLET ]; then
      HOST_LIBDIR="$HOST_LIBDIR /lib/$FAMILY_TRIPLET"
    fi
    if [ -d /usr/lib/$FAMILY_TRIPLET ]; then
      HOST_LIBDIR="$HOST_LIBDIR /usr/lib/$FAMILY_TRIPLET"
    fi

  # default multiarch support
    case "`uname -m`" in
      i*86)
        if [ -d /lib32 ]; then
          HOST_LIBDIR="$HOST_LIBDIR /lib32"
        fi
        if [ -d /usr/lib32 ]; then
          HOST_LIBDIR="$HOST_LIBDIR /usr/lib32"
        fi
      ;;
      x86_64)
        if [ -d /lib64 ]; then
          HOST_LIBDIR="$HOST_LIBDIR /lib64"
        fi
        if [ -d /usr/lib64 ]; then
          HOST_LIBDIR="$HOST_LIBDIR /usr/lib64"
        fi
      ;;
    esac

  # default dirs
    HOST_LIBDIR="$HOST_LIBDIR /lib /usr/lib"
    HOST_INCDIR="$ROOT/$TOOLCHAIN/include /usr/include"
