# define the base Qt directory (this won't be necessary if the qt
# header files are in /usr/include/qt and the qt lib files are in
# /usr/lib - but most distributions put them elsewhere)
QTDIR = /usr/lib/qt
#QTDIR = /usr/lib/qt-1.44
#QTDIR = /usr/lib/qt-2.0.1

# define where moc is
MOC = /usr/bin/moc
#MOC = /usr/lib/qt-1.44/bin/moc
#MOC = /usr/lib/qt-2.0.1/bin/moc

# compiler is g++
CC = g++

# uncomment the next line if compiling with egcs/gcc-2.9 to make
# smaller binaries
#EGCS_FLAGS = -fno-exceptions

# these are the flags for normal compiling
CFLAGS = -c $*.cpp $(EGCS_FLAGS) -fno-rtti -Wall -O2

# these are the flags for debugging
#CFLAGS = -c $*.cpp $(EGCS_FLAGS) -g -Wall

# additional include directories (the reference to /usr/include/qt
# will not be necessary in the standard qt distribution, but some
# Linux rpms put the qt header files there, and redundancy does no
# harm)
INCLUDEFLAGS = -I$(QTDIR)/include -I/usr/include/qt

# link options for normal compiling
LDFLAGS = -L$(QTDIR)/lib -lqt -s -o $@

# link options for debugging
#LDFLAGS = -L$(QTDIR)/lib -lqt -o $@

# this is where the program will be installed by 'make install'
INSTALLDIR = /usr/local/kamdir

# this is where the lock files are normally stored
LOCKDIR = /var/lock

# CHARSET defines whether the X server on which the program is
# displayed shows only ASCII characters or whether it displays Latin-1
# or Code Page 437 - the options are LATIN_1, CP437 or ASCII.  To
# display continental characters with most Unix systems use LATIN_1
# NOTE: transmitted characters use the 'de facto' standard of CP437
# this option is concerned with the local display, not with what is
# transmitted
CHARSET = LATIN_1

all: kam-qt endhost

kam-qt: main.o tnc.o buffers.o com.o pipes.o widgets.o moc_widgets.o dialogs.o moc_dialogs.o filesend.o event_slots.o moc_event_slots.o download.o
	$(CC) $(LDFLAGS) main.o tnc.o buffers.o com.o pipes.o widgets.o moc_widgets.o dialogs.o moc_dialogs.o filesend.o event_slots.o moc_event_slots.o download.o

main.o: main.cpp qqueue.cpp qqueue.h dlist.h dlist.cpp prog_defs.h buffers.h com.h widgets.h pipes.h tnc.h filesend.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

widgets.o: widgets.h widgets.cpp dialogs.h prog_defs.h tnc.h event_slots.h icons.h buffers.h download.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

moc_widgets.o:  widgets.h dialogs.h prog_defs.h tnc.h event_slots.h
	$(MOC) widgets.h -o moc_widgets.cpp 
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

dialogs.o: dialogs.h dialogs.cpp prog_defs.h tnc.h gpl.h widgets.h buffers.h filesend.h download.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

moc_dialogs.o:  dialogs.h prog_defs.h tnc.h
	$(MOC) dialogs.h -o moc_dialogs.cpp
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

event_slots.o: event_slots.cpp event_slots.h prog_defs.h tnc.h widgets.h buffers.h filesend.h dialogs.h download.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS) -DCHAR_SET=$(CHARSET)

moc_event_slots.o:  event_slots.h prog_defs.h tnc.h widgets.h buffers.h dialogs.h
	$(MOC) event_slots.h -o moc_event_slots.cpp
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

tnc.o: tnc.cpp tnc.h prog_defs.h pipes.h qqueue.cpp qqueue.h buffers.h widgets.h dialogs.h download.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS) -DCHAR_SET=$(CHARSET)

buffers.o: buffers.cpp qqueue.cpp qqueue.h buffers.h
	$(CC) $(CFLAGS)

filesend.o: filesend.cpp filesend.h dlist.h dlist.cpp qqueue.cpp qqueue.h widgets.h buffers.h prog_defs.h tnc.h dialogs.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS) -DCHAR_SET=$(CHARSET)

download.o: download.cpp download.h dialogs.h dlist.h dlist.cpp prog_defs.h
	$(CC) $(INCLUDEFLAGS) $(CFLAGS)

pipes.o: pipes.cpp pipes.h
	$(CC) $(CFLAGS)

com.o: com.cpp com.h
	$(CC) $(CFLAGS) -DLOCK_DIR=\"$(LOCKDIR)\"

endhost: endhost.o com.o
	$(CC) $(LDFLAGS) endhost.o com.o

endhost.o: endhost.cpp com.cpp com.h
	$(CC) $(CFLAGS)

install: kam-qt endhost
	install -d -gusers -m777 $(INSTALLDIR)
	install -d -gusers -m777 $(INSTALLDIR)/parms
	install -m664 -oroot -gusers kam-qt endhost cq messages helpfile-qt $(INSTALLDIR)/
	install -m664 -oroot -gusers tnc.parms home away $(INSTALLDIR)/parms/
	chmod +x $(INSTALLDIR)/kam-qt
	chmod +s $(INSTALLDIR)/kam-qt
	chmod +x $(INSTALLDIR)/endhost
	chmod +s $(INSTALLDIR)/endhost
	install -m644 -oroot -gusers kamrc /etc

clean:
	rm -f *.o
	rm -f moc_*
	rm -f kam-qt
	rm -f endhost
