1#!/bin/sh
2
3if test "x$DEBUG_LAUNCHER" != x; then
4    set -x
5fi
6
7# $0 is possibly relative path to this script.
8SCRIPT_PATH="$( cd "$( dirname "$0" )" && pwd )"
9PKGBASEPATH="$( cd "${SCRIPT_PATH}/../.." && pwd )"
10
11echo "PKGBASE: $PKGBASEPATH"
12
13name=`basename "$0"`
14tmp="$0"
15tmp=`dirname "$tmp"`
16tmp=`dirname "$tmp"`
17bundle=`dirname "$tmp"`
18bundle=$PKGBASEPATH
19scriptdir=$PKGBASEPATH/Contents/MacOS/
20bundle_contents="$bundle"/Contents
21bundle_res="$bundle_contents"/Resources
22bundle_fw="$bundle_contents"/Frameworks
23bundle_lib="$bundle_res"/opt/local/lib
24bundle_bin="$bundle_res"/opt/local/bin
25bundle_data="$bundle_res"/opt/local/share
26bundle_etc="$bundle_res"/opt/local/etc
27bundle_share="$bundle_res"/opt/local/share
28
29export XDG_CONFIG_DIRS="$bundle_etc"/xdg
30export XDG_DATA_DIRS="$bundle_data"
31export GTK_DATA_PREFIX="$bundle_res"
32export GTK_EXE_PREFIX="$bundle_res"
33export GTK_PATH="$bundle_res"
34
35export GTK2_RC_FILES="$bundle_etc/gtk-2.0/gtkrc"
36export GTK_IM_MODULE_FILE="$bundle_etc/gtk-2.0/gtk.immodules"
37export GDK_PIXBUF_MODULE_FILE="$bundle_etc/gtk-2.0/gdk-pixbuf.loaders"
38
39export LANG=en_US.UTF-8
40
41WRAPPER=
42
43if [ x"$1" == "x--debug" -o x"$1" == "x--debug-clearenv" ]; then
44
45    if [ x"$1" == "x--debug-clearenv" ]; then
46       # the user has instructed us to flush their environment
47       echo "flushing some python related environment variables for this script..."
48       unset PYTHONHOME
49       unset LD_LIBRARY_PATH
50       unset PYTHONPATH
51       alias python=/usr/bin/python
52       export PATH="/usr/bin:$PATH"
53       echo "Also selected the default python executable."
54       type -all python
55    fi
56
57    if command -v lldb 2>/dev/null; then
58
59        export PYTHONPATH="$PKGBASEPATH/Contents/MacOS/Even.app/Contents/Resources/lib/"
60        export PATH="$PATH:$bundle_bin"
61        export PYTHON="$PKGBASEPATH/Contents/Frameworks/Python.framework/Versions/Current/bin/python"
62
63        echo "have set up python stuff... PYTHONHOME: $PYTHONHOME "
64        echo "have set up python stuff... PYTHON:     $PYTHON "
65
66        WRAPPER="gdb --args"
67        WRAPPER="script $HOME/FontForge-Debug-Output.txt lldb --debug --source $PKGBASEPATH/Contents/MacOS/debug-script -- "
68        $WRAPPER
69        # $WRAPPER $bundle_bin/fontforge "$2" "$3" "$4" "$5" "$6"
70        exit
71    else
72        echo "You must installed the XCode Command Lines Tools to run FontForge"
73        echo "in debug mode. For 10.7 they are available in the App Store. For"
74        echo "10.6, install XCode from the App Store then install them by running"
75        echo "XCode and looking in Preferences."
76        exit
77    fi
78fi
79
80#
81# only change these here to the local bundle ones so the scripts
82# can run.
83export PYTHONPATH="$bundle_lib/python2.7:$PKGBASEPATH/Contents/MacOS/Even.app/Contents/Resources/lib/"
84# This line allows python to find the compiled libraries so for example the gdraw
85# module can use _libraries['libgdraw.so.5'] = CDLL('libgdraw.so.5')
86export LD_LIBRARY_PATH="$bundle_lib"
87
88
89#/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -f FontForge.app
90
91# This ensures that File Open and File Save (etc) dialogs open in Home
92# when FontForge is launched via normal OS X methods (double-clicking
93# on the application or a SFD file, spotlight, etc.). If this script is
94# invoked via command line, assume the user knows what they are doing,
95# and don't change the current directory.
96if [ "$( ps -o comm= $PPID)" = "/sbin/launchd" ] ; then
97    cd ~/ || true
98fi
99
100export PATH="$PATH:$bundle_bin"
101echo $WRAPPER $bundle_bin/fontforge > /tmp/oo
102
103if [ $# -eq 0 ] ; then
104    ( exec $WRAPPER $bundle_bin/fontforge -new  )
105else
106    ( exec $WRAPPER $bundle_bin/fontforge "$@"  )
107fi
108