#
# Xtend is Copyright (C) 1998 David M. Shaw <dshaw@jabberwocky.com>
# 
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
# 
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
# 
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# 
# $Id: Makefile,v 2.19 1998-04-06 01:38:13-04 dshaw Exp $

# Your C compiler

CC=gcc

# Flags to pass

FLAGS=-Wall -O3

# Where to install the program and the man page?

BINDIR=/usr/local/bin
MANDIR=/usr/local/man/man1

# Only uncomment ONE of the below sections!

# Linux
LOCKDIR=/var/lock
OWNER=root
GROUP=uucp
PERMS=2555

# BSD/OS
# LOCKDIR=/var/spool/uucp
# OWNER=root
# GROUP=uucp
# PERMS=2555

# Solaris
# LOCKDIR=/var/spool/locks
# OWNER=uucp
# GROUP=uucp
# PERMS=4555

# OpenBSD
# LOCKDIR=/var/spool/lock
# OWNER=uucp
# GROUP=uucp
# PERMS=4555

# Other
# LOCKDIR=/put/your/lock/dir/here
# OWNER=whatever
# GROUP=whatever
# PERMS=whatever

#############################################################
# You shouldn't need to change anything under here

VERSION=1.1
PREVIOUS=1
CFLAGS=$(FLAGS) -DDEFAULT_LOCKDIR=\"$(LOCKDIR)\"
DISTFILES=COPYING README INSTALL ANNOUNCE FAQ \
	*.h *.c Makefile sample-xtendrc *.1 \
	tools/xtend.pm tools/xtend.bash tools/status \
	tools/status2 tools/status.bash tools/parse-status \
	tools/README

PROGS=xtend

all: $(PROGS)
	@echo "Built $(PROGS) version $(VERSION)"
clean:
	rm -f *.o *.core core $(PROGS)

exec.o: exec.h x10.h util.h
util.o: util.h x10.h
xtend.o: util.h parse.h x10.h exec.h version.h
parse.o: parse.h x10.h
xtend:	xtend.o util.o parse.o exec.o
	$(CC) xtend.o util.o parse.o exec.o -o xtend

install: $(PROGS)
	-mv $(BINDIR)/xtend $(BINDIR)/xtend.old
	cp xtend $(BINDIR)
	chown $(OWNER).$(GROUP) $(BINDIR)/xtend
	chmod $(PERMS) $(BINDIR)/xtend
	cp xtend.1 $(MANDIR)
	chmod 444 $(MANDIR)/xtend.1

version.h: Makefile
	rm -f version.h
	echo '#define VERSION "$(VERSION)"' > version.h

diffs:  $(DISTFILES)
	rm -f diffs
	-rcsdiff -qcr$(PREVIOUS) $(DISTFILES) > diffs

dist:	xtend-$(VERSION).tar.gz LSM

MANIFEST: $(DISTFILES)
	rm -f MANIFEST
	for i in $(DISTFILES); \
	do echo xtend-$(VERSION)/$$i >> MANIFEST; done

xtend-$(VERSION).tar.gz: MANIFEST version.h
		rm -f xtend-$(VERSION).tar.gz
		(cd ..; tar -cvf - `cat xtend-$(VERSION)/MANIFEST` \
		 xtend-$(VERSION)/MANIFEST \
		 | gzip -9 > xtend-$(VERSION)/xtend-$(VERSION).tar.gz;)

LSM:	version.h xtend-$(VERSION).tar.gz
	rm -f LSM
	echo "Begin3" > LSM
	echo "Title: Xtend: The X10 to UNIX controller" >> LSM
	echo "Version: $(VERSION)" >> LSM
	echo "Entered-date: `date +%d%b%y | tr a-z A-Z`" >> LSM
	echo "Description: xtend is a daemon that is used in combination with a" >> LSM
	echo "	CM11a X10 interface that hooks to one of your serial ports." >> LSM
	echo "	It executes arbitrary shell commands depending on what X10" >> LSM
	echo "	commands it sees." >> LSM
	echo "Keywords: X10 home automation" >> LSM
	echo "Author: dshaw@jabberwocky.com (David Shaw)" >> LSM
	echo "Primary-site: ftp.jabberwocky.com /pub/xtend/" >> LSM
	echo "	`ls -s xtend-$(VERSION).tar.gz | sed 's/ *\([0-9]*\).*/\1/g'` kB xtend-$(VERSION).tar.gz" >> LSM
	echo "Copying-policy: GPL" >> LSM
	echo "End" >> LSM
