# Makefile for saywha
#
# Copyright (C) 1990,1991 by Jef Poskanzer and Craig Leres.
# All rights reserved.
#
# 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 BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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.

# CONFIGURE: the directory where you want the executables installed
BINDIR =	/usr/local/bin

# CONFIGURE: the directory tree where you want the man pages installed
MANDIR =	/usr/local/man

# CONFIGURE: the manual section
MANSEC =	1

# CONFIGURE: Define this if you want to enable the mail_editor option.
# If you don't know what mail_editor is, don't worry about it.
#ME_DEF =	-DMAIL_EDITOR=\"/usr/local/bin/red\"

# CONFIGURE: As far as I know, all implementations of NFS choke on
# write-only files.  Normally, say and wha use write-only files to record
# the messages, but if your home directories are NFS-ized this won't work.
# In this case you have two options.  One, set the WORLD_READABLE flag
# below; this will make your .sayfiles world-readable, which is undesireable,
# but it works.  Two, define GROUP_WRITE (and INSTALLOPTS) and install the
# say and wha executables set-group-id to tty. This will allow say and wha
# to automatically make the .sayfiles group read/write.
#NFS_DEF =	-DWORLD_READABLE
#GROUP =		tty
#NFS_DEF =	-DGROUP_WRITE=\"$(GROUP)\"
#INSTALLOPTS =	-m 2755 -g $(GROUP)

# CONFIGURE: Define what type of file locking you want to use.  lockf()
# works on NFS files, but is a little slow and is subject to deadlock.
# Linking might work over NFS, and it's also slow.  flock() is fast,
# won't deadlock, but definitely does not work over NFS.  Still, we ran
# without any sort of locking for two years and only saw a couple of
# collisions, and those were on a single machine so flock() would
# have worked.
#LOCK =		-DLOCK_LOCKF
#LOCK =		-DLOCK_LINK
LOCK =		-DLOCK_FLOCK

# CONFIGURE: Change these if you want to use something besides write(1).
WR_DEF =	-DWRITE=\"/bin/write\"
WR_HD_DEF =	-DWRITE_HEAD=\"Message\ from\ %s@%s\ on\ %s\ at\ %s\ ...\\n\"
#WR_HD_DEF =	-DWRITE_HEAD=\"\\tMessage\ from\ %s\ on\ %s\ \(%s\)\ \[\ %s\ \]\ ...\\n\"
WR_TL_DEF =	-DWRITE_TAIL=\"EOF\\n\"
#WR_TL_DEF =	-DWRITE_TAIL=\"\<EOT\>\\n\"

# CONFIGURE: Set this if your system has very slow userid lookups.
#BG_DEF =	-DBACKGROUND

# CONFIGURE: Set this if 'write' shows only the time, not the full date.
TO_DEF =	-DWRITE_TIME_ONLY

# CONFIGURE: Set this if you need wha to write out the full date/time.
AD_DEF =	-DWHA_ADD_DATE

# CONFIGURE: your favorite C compiler
#CC =		cc
CC =		gcc -fpcc-struct-return -fwritable-strings

# CONFIGURE: your favorite C flags
CFLAGS =	-O
#CFLAGS =	-g
#CFLAGS =	-g -O

# CONFIGURE: your favorite linker flags
LDFLAGS =	-s
#LDFLAGS =	

# CONFIGURE: your favorite lint flags
LINTFLAGS =	-hxz

# End of configurable definitions.

DEFINES =	$(ME_DEF) $(NFS_DEF) $(LOCK) $(WR_DEF) $(WR_HD_DEF) $(WR_TL_DEF) $(BG_DEF) $(TO_DEF) $(AD_DEF)
ALLCFLAGS =	$(CFLAGS) $(DEFINES)
ALLLINTFLAGS =	$(LINTFLAGS) $(DEFINES)
INSTALL =	/usr/bin/install

EXES =		say wha rep
MANS =		say wha rep

all:		$(EXES)

say:		say.c libsaywha.h libsaywha.o
	$(CC) $(ALLCFLAGS) say.c libsaywha.o $(LDFLAGS) -o say

wha:		wha.c libsaywha.h libsaywha.o
	$(CC) $(ALLCFLAGS) wha.c libsaywha.o $(LDFLAGS) -o wha

rep:		rep.c libsaywha.h libsaywha.o
	$(CC) $(ALLCFLAGS) rep.c libsaywha.o $(LDFLAGS) -o rep

libsaywha.o:	libsaywha.c libsaywha.h
	$(CC) $(ALLCFLAGS) -c libsaywha.c

lint:
	lint $(ALLLINTFLAGS) say.c libsaywha.c | grep -v 'but never used'
	lint $(ALLLINTFLAGS) wha.c libsaywha.c | grep -v 'but never used'
	lint $(ALLLINTFLAGS) rep.c libsaywha.c | grep -v 'but never used'

install:	install.bin install.man

install.bin:	all
	$(INSTALL) -c $(INSTALLOPTS) say $(BINDIR)
	$(INSTALL) -c $(INSTALLOPTS) wha $(BINDIR)
	$(INSTALL) -c rep $(BINDIR)

install.man:
	for i in $(MANS) ; do \
	    $(INSTALL) -c $$i.1 $(MANDIR)/man$(MANSEC)/$$i.$(MANSEC) ; \
	done

clean:
	-rm -f *.o core $(EXES) *.shar

shar:		saywha.shar
saywha.shar:	README Makefile say.c say.1 wha.c wha.1 rep.c rep.1 libsaywha.c libsaywha.h
	shar -v -c -p X README Makefile say.c say.1 wha.c wha.1 rep.c rep.1 libsaywha.c libsaywha.h > $@
