#!/bin/sh

# Shell script for invoking Wing.  If the first argument is --winghome
# then the directory wing is installed in is echoed to stdout and the script exits.
# Other arguments are:
#  --verbose     Print debugging output
#  --silent      Run silently
#  --system-gtk  Use system-wide version of gtk, rather than Wing's copy
#  --private-gtk Use Wing's copy of gtk rather than the system version
#
# To develop and run from sources, set WINGHOME and WINGPYTHON
# 
# Copyright (c) 2000-2018, Archaeopteryx Software, Inc.  All rights reserved.
#
# Written by Stephan R.A. Deibel and John P. Ehresman

# Unalias commands we rely on being the defaults; don't use shopt because
# it does not exist under some shells used on Linux
alias dirname=xxx
unalias dirname

# Find WINGHOME unless caller has passed it in
if [ "${WINGHOME}" = "" ]; then
    BOOTSTRAP_DIR=`dirname "$0"`
    WINGHOME=`dirname "${BOOTSTRAP_DIR}"`; export WINGHOME
fi

UNAME=`uname`
if [ ${UNAME} = "Darwin" ]; then
    MACOS_EXECUTABLE="${WINGHOME}/../MacOS/Wing Pro"
    if [ -x "${MACOS_EXECUTABLE}" ]; then
        exec "${MACOS_EXECUTABLE}" "$@"
    fi
fi

# Location of Python interpreter to use, if not already set
TARGET_PYTHON="python3.12"
WING_PLATFORM="linux-x64"
if [ "${WINGPYTHON}" = "" ]; then
    WINGPYTHON="${WINGHOME}/bin/__os__/${WING_PLATFORM}/runtime-${TARGET_PYTHON}/bin/${TARGET_PYTHON}"
fi

# Just echo home and exit if requested
if [ "$1" = "--winghome" ]; then
    echo ${WINGHOME}
    exit 0
fi

# Run Python optimized, don't import site, ignore environment, don't use 
# user site-packages even if site is imported
PYTHON_ARGS="-OSEs"

# Run the IDE
if [ -f "${WINGHOME}/bootstrap/wing.py" ]; then
  exec "${WINGPYTHON}" ${PYTHON_ARGS} "${WINGHOME}/bootstrap/wing.py" "$@"
fi

echo "wing: Error: wing.py not found.  Please check your Wing installation"
