# Copyright (c) 1998-2005 by Wayne C. Gramlich.
# All rights reserved.

ROOT = ..

include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk

STIPPLE_DIRECTORY = $(ROOT)/stipple
STC_DIRECTORY = $(STIPPLE_DIRECTORY)/stc
NSTC_DIRECTORY = $(STIPPLE_DIRECTORY)/nstc
LIBSTIPPLE_DIRECTORY = $(STIPPLE_DIRECTORY)/libstipple

STC = $(STC_DIRECTORY)/$(PLATFORM)/stc
STL = $(STC_DIRECTORY)/$(PLATFORM)/stl
NSTC = $(NSTC_DIRECTORY)/$(PLATFORM)/nstc

STC_INCLUDES =					\
	-I $(LIBSTIPPLE_DIRECTORY)/$(PLATFORM)	\
	-I $(PLATFORM)
STC_FLAGS = $(STC_OPTIONS) $(STC_INCLUDES)

OS_LDOPTS_X11 = -L/usr/X11/lib

TCP_MONITOR_BASES =	\
	tcp_monitor
TCP_MONITOR_SOURCES = ${TCP_MONITOR_BASES:%=%.sts}
TCP_MONITOR_INTERFACES = ${TCP_MONITOR_BASES:%=$(PLATFORM)/%.sti}
TCP_MONITOR_OBJECTS = ${TCP_MONITOR_BASES:%=$(PLATFORM)/%.o}
TCP_MONITOR = $(PLATFORM)/tcp_monitor

TCP_MONITOR_TEST_BASES =	\
	tcp_monitor_test
TCP_MONITOR_TEST_SOURCES = ${TCP_MONITOR_TEST_BASES:%=%.sts}
TCP_MONITOR_TEST_INTERFACES = ${TCP_MONITOR_TEST_BASES:%=$(PLATFORM)/%.sti}
TCP_MONITOR_TEST_OBJECTS = ${TCP_MONITOR_TEST_BASES:%=$(PLATFORM)/%.o}
TCP_MONITOR_TEST = $(PLATFORM)/tcp_monitor_test

STS_BASES =				\
	${TCP_MONITOR_BASES}		\
	${TCP_MONITOR_TEST_BASES}

STS_SOURCES = 			\
	${TCP_MONITOR_SOURCES}		\
	${TCP_MONITOR_TEST_SOURCES}
STS_HTMLS = ${STS_SOURCES:%.sts=%.html}


INTERFACES =				\
	${TCP_MONITOR_INTERFACES}	\
	${TCP_MONITOR_TEST_INTERFACES}
OBJECTS =				\
	${TCP_MONITOR_OBJECTS}		\
	${TCP_MONITOR_TEST_OBJECTS}

PROGRAMS =				\
	$(TCP_MONITOR)			\
	$(TCP_MONITOR_TEST)

OTHER_HTMLS =				\
	index.html
HTMLS =					\
	${STS_HTMLS}			\
	${OTHER_HTMLS}			\
	source.html

OTHER_SOURCES =				\
	Makefile
SOURCES =				\
	${STS_SOURCES}			\
	${OTHER_SOURCES}		\
	${OTHER_HTMLS}

COPY_LIST =				\
	${SOURCES}			\
	${STS_HTMLS}			\
	source.html

.PHONY: all clean copy spell

# Some targets:

all: $(PLATFORM) $(WAIT) ${SOURCES} $(WAIT) ${PROGRAMS} $(WAIT) source.html

$(TCP_MONITOR): ${TCP_MONITOR_INTERFACES} $(WAIT) ${TCP_MONITOR_OBJECTS}
	$(STL) -o $@ -E $(PLATFORM) 				\
	    ${TCP_MONITOR_INTERFACES} ${TCP_MONITOR_OBJECTS}

$(TCP_MONITOR_TEST): ${TCP_MONITOR_TEST_INTERFACES} $(WAIT)	\
    ${TCP_MONITOR_TEST_OBJECTS}
	$(STL) -o $@ -E $(PLATFORM)				\
	   ${TCP_MONITOR_TEST_INTERFACES} ${TCP_MONITOR_TEST_OBJECTS}

clean:
	rm -rf $(PLATFORM) ${STS_HTMLS} source.html STDB
	$(CLEAN)

$(NSTC):
	$(MAKE) -C $(NTSC_DIR)

source.html: Makefile $(NSTC) $(WAIT) ${STS_HTMLS}
	@echo -n "Generating $@..."
	@rm -f $@
	@echo '<HTML>' > $@
	@echo '<Head>' >> $@
	@echo '<Title>TCP Monitor Source Files</Title>' >> $@
	@echo '</Head>' >> $@
	@echo '<Body>' >> $@
	@echo '<P>These are the source files for the' >> $@
	@echo '<A HRef="index.html">TCP Monitoring Program</A>.</P>' >> $@
	@echo '<H1>' >> $@
	@echo 'TCP Monitor Source Files' >> $@
	@echo '</H1>' >> $@
	@echo '<P>The following extracted documentation is available:</P>'>> $@
	@echo '<UL>' >> $@
	@for i in ${STS_BASES} ; do					\
		echo "  <LI><A HRef='$$i.html'>$$i</A></LI>" >> $@ ;	\
		done
	@echo '</UL>' >> $@
	@echo '<P>The following source files are available:</P>' >> $@
	@echo '<UL>' >> $@
	@for i in `ls Makefile ${STS_SOURCES} | sort`; do \
		echo "  <LI><A HRef='$$i'>$$i</A></LI>" >> $@ ;		\
		done
	@echo '</UL>' >> $@
	@echo '<HR>' >> $@
	@echo '<Address>' >> $@
	@echo '<A HRef="../../../copyright.html">' >> $@
	@echo 'Copyright</A> (c) 1997 by' >> $@
	@echo '<A HRef="../../../gramlich.html">' >> $@
	@echo 'Wayne Gramlich</A> All rights reserved.' >> $@
	@echo '</Address>' >> $@
	@echo '</Body>' >> $@
	@echo '</HTML>' >> $@
	@echo "Done"


