#!/bin/sh
#
# file     : install_macosx.sh
#
# author   : Bastian Spiegel <http://tkscript.de>
# copyright: (c) 2004-2005. Released under the terms of the GNU General Public License. 
#            See <http://www.gnu.org/licenses/licenses.html#GPL>
#
# info     : web-install script for the tkScript engine and the
#            SDL,OpenGL, freetype2 and tkui plugins.
#            Usage:
#                    # . install_macosx.sh download|unzip|compile|test|xtest|xtest2|xtest3|install
#
# changed  : 22-Aug-2005 / 20Sep2005
#
#
#
DL=wget
UZ=unzip

_URL=http://tkScript.de

f_download_file() {
  if test -e `basename "$1"`; then
     echo "skipping download of \"$1\""
  else
     $DL "$_URL/$1"
  fi
}

f_unzip_file() {
  if test -d "$1"; then
     echo "skipping unzip of directory \"$1\" ($1.zip)"
  else
     $UZ "$1"
  fi
}

f_download() {
  f_download_file "files/yac.zip"
  f_download_file "files/tks-source.zip"
  f_download_file "files/tks-examples.zip"
  f_download_file "plugins/tksdl.zip"
  f_download_file "plugins/tkopengl.zip"
  f_download_file "plugins/tkfreetype2.zip"
  f_download_file "plugins/tkui.zip"
}

f_unzip() {
  f_unzip_file "yac"
  f_unzip_file "tks-source"
  f_unzip_file "tks-examples"
  f_unzip_file "tksdl"
  f_unzip_file "tkopengl"
  f_unzip_file "tkfreetype2"
  f_unzip_file "tkui"
}

f_compile() {
  cd tksdl       && make -f makefile.macosx static ; cd ..
  cd tkopengl    && make -f makefile.macosx static ; cd ..
  cd tkfreetype2 && make -f makefile.macosx plugin ; cd ..
  cd tkui        && make -f makefile.macosx plugin ; cd ..
  cd tks-source  && make -f makefile.macosx tksdl  ; cd ..
}

f_install() {
#  cd tksdl       && make -f makefile.macosx install ; cd ..
#  cd tkopengl    && make -f makefile.macosx install ; cd ..
  cd tkfreetype2 && make -f makefile.macosx install ; cd ..
  cd tkui        && make -f makefile.macosx install ; cd ..
  cd tks-source  && make -f makefile.macosx install-tksdl ; cd ..
}

f_xtest() {
   f_download_file "$_URL/tkx/juliaattractor.tkx"
   tks-source/tks juliaattractor
}

f_xtest2() {
   f_download_file "$_URL/tkx/bobfield.tkx"
   tks-source/tks bobfield
}

f_xtest3() {
   f_download_file "$_URL/tkx/fire3.tks"
   tks-source/tks fire3
}

f_test() {
   tks-source/tks tks-source/sieve.tks
}

f_testui() {
   $(DL) http://tkscript.de/tkx/testui-21Aug2005-align.tkx
   tks-source/tks testui-21Aug2005-align.tkx
}

case "$1" in
    "")
      echo "Usage:"
      echo "    ./install_tks.sh download  "
      echo "                     unzip"
      echo "                     compile"
      echo "                     install"
      echo "                     test   (tks-source/sieve.tks)"
      echo "                     xtest  (downloads juliaattractor.tks)"
      echo "                     xtest2 (downloads bobfield.tks)"
      echo "                     xtest3 (downloads fire3.tks)"
      echo " "
      echo " Suggestion: ./install_tks.sh install"
      echo "             ./install_tks.sh test"
      echo " "
      ;;
    "all")
       f_download;
       f_unzip;
       f_install;
       f_test;
       f_xtest;
       ;;
    "install")
       f_download;
       f_unzip;
       f_compile;
       f_install;
       ;;
    "download")
       f_download;
       ;;
    "unzip")
       f_download;
       f_unzip;
       ;;
    "compile")
       f_download;
       f_unzip;
       f_compile;
       ;;
    "test")
       f_download;
       f_unzip;
       f_compile;
       f_test;
       ;;
    "xtest")
       f_download;
       f_unzip;
       f_compile;
       f_xtest;
       ;;
    "testui")
       f_download;
       f_unzip;
       f_compile;
       f_testui;
       ;;
    "xtest2")
       f_download;
       f_unzip;
       f_compile;
       f_xtest2;
       ;;
    "xtest3")
       f_download;
       f_unzip;
       f_compile;
       f_xtest3;
       ;;
esac    

