TOPDIR=/
BINDIR=$(TOPDIR)/usr/sbin
MANDIR=$(TOPDIR)/usr/share/man/man8
LOGDIR=$(TOPDIR)/var/log/ttywatch
ETCDIR=$(TOPDIR)/etc
INCDIR=$(TOPDIR)/usr/include
INITDIR=$(ETCDIR)/rc.d/init.d
LOGRDIR=$(ETCDIR)/logrotate.d

CFLAGS = -Wall $(shell glib-config --cflags) -O2
LDFLAGS = $(shell glib-config --libs) -lpopt -ldl
CC = gcc

all: ttywatch

ttywatch: socket.o telnet.o logfile.o errors.o ttywatch.o

ttywatch.c: ttywatch.h

clean:
	rm -f ttywatch *.o

install: ttywatch
	mkdir -p $(BINDIR) $(MANDIR) $(LOGDIR) $(ETCDIR) $(INITDIR) $(LOGRDIR) $(INCDIR)
	install -m 755 ttywatch $(BINDIR)
	install -m 644 ttywatch.8 $(MANDIR)
	install -m 644 ttywatch.conf $(ETCDIR)
	install -m 644 ttywatch.logrotate $(LOGRDIR)/ttywatch
	install -m 644 ttywatch.h $(INCDIR)
	install -m 755 ttywatch.init $(INITDIR)/ttywatch


VERSION=$(shell awk '/Version:/ { print $$2 }' ttywatch.spec)
CVSTAG = r$(subst .,-,$(VERSION))

tag-archive:
	@cvs -Q tag -F $(CVSTAG)

create-archive: tag-archive
	@rm -rf /tmp/ttywatch
	@cd /tmp; cvs -Q -d $(shell cat CVS/Root) export -r$(CVSTAG) ttywatch || echo GRRRrrrrr -- ignore [export aborted]
	@mv /tmp/ttywatch /tmp/ttywatch-$(VERSION)
	@cd /tmp; tar czSpf ttywatch-$(VERSION).tar.gz ttywatch-$(VERSION)
	@rm -rf /tmp/ttywatch-$(VERSION)
	@cp /tmp/ttywatch-$(VERSION).tar.gz .
	@rm -f /tmp/ttywatch-$(VERSION).tar.gz 
	@echo " "
	@echo "The final archive is ttywatch-$(VERSION).tar.gz"

archive: clean tag-archive create-archive
