#!/bin/sh

set -e

compiler_check()
{
  # Check for a working C compiler
  #
  # This check needs to be done since C compiler alternatives may not
  # be up to date and may point to a bogus C compiler.  This would
  # cause libtool's ltconfig script to choke during the postinst
  # phase of installation.

  # Check for an executable file with the name `cc'.  If it doesn't
  # exist then check for gcc.  If gcc exists then update the C
  # compiler alternatives to point to gcc.
  if test -x /usr/bin/cc; then
    : # Success
  elif test -x /usr/bin/gcc; then
    update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 20 \
      --slave /usr/man/man1/cc.1.gz cc.1.gz /usr/man/man1/gcc.1.gz
  else
    echo "ERROR: /usr/bin/cc was not found." 1>&2
    echo "       Make sure you have a C compiler installed." 1>&2
    exit 1; # Failure
  fi
}

case "$1" in
configure)
  echo Configuring libtool...

  compiler_check

  cd /usr/share/libtool
  ./ltconfig --quiet ltmain.sh > /dev/null
  chmod 755 libtool
  chown root.root libtool
  mv -f libtool /usr/bin/libtool
  rm -f config.log
  ;;

*)
  case "$1" in
  abort-upgrade|abort-remove|abort-deconfigure) ;;
  *)
    echo "ERROR: unrecognized libtool postinst arguments: $@" 1>&2
    echo -n "Aborting configuration of libtool package..." 1>&2
    ;;
  esac

  rm -f /usr/bin/libtool /usr/share/libtool/libtool \
        /usr/share/libtool/config.log

  case "$1" in
  abort-upgrade|abort-remove|abort-deconfigure) ;;
  *)
    echo " done." 1>&2
    exit 1
    ;;
  esac
  ;;
esac

# Automatically added by dh_installdocs
if [ "$1" = "configure" ]; then
	if [ -d /usr/doc -a ! -e /usr/doc/libtool -a -d /usr/share/doc/libtool ]; then
		ln -sf ../share/doc/libtool /usr/doc/libtool
	fi
fi
# End automatically added section

