#!/usr/bin/make -f

# Makefile for cereal

# (c) 2007 Jameson Graef Rollins <jrollins@finestructure.net>
# Licensed under GPL v3 or later

VERSION := `head -n1 debian/changelog | sed 's/.*(\([^-]*\)-.*/\1/'`

# these defaults are for debian.  porters should probably adjust them
# before calling make install
ETCPREFIX ?= 
ETCSUFFIX ?= 
PREFIX ?= /usr
MANPREFIX ?= $(PREFIX)/share/man

# nothing to do for builds: this is a package of mostly scripts.
build:
	

tarball: clean
	rm -rf cereal-$(VERSION)
	mkdir -p cereal-$(VERSION)
	ln -s ../COPYING ../Makefile ../src ../etc ../man ../doc cereal-$(VERSION)
	tar ch --exclude='*~' --exclude='*.svn*' cereal-$(VERSION) | gzip -n > cereal_$(VERSION).orig.tar.gz
	rm -rf cereal-$(VERSION)

debian-package: tarball
	tar xzf cereal_$(VERSION).orig.tar.gz
	tar c --exclude='*~' --exclude='*.svn*' debian | tar x -C cereal-$(VERSION)
	(cd cereal-$(VERSION) && debuild -us -uc)
	rm -rf cereal-$(VERSION)

install: installman
	install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(PREFIX)/sbin $(DESTDIR)$(PREFIX)/share/cereal
	install -d $(DESTDIR)$(ETCPREFIX)/etc/cereal
	install -d $(DESTDIR)$(PREFIX)/share/doc/cereal
	install src/cereal $(DESTDIR)$(PREFIX)/bin
	install src/cereal-admin $(DESTDIR)$(PREFIX)/sbin
	install -m 0644 src/common $(DESTDIR)$(PREFIX)/share/cereal
	install src/mainrun src/logrun src/finish $(DESTDIR)$(PREFIX)/share/cereal
	install -m 0644 etc/cereal-admin.conf $(DESTDIR)$(ETCPREFIX)/etc/cereal/cereal-admin.conf$(ETCSUFFIX)
	install -m 0644 etc/screenrc $(DESTDIR)$(ETCPREFIX)/etc/cereal/screenrc$(ETCSUFFIX)
	install doc/* $(DESTDIR)$(PREFIX)/share/doc/cereal

installman:
	install -d $(DESTDIR)$(MANPREFIX)/man1 $(DESTDIR)$(MANPREFIX)/man8
	gzip -n man/*/*
	install man/man1/* $(DESTDIR)$(MANPREFIX)/man1
	install man/man8/* $(DESTDIR)$(MANPREFIX)/man8
	gzip -d man/*/*

clean:
	rm -f cereal_*

.PHONY: build tarball debian-package install installman clean
