Merge pull request #2034 from alexrp/ctx-cleanup
[mono.git] / mcs / tools / macpack / LOADER
1 #!/bin/sh
2 #
3 # This is a stub script that allows .apps to be relocatable on OSX but still
4 # find the managed assembly.
5 #
6 # You should never have to edit this file directly as its generated by the 
7 # bundle maker.
8 #
9
10 X11_MODE=%X11_MODE%
11 MWF_MODE=%MWF_MODE%
12 COCOASHARP_MODE=%COCOASHARP_MODE%
13
14 PWD=`pwd`
15 # Fetch the path relative to the launch point where this shell script exists.
16 APP_PATH=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+3] != "") { if (patharr[idx] != "/") {printf("%s/", patharr[idx]); idx++ }} }'`
17
18 # Fetch the app name (its our own name)
19 APP_NAME=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") {idx++} printf("%s", patharr[idx]); }'`
20 ASSEMBLY=`echo $0 | awk '{split($0,patharr,"/"); idx=1; while(patharr[idx+1] != "") {idx++} printf("%s.exe", patharr[idx]); }'`
21
22 # Setup the environment for MWF if needed
23 if [ "$MWF_MODE" -eq "1" ]; then
24         export MONO_MWF_USE_CARBON_BACKEND=1
25         export GDIPLUS_NOX=1
26 fi
27
28 # Setup the environment for Cocoa# if needed
29 if [ "$COCOASHARP_MODE" -eq "1" ]; then
30         export MONO_GDIP_USE_COCOA_BACKEND=1
31         export DYLD_LIBRARY_PATH=$PWD/$APP_PATH/Contents/Resources:$DYLD_LIBRARY_PATH
32 fi
33
34 cd "$APP_PATH/Contents/Resources"
35
36 if [ "$X11_MODE" -eq "1" ]; then
37         open-x11 "$APP_NAME"
38
39 # rcruzs00
40 # El Capitan FIX: `which` wont work (system-integrity-protection)
41 # elif: Keep compatibility with previous code
42 elif [ -f /usr/local/bin/mono ]; then
43         DIR=$(cd "$(dirname "$0")"; pwd)
44         /usr/local/bin/mono $DIR/../Resources/"$ASSEMBLY"
45
46 else
47         if [ ! -d "./bin" ]; then mkdir bin ; fi
48         if [ -f "./bin/$APP_NAME" ]; then rm -f "./bin/$APP_NAME" ; fi
49         ln -s `which mono` "./bin/$APP_NAME" 
50         "./bin/$APP_NAME" "$ASSEMBLY"
51 fi