#!/bin/sh
# Makefile supplies a phony packagedir, so try not to use it without
# fixing Makefile first.
PACKAGEDIR="$1"
INSTALLDIR="$2"
UNIX_PREFIX="/usr/local"
# check if we are run from Installer.app
if [ x"$PACKAGEDIR" != x"from_Makefile" ]; then
  INSTALLDIR=$INSTALLDIR/Emacs.app
else
  if [ x"$3" != x ]; then
    UNIX_PREFIX="$3"
  fi
fi
echo
echo "Creating links from $UNIX_PREFIX/bin to the Emacs binaries."
/bin/mkdirs $UNIX_PREFIX/bin
for binary in b2m ctags emacs emacsclient etags rcs-checkin; do
  /bin/ln -s $INSTALLDIR/bin/$binary $UNIX_PREFIX/bin
done

echo "Creating links from $UNIX_PREFIX/man subdirectories to the Emacs man pages."
/bin/mkdirs $UNIX_PREFIX/man/man1 $UNIX_PREFIX/man/man6
for man in man/man1/emacs.1 man/man1/etags.1 man/man1/ctags.1 share/emacs/*/etc/celibacy.1 share/emacs/*/etc/condom.1; do
  /bin/ln -s $INSTALLDIR/$man $UNIX_PREFIX/man/man1
done
/bin/ln -s  $INSTALLDIR/share/emacs/*/etc/sex.6 $UNIX_PREFIX/man/man6

echo "Creating a link from $UNIX_PREFIX/share/emacs to the emacs library directory."
/bin/mkdirs $UNIX_PREFIX/share
/bin/ln -s $INSTALLDIR/share/emacs $UNIX_PREFIX/share

echo "Done."
exit 0
