#Top level Makefile for HuggieTag

#Where tags ends up
BINDIR=/usr/local/bin
#Where the man page ends up
MANDIR=/usr/local/man
VERSION := $(shell grep VERSION src/common.h|awk -F \" '{print $$2}')
BUILD := $(shell grep BUILD src/common.h|awk -F \" \
	  '{print $$2}')
OLDBUILD := $(shell expr $(BUILD) - 1)
NEWBUILD := $(shell expr $(BUILD) + 1)
DIR=huggietag-$(VERSION).pre$(NEWBUILD)

#What shall we make...
.PHONY: tags
tags:	
	(cd src && make)
clean:
	rm -f src/*.o src/*~ tags src/core core *~
install: tags
	install tags $(BINDIR)/tags
	install man/tags.1 $(MANDIR)/man1/tags.1
	install man/huggietag.1 $(MANDIR)/man1/huggietag.1

newpre: 
	cp . ../$(DIR) -a
	(cd ../$(DIR) && \
	sed -e "s/pre$(BUILD)/pre$(NEWBUILD)/g" src/common.h >src/common.new && \
	mv -f src/common.new src/common.h)
	(cd .. && rm -f huggietag-$(VERSION) && \
	ln -s $(DIR) huggietag-$(VERSION) )

newdiff:
	-(cd .. && \
	diff -urN huggietag-$(VERSION).pre$(OLDBUILD) \
		  huggietag-$(VERSION).pre$(BUILD) \
		>ht-$(VERSION)-pre$(OLDBUILD)-to-pre$(BUILD).diff)
	echo "This target should always have an error of 1"