#
# Makefile template for screader 
#
# See machine dependant config.h for more configuration options.
#

srcdir = @srcdir@
VPATH = @srcdir@

# Where to install screader.

prefix = /opt
exec_prefix = $(prefix)

bindir  = $(exec_prefix)/bin


ETCSCREENRC = `sed < config.h -n -e '/define ETCSCREENRC/s/^.*"\([^"]*\)"/\1/p'`

CC = @CC@
CFLAGS = -O2 -D__SCREADER -Wall
LDFLAGS = -s
LIBS = @LIBS@

CPP_DEPEND=/lib/cpp -MM

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

AWK = @AWK@

### Chose some debug configuration options:
# -DDEBUG
#	Turn on really heavy debug output. This is written to 
#	/tmp/debug/screader.{front,back} Look at these files and quote
#	questionable sections when sending bug-reports to the author.
# -DTMPTEST
#	Change the socket directory to a location that does not interfere
#	with the (suid-root) installed screader version. Use that in
#	combination with -DDEBUG
# -DDUMPSHADOW
#	With shadow-pw screader would never dump core. Use this option if you
#	still want to have a core. Use only for debugging.
# -DFORKDEBUG
#	Swap roles of father and son when forking the SCREEN process. 
#	Useful only for debugging.
OPTIONS=
#OPTIONS= -DDEBUG -DTMPTEST

SHELL=/bin/sh

CFILES=	screader.c tts.c scr.c ansi.c fileio.c mark.c misc.c resize.c socket.c \
	search.c tty.c term.c window.c utmp.c loadav.c putenv.c help.c \
	termcap.c input.c attacher.c pty.c process.c display.c comm.c \
	kmapdef.c acls.c
OFILES=	screader.o ansi.o fileio.o mark.o misc.o resize.o socket.o \
	search.o tty.o term.o window.o utmp.o loadav.o putenv.o help.o \
	termcap.o input.o attacher.o pty.o process.o display.o comm.o \
	kmapdef.o acls.o scr.o tts.o

all:	screader

screader: $(OFILES)
	$(CC) $(LDFLAGS) -o $@ $(OFILES) $(LIBS)

.c.o:
	$(CC) -c -I$(srcdir) $(M_CFLAGS) $(DEFS) $(OPTIONS) $(CFLAGS) $<

term.h: term.c term.sh
	AWK=$(AWK) srcdir=$(srcdir) sh $(srcdir)/term.sh

kmapdef.c: term.h

tty.c:	tty.sh 
	sh $(srcdir)/tty.sh tty.c

comm.h: comm.c comm.sh config.h
	AWK=$(AWK) CC="$(CC) $(CFLAGS)" srcdir=${srcdir} sh $(srcdir)/comm.sh

osdef.h: osdef.sh config.h osdef.h.in
	CC="$(CC) $(CFLAGS)" srcdir=${srcdir} sh $(srcdir)/osdef.sh

mostlyclean:
	rm -f $(OFILES) screader

clean celan: mostlyclean
	rm -f tty.c term.h comm.h osdef.h
	rm -f config.status Makefile
	rm -f tty.c term.h comm.h
	rm -f config.h
	@echo -e "all:\n\t./configure; make" > Makefile

TAGS: $(CFILES)
	ctags $(CFILES) *.h
	ctags -e $(CFILES) *.h

# Perform self-tests (if any).
check:

lint:
	lint -I. $(CFILES)

saber:
	#load $(CFLAGS) screader.c ansi.c $(LIBS)

mdepend: $(CFILES) term.h
	@rm -f DEPEND ; \
	for i in ${CFILES} ; do \
	  echo "$$i" ; \
	  echo `echo "$$i" | sed -e 's/.c$$/.o/'`": $$i" `\
            cc -E $$i |\
            grep '^# .*"\./.*\.h"' |\
            sort -t'"' -u +1 -2 |\
            sed -e 's/.*"\.\/\(.*\)".*/\1/'\
          ` >> DEPEND ; \
	done


depend: $(CFILES) term.h
	cp Makefile Makefile~
	sed -e '/\#\#\# Dependencies/q' < Makefile > tmp_make
	for i in $(CFILES); do echo $$i; $(CPP_DEPEND) $$i >> tmp_make; done
	mv tmp_make Makefile

screader.o socket.o: Makefile

### Dependencies:
screader.o: screader.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h patchlevel.h rcs.h screader.h term.h window.h
ansi.o: ansi.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
fileio.o: fileio.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
mark.o: mark.c acls.h ansi.h comm.h config.h display.h extern.h image.h mark.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
misc.o: misc.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
resize.o: resize.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
socket.o: socket.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
search.o: search.c acls.h ansi.h comm.h config.h display.h extern.h image.h mark.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
tty.o: tty.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
term.o: term.c rcs.h term.h
window.o: window.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
utmp.o: utmp.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
loadav.o: loadav.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
putenv.o: putenv.c config.h rcs.h
help.o: help.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
termcap.o: termcap.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
input.o: input.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
attacher.o: attacher.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
pty.o: pty.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
process.o: process.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
display.o: display.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h
comm.o: comm.c acls.h comm.h config.h rcs.h
kmapdef.o: kmapdef.c config.h
acls.o: acls.c acls.h ansi.h comm.h config.h display.h extern.h image.h os.h osdef.h overlay.h rcs.h screader.h term.h window.h

install: all
	@./install.sh
