#!/bin/bash
################################################################################
#
# dosym - creates symlink to install path
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006, 2007 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://cygwinports.dotsrc.org/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
# $Id: dosym 4155 2008-08-07 04:58:41Z yselkowitz $
#
################################################################################
set -e

_argv=(${0} ${@})
_argc=$#

if ((_argc < 2))
then
	error "dosym: requires at least two arguments"
fi

dest="${_argv[${_argc}]}"

# cd should allow for relative symlinks
# e.g. dosym ../../share/foo /usr/lib/
if [ -d ${D}${dest} ]
then
	cd ${D}${dest}
elif [ -d ${D}${dest%/*} ]
then
	cd ${D}${dest%/*}
else
	error "dosym: ${dest%/*} is not a directory"
fi

ln -sf ${_argv[*]:1:$((_argc - 1))} ${D}${dest} || error "dosym failed"
