#######################################################################
#
# adjust paths here
# and in tclhaskell.conf.nt
#
#######################################################################

PREFIX = C:/ExtraUtils/built

# where to install the libHSTclHaskell.a library
LIBDIR = $(PREFIX)/tclhaskell

# where to install the TclHaskell interface files
IMPORTS = $(PREFIX)/tclhaskell/imports

# The Root directory in which Tcl was installed
TCLROOT = /ExtraUtils/Tcl

TCLLIBDIR = /ExtraUtils/Tcl/bin

# the library files to use - change for different version
TCLLIBS = -ltk80 -ltcl80

# Location of ghc package configuration file. This
# will be in the directory in which ghc was installed
PKGFILE = c:/Program\ Files/Glasgow\ Haskell\ Compiler/ghc-5.02/package.conf

# Ununcomment this line to support concurrency. 
# This support does NOT work with ghci. It does not currently export 
# the special run_head_queue variable. Will allegedly 
# be fixed in a future version of ghc.

# this version supports concurrency
#SUPPORTCONCURRENCY = TclCompatibilityGhcSupportsConcurrency.hs

# this version does not
SUPPORTCONCURRENCY = TclCompatibilityGhc.hs

#######################################################################
#
# the C compiler must find the tcl/tk include files
#
# ( and the linker must find the tcl/tk libs
#   these paths are in frantk.conf )
#
#######################################################################

CC = gcc
CC_OPTS = -O -mno-cygwin
CC_INC = -I$(TCLROOT)/include -I$(TCLROOT)/include/X11

GHC = ghc

RM   = rm -f

#######################################################################
#
# do not modify
#
#######################################################################


# Standard defs:
OBJS = $(SRC:.hs=.o)
HIS = *.hi

GHC_OPTS = -O -fglasgow-exts -recomp -dcore-lint -fvia-C \
           -package concurrent -package-name TclHaskell

GHC_INC =

DEPENDFLAGS = -fglasgow-exts -syslib concurrent

SRC = Tcl.hs TclWidgets.hs TclHandle.hs GUIMonad.hs \
      TclPrimExports.hs TclPrimImpl.hs PlacePos.hs TclConf.hs \
      TclPrimWidgets.hs TclPrimCore.hs TclGUI.hs TclTrie.hs \
      $(SUPPORTCONCURRENCY) TclTime.hs ConcTcl.hs \
      TrieIO.hs TclPrimGhc.hs ExtArray.hs Remover.hs Utils.hs



#######################################################################
#
# make targets
#
#######################################################################

LIBS = libHSTclHaskell.a HSTclHaskell_cbits.dll libHSTclHaskell_cbits.a  HSTclHaskell.o 

all : $(LIBS)

install : $(LIBS)
	mkdir -p $(LIBDIR)
	mkdir -p $(IMPORTS)
	cp -p $(LIBS) $(LIBDIR)/
	cp -p $(HIS) $(IMPORTS)/

pkg : 
	$(RM) $(PKGFILE).old
	ghc-pkg  -a < tclhaskell.conf.nt

unpkg:
	$(RM) $(PKGFILE).old
	ghc-pkg -r TclHaskell

tclprim : TclPrimImpl.o tclhaskell.o

HSTclHaskell_cbits.dll: tclhaskell.o
	dllwrap -mno-cygwin --target=i386-mingw32 --output-lib libHSTclHaskell_cbits.a --export-all --output-def tclhaskell.def -o HSTclHaskell_cbits.dll tclhaskell.o -L$(TCLLIBDIR) $(TCLLIBS)

HSTclHaskell.o: libHSTclHaskell.a
	ld -r --whole-archive -o HSTclHaskell.o libHSTclHaskell.a

libHSTclHaskell.a: $(OBJS)
	ar -r libHSTclHaskell.a $(OBJS)

TclPrim.hi: TclPrimGhc.o
		@:

TclPrimGhc.o: tclhaskell.h TclPrimGhc.hs
	$(GHC) $(GHC_OPTS) $(GHC_INC) -c  TclPrimGhc.hs -ohi TclPrim.hi -o $@ 

TclCompatibility.hi: TclCompatibilityGhc.o
		@:

TclCompatibilityGhc.o: Check.h TclPrim.hi
	$(GHC) $(GHC_OPTS) $(GHC_INC) '-#include "Check.h"' -c  $(SUPPORTCONCURRENCY) -ohi TclCompatibility.hi -o $@ 



#
# tclhaskell.o
#

tclhaskell.o: tclhaskell.c tclhaskell.h
	$(CC) -c $(CC_OPTS) $(CC_INC) tclhaskell.c -o tclhaskell.o


#
# Hugs Stuff
#

hugs: TclPrim.dll

TclPrim.dll: TclPrim.c tclhaskell.h tclhaskell.o
	$(CC) -c $(CC_OPTS) $(CC_INC) TclPrim.c -o TclPrim.o 
	dllwrap -mno-cygwin --target=i386-mingw32 --output-lib libtclprim_imp.a --export-all --output-def tclprim.def -o TclPrim.dll TclPrim.o tclhaskell.o -L$(TCLLIBDIR) $(TCLLIBS)
	$(CC) -c $(CC_OPTS) $(CC_INC) TclPrim.c -o TclPrim.o 
	$(RM) TclPrim.o

### Boilerplate GHC stuff

.SUFFIXES	: .lhs .hs .hi .o

depend :: 	$(SRC)
		$(GHC) -M $(DEPENDFLAGS) $(SRC)

clean ::
	$(RM) *.o *.hi *.exe *.a

%.hi		: %.o
		@:

%.o		: %.hs
		$(RM) $@
		$(GHC) $(GHC_OPTS) $(GHC_INC) -c $< 


# DO NOT DELETE: Beginning of Haskell dependencies
Tcl.o : Tcl.hs
Tcl.o : ./TclPrimExports.hi
Tcl.o : ./GUIMonad.hi
Tcl.o : ./TclWidgets.hi
Tcl.o : ./TclHandle.hi
TclWidgets.o : TclWidgets.hs
TclWidgets.o : ./TclPrimExports.hi
TclWidgets.o : ./TclPrimImpl.hi
TclWidgets.o : ./TclConf.hi
TclWidgets.o : ./GUIMonad.hi
TclHandle.o : TclHandle.hs
TclHandle.o : ./TclWidgets.hi
TclHandle.o : ./TclPrimImpl.hi
GUIMonad.o : GUIMonad.hs
GUIMonad.o : ./TclPrimExports.hi
GUIMonad.o : ./Utils.hi
GUIMonad.o : ./TclGUI.hi
TclPrimExports.o : TclPrimExports.hs
TclPrimExports.o : ./TclGUI.hi
TclPrimExports.o : ./TclPrimCore.hi
TclPrimExports.o : ./TclPrimWidgets.hi
TclPrimImpl.o : TclPrimImpl.hs
TclPrimImpl.o : ./TclGUI.hi
TclPrimImpl.o : ./TclPrimCore.hi
TclPrimImpl.o : ./TclPrimWidgets.hi
PlacePos.o : PlacePos.hs
TclConf.o : TclConf.hs
TclConf.o : ./Utils.hi
TclConf.o : ./PlacePos.hi
TclConf.o : ./GUIMonad.hi
TclConf.o : ./TclPrimImpl.hi
TclConf.o : ./TclPrimExports.hi
TclPrimWidgets.o : TclPrimWidgets.hs
TclPrimWidgets.o : ./Utils.hi
TclPrimWidgets.o : ./Remover.hi
TclPrimWidgets.o : ./TclPrimCore.hi
TclPrimWidgets.o : ./TclGUI.hi
TclPrimCore.o : TclPrimCore.hs
TclPrimCore.o : ./PlacePos.hi
TclPrimCore.o : ./Utils.hi
TclPrimCore.o : ./Remover.hi
TclPrimCore.o : ./TclTrie.hi
TclPrimCore.o : ./TclGUI.hi
TclGUI.o : TclGUI.hs
TclGUI.o : ./TclTime.hi
TclGUI.o : ./ExtArray.hi
TclGUI.o : ./TclTrie.hi
TclGUI.o : ./TclCompatibility.hi
TclGUI.o : ./Remover.hi
TclTrie.o : TclTrie.hs
TclTrie.o : ./Remover.hi
TclTrie.o : ./Utils.hi
TclTrie.o : ./TrieIO.hi
TclCompatibilityGhc.o : $(SUPPORTCONCURRENCY)
TclCompatibilityGhc.o : ./TclPrim.hi
TclTime.o : TclTime.hs
TclTime.o : ./TclCompatibility.hi
TrieIO.o : TrieIO.hs
TclPrimGhc.o : TclPrimGhc.hs
ExtArray.o : ExtArray.hs
Remover.o : Remover.hs
Utils.o : Utils.hs
# DO NOT DELETE: End of Haskell dependencies
