#!/bin/sh

# Author: Marc Christensen (mchristensen@novell.com)
#         Michael Hutchinson (mhutchinson@novell.com)

MONO_FRAMEWORK_PATH=/Library/Frameworks/Mono.framework/Versions/Current
export DYLD_FALLBACK_LIBRARY_PATH=$MONO_FRAMEWORK_PATH/lib:/lib:/usr/lib

#we need lots of file handles
ulimit -n 1024

#prevent Macports from messing up mono and pkg-config
export PATH="$MONO_FRAMEWORK_PATH/bin:$PATH"

DIR=$(cd "$(dirname "$0")"; pwd)

EXE_PATH="$DIR/lib/monodevelop/bin/mdrun.exe"

PKG_CONFIG_PATH="$DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
export PKG_CONFIG_PATH

# Work around a bug in 'exec' in older versions of macosx
OSX_VERSION=$(uname -r | cut -f1 -d.)
if [ $OSX_VERSION -lt 9 ]; then  # If OSX version is 10.4
	MONO_EXEC="mono"
else
	MONO_EXEC="exec -a monodevelop mono"
fi

## use an app-specific registry if possible
#if [ -w "$DIR" ]; then
#	export MONO_ADDINS_REGISTRY="$DIR"
#fi

## Moonlight SDK
if [ -d "$DIR/lib/moonlight" ]; then
	export MOONLIGHT_SDK_PATH="$DIR/lib/moonlight"
fi

### END MAC-SPECIFIC SETUP
### Beyond this, all is from the Linux mdtool.in. Only the values of EXE_PATH and MONO_EXEC differ

_MONO_OPTIONS=$MONO_OPTIONS

$MONO_EXEC $_MONO_OPTIONS "$EXE_PATH" $*

