
BINDIR=/usr/local/bin
SBINDIR=/usr/local/sbin
MANDIR=/usr/local/man

CC = gcc 

#if you have libident and snprintf and are compiling this on Linux
#CFLAGS = -O2 -Wall  

#if you have libident and snprintf and GNU libreadline
#CFLAGS = -O2 -Wall -DREADLINE

#or, if you do not have libinent at all:
CFLAGS = -O2 -Wall -DDONT_HAVE_LIBIDENT
#and if you do not have snprintf
#CFLAGS = -O2 -Wall -DDONT_HAVE_SNPRINTF

#and if you do not have both 
#CFLAGS = -O2 -Wall -DDONT_HAVE_SNPRINTF -DDONT_HAVE_LIBIDENT

#add -DBSD_COMPILE to CFLAGS if you are compiling this on FreeBSD, like this:
#CFLAGS = -O2 -Wall -DDONT_HAVE_LIBIDENT -DBSD_COMPILE

#uncomment the following line if you do have libident.so
#LDFLAGS = -lident

#if you have GNU libreadline, you can use it:
#LDFLAGS = -lreadline

#use the following line in case you have only libident.a, not shared 
#library (or you want to link staticly against libident)
#LDFLAGS=/usr/lib/libident.a

#LDFLAGS should stay empty if you do not have libident and GNU libreadline at all
LDFLAGS =

all: xtell xtelld

xtelld: xtelld.o daemon.o child.o tty.o common.c
	$(CC) $(CFLAGS) xtelld.o daemon.o child.o tty.o common.o $(LDFLAGS) -o xtelld
	strip xtelld

xtell: xtell.o utils.o
	$(CC) $(CFLAGS) xtell.o utils.o $(LDFLAGS) -o xtell

xtelld.o: xtelld.c
	$(CC) $(CFLAGS) -c xtelld.c

common.o: common.c
	$(CC) $(CFLAGS) -c common.c

daemon.o: daemon.c
	$(CC) $(CFLAGS) -c daemon.c

child.o: child.c
	$(CC) $(CFLAGS) -c child.c

tty.o: tty.c
	$(CC) $(CFLAGS) -c tty.c

xtell.o: xtell.c
	$(CC) $(CFLAGS) -c xtell.c

clean:
	rm -f *~ *.o xtell xtelld

install: xtelld xtell
	cp xtelld $(SBINDIR)
	chgrp tty $(SBINDIR)/xtelld
	chmod g+s $(SBINDIR)/xtelld
	cp xtell $(BINDIR)

install-doc: 
	mkdir -p $(MANDIR)/man1 $(MANDIR)/man8
	mkdir -p $(MANDIR)/man1 $(MANDIR)/man1
	gzip -9 xtell.1 -c >$(MANDIR)/man1/xtell.1.gz
	gzip -9 xtelld.8 -c >$(MANDIR)/man8/xtelld.8.gz

