# Makefile - makefile for xhotkeys
PACKAGE=xhotkeys

# Destination directoy
DESTDIR= 

# Define destination directories

BINDIR=$(DESTDIR)/usr/bin
SBINDIR=$(DESTDIR)/usr/sbin
MAN1DIR=$(DESTDIR)/usr/share/man/man1
SHAREDIR=$(DESTDIR)/usr/share/$(PACKAGE)
LIBDIR=$(DESTDIR)/usr/lib/$(PACKAGE)
APPDIR=$(DESTDIR)/usr/share/applications
ETCDIR=$(DESTDIR)/etc


# Useful variables
DEBIANVERSION=$(shell cat debian/changelog | head -n1 | awk '{print $$2}' | sed "s/^.//" | sed "s/.$$//")
VERSION=$(shell echo $(DEBIANVERSION) | sed "s/-/./")
TARBALL=$(PACKAGE)-$(VERSION).tar.gz
ARCH=$(shell dpkg --print-architecture)
DEBPACKAGE=$(PACKAGE)_$(DEBIANVERSION)_$(ARCH).deb
FTPSERVER=ftp://savannah.gnu.org/incoming/savannah/$(PACKAGE)/

# ------------- don't edit anything below this line --------------

FILES=xhotkeys xhotkeys.glade README TODO Makefile xhotkeys.conf \
	debian/changelog xhotkeys.desktop xhotkeys.png 

all: 

install: all
	# Create directories
	mkdir -p $(SHAREDIR)
	
	# Install files
	install -m 755 xhotkeys $(BINDIR)
	install -m 644 xhotkeys.glade $(SHAREDIR)
	install -m 644 xhotkeys.1 $(MAN1DIR)
	install -m 644 xhotkeys.png $(SHAREDIR)
	install -m 644 xhotkeys.desktop $(APPDIR)
	
	# Install configuration files
	if [ ! -e $(ETCDIR)/xhotkeys.conf ]; then \
		install -m 644 xhotkeys.conf $(ETCDIR) ;\
	fi
	install -m 644 xhotkeys.conf $(SHAREDIR)/xhotkeys.conf.example
	

dist: ../$(TARBALL) ../$(DEBPACKAGE)

../$(TARBALL): clean $(FILES)
	cp debian/changelog ChangeLog
	fakeroot debian/rules clean
	(cd ..; tar --exclude=CVS -czf $(TARBALL) $(PACKAGE))
	rm -f ../$(TARBALL).sig
	gpg -b --use-agent ../$(TARBALL) || true

../$(DEBPACKAGE): ../$(TARBALL)
	(cp ../$(TARBALL) /tmp; cd /tmp; tar xvzf $(TARBALL); cd $(PACKAGE); fakeroot dpkg-buildpackage)
	cp /tmp/$(DEBPACKAGE) ..
	rm -f ../$(DEBPACKAGE).sig
	gpg -b --use-agent ../$(DEBPACKAGE) || true
	
upload: dist web-upload
	(cd ..; wput $(TARBALL)* $(FTPSERVER))
	(cd ..; wput $(DEBPACKAGE)* $(FTPSERVER))

web-upload:
	(cd web/$(PACKAGE); cvs ci -m "automatic commit" .)
	
web: web/$(PACKAGE)/index.html 

web/$(PACKAGE)/index.html: web/$(PACKAGE)/index-template.html
	cat web/$(PACKAGE)/index-template.html | sed "s/@DEBIAN_PACKAGE@/$(DEBPACKAGE)/" | sed "s/@TARBALL@/$(TARBALL)/" | sed "s/@DATE@/$(shell LC_ALL=C date)/" | sed "s/@VERSION@/$(VERSION)/" >  web/$(PACKAGE)/index.html

clean:
	rm -f *.pyc


