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

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

all: ttywatch

ttywatch: ttywatch.c

clean:
	rm -f ttywatch

install: ttywatch
	mkdir -p $(BINDIR) $(MANDIR) $(LOGDIR) $(ETCDIR) $(INITDIR) $(LOGRDIR)
	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 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 $(CVSROOT) 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
