#!/bin/sh
#
# wrapper.sh - Create a clrwrap wrapper for an IL executable.
#
# Copyright (C) 2003  Southern Storm Software, Pty Ltd.
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Usage: wrapper.sh $(DESTDIR)$(bindir)/foo$(EXEEXT)

# Variables that are substituted in by configure.
LN_S="@LN_S@"
CLRWRAP="@CLRWRAP@"
host="@host@"
INSTALL_AS_DEFAULT="@INSTALL_AS_DEFAULT@"

# Don't do anything if we aren't the default install version.
if test "x$INSTALL_AS_DEFAULT" = "xfalse" ; then
	exit 0
fi

# Determine whether we should use the Win32 or Unix wrapping mechanism.
case "$host" in
	*-*-mingw*|*-*-cygwin*)
		# Copy the "clrwrap" binary to the final location.
		echo rm -f "$1"
		rm -f "$1"
		echo cp "${CLRWRAP}.exe" "$1"
		if cp "${CLRWRAP}.exe" "$1" ; then
			echo strip "$1"
			strip "$1" 2>/dev/null
			exit 0
		else
			exit 1
		fi
		;;
	*)
		# Create a symbolic link from the name to "clrwrap".  We link
		# to "clrwrap" in the same directory, because $CLRWRAP points to
		# the build time "clrwrap", not the runtime version.
		echo rm -f "$1"
		rm -f "$1"
		echo $LN_S clrwrap "$1"
		exec $LN_S clrwrap "$1"
		;;
esac
exit 0
