# Makefile written by Paul Pomes, University of Illinois,
# Computing Services Office
#
# Copyright (C) 1986 by Paul Pomes and the University of Illinois Board
# of Trustees
#
# This Makefile is distributed in the hope that it will be useful,
# but without any warranty.  No author or distributor accepts
# responsibility to anyone for the consequences of using it or for
# whether it serves any particular purpose or works at all, unless
# s/he says so in writing.
#
# Everyone is granted permission to copy, modify and redistribute
# this Makefile under the following conditions:
#
#    Permission is granted to anyone to make or distribute copies
#    of Makefile source code, either as received or modified, in any
#    medium, provided that all copyright notices, permission and
#    nonwarranty notices are preserved, and that the distributor
#    grants the recipient permission for further redistribution as
#    permitted by this document, and gives him and points out to
#    him an exact copy of this document to inform him of his rights.
#
#    Permission is granted to distribute this Makefile in compiled
#    or executable form under the same conditions applying for
#    source code, provided that either
#    A. it is accompanied by the corresponding machine-readable
#       source code, or
#    B. it is accompanied by a written offer, with no time limit,
#       to give anyone a machine-readable copy of the corresponding
#       source code in return for reimbursement of the cost of
#       distribution.  This written offer must permit verbatim
#       duplication by anyone.
#    C. it is distributed by someone who received only the
#       executable form, and is accompanied by a copy of the
#       written offer of source code which he received along with it.
#
# In other words, you are welcome to use, share and improve this
# Makefile.  You are forbidden to forbid anyone else to use, share
# and improve what you give them.   Help stamp out software-hoarding!
#
# UUCP:     {ihnp4,seismo}!uiucuxc!paul
# Internet: paul@uxc.cso.uiuc.edu   BITNET: paul@uiucuxc
# MILNET:   paul@uiucuxc.arpa       CSNET:  paul%uxc@uiuc.csnet
# US Mail:  Univ of Illinois, CSO, 1304 W Springfield Ave, Urbana, IL  61801

# .PREFIXES:	./RCS
.SUFFIXES:	.c,v .h,v .y,v

CC     = gcc
CO     = co
RM     = /bin/rm -f

HOF_FILE= ${DESTLIB}/robots2_hof
TMP_FILE= ${DESTLIB}/robots2_tmp
T_HOF_FILE= ${DESTLIB}/torus_hof
T_TMP_FILE= ${DESTLIB}/torus_tmp

# -DBSD42 provides big performance win, but not for Linux!

#DEFS   = -DBSD42 -DHOF_FILE='"${HOF_FILE}"' -DTMP_FILE='"${TMP_FILE}"' -DT_HOF_FILE='"${T_HOF_FILE}"' -DT_TMP_FILE='"${T_TMP_FILE}"'
DEFS   =  -DHOF_FILE='"${HOF_FILE}"' -DTMP_FILE='"${TMP_FILE}"' -DT_HOF_FILE='"${T_HOF_FILE}"' -DT_TMP_FILE='"${T_TMP_FILE}"'
CFLAGS = ${DEFS} -O
FFLAGS = ${DEFS}
PFLAGS = ${DEFS}
LFLAGS = 
YFLAGS = 
LDFLAGS= 
LIBS   = -lcurses -ltermcap

DESTBIN= /usr/games
DESTETC= /usr/games/etc
DESTLIB= /usr/games/lib
MS     = l


HDRS   = robots.h
SRCS   = good.c main.c opt.c robot.c score.c user.c
OBJS   = good.o main.o opt.o robot.o score.o user.o
VERS   = 

.c,v.o:
	${CO} -q $*.c
	${CC} ${CFLAGS} -c $*.c
	${RM} $*.c

.c,v.c:
	${CO} -q $*.c

.h,v.h:
	${CO} -q $*.h

.y,v.y:
	${CO} -q $*.y

all:	torus

torus:  ${OBJS}
	${CC} -o torus ${LDFLAGS} ${OBJS} ${LIBS}

install:	torus
	install -s -m 2511 -g games torus ${DESTBIN}
	touch ${HOF_FILE} ${TMP_FILE}
	chmod 664 ${HOF_FILE} ${TMP_FILE}
	chgrp games ${HOF_FILE} ${TMP_FILE}
	touch ${T_HOF_FILE} ${T_TMP_FILE}
	chmod 664 ${T_HOF_FILE} ${T_TMP_FILE}
	chgrp games ${T_HOF_FILE} ${T_TMP_FILE}
	install -c -m 444 torus.6 ${MANDIR}/torus.${MS}

uninstall:	/tmp
	rm -f ${DESTBIN}/torus \
		${MANDIR}/torus.${MS} ${CATDIR}/torus.${MS} \
		${HOF_FILE} ${TMP_FILE}

lint:	${HDRS} ${SRCS}
	lint -habx ${DEFS} ${SRCS}

shar:	${HDRS} ${SRCS} ${OTHERS}
	shar ${HDRS} ${SRCS} ${OTHERS} > torus.shar

tags:	${HDRS} ${SRCS}
	ctags ${HDRS} ${SRCS}

clean:
	@echo "Removing object and junk files."
	rm -f robots2 *.o core a.out make.log lint.out Makefile.bak torus.shar

clobber:
	@echo "Removing read-only source files that have RCS parents."
	@echo "Error code 1 indicates last file in SRCS list was not removed."
	@echo "(Which is OK)"
	make clean
	-if [ `whoami` != root ]; then \
	   for i in ${HDRS} ${SRCS}; do \
	      if [ ! -w $$i ]; then \
	         ( if   [ -f $$i,v ];     then rm -f $$i; \
	           elif [ -f RCS/$$i,v ]; then rm -f $$i; \
	         fi ); \
	      else echo $$i "writeable, not removed"; \
	      fi; \
	   done; \
	else echo "Running \"make clobber\" as root will zap ALL SRCS,\
		RCS'ed or not (not done)."; \
	fi

compress:
	make clean
	@echo "Compressing source and RCS files."
	find . -size +2 \( -name \*.h -o -name \*.c -o -name \*.f \
		-o -name \*.p -o -name \*.l -o -name \*.y -o -name \*,v \) \
		-exec compress {} \;

uncompress:
	uncompressdir .

# RCS stuff

ci:		${HDRS} ${SRCS}
		-ci $?
		@touch ci

coall:
		co -l ${HDRS} ${SRCS}

update:
		ci -sDist -u -f${VERS} ${HDRS} ${SRCS}
		@touch ci

depend:
	grep '^#[ 	]*include' /dev/null ${SRCS} \
		| sed -e '/"/s/:[^"]*"\([^"]*\)".*/: \1/' \
		      -e '/</s/:[^<]*<\([^>]*\)>.*/: \/usr\/include\/\1/' \
		| sed -e 's/\.c:/.o:/' -e 's/\.p:/.o:/' \
			-e 's/\.y:/.o:/' -e 's/\.l:/.o:/' >makedep
	echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ed - Makefile < eddep
	rm eddep makedep
	echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
	echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
	echo '# see make depend above' >> Makefile

# DO NOT DELETE THIS LINE -- make depend uses it

good.o: robots.h
main.o: robots.h
main.o: /usr/include/sys/stat.h
opt.o: robots.h
robot.o: robots.h
score.o: robots.h
user.o: robots.h
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
