#!/bin/sh
#
# $Id$
#
WINGS_VSN="%WINGS_VSN%"

if test x"$1" = x"" ; then
    INSTALL_DIR="$HOME/wings-$WINGS_VSN"
else
    INSTALL_DIR="$1/wings-$WINGS_VSN"
fi

echo "Installing Wings 3D $WINGS_VSN in $INSTALL_DIR"
mkdir -p $INSTALL_DIR
tar cf - * | (cd $INSTALL_DIR; tar xf -)
rm -f $INSTALL_DIR/install_wings

sed <<'EOF' -e "s^%ROOTDIR%^$INSTALL_DIR^" > $INSTALL_DIR/wings
#!/bin/sh
ROOTDIR=%ROOTDIR%
BINDIR=$ROOTDIR/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
unset ERL_LIBS
export EMU
export ROOTDIR
export BINDIR
export PROGNAME
GDK_BACKEND=x11
export GDK_BACKEND
exec $BINDIR/erlexec -noinput -smp -run wings_start start_halt ${1+"$@"}
EOF

chmod +x $INSTALL_DIR/wings

sed <<'EOF' -e "s^%ROOTDIR%^$INSTALL_DIR^" > $INSTALL_DIR/bin/erl
#!/bin/sh
ROOTDIR=%ROOTDIR%
BINDIR=$ROOTDIR/bin
EMU=beam
PROGNAME=`echo $0 | sed 's/.*\///'`
unset ERL_LIBS
export EMU
export ROOTDIR
export BINDIR
export PROGNAME
GDK_BACKEND=x11
export GDK_BACKEND
exec "$BINDIR/erlexec" ${1+"$@"}
EOF

chmod +x $INSTALL_DIR/bin/erl

sed <<'EOF' -e "s^%ROOTDIR%^$INSTALL_DIR^;s^%WINGS_VSN%^$WINGS_VSN^" > $INSTALL_DIR/wings.desktop
[Desktop Entry]
Type=Application
Terminal=false
Exec=%ROOTDIR%/wings
Name=Wings 3D
GenericName=A 3D Subdivision Modeler
Comment=A 3D modeler that is both powerful and easy to use
GenericName[en]=A 3D Subdivision Modeler
Comment[en]=A 3D modeler that is both powerful and easy to use
Icon=%ROOTDIR%/lib/wings-%WINGS_VSN%/ebin/wings_icon_379x379.png
Categories=GNOME;GTK;Graphics;3DGraphics;
EOF

chmod +x $INSTALL_DIR/wings.desktop

exit 0;
