function fixlinks() { # $1 = install root
  if [ ! -L $1/lib/libncurses.so.$VERSION  -a -f $1/lib/libncurses.so.$VERSION  ]; then
    # hardcode this link for bash of an upgrade from not this spell
    ln -fs libncurses.so.$VERSION   $1/lib/libncursesw.so.$MVERSION
  fi &&
  if [ ! -L $1/lib/libncursesw.so.$VERSION -a -f $1/lib/libncursesw.so.$VERSION ]; then
    # hardcode this link for bash an upgrade from not this spell
    ln -fs libncursesw.so.$VERSION  $1/lib/libncurses.so.$MVERSION
  fi
}

# setup staging
MVERSION=${VERSION/.*/}                         &&

# install to real install root
make  install.libs  DESTDIR="$INSTALL_ROOT"     &&
fixlinks                     $INSTALL_ROOT      &&

# Do not install the libs again. Causes problems.  Bug #13408

sed '/cd ncurses /d' -i Makefile &&

# really install it -- all the libs should be in place
make  install       DESTDIR="$INSTALL_ROOT"     &&

if [[ $UTF8 == y ]]; then
  # links from non-utf-8 ncurses extras to utf-8 ncurses extras
  for  i  in  libformw  libmenuw  libncursesw  libpanelw  libcursesw
  do
    ln  -sf  $i.a                   \
             $INSTALL_ROOT/lib/${i/w/}.a              &&
    ln  -sf  $i.so                  \
             $INSTALL_ROOT/lib/${i/w/}.so             &&
    ln  -sf  $i.so.${MVERSION}      \
             $INSTALL_ROOT/lib/${i/w/}.so.${MVERSION} &&
    ln  -sf  $i.so.${VERSION}       \
             $INSTALL_ROOT/lib/${i/w/}.so.${VERSION}
  done  &&

  # links from plain curses ${i//[wn]/} and non-utf-8 ncurses ${i/w/} to utf-8 ncurses $i
  for  i  in  libncursesw.a libncursesw.so libncursesw.so.${MVERSION} libncursesw.so.${VERSION}
  do
    ln  -sf  $i                     \
             $INSTALL_ROOT/lib/${i//[wn]/}            &&
    ln  -sf  $i                     \
             $INSTALL_ROOT/lib/${i/w/}
  done &&

  for i in form menu ncurses++ ncurses panel; do
    ln -sf "${TRACK_ROOT}/usr/lib/pkgconfig/${i}w.pc" \
           "${INSTALL_ROOT}/usr/lib/pkgconfig/${i}.pc"
  done

else

  # links from plain curses ${i//[wn]/} and utf-8 ncurses $i to non-utf-8 ncurses ${i/w/}
  for  i  in  libncursesw.a libncursesw.so libncursesw.so.${MVERSION} libncursesw.so.${VERSION}
  do
    ln  -sf  ${i/w/}                \
             $INSTALL_ROOT/lib/${i//[wn]/}            &&
    ln  -sf  ${i/w/}                \
             $INSTALL_ROOT/lib/$i
  done

fi &&

ln -sf libcurses.so.${MVERSION} ${INSTALL_ROOT}/lib/libtinfo.so.${MVERSION} &&

case "$HOST" in *-gnu) ldconfig;; esac
