####################################
# $Id: Makefile,v 1.3 91/05/17 12:09:42 dhay Exp $
#
# EIF Makefile, D.Hay
#
# Targets:
#   all     - eif
#   eif     - make the program
# 
#*******************************************************
#*  Copyright (C) Doug Hay, 1989,90,91.
#*  Permission to use and abuse this code, as long
#*  as this copyright notice stays intact and with the
#*  code.  No warranty implied.  This code supplied as is.
#*******************************************************

###################
# Compile flags

CFLAGS = $(FLAGS)
LINTFLAGS = -u -h -x -v $(FLAGS)
LINT = /bin/lint

MKDEPFLAGS = $(FLAGS)
TARFILE = eif.tar
BKUPDIR = ../bkup
BKUPBASE = eif.tar.Z

FLAGS = 
SLIBS = -ltermcap -lm
LLIBS = readline.a connect.a

# List of what we want to create
DESTS = \
	eif

DESTSALL = $(DESTS)

# All the include files
INC = \
	cntl.h\
	data.h

INCCONNECT = \
	connect/proto.h

INCCONSTRUCTED = version.h

INCALL = $(INC) $(INCCONSTRUCTED) $(INCCONNECT)
INCNOCONST = $(INC)

# All the source routine files
SRCLOC = \
	eif.c\
	alias.c\
	compick.c\
	empcon.c\
	games.c\
	gencoms.c\
	getcom.c\
	init.c\
	main.c\
	print.c\
	vars.c

SRCCONNECT = \
	connect/connect.c \
	connect/expect.c \
	connect/login.c \
	connect/sock.c

SRCALL = $(SRCLOC) $(SRCCONNECT)
LINTALL = $(SRCALL:.c=.ln)

# List of intermediate object files
OBJSLOC = $(SRCLOC:.c=.o)
OBJSCONNECT = $(SRCCONNECT:.c=.o)

# All the utility files
UTILS = \
	Makefile\
	RCS/.\
	connect/RCS/.\
	readline


FILESALL = $(UTILS) $(INCALL) $(SRCALL)


default: $(DESTS)
	@echo "done default"

.PRECIOUS: $(FILESALL)

all: $(DESTSALL)
	echo "done all"

readline.a:
	cd readline ; $(MAKE)

connect.a: $(OBJSCONNECT)
	rm -f $@
	ar ru $@ $(OBJSCONNECT)
	ranlib $@

eif: $(OBJSLOC) $(LLIBS)
	$(CC) $(CFLAGS) -o $@ $(OBJSLOC) $(LLIBS) $(SLIBS)

# Some utility targets
cleanreadline:
	cd readline ; $(MAKE) clean

clean: cleanreadline
	rm -f *.o *.ln core a.out cpr.list $(OBJSCONNECT) $(LLIBS)

cleanall veryclean: clean
	rm -f $(DESTS)

lint: $(LINTALL)
	$(LINT) $(LINTFLAGS) $(LINTALL)

.c.o:
	$(CC) $(CFLAGS) -c -o $@ $<

.c.ln:
	$(LINT) $(LINTFLAGS) -i $<

# Make a tarfile of all useful files
tarall tar: $(TARFILE).Z

$(TARFILE).Z : cleanreadline $(FILESALL)
	tar -cvf $(TARFILE) $(FILESALL)
	compress $(TARFILE)

bkup: $(TARFILE).Z
	chmod a-wx $(TARFILE).Z
	DT=`date +%y%m%d`;mv $(TARFILE).Z $(BKUPDIR)/$(BKUPBASE).$$DT
	cd $(BKUPDIR) ; make rdist


# depend
#   Use -M option of cc to output dependancies.
#   Change ../<dif>/../fn to ../fn  (sed)
#   Remove /usr/include/fn  files   (sed)
#   Put more than one dependancy on a line, up to 78 chars.
#   Add a .ln dependancy to each .o dependancy.  (sed)  (for lint)
depend:
	rm -f eddep makedep makelndep
	$(CC) -M $(MKDEPFLAGS) $(SRCALL) | \
	sed -e ':loop' -e 's/\.\.\/[^ /]*\/\.\./../' \
	    -e 's/^.*\/usr\/include\/.*$$//' -e 't loop' | \
	awk ' { if ($$1 != "") { if ($$1 != prev) \
	           { print rec; rec = $$0; prev = $$1; } \
	        else { if (length(rec $$2) > 68) { print rec; rec = $$0; } \
	           else rec = rec " " $$2 } } } \
	      END { print rec } ' | \
	sed -e 's/^.*\.o:/& &.ln:/' -e 's/\.o:\.ln:/.ln:/' \
	    -e /.*:.*:/s/:// >> makedep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ex - Makefile < eddep
	rm eddep makedep

# Remove all the depend stuff at the end.
dependclean:
	rm -f eddep
	echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ex - Makefile < eddep
	rm -f eddep

# version.h
# A file containing all the RCS header strings, for use
# in a version command.
# Use ident to grab RCS id strings.
# egrep strips anything not Header or Id.
# sed adds stuff to make it an array declaration.
#version.h:  $(INCNOCONST) $(SRCALL)
version.h:  $(INCNOCONST)
	@echo "Making $@"
	@rm -f $@
	@echo "/* This file is automatically created by MAKE. */" > $@
	@echo "/* It is included by main.c, used for the -v (version) option */" >> $@
	@ident -q $(INCNOCONST) $(SRCALL) | \
	egrep '(Header|Id)' | \
	sed -e 's/$$Header:/"/' \
	    -e 's/$$Id:/"/' \
	    -e 's/$$$$/",/' \
	>> $@
	@echo \" Host: `hostname` \", >>$@
	@chmod a-w $@

# Everything after this line changes, in "make depend"
# DO NOT DELETE THIS LINE (or the following blank line)

eif.c:
eif.o eif.ln: eif.c ./cntl.h ./data.h
alias.c:
alias.o alias.ln: alias.c
compick.c:
compick.o compick.ln: compick.c
empcon.c:
empcon.o empcon.ln: empcon.c ./cntl.h ./data.h
games.c:
games.o games.ln: games.c ./cntl.h ./data.h
gencoms.c:
gencoms.o gencoms.ln: gencoms.c
getcom.c:
getcom.o getcom.ln: getcom.c
init.c:
init.o init.ln: init.c ./cntl.h ./data.h
main.c:
main.o main.ln: main.c ./cntl.h ./data.h ./version.h
print.c:
print.o print.ln: print.c
vars.c:
vars.o vars.ln: vars.c
connect/connect.c:
connect.o connect.ln: connect/connect.c
connect/expect.c:
expect.o expect.ln: connect/expect.c connect/proto.h
connect/login.c:
login.o login.ln: connect/login.c connect/proto.h
connect/sock.c:
sock.o sock.ln: connect/sock.c connect/proto.h
