#!/bin/sh
# Helper script to create a symlink to sharedlib,
#   like libgauche-0.9.so -> libgauche-0.9.so.0.1
# Assumes $TARGETLIB and $DESTDIR is set by the caller.

# In some occasions, TARGETLIB contains a path like
# '@executable_path/../Frameworks/Gauche.framework'.
# We don't need to create links in such case.

# NB: In 0.9.x series, we create a link libgauche.so -> libgauche-0.9.so
# for the backward comatibility.  This feature should be removed on 1.0
# release.

case "$TARGETLIB" in
  "@*")
    exit 0;;
esac

LIBGAUCHE=$1

MICRO_VERSION=@GAUCHE_MICRO_VERSION@

LIB_VVV=$LIBGAUCHE.0.$MICRO_VERSION
LIB_V=$LIBGAUCHE.0
LIB_COMPAT=libgauche.so

cd $DESTDIR$TARGETLIB
# avoid re-running mkverslink.
if test -f $LIB_VVV -a -L $LIBGAUCHE; then exit; fi
rm -f $LIB_VVV
mv $LIBGAUCHE $LIB_VVV
ln -s $LIB_VVV $LIBGAUCHE
rm -f $LIB_V
ln -s $LIB_VVV $LIB_V

if [ -f $LIB_COMPAT ]; then
  rm -f $LIB_COMPAT
  ln -s $LIBGAUCHE $LIB_COMPAT
fi
if [ -f $LIB_COMPAT.0 ]; then
  rm -f $LIB_COMPAT.0
  ln -s $LIB_V $LIB_COMPAT.0
fi
if [ -f $LIB_COMPAT.0.9.0 ]; then
  rm -f $LIB_COMPAT.0.9.0
  ln -s $LIB_VVV $LIB_COMPAT.0.9.0
fi


