#
# set TCLSRCDIR to the location of the tcl source
#
TCLSRCDIR = /usr/local/src/tk3.2/tcl

#
# add -DMIDIPLAY to defines if you wish to compile in the ability to
# play standard MIDI files.  This will only work on systems
# equipped with a MIDI interface and systems with an interface
# between tclm and the MIDI device.  See the DRIVER define
# for a list of currently available interfaces.
#
# add -DUNION_WAIT if your wait3(2) system call needs a
# union wait and not an int.
#
# DEFS = -DUNION_WAIT
DEFS = -DMIDIPLAY

#
# add driver type.  This only matters if PLAYMIDI is defined
# current choices are:
#   mpu_bsd386.o        MPU-401 compatibles on BSD/386
#
# DRIVER =
DRIVER = mpu_bsd386.o

#
# set RANLIB to ranlib if your system has it - otherwise set it to
# true
#
# RANLIB = true
RANLIB = ranlib

#
# set INSTALL to be your install program
#
# INSTALL = cp
INSTALL = install

#
# set INSTALLEXECFLAG to be flags needed when installing
# executables
#
INSTALLEXECFLAG = -c -m 755

#
# set INSTALLTEXTFLAG to be flags needed when installing
# text files
#
INSTALLTEXTFLAG = -c -m 644

#
# set BINDIR to the directory where the executables should go
#
BINDIR = /usr/local/bin

#
# set LIBDIR to the directory where libtclm.a and libmutil.a should go
#
LIBDIR = /usr/local/lib

#
# set INCDIR to the directory where the .h files should go
#
INCDIR = /usr/local/include

#
# tclm library stuff
#
TCLMLIB = libtclm.a
TCLMLIBOBJS = tclmCmd.o tclmPlay.o

#
# stuff for a tclm executable
#
TCLMSRC = main.c
TCLMOBJ = main.o
TCLMEXEC = tclm

#
# some sample scripts
#
TCLMSCRIPTS = mplay minfo mseq m1to0 infom mrecord

#
# where the MIDI library routines are located
#
MIDILIBDIR = ./mlib
MIDILIB = $(MIDILIBDIR)/libmutil.a

#
# flags and libraries
# using the -lm flag in case someone has tclx which wants pow(3)
#
LIBS = -ltcl -ltclm -lmutil -lm
LDFLAGS = -L. -L$(MIDILIBDIR) -L$(LIBDIR) $(LIBS)
CFLAGS = $(DEFS) -O -I$(TCLSRCDIR) -I$(MIDILIBDIR)
CC = cc


$(TCLMEXEC): $(MIDILIB) $(TCLMLIB) $(TCLMOBJ)
	$(CC) -o $(TCLMEXEC) $(TCLMOBJ) $(LDFLAGS)

$(TCLMLIB): $(TCLMLIBOBJS)
	rm -f $(TCLMLIB)
	ar cr $(TCLMLIB) $(TCLMLIBOBJS)
	$(RANLIB) $(TCLMLIB)

$(MIDILIB): FORCE
	cd $(MIDILIBDIR); \
	$(MAKE) DEFS=$(DEFS) RANLIB=$(RANLIB) DRIVER=$(DRIVER)

install: $(TCLMEXEC) $(TCLMSCRIPTS)
	$(INSTALL) $(INSTALLEXECFLAG) $(TCLMEXEC) $(TCLMSCRIPTS) $(BINDIR)
	$(INSTALL) $(INSTALLTEXTFLAG) $(TCLMLIB) $(LIBDIR)
	$(RANLIB) $(LIBDIR)/$(TCLMLIB)
	$(INSTALL) $(INSTALLTEXTFLAG) tclm.h tclmPlay.h $(INCDIR)
	cd $(MIDILIBDIR); \
	$(MAKE) install \
	    LIBDIR="$(LIBDIR)" \
	    RANLIB="$(RANLIB)" \
	    INCDIR="$(INCDIR)" \
	    INSTALL="$(INSTALL)" \
	    INSTALLEXECFLAG="$(INSTALLEXECFLAG)" \
	    INSTALLTEXTFLAG="$(INSTALLTEXTFLAG)"

install-man-cooked:
	cd doc; $(MAKE) install-man-cooked

install-man-raw:
	cd doc; $(MAKE) install-man-raw

clean:
	rm -f $(TCLMEXEC) $(TCLMLIB) $(TCLMLIBOBJS) $(TCLMOBJ)
	cd $(MIDILIBDIR); $(MAKE) clean
	cd doc; $(MAKE) clean

FORCE:
