#
# Makefile for tkmh
#
# Change these three variables to point to the directories where wish can
# be found, and where you want to install the tkmh library and executable.
# You will need write permission in those directories.
#
# To complete the configuration, you will also need to edit the file
# tkmh.rc, and set the commands to use and the bindir for MH.
#

WISH = /usr/tclocal/bin/wish
LIBDIR = /usr/tclocal/lib
BINDIR = /usr/tclocal/bin

#
# Do not change anything below this, TkMH might not work correctly if you do.
#

TKMH_LIB = $(LIBDIR)/tkmh
TKMH_BITMAP = $(TKMH_LIB)/bitmaps
TKMH_HELP = $(TKMH_LIB)/help

TCLSRC = alias.tcl bindings.tcl config.tcl folders.tcl general.tcl \
         help.tcl main.tcl message.tcl utils.tcl convert.tcl sequence.tcl

TKMH_RC = dot_tkmh dot_mh tkmh.rc app-defaults

# Rules

all: clean tkmh elm2mh

install: all instlib index instbitmaps insthelp
	@echo Installing TkMH executable in $(BINDIR)
	@cp tkmh $(BINDIR)
	@chmod 755 $(BINDIR)/tkmh
	@if [ -f elm2mh ] ; then \
	  echo "Installing elm2mh in $(BINDIR)"; \
	  cp elm2mh $(BINDIR); \
	  chmod 755 $(BINDIR)/elm2mh; \
	else true; \
	fi

instlib:
	@rm -rf $(TKMH_LIB)
	@mkdir $(TKMH_LIB)
	@chmod 755 $(TKMH_LIB)
	@echo Installing library in $(TKMH_LIB)
	@for i in $(TCLSRC) $(TKMH_RC); \
	do \
	  cp ./lib/$$i $(TKMH_LIB); \
	  chmod 644 $(TKMH_LIB)/$$i; \
	done

insthelp:
	@echo Installing help files in $(TKMH_HELP)
	@mkdir $(TKMH_HELP)
	@chmod 755 $(TKMH_HELP)
	@cp -r ./lib/help/* $(TKMH_HELP)
	@chmod -R 755 $(TKMH_HELP)

instbitmaps:
	@echo Installing bitmaps in $(TKMH_BITMAP)
	@mkdir $(TKMH_BITMAP)
	@chmod 755 $(TKMH_BITMAP)
	@cp -r ./lib/bitmaps/* $(TKMH_BITMAP)
	@chmod -R 755 $(TKMH_BITMAP)

tkmh:
	@echo Creating TkMH
	@echo \#!$(WISH) -f >tkmh
	@echo set tkmh_lib $(TKMH_LIB) >>tkmh
	@echo lappend auto_path \$$tkmh_lib >>tkmh
	@echo "" >>tkmh
	@echo \# >>tkmh
	@echo \# Main program >>tkmh
	@echo \# >>tkmh
	@echo "" >>tkmh
	@echo Init >>tkmh
	@echo makeControl >>tkmh
	@echo Loop >>tkmh
	@echo "" >>tkmh
	@chmod 755 tkmh

index: $(TKMHLIB)
	@echo Creating tclIndex in $(TKMH_LIB)
	@echo "auto_mkindex $(TKMH_LIB) *.tcl; exit" | $(WISH)

elm2mh: elm2mh.c
	@echo Compiling elm2mh
	@cc -o elm2mh elm2mh.c

test:
	@echo Creating test
	@echo \#!$(WISH) -f >tkmh.test
	@echo set tkmh_lib [pwd]/lib >>tkmh.test
	@echo lappend auto_path \$$tkmh_lib >>tkmh.test
	@echo Init >>tkmh.test
	@echo makeControl >>tkmh.test
	@echo Loop >>tkmh.test
	@chmod 755 tkmh.test
	@echo Running tkmh test
	@./tkmh.test
	@rm tkmh.test

clean:
	@rm -f tkmh elm2mh

uninstall: clean
	@rm -rf $(TKMH_LIB) $(BINDIR)/tkmh $(BINDIR)/elm2mh
