PKGNAME=booty
VERSION=$(shell awk '/Version:/ { print $$2 }' ${PKGNAME}.spec)
RELEASE=$(shell awk '/Release:/ { print $$2 }' ${PKGNAME}.spec)
CVSTAG=r$(subst .,_,$(VERSION)-$(RELEASE))
SNAPRELEASE = $(RELEASE)$(shell date "+.%Y%m%d%H%M")

SUBDIRS := edd

PYFILES = $(wildcard *.py)
PYTHONLIBDIR = /usr/lib/booty

PYTHON = python2.4
PYTHONINCLUDE = /usr/include/$(PYTHON)

PYTHONLIBDIR = /usr/lib/booty

CFLAGS=-Wall -O -g -fpic -I$(PYTHONINCLUDE)# -DDEBUG

all: subdirs

clean:
	rm -f *.o *.so *.pyc *.lo
	if [ "$(SUBDIRS)" != "" ];then \
		for d in $(SUBDIRS); do make -C $$d clean; done \
	fi

subdirs:
	for d in $(SUBDIRS); do make -C $$d; [ $$? = 0 ] || exit 1; done

# this rule is a hack
install-python:
	cp -var $(PYFILES) $(DESTDIR)/$(PYTHONLIBDIR)
	./py-compile --basedir $(DESTDIR)/$(PYTHONLIBDIR) $(PYFILES)

install: 
	@if [ "$(DESTDIR)" = "" ]; then \
		echo " "; \
		echo "ERROR: A destdir is required"; \
		exit 1; \
	fi

	mkdir -p $(DESTDIR)/$(PYTHONLIBDIR)

	cp -var $(PYFILES) $(DESTDIR)/$(PYTHONLIBDIR)
	./py-compile --basedir $(DESTDIR)/$(PYTHONLIBDIR) $(PYFILES)
	for d in $(SUBDIRS); do make DESTDIR=`cd $(DESTDIR); pwd` -C $$d install; [ $$? = 0 ] || exit 1; done

force-tag:
	cvs tag -cFR $(CVSTAG)

tag:
	cvs tag -cR $(CVSTAG)

archive: tag create-archive

src: tag create-archive
	@rpmbuild -ts --nodeps booty-$(VERSION).tar.bz2

snapsrc: create-snapshot
	@rpmbuild -ts --nodeps booty-$(VERSION).tar.bz2

create-snapshot:
	@rm -rf /tmp/booty
	@rm -rf /tmp/booty-$(VERSION)
	@tag=`cvs status Makefile | awk ' /Sticky Tag/ { print $$3 } '` 2> /dev/null; \
	[ x"$$tag" = x"(none)" ] && tag=HEAD; \
	cvsroot=`cat CVS/Root` 2>/dev/null; \
	echo "*** Pulling off $$tag from $$cvsroot!"; \
	cd /tmp ; cvs -Q -d $$cvsroot export -r $$tag booty || echo "Um... export aborted."
	@mv /tmp/booty /tmp/booty-$(VERSION)
	@cd /tmp ; tar --bzip2 -cSpf booty-$(VERSION).tar.bz2 booty-$(VERSION)
	@rm -rf /tmp/booty-$(VERSION)
	@cp /tmp/booty-$(VERSION).tar.bz2 .
	@rm -f /tmp/booty-$(VERSION).tar.bz2
	@echo ""
	@echo "The final archive is in booty-$(VERSION).tar.bz2"

create-archive:
	make SNAPRELEASE=$(RELEASE) create-snapshot

pycheck:
	PYTHONPATH=edd pychecker *.py textw/*.py iw/*.py  | grep -v "__init__() not called" 

pycheck-file:
	PYTHONPATH=.:edd pychecker $(CHECK) | grep -v "__init__() not called" 
