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

PREFIX = /local/www.people/personal/meurig/haskell/built/tclhaskell

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

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

# the library files to use - change for different version
TCLLIBS = -ltk8.3 -ltcl8.3

# 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
CC_INC = -I/usr/X11/include -I/usr/local/include

# ld options for generating shared libraries for Hugs:

# SLD_OPTS   = -r		# (Solaris)
SLD_OPTS = -shared	# (OSF/1+Linux)


# The directories containing the X11, Tcl and Tk (binary) libraries:

CCLIB = -L /usr/lib/X11 -L /usr/local/lib


# the libraries required by Tcl/Tk:

#TCLREQ =  -ltk8.3 -ltcl8.3 -lX11 -lm -lsocket -lnsl -lintl -lw # (Solaris)
TCL_REQ  = -ltk8.3 -ltcl8.3 -lm -lc                   # (OSF/1+Linux)

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
#
#######################################################################

all : libHSTclHaskell.a HSTclHaskell.o libHSTclHaskell_cbits.a HSTclHaskell_cbits.o

install : libHSTclHaskell.a HSTclHaskell.o
	mkdir -p $(LIBDIR)
	mkdir -p $(IMPORTS)
	cp -p libHSTclHaskell.a $(LIBDIR)/
	cp -p HSTclHaskell.o $(LIBDIR)/
	cp -p libHSTclHaskell_cbits.a $(LIBDIR)/
	cp -p HSTclHaskell_cbits.o $(LIBDIR)/
	cp -p $(HIS) $(IMPORTS)/

pkg : 
	ghc-pkg -a < tclhaskell.conf

unpkg:
	ghc-pkg -r TclHaskell


tclprim : TclPrimImpl.o tclhaskell.o

libHSTclHaskell_cbits.a: tclhaskell.o 
	ar -r libHSTclHaskell_cbits.a tclhaskell.o

HSTclHaskell_cbits.o: libHSTclHaskell_cbits.a
	ld -r --whole-archive -o HSTclHaskell_cbits.o libHSTclHaskell_cbits.a

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.so

TclPrim.so: TclPrim.o tclhaskell.o
	$(LD) $(SLD_OPTS) \
		$(CCLIB) \
		-o TclPrim.so TclPrim.o tclhaskell.o \
			$(TCL_REQ)

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


### Boilerplate GHC stuff

.SUFFIXES	: .lhs .hs .hi .o

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

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

%.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
TclTime.o : TclTime.hs
TclTime.o : ./TclCompatibility.hi
ConcTcl.o : ConcTcl.hs
ConcTcl.o : ./TclCompatibility.hi
ConcTcl.o : ./TclPrimImpl.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
