#
# The path to your tcl interpreter
#
TCLSH=/usr/local/bin/tclsh8.0

#
# The directory containing the tcl correct version of tcl.h
#
TCL_INCLUDE_DIR=/usr/local/include/tcl8.0

#
# The path to your SmallEiffel installation
# Note: At the time of the writing, the latest SmallEiffel release,
#       -0.78 does not work, use -0.79
#
EPATH=/usr/local/src/eiffel/SmallEiffel-0.79

#
# Where you want to install the tclmidi library
#
DESTDIR=/usr/local/lib/tclmidi

#
# Where you want to install the tclmidi man pages
#
MANDIR=/usr/local/man

#
# How to install things
#
INSTALL=install -c

#
# If you encounter a bug, remove -boost from this list a rebuild from
# scratch.  This will enable all the Eiffel assertion checks.  Things
# will run much slower, but hopefully there will be a useful stack trace
# after the crash.
#
# Add -DCOMPAT_3 if you want track and channel numbering to start at
# 0 instead of 1.
#
EFLAGS=-boost -case_insensitive -no_main -cecil cecil.se -no_strip

# The rest of this should be fine as is - yeah, right
SONAME=libtclmidi.so
LIB=$(SONAME).4

CFILES=tclmidiCmd.c tcl_channel_hooks.c tcl_list_hooks.c
EFILES=lib/*.e

EC=$(EPATH)/bin/compile
ECLEAN=$(EPATH)/bin/clean
LDFLAGS=-fpic -shared -I$(TCL_INCLUDE_DIR) -Wl,-soname,$(SONAME)

all: pkgIndex.tcl

pkgIndex.tcl: $(SONAME)
	@echo 'pkg_mkIndex . $(SONAME)' | $(TCLSH)

$(LIB): $(EFILES) $(CFILES)
	@echo
	@echo '*** Ignore the gcc linker file warnings ***'
	@echo
	$(EC) $(EFLAGS) c_factory $(CFILES) $(LDFLAGS) -o $(LIB)

$(SONAME): $(LIB)
	ln -s $(LIB) $(SONAME)

install: $(LIB)
	-mkdir -p $(DESTDIR)
	$(INSTALL) -m 644 $(LIB) $(DESTDIR)
	cd $(DESTDIR) ; ln -sf $(LIB) $(SONAME)
	echo 'pkg_mkIndex $(DESTDIR) *.so' | $(TCLSH)
	cd man ; make MANDIR="$(MANDIR)" INSTALL="$(INSTALL)" install
	@echo
	@echo
	@echo "===================================================="
	@echo "You must add $(DESTDIR) to your"
	@echo "TCLLIBPATH environment variable.  This environment"
	@echo "variable is a list of directories a tcl interpreter"
	@echo "will search to find loadable modules.  The list is"
	@echo "white space separated (as opposed to colon separated"
	@echo "like many other Unix environment variables)."
	@echo "===================================================="

clean:
	$(ECLEAN) c_factory
	rm -f $(SONAME) $(LIB) eiffel.h *.core pkgIndex.tcl
