# Makefile for parser command program
#
# $Id: Makefile,v 1.11 2004/07/10 06:27:03 grog Exp grog $

# Copyright (c) 2004 by Greg Lehey
# 
#  This software is distributed under the so-called ``Berkeley 
#  License'': 
# 
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions 
# are met: 
# 
# 1. Redistributions of source code must retain the above copyright 
#    notice, this list of conditions and the following disclaimer. 
# 2. Redistributions in binary form must reproduce the above copyright 
#    notice, this list of conditions and the following disclaimer in the 
#    documentation and/or other materials provided with the distribution. 
# 
# This software is provided ``as is'', and any express or implied 
# warranties, including, but not limited to, the implied warranties of 
# merchantability and fitness for a particular purpose are disclaimed. 
# In no event shall Domenick Venezia be liable for any 
# direct, indirect, incidental, special, exemplary, or consequential 
# damages (including, but not limited to, procurement of substitute 
# goods or services; loss of use, data, or profits; or business 
# interruption) however caused and on any theory of liability, whether 
# in contract, strict liability, or tort (including negligence or 
# otherwise) arising in any way out of the use of this software, even if 
# advised of the possibility of such damage. 

# Parameters that may need changing to build on non-FreeBSD systems.

# Where to install the program
INSTALLDIR=	/usr/local/bin

# Where we store our private stuff (config file)
PRIVDIR	=	/usr/local/share/tempcontrol

# Where to install the startup script
RCDIR	=	/usr/local/etc/rc.d
CFLAGS	=	-g -O3 -Wall -Wno-parentheses ${INCLUDES}

LINK=gcc
LFLAGS= -g

# Version of this program
VERSION	=	1.1

# local header files
HDRS	=	main.h statemachine.h config.h

# source files for program that get checked into RCS
RCSRCS	=	main.c commands.c parser.c monitor.c statemachine.c

# in case there are more that we don't want to check in
# (generated, for example).
SRCS	=	${RCSRCS}

# Other file that get checked into RCS but don'g get compiled.
AUX	=	LICENSE makekw Makefile keywords temperaturecontrolrc.sample \
		temperaturecontrol.sh.sample README

# Name of program.
PROG	=	tempcontrol

# Name of distribution archive
DIST	=	tempcontrol-${VERSION}.tar.gz

# And what to put in it
DISTFILES =	${RCSFILES} webpage.pdf depend

# All files to check into RCS
RCSFILES=	${HDRS} ${RCSRCS} ${AUX}

# object files to build program.
OBJS	=	${SRCS:.c=.o}


all:	${PROG}

TAGS:	${HDRS} ${RCSSRCS} 
	rm -f TAGS
	etags ${HDRS} ${SRCS}

depend: parser.h .FORCE
	${CC} -M ${CFLAGS} ${SRCS} > $@

.FORCE:

${PROG}:	${OBJS}
	${CC} -o ${PROG} ${CFLAGS} ${OBJS} -lreadline -lcurses

clean:
	rm -f *~ myparser* parser.h parserc.h parsercommands.c.sample parserkeys.h *.o ${PROG}

# Get rid of everything that belongs in RCS. Since it might be checked out,
# try to check it in first.
ci:
	@echo Checking in RCS files
	ci -u ${RCSFILES}
	co Makefile

co:
	@echo Checking out RCS files
	-co -M ${RCSFILES}

install: all
	cp -p $(PROG) $(INSTALLDIR)
	mkdir -p ${PRIVDIR}
	cp -p temperaturecontrolrc.sample ${PRIVDIR}
	if [ ! -f ${PRIVDIR}/.temperaturecontrol ]; then \
	  ln ${PRIVDIR}/temperaturecontrolrc.sample ${PRIVDIR}/.temperaturecontrol; \
	fi
	cp -p temperaturecontrol.sh.sample ${RCDIR}

# Make the distribution archive
dist ${DIST}:
	> depend
	tar czvf ${DIST} ${DISTFILES}

parser.o: parserc.h

# main depends on the parser.
main.o:  parserkeys.h parser.h

parser.h parserc.h parserkeys.h: keywords makekw
	./makekw parser

${RCSFILES}:
	co $@
	
include depend
