## GENERIC DEFINES ##
#
# These are generic defaults that should work for most systems.  Before
# changing them, skip down to the SYSTEM-DEPENDENT OPTIONS section and
# see if the defaults there are more suitable for your system.

CXX = g++
CC  = gcc
RANLIB = ranlib

## OPTIMIZATION FLAGS ##
#
# Debug and/or optimize

#OFLAGS = -g
#OFLAGS = -O -g
OFLAGS = -O

## ADDITIONAL COMPILATION OPTIONS ##
#
# -DTCL_7_3		Define if you use Tcl 7.3 instead of Tcl 7.4
# -DUSE_PTHREADS	Define if you want pthread support.  Incomplete.
#
# Feel free to add any other flags you like.

COMPFLAGS = -Wall
#COMPFLAGS =

# where to find the TCL library and header files
TCLLIBDIR = /usr/local/lib
TCLINCDIR = /usr/local/include

# where to find X11 (needed only if you want to make tkmidi)
XLIBDIR = /usr/X11/lib
XINCDIR = /usr/X11/include

# where to install the finished product.. typically /usr/local
# binaries will go in $(PREFIX)/bin, libs in $(PREFIX)/lib, etc..
PREFIX = /usr/local


## MPU401 INTERFACE OPTIONS ##
#
# Remove the USE_MPU401 define if you haven't installed the mpu401
# driver I've supplied.  You won't be able to play or record, but
# you'll still be able to maninpulate the songs.
# Here is a list of the possible defines
#   -DUSE_MPU401        Include support for the MPU401 MIDI card
#   -DUSE_MPU401THREAD	Threaded device interface.  Incomplete, not tested.
#
# One of the SVR4, LINUX or BSD flags must be defined if you are
# defining USE_MPU401 or USE_MPU401THREAD.

MIDIDEF=-DUSE_MPU401


## SYSTEM-DEPENDENT OPTIONS ##
# 
# The following definitions will override the generic ones above.
# Uncomment whatever applies, and make sure the rest is commented out..
# You can set the above, plus the following:
#
# OSDEF - OS type, currently one of BSD, linux, SVR4 or osf1
# EXTRALIB - any extra libraries you might need


# ------------------- BSD -------------------------------------------
# If you don't want to use gcc-1.40
##CC=gcc2
#OSDEF=-DBSD
#
# BSD/386 1.1 wants gnulib to resolve ___eprintf if compiled with
# stock tcl/tk and gcc-2.5.8
##EXTRALIB = -lgnulib


# ------------------- SVR4 ------------------------------------------
#OSDEF=-DSVR4
#
# SVR4 doesn't need ranlib.. set it to /bin/true instead
#RANLIB = true
#
# I think this is right for UnixWare 2.0
#XLIBDIR = /usr/X/lib
#XINCDIR = /usr/X/include


## ------------------- Linux -----------------------------------------
#OSDEF=-Dlinux
#
# At least Slackware puts them here..
#TCLLIBDIR=/usr/lib
#TCLINCDIR=/usr/include/tcl
#
# Default XFree86 versions of x11r5
#XLIBDIR = /usr/X386/lib
#XINCDIR = /usr/X386/include
# and x11r6..
#XLIBDIR = /usr/X11R6/lib
#XINCDIR = /usr/X11R6/include
#
#OFLAGS = -O2
##OFLAGS = -O2 -m486 


# ------------------- OSF/1 -----------------------------------------
#OSDEF=-Dosf1
# Don McKillican dmckilli@qc.bell.ca says the CFLAGS for the Dec Alpha
# using cxx should be
#       CFLAGS = -I/usr/include/cxx -O -Dosf1 -D__STDC__
#
#OSDEF=-Dosf1
#COMPFLAGS=-I/usr/include/cxx -D__STDC__
#OFLAGS=-O
#CC=cc
#CXX=cxx
#
# I've also had good luck with gcc/g++  (GJW)
#OSDEF=-Dosf1
#CC=gcc
#CXX=g++
#
# No midi hardware for osf/1
#MIDIDEF=


# ------------------- Sun -------------------------------------------
#OSDEF=-Dsun			# doesn't do anything special..
#
# No midi hardware for sun
#MIDIDEF=
#
# I never tried cc.. but it seems to work fine with gcc/g++  (GJW)
#CC=gcc
#CXX=g++
#
# Maybe an old sun, or links for compatibility
#XLIBDIR = /usr/lib/X11
#XINCDIR = /usr/include/X11


# ------------------- Your system -----------------------------------
#
# If you add support for a new architecture, please send a patch!

## end of system-dependent options ##



# You shouldn't need to change anything below here
# =======================================================================

CFLAGS = $(COMPFLAGS) $(OFLAGS) $(OSDEF) $(MIDIDEF)

BINDIR = $(PREFIX)/bin
LIBDIR = $(PREFIX)/lib
INCDIR = $(PREFIX)/include
MANPATH= $(PREFIX)/man

LFLAGS = -L. -Lrb -ltclmidi -L$(TCLLIBDIR) -ltcl -lmidi++ -lrb -lm $(EXTRALIB)
TKLFLAGS = -L. -Lrb -ltclmidi -L$(TCLLIBDIR) -ltk -ltcl -lmidi++ -lrb -lm \
    -L$(XLIBDIR) -lX11 $(EXTRALIB)
INCDIRS = -Ievents -Isong -Ismf -Idevice -Irb -I$(TCLINCDIR)

TCLMFILES = tclmCmd.o tclmUtil.o tclmEvnt.o tclmPlay.o TclmIntp.o
APPINIT = tclmApIn.o
TKAPPINIT = tkmApIn.o

.SUFFIXES: .cc $(SUFFIXES)

.cc.o:
	$(CXX) $(CFLAGS) $(INCDIRS) -c -o $@ $<

all: tclmidi

events/objs: FORCE
	cd events; make objs CXX=$(CXX) CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)"

smf/objs: FORCE
	cd smf; make objs CXX=$(CXX) CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)"

song/objs: FORCE
	cd song; make objs CXX=$(CXX) CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)"

device/objs: FORCE
	cd device; make objs CXX=$(CXX) CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)"

rb/librb.a: FORCE
	cd rb; make librb.a CC=$(CC) CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)"

libmidi++.a: events/objs smf/objs song/objs device/objs
	-rm libmidi++.a
	ar ru libmidi++.a events/*.o smf/*.o song/*.o device/*.o
	$(RANLIB) libmidi++.a

libtclmidi.a: $(TCLMFILES)
	-rm libtclmidi.a
	ar ru libtclmidi.a $(TCLMFILES)
	$(RANLIB) libtclmidi.a

tclmidi: libmidi++.a rb/librb.a libtclmidi.a $(APPINIT)
	$(CXX) -o tclmidi $(APPINIT) $(LFLAGS)

tkmidi: libmidi++.a rb/librb.a libtclmidi.a $(TKAPPINIT)
	$(CXX) -o tkmidi $(TKAPPINIT) $(TKLFLAGS)

tkmApIn.o: tkmApIn.cc
	$(CXX) $(CFLAGS) $(INCDIRS) -I$(XINCDIR) -c -o $@ $<

install: tclmidi
	cp tclmidi $(BINDIR)/tclmidi
	chmod 755 $(BINDIR)/tclmidi
	for script in mplay mrec minfo midtotcl ; do \
		sed "s,#!./tclmidi,#!$(BINDIR)/tclmidi," < $$script \
		    > $(BINDIR)/$$script ; \
		chmod 755 $(BINDIR)/$$script ; \
	done
	cp libtclmidi.a $(LIBDIR)/libtclmidi.a
	cp libmidi++.a $(LIBDIR)/libmidi++.a
	cp tclmidi.h $(INCDIR)/tclmidi.h
	$(RANLIB) $(LIBDIR)/libtclmidi.a
	$(RANLIB) $(LIBDIR)/libmidi++.a

install-tkmidi: tkmidi
	cp tkmidi $(BINDIR)

install-man-cooked:
	cd man; make install-cooked MANPATH="$(MANPATH)"

install-man-raw:
	cd man; make install-raw MANPATH="$(MANPATH)"

clean:
	-rm *.o *.a tclmidi tkmidi
	cd events; make clean
	cd smf; make clean
	cd song; make clean
	cd device; make clean
	cd rb; make clean
	cd man; make clean

FORCE:

tclmCmd.o: tclmidi.h TclmIntp.h song/Song.h song/EvntTree.h \
    song/EvTrDefs.h events/Event.h \
    smf/SMFTrack.h device/MidiDev.h device/SMPTE.h tclmEvnt.h \
    events/AllEvent.h events/NormEvnt.h events/Note.h events/NoteOff.h \
    events/NoteOn.h events/KeyPres.h events/Param.h events/Program.h \
    events/ChanPres.h events/PitchWhl.h events/SysEx.h \
    events/MEvent.h events/MSeqNum.h events/MText.h \
    events/MCopy.h events/MSeqNam.h events/MInstNam.h \
    events/MLyric.h events/MMarker.h events/MCue.h \
    events/MChanPrf.h events/MPortNum.h events/MEOT.h \
    events/MTempo.h events/MSMPTE.h events/MTime.h events/MKey.h \
    events/MSeqSpec.h events/MUnknown.h \
    patchlvl.h
tclmEvnt.o: tclmidi.h TclmIntp.h song/Song.h song/EvntTree.h \
    song/EvTrDefs.h \
    events/Event.h smf/SMFTrack.h device/MidiDev.h device/SMPTE.h tclmEvnt.h \
    events/AllEvent.h events/NormEvnt.h events/Note.h events/NoteOff.h \
    events/NoteOn.h events/KeyPres.h events/Param.h events/Program.h \
    events/ChanPres.h events/PitchWhl.h events/SysEx.h \
    events/MEvent.h events/MSeqNum.h events/MText.h \
    events/MCopy.h events/MSeqNam.h events/MInstNam.h \
    events/MLyric.h events/MMarker.h events/MCue.h \
    events/MChanPrf.h events/MPortNum.h events/MEOT.h \
    events/MTempo.h events/MSMPTE.h events/MTime.h events/MKey.h \
    events/MSeqSpec.h events/MUnknown.h
tclmPlay.o: tclmidi.h TclmIntp.h song/Song.h song/EvntTree.h events/Event.h \
    song/EvTrDefs.h \
    smf/SMFTrack.h device/MidiDev.h device/SMPTE.h tclmEvnt.h \
    events/AllEvent.h events/NormEvnt.h events/Note.h events/NoteOff.h \
    events/NoteOn.h events/KeyPres.h events/Param.h events/Program.h \
    events/ChanPres.h events/PitchWhl.h events/SysEx.h \
    events/MEvent.h events/MSeqNum.h events/MText.h \
    events/MCopy.h events/MSeqNam.h events/MInstNam.h \
    events/MLyric.h events/MMarker.h events/MCue.h \
    events/MChanPrf.h events/MPortNum.h events/MEOT.h \
    events/MTempo.h events/MSMPTE.h events/MTime.h events/MKey.h \
    events/MSeqSpec.h events/MUnknown.h \
    device/MPU401.h device/401Thrd.h
TclmIntp.o: TclmIntp.h song/Song.h song/EvntTree.h song/EvTrDefs.h \
    events/Event.h smf/SMFTrack.h device/MidiDev.h device/SMPTE.h
tclmApIn.o: tclmidi.h TclmIntp.h song/Song.h song/EvntTree.h \
    song/EvTrDefs.h events/Event.h smf/SMFTrack.h device/MidiDev.h \
    device/SMPTE.h
tkmApIn.o: tclmidi.h TclmIntp.h song/Song.h song/EvntTree.h \
    song/EvTrDefs.h events/Event.h smf/SMFTrack.h device/MidiDev.h \
    device/SMPTE.h
