#!/bin/sh

# -----------------------------------------------------------------------------
# Compile and install Sparky for Microsoft Windows 95/98/NT/2000/ME/XP.
#
# This script sets environment variables and invokes make.
#
# To build, install and package Sparky for distribution you edit the paths
# to the Sparky source code, Tcl/Tk libraries, and Python below and run the
# following commands in a bash shell:
#
#	% cd [SPARKY-SOURCE-DIR]
#	% mkdir obj
#	% bin/make-sparky-win32
#	   ... (compilation output)
#	% bin/make-sparky-win32 install
#	   ... (installation output)
#	% cd [PARENT-OF-SPARKY-INSTALL-DIR]
#	% zip -r sparky-win32.zip sparky
#
# Make sure the MinGW bin directory is in your path in front of
# the Cygwin bin directory so the MinGW compilers and make are used.
#
# The compilation on Windows is done in Unix style with make and the GNU
# compiler.  Most of the needed tools are provided in the Minimalist GNU
# for Windows (MinGW) package and Cygnus GNU Windows package Cygwin.
# The following are needed.
#
#	Tcl/Tk 8.3.4	- libraries needed by Sparky
#	Python 2.1.1	- for Sparky extensions
#
# From MinGW-1.1:
#
#	gcc 2.95.3		- C++ and C compilers
#	dlltool, dllwrap	- utilities to build shared libraries
#	make			- GNU make 3.79.1
#
# From Cygwin (a Fall 2001 release)
#
#	sh			- for running the make-sparky-win32 script
#	cp, chmod, rm		- for installing
#
# Command line zip.  Don't remember where on the web it comes from.
#
#	zip			- for compressing postscript manual
#
# Some other optional tools I use:
#
#	bash			- shell, comes with Cygwin
#	emacs 20.3.1		- editor
#	gdb			- debugger, comes with Cygwin
#
# URLs for tools:
#
#	www.scriptics.com (Tcl/Tk)
#	www.python.org
#	www.mingw.org
#	cygwin.com
#	ftp://ftp.gnu.org/gnu/windows/emacs
#

# -----------------------------------------------------------------------------
# Sparky source code location, directory for object files, and where to
# install, other Sparky specific variables.
#
# Drive letters in the SPARKY_INSTALL path confuse some versions of make
# because of the colon.  Specifically rules for building the install
# directories end up with a colon in the target name.  Replacing the drive
# letter c: with //c works in Cygnus make but was not understood by MinGW
# gcc (circa 2000).  A drive letter in the SPARKY path works.
#
BASEDIR=c:/cygwin/home/Tom/sparky
SPARKY=$BASEDIR/sparky
SPARKY_INSTALL=$BASEDIR/sparky-install
SPARKY_OBJ=$SPARKY/obj
SPARKY_SCRIPT=sparky-win32.bat
SCRIPT_SUFFIX=.bat
POSTSCRIPT_MANUAL=manual-postscript.zip
PLATFORM=win32
PYMOD_SUFFIX=.dll
EXE_SUFFIX=.exe

# -----------------------------------------------------------------------------
# Tcl/Tk version and paths.
#
TCLTK_VERSION=8.4
TCLTK_VER=84
TCLTK_PATCH_VERSION=8.4.5
TK_PREFIX=$BASEDIR/tcltk-$TCLTK_PATCH_VERSION
WIN32_TK_LIB=$TK_PREFIX/lib/tk$TCLTK_VER.lib
WIN32_TCL_LIB=$TK_PREFIX/lib/tcl$TCLTK_VER.lib
TKLIBS="-L./ -ltk$TCLTK_VER -ltcl$TCLTK_VER -luser32 -lgdi32"
TKFLAGS=-I$TK_PREFIX/include
TCL_TK_SHLIB=$TK_PREFIX/bin
TCL_SHLIB=tcl$TCLTK_VER.dll
TK_SHLIB=tk$TCLTK_VER.dll
TCL_TK_LIB=$TK_PREFIX/lib

# -----------------------------------------------------------------------------
# Python version and paths.
#
PY_VERSION=2.3
PY_VER=23
PYTHON_PREFIX=$BASEDIR/python-2.3.3
PYTHON_EXE=$PYTHON_PREFIX/python.exe
PYTHON_LIB=$PYTHON_PREFIX/Lib
WIN32_PYTHON_LIB=$PYTHON_PREFIX/libs/python$PY_VER.lib
PYLIBS="-L./ -lpython$PY_VER"
PYFLAGS="-I$PYTHON_PREFIX/include -I$PYTHON_PREFIX/lib/config"

# -----------------------------------------------------------------------------
# Compilation flags.
#
CXXFLAGS="-O -Wall -DSPARKY_NO_FSEEKO"
CFLAGS="-O -Wall"
LDLIBS="$PYLIBS $TKLIBS -lm"
SYSLIBS="-luser32 -lm"

# -----------------------------------------------------------------------------
# Commands used for installing.
#
INSTALL=cp
INSTALLDIR="cp -R"
REMOVE="rm -f"
REMOVEDIR="rm -r"

# turn on command echo
set -x

mingw32-make -f $SPARKY/Makefile -k \
	"SPARKY=$SPARKY" \
	"SPARKY_OBJ=$SPARKY_OBJ" \
	"SPARKY_INSTALL=$SPARKY_INSTALL" \
	"PY_VERSION=$PY_VERSION" \
	"PY_VER=$PY_VER" \
	"PYTHON_PREFIX=$PYTHON_PREFIX" \
	"PYTHON_DIR=$PYTHON_PREFIX" \
	"PYTHON=$PYTHON_EXE" \
	"PYTHON_LIB=$PYTHON_LIB" \
	"WIN32_PYTHON_LIB=$WIN32_PYTHON_LIB" \
	"PLATFORM=$PLATFORM" \
	"CXXFLAGS=$CXXFLAGS" \
	"CFLAGS=$CFLAGS" \
	"PYFLAGS=$PYFLAGS" \
	"TCLTK_VERSION=$TCLTK_VERSION" \
	"TCLTK_VER=$TCLTK_VER" \
	"TKFLAGS=$TKFLAGS" \
	"TKLIBS=$TKLIBS" \
	"TCL_TK_LIB=$TCL_TK_LIB" \
	"TCL_TK_SHLIB=$TCL_TK_SHLIB" \
	"TCL_SHLIB=$TCL_SHLIB" \
	"TK_SHLIB=$TK_SHLIB" \
	"WIN32_TK_LIB=$WIN32_TK_LIB" \
	"WIN32_TCL_LIB=$WIN32_TCL_LIB" \
	"EXE_SUFFIX=$EXE_SUFFIX" \
	"PYMOD_SUFFIX=$PYMOD_SUFFIX" \
	"LDSHARED=" \
	"LDLIBS=$LDLIBS" \
	"SYSLIBS=$SYSLIBS" \
	"SPARKY_SCRIPT=$SPARKY_SCRIPT" \
	"SCRIPT_SUFFIX=$SCRIPT_SUFFIX" \
	"POSTSCRIPT_MANUAL=$POSTSCRIPT_MANUAL" \
	"INSTALL=$INSTALL" \
	"INSTALLDIR=$INSTALLDIR" \
	"REMOVE=$REMOVE" \
	"REMOVEDIR=$REMOVEDIR" \
	$*
