#!/bin/bash

# Launcher for building tclMuPdf on Linux/MacOsX/MingW environments
#  using the standard GNU/C tool-chain 
#  Read build-notes.tx for further info

function Usage {
	echo "Usage: ${_THISCMD} _tcl_ [args]"
	echo "    _tcl_ : \"tcl-8\" or \"tcl-9\""
	echo "    optional args are passed to make"
}

_THISCMD=$0
_TCL_MAJOR_VER=$1
_ARCH=x64

shift

if [ "${_TCL_MAJOR_VER}" != "tcl-8" -a "${_TCL_MAJOR_VER}" != "tcl-9" ] ; then
	Usage
	exit 1
fi

echo =================================
echo Preliminary checks .....
echo =================================

# currently only x64 architecture is supported, then no need for an input parameter

_ARCH=x64

# ... We presume the C-build environment is properly set ..
 

echo =================================
echo Preliminary checks ..... DONE.
echo =================================
echo

 function toLower {
 	echo $* | tr '[:upper:]' '[:lower:]'
 }                                   
_OS=$(uname -s)
_OS=$(toLower $_OS)

case $_OS in
  linux*)  _OS=linux
  ;;
  darwin*) _OS=darwin
  ;;
  mingw*|msys*|cygwin*)  _OS=win
  ;;
  *) echo Unsupported OS "$_OS"
     exit 1
     ;;
esac


 ## you can also pass extra args to make ...
shift
_MAKEOPTS="--no-builtin-rules --no-builtin-variables"  ;# you must be EXPLICIT !
make ${_MAKEOPTS} -f unix-makefile OS=${_OS} TCL_MAJOR_VER=${_TCL_MAJOR_VER} ARCH=${_ARCH}  $*
