#!/bin/sh
# Helper script to create a symlink to sharedlib,
#   like libgauche.so -> libgauche.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.

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

LIBGAUCHE=$1

API_VERSION=`cat ../VERSION | sed 's/_.*//'`

oldifs=$IFS
IFS="."
set $API_VERSION
IFS=$oldifs

API_MAJOR_VERSION=$1
API_MINOR_VERSION=$2
API_MICRO_VERSION=$3

: ${API_MINOR_VERSION:=0}
: ${API_MICRO_VERSION:=0}

LIB_VVV=$LIBGAUCHE.$API_MAJOR_VERSION.$API_MINOR_VERSION.$API_MICRO_VERSION
LIB_V=$LIBGAUCHE.$API_MAJOR_VERSION

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

