#
# Makefile for screen 
# a la GNU but still without configure (2.11. jw)
#
# See machine dependant config.h for more configuration options.
#

SHELL=/bin/sh
CPP_DEPEND=/lib/cpp -MM
ETCSCREENRC=/local/etc/screenrc
INSTALL=install -c
#INSTALL_PROGRAM=$(INSTALL) -o root -m 4755
INSTALL_PROGRAM=$(INSTALL) -o root -m 4755
INSTALL_DATA=$(INSTALL)
bindir=/local/bin
mandir=/local/man
VERSION=3.2.19

### If you choose to compile with the tried and true:
CC= cc
#CFLAGS= -O
CFLAGS= -g 
### gcc specific CFLAGS:
CC= gcc
# If your system include files are bad, don't use -Wall
CFLAGS= -O6 -g #-Wall 
#CFLAGS = -g -fstrength-reduce -fcombine-regs -finline-functions #-Wall

### On some machines special CFLAGS are required:
M_CFLAGS=
#M_CFLAGS= -Dapollo -A cpu,mathchip -A nansi	# Apollo DN3000/4000/4500
#M_CFLAGS= -DBSDI				# bsd386
#M_CFLAGS= -DISC -D_POSIX_SOURCE		# isc
#M_CFLAGS= -systype bsd43 -DMIPS		# mips
#M_CFLAGS= -fforce-mem -fforce-addr\
 -fomit-frame-pointer -finline-functions -bsd 	# NeXT
#M_CFLAGS= -qlanglvl=ansi			# RS6000/AIX
#M_CFLAGS= -qlanglvl=ansi -D_AIX32		# RS6000/AIX 3.2
#M_CFLAGS= -ansi				# sgi/IRIX 3.x ansi 
#M_CFLAGS= -xansi				# sgi/IRIX 4.x ext ansi 
#M_CFLAGS= -YBSD				# Ultrix 4.x

### Choose one of the LIBS setting below:
#LIBS= -ltermcap -lc -lsocket -linet -lsec -lseq	# Sequent/ptx
LIBS= -ltermcap 			# SunOS, Linux, Apollo,
#					  gould_np1, NeXT, Ultrix
#LIBS= -ltermcap -lelf			# SVR4
#LIBS= -ltermlib -linet -lcposix	# isc
#LIBS= -ltermcap -lmld			# mips (nlist is in mld)
#LIBS= -ltermlib -lsun -lmld #-lc_s	# sgi/IRIX
#LIBS= -lcurses				# RS6000/AIX
#LIBS= -lcrypt_d -ltinfo		# sco32
#LIBS= -lcrypt_i -ltinfo		# sco32
#LIBS= -lcrypt -lsec			# sco322 (msilano@sra.com)
#LIBS= -ltermcap -lcrypt.o -ldir -lx	# SCO XENIX 2.3.4
#LIBS= -ltermcap -lcrypt -ldir -l2.3 -lx	# SCO UNIX XENIX cross dev.

### Choose a stripped or unstripped binary
LDFLAGS=
#LDFLAGS=-s

### Chose some configuration options:
# -DHOMESOCKDIR
#	In case you want the sockets/pipes to reside in $HOME/.screen directory.
#	Not recommended where home directories come over NFS.
# -DDEBUG
#	Turn on really heavy debug output. This is written to 
#	/tmp/debug/screen.{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 screen version. Use that in
#	combination with -DDEBUG
# -DTOPSTAT
#	If you'd rather see the status line on the first line of 
#	your terminal rather than the last.
# -DSIMPLESCREEN
#	Disable the 'screenlock' feature, disable the security mechanism,
#	disable the copy and paste feature, disable 'remote detach' (-d) and 
#	'pow_detach' (instant logout). See your config.h for more details.
# -DNONETHACK
#	Do not even use the funny and fuzzy messages if user has
#	$NETHACKOPTIONS set in his environment.
OPTIONS=
#OPTIONS= -DDEBUG -DTMPTEST

CFILES=	screen.c ansi.c help.c fileio.c mark.c misc.c window.c \
	socket.c search.c tty.c term.c exec.c utmp.c loadav.c putenv.c \
	termcap.c input.c attacher.c pty.c process.c display.c comm.c
OFILES=	screen.o ansi.o help.o fileio.o mark.o misc.o window.o \
	socket.o search.o tty.o term.o exec.o utmp.o loadav.o putenv.o \
	termcap.o input.o attacher.o pty.o process.o display.o comm.o

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

all:	screen

install_bin: screen
	$(INSTALL_PROGRAM) screen $(bindir)/screen-$(VERSION)
	if [ ! -f $(bindir)/screen.old ]; then mv $(bindir)/screen $(bindir)/screen.old; fi
	-@rm $(bindir)/screen
	ln -s $(bindir)/screen-$(VERSION) $(bindir)/screen

install: install_bin
	-$(INSTALL_DATA) etcscreenrc $(ETCSCREENRC)
	-$(INSTALL_DATA) screen.1 $(mandir)/man1/screen.1
	-tic terminfo/screeninfo.src
# Better do this by hand. E.g. under RCS...
#	cat terminfo/screencap >> /etc/termcap

uninstall:
	rm -f $(INSTALLBIN)/screen-$(VERSION)
	rm -f $(INSTALLBIN)/screen
	mv $(INSTALLBIN)/screen.old $(INSTALLBIN)/screen
	rm -f $(INSTALLETC)/screenrc
	rm -f $(INSTALLMAN)/man1/screen.1

screen: $(OFILES)
	$(CC) $(CFLAGS) $(LDFLAGS) -o screen $(OFILES) $(LIBS)

config.h:
	@echo "CC=$(CC)"
	@echo "CFLAGS=$(CFLAGS)"
	@echo "LDFLAGS=$(LDFLAGS)"
	@echo "LIBS=$(LIBS)"
	@echo "If the above defines are incorrect, press CTRL-C and edit Makefile."
	@echo "Choose one of these config files:"
	@echo ""
	@cd config; ls -m config.*
	@echo -n "Enter filename: "
	@read a; ln -s config/$$a config.h
	make mostlyclean

term.h: term.c term.sh
	sh term.sh

tty.c:	tty.sh 
	sh tty.sh tty.c

comm.h: comm.c comm.sh config.h
	sh comm.sh

clean:
	rm -f $(OFILES) tty.c term.h comm.h screen

# Delete all files from the current directory that are created by 
# configuring or building the program.
# building of term.h requires awk. Keep it in the distribution
distclean:	mostlyclean
	rm -f screen-$(VERSION).tar screen-$(VERSION).TZ

# Delete everything from the current directory that can be
# reconstructed with this Makefile.
realclean:	distclean

mostlyclean:
	rm -f $(OFILES) screen

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

dist: screen-$(VERSION).tar screen-$(VERSION).TZ

screen-$(VERSION).tar:
	-rm -rf dist
	mkdir dist
	mkdir dist/screen-$(VERSION)
	ln ansi.h display.h extern.h mark.h os.h overlay.h \
	   patchlevel.h rcs.h screen.h window.h \
	   term.sh tty.sh comm.sh newsyntax \
	   ansi.c attacher.c comm.c display.c exec.c fileio.c help.c \
	   input.c loadav.c mark.c misc.c process.c pty.c putenv.c \
	   screen.c search.c socket.c term.c termcap.c utmp.c window.c \
	   screen.1 Makefile ChangeLog COPYING INSTALLATION readme.quick \
	   dist/screen-$(VERSION)
	-ln term.h dist/screen-$(VERSION)
	-ln tty.c dist/screen-$(VERSION)
	-ln comm.h dist/screen-$(VERSION)
	mkdir dist/screen-$(VERSION)/config
	ln config/config* dist/screen-$(VERSION)/config
	mkdir dist/screen-$(VERSION)/terminfo
	-ln terminfo/* dist/screen-$(VERSION)/terminfo
	mkdir dist/screen-$(VERSION)/terminfo/s
	ln terminfo/s/* dist/screen-$(VERSION)/terminfo/s
	sed -e 's/^startup/#startup/' < $(ETCSCREENRC) > dist/screen-$(VERSION)/etcscreenrc 
	cp $(HOME)/.iscreenrc dist/screen-$(VERSION)/.iscreenrc
	cd dist; tar chf ../screen-$(VERSION).tar screen-$(VERSION)
	-rm -rf dist

screen-$(VERSION).TZ: screen-$(VERSION).tar
	compress < screen-$(VERSION).tar > screen-$(VERSION).TZ
	rm screen-$(VERSION).tar

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

lint:
	lint -I. $(CFILES)

saber:
	#load $(CFLAGS) screen.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


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