#
# stund/Makefile
#
# $Id: Makefile,v 1.3 2002/11/03 20:22:47 alan Exp $
# 
# Copyright (c) 2002 Alan Hawrylyshen
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

DOCFILES=stun.cxx stun.h udp.cxx udp.h util.h util.cxx stund.cxx stunq.cxx
SRCS=$(DOCFILES)
DOCDIR=docs
TARS=$(SRCS) Makefile overview.html \
	     stund.dsp stunc.dsp stun.dsw \
	     stund.sysconfig stund.svc

VERSION=0.8.2

DOCARGS=--filenames --no-define  --tables
DOCINSTDIR=/usr/share/doc/stund-$(VERSION)
#CXXFLAGS+=-O2
#LDFLAGS+=-O2
STUNLIB=libstun.a

#
# Alternatively, for debugging.
#
CXXFLAGS+=-g
LDFLAGS+=-g -Wall

all: stund stunq 

tar: $(TARS)
	cd ..; tar cvfz - $(addprefix stund/, $(TARS))  > \
		 ` date +"stund_$(VERSION)_$(PROG)%b%d.tgz" `

install-doc: doc
	mkdir -p $(DOCINSTDIR)
	cp -a docs/* $(DOCINSTDIR)
	/bin/rm -f $(DOCINSTDIR)/overview.html
	cp -f overview.html $(DOCINSTDIR)

install: stund stunq stund.sysconfig stund.svc 
	install -C -m 0555 -s stund /usr/sbin/stund
	install -C -m 0555 -s stunq /usr/sbin/stunq
	install -C -m 0555 stund.svc /etc/init.d/stund
	install -C -m 0444 stund.sysconfig /etc/sysconfig/stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc0.d/K50stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc1.d/K50stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc2.d/S60stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc3.d/S60stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc4.d/S60stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc5.d/S60stund
	ln -sf /etc/init.d/stund /etc/rc.d/rc6.d/K50stund

$(DOCDIR)/index.html: $(SRCS)
	doc++ --dir $(DOCDIR) $(DOCARGS) $(DOCFILES)

$(DOCDIR)/overview.html: overview.html
	 ln -s ../$^ $(DOCDIR)/$^

doc: $(DOCDIR)/index.html $(DOCDIR)/overview.html 


clean:
	/bin/rm -f *.o core stunq stund $(STUNLIB) *~

distclean: clean
	-/bin/rm -rf $(DOCDIR)
	-@rcsclean

$(STUNLIB): stun.o udp.o util.o
	ar crv $(STUNLIB) $^

stund: stund.o  $(STUNLIB)
	$(CXX) $(LDFLAGS) -o $@ stund.o -lstun -L.

stunq: stunq.o  udp.o $(STUNLIB)
	$(CXX) $(LDFLAGS) -o $@ stunq.o -lstun -L.

%.o:%.cxx
	$(CXX)  -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

%:RCS/%
	co $@

# Dependancies
stun.o: stun.h udp.h
stund.o: stun.h udp.h  util.h
stunq.o: stun.h udp.h  util.h
udp.o: udp.h  
