LC_ALL=C
LC_CTYPE=C
LANG=C
local OLD_SPELL_VERSION=""
spell_ok $SPELL && OLD_SPELL_VERSION="$(installed_version $SPELL)"
if [ "$VERSION" != "$OLD_SPELL_VERSION" ]; then
  # recast the split compiler spells on a gcc version update, see bug #9813
  # this includes g77 for the upgrade from 3.4.x to 4.x compilers
  for each in ada fortran g++ g77 gcj objc; do
    if  spell_ok  $each; then
      up_trigger $each cast_self
    fi
  done &&

  # for C++ ABI change in 5.1 and, probably, for each major version change too
  if   list_find "$GCC_COMPILER" c++ \
    && [[ ${OLD_SPELL_VERSION%%.*} != ${VERSION%%.*} ]]; then
# gcc-5.x,y seems ok
if [[ ${OLD_SPELL_VERSION%%.*} < "5" ]];then
    message "${MESSAGE_COLOR}This is an ABI-incompatible update of g++..."
    message "Determining which spells need to be recast, this may take a while.${DEFAULT_COLOR}"

    for other_spell in $(gaze installed | cut -d: -f1); do
      [[ $SPELL != $other_spell ]] || continue
      if gaze install $other_spell \
         | xargs file -e apptype -e ascii -e compress -e tar \
         | grep '\<ELF\>.*\<dynamically linked\>' \
         | cut -d: -f1 \
         | xargs readelf -d 2> /dev/null \
         | grep -q 'NEEDED)[[:space:]]*Shared library: \[libstdc++'; then
        up_trigger $other_spell cast_self
      fi
    done
fi # not v5
  fi
fi

if [[ -e "$INSTALL_ROOT/usr/lib/libstdc++.la" ]]; then
  . $GRIMOIRE/la_remove_up_trigger.function
  la_remove_up_trigger 1
fi
