# Term program makefile for mint 
# valid targets are:
#	all linecheck termtest clean binclean realclean ... 
#	bin install.bin install.share install.net
#	lib install.lib

SRCDIR=.
VPATH=.

SHELL=/bin/sh
# Note: If you change the version #, you must "make realclean"
VERSION_MAJOR = 2
VERSION_MINOR = 2
PATCH_LEVEL   = 4
PATCH_NAME    = .4
VERSION_NUM   = 20204

CC=gcc -Wall
CPP=$(CC) -E

# ADDFLAGS=-DTERM_NFS_DIR is needed if your .term directory is
# ADDFLAGS=-DNO_LOOPBACK keep "termnet" from connecting to localhost.
# mounted with NFS.
ADDFLAGS = 


CFLAGS = -O -D__MINT__ -I/usr/src/portlib $(ADDFLAGS) \
	-DSHAREDIR='"$(SHAREDIR)"' -DVERSION=$(VERSION_NUM)

AR		= ar rcs
RANLIB		= echo
AS		= as
CHGRP		= chgrp term
CHMOD		= chmod
CP		= cp
LN		= ln 
RM		= rm -f
RMDIR		= rmdir
MKDIR		= mkdir
MV		= mv
NM		= nm
SED		= sed
STRIP		= strip
SHAREDIR	= /usr/lib/term
BINDIR		= /usr/bin
LIBDIR		= /usr/lib
INCDIR		= /usr/include
MANDIR		= /usr/man/man1
OSLIBS		= -L/usr/src/portlib -lsocket -lportlib
LIBS		= $(TERMNETLIB) $(OSLIBS) 
LINKFLAGS	= 
USRTMP		= /usr/tmp

#
# Change this if yours is different.
#
CURSES= -ltermcap

TERMNETDEP=libtermnet.a
TERMNETLIB=$(TERMNETDEP)

TERMOBJS=main.o serial.o misc.o do_link.o pty.o compress.o \
		meta.o statistics.o sevenbit.o 

CLIENTOBJS=utils.o client.o termnet.o terminal.o do_select.o sockets.o do_connect.o \
		spipe.o term_getopt.o term_putenv.o term_herror.o \
		term_spair.o checksum.o host_lookup.o

MANPAGES=term.1 term_clients.1 term_setup.1 termtest.1 linecheck.1

LINKS = trdated
LINK_FROM = trdate
CLIENTS = tdownload tudpredir tmon tshutdown \
	trsh tupload tredir txconn trdate


PROGS=term $(CLIENTS) linecheck


all: bin $(LINKS) libtermnet.a

help:
	@echo "To install, make one of the following:"
	@echo "  install - binaries, dynamic and static library, include file"
	@echo "  install.bin - binaries"
	@echo "  install.share - binaries in shared mode"
	@echo "  install.lib - static library"
	@echo "  install.include - include file"
	@echo "  install.man - manual pages"
	@echo "  install.net - full networking flag"

install:  install.bin install.lib

install.bin: all
	if [ ! -d $(BINDIR) ] ; then $(MKDIR) $(BINDIR); else true; fi 
	-cd $(BINDIR); $(RM) $(LINKS)
	-cd $(BINDIR); for i in $(PROGS) $(LINKS); do \
		if [ -f $$i ]; then $(MV) $$i $$i.old ; fi ; \
	done
	for i in $(PROGS); do \
		$(CP) $$i $(BINDIR)/. ; \
		$(STRIP) $(BINDIR)/$$i ; \
		$(CHMOD) 755 $(BINDIR)/$$i ; \
	done
	-cd $(BINDIR); for i in $(LINKS); do \
		$(LN) -s ./$(LINK_FROM) $$i ; \
	done
	if [ ! -d $(LIBDIR) ] ; then $(MKDIR) $(LIBDIR); else true; fi

install.lib: libtermnet.a install.include
	$(CP) ./libtermnet.a $(LIBDIR)
	-cd $(LIBDIR);$(RANLIB) libtermnet.a

install.net installnet: install
	if [ ! -d $(SHAREDIR) ] ; then $(MKDIR) $(SHAREDIR); else true; fi
	echo "# This file activates full term networking" > $(SHAREDIR)/termnet

install.include:
	if [ ! -d $(INCDIR) ]; then $(MKDIR) $(INCDIR); else true; fi
	$(CP) termnet.h $(INCDIR)/.
	$(CHMOD) 644 $(INCDIR)/termnet.h


install.share installshare share: install 
	cd $(BINDIR) ; \
	for i in $(PROGS) ; do \
		$(CHGRP) $$i ; \
		$(CHMOD) g+s $$i ; \
	done
	if [ ! -d $(SHAREDIR) ] ; then $(MKDIR) $(SHAREDIR); else true; fi 
	$(CHGRP) $(SHAREDIR)
	$(CHMOD) 0775 $(SHAREDIR)
	-if [ -d $(SHAREDIR)/tmp ] ; then \
		$(MV) $(SHAREDIR)/tmp $(SHAREDIR)/tmp.old ; \
		$(RM) -r $(SHAREDIR)/tmp.old ; \
	else true; fi
	-$(LN) -s $(USRTMP) $(SHAREDIR)/tmp
	-if [ ! -d $(SHAREDIR)/.term ]; then \
		 $(LN) -s $(SHAREDIR)/tmp/private $(SHAREDIR)/.term ; \
	else true; fi

install.man installman: $(MANPAGES)
	if [ ! -d $(MANDIR) ]; then $(MKDIR) $(MANDIR); else true; fi
	cd $(SRCDIR); for i in *.1; do \
		$(CP) $$i $(MANDIR)/.; \
		$(CHMOD) 644 $(MANDIR)/$$i; \
	done
	for i in $(CLIENTS) $(LINKS); do \
		echo ".so man1/term_clients.1" > $(MANDIR)/$$i.1; \
		$(CHMOD) 644 $(MANDIR)/$$i.1; \
	done

# The next two targets are only used by GNU Make, as far as I know.
# They automatically rebuild Makefile and config.status when necessary.

Makefile: config.status Makefile.in
	./config.status

config.status: configure
	./configure

#-----------------------------------------------------------------
# may need to uncomment following two lines.. (for gnu make).
#%.o: %.c
#	$(CC) $(CFLAGS) -c $< -o $@
#     --- or following 5 lines ------
#.SUFFIXES
#.SUFFIXES:  .o .c
#
#.c.o:
#	$(CC) $(CFLAGS) -c $< -o $@
#-----------------------------------------------------------------

libtermnet.a: $(CLIENTOBJS)
	$(RM) libtermnet.a
	$(AR) libtermnet.a $(CLIENTOBJS)
	$(RANLIB) libtermnet.a

bin: $(PROGS)

termtest: termtest.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o termtest termtest.o $(LIBS)

term: $(TERMNETDEP) $(TERMOBJS) 
	$(CC) $(LINKFLAGS) -o term $(TERMOBJS) $(LIBS)

$(LINKS): $(LINK_FROM)
	for i in $(LINKS); do \
		$(RM) $$i ; \
		$(LN) -s ./$(LINK_FROM) $$i ; \
	done

linecheck: $(TERMNETDEP) linecheck.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o linecheck linecheck.o $(LIBS)


trsh: $(TERMNETDEP) trshell.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o trsh trshell.o $(LIBS)

tupload: $(TERMNETDEP) upload.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tupload upload.o $(LIBS)

tdownload: $(TERMNETDEP) download.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tdownload download.o $(LIBS)

tredir: $(TERMNETDEP) redir.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tredir redir.o $(LIBS)

tudpredir: $(TERMNETDEP) udpredir.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tudpredir udpredir.o $(LIBS)

txconn: $(TERMNETDEP) xconn.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o txconn xconn.o $(LIBS)

tshutdown: $(TERMNETDEP) shutdown.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tshutdown shutdown.o $(LIBS)

tmon: $(TERMNETDEP) tmon.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o tmon tmon.o $(CURSES) $(LIBS)

trdate: $(TERMNETDEP) trdate.o
	$(CC) $(LINKFLAGS) $(NOPAG) -o trdate trdate.o $(CURSES) $(LIBS)

tags:
	etags *.h *.c


clean:
	$(RM) *.o lib*.a lib*.sa lib*.so.* core compress.debug *.out *~ 

realclean: clean
	$(RM) $(PROGS) $(LINKS) termtest 1 TAGS tags
	-$(RM) *.log


depend:
	cd $(SRCDIR) && \
	$(SED) '/^\#\#\# Dependencies/q' Makefile > tmp_make && \
	for i in *.c; do echo $$i; gcc -E -MM $$i >> tmp_make; done && \
	$(MV) tmp_make Makefile







#
# The following targets are mostly for my personal use. I use them to 
# update the version of term when I am developing.
#

VERSION_NAME = term-$(VERSION_MAJOR).$(VERSION_MINOR)$(PATCH_NAME)
ARCHIVE = /usr/local/src/term.old/$(VERSION_NAME)
ALPHA_DIR = /opt/ftp/pub/bcr/term/ALPHA
BETA_DIR = /opt/ftp/pub/bcr/term

distclean: realclean
	$(RM) config.status Makefile
	-$(RM) `find . -name \*.orig`
	-$(RM) `find . -name \*.rej`

rcs_extract:
	-co -q`expr $(VERSION_MAJOR) \* 100 + $(VERSION_MINOR)`.$(PATCH_LEVEL) \
	  `find . -name \*,v -print | sed 's/,v$$//'`
	$(CHMOD) ugo+x configure

rcs_purge: rcs_extract
	rcs -o`expr $(VERSION_MAJOR) \* 100 + $(VERSION_MINOR)`.$(PATCH_LEVEL) \
	  `find . -name \*,v -print | sed 's/,v$$//'`

rcs_ver: distclean rcs_extract
	rcs -U `find . -name \*,v -print`
	yes|tr y .|ci -f`expr $(VERSION_MAJOR) \* 100 + $(VERSION_MINOR)`.$(PATCH_LEVEL) \
	  -n`echo term-$(VERSION_MAJOR).$(VERSION_MINOR)$(PATCH_NAME)|tr . _` \
	  `find . -type f -not -name \*,v -not -name \*.gz -print`
	co -q`expr $(VERSION_MAJOR) \* 100 + $(VERSION_MINOR)`.$(PATCH_LEVEL) \
	  `find . -name \*,v -print | sed 's/,v$$//'`
	$(CHMOD) ugo+x configure

rcs_tar: distclean rcs_extract
	$(RM) /tmp/$(VERSION_NAME)
	$(LN) -s `pwd` /tmp/$(VERSION_NAME)
	cd /tmp ; \
	  find $(VERSION_NAME) -follow -type f -not -empty -not -name \*,v -print | \
	  sort -u | tar Tcvvfz - $(ARCHIVE).tar.gz

rcs_patch: distclean rcs_extract
	$(RM) /tmp/$(VERSION_NAME)
	$(LN) -s `pwd` /tmp/$(VERSION_NAME)
	if [ $(PATCH_LEVEL) -gt 0 ] ; then \
	  (cd /tmp; version_name=$(VERSION_NAME); rcsdiff \
	  -u -r`expr $(VERSION_MAJOR) \* 100 + $(VERSION_MINOR)`.`expr $(PATCH_LEVEL) - 1` \
	  `find $$version_name -follow -type f -not -name \*,v -not -name \*.gz -print` \
	  | gzip -c ) > $(ARCHIVE).patch.gz ; \
	  if [ $(PATCH_LEVEL) -le 50 ] ; then \
		$(CP) $(ARCHIVE).patch.gz $(SRCDIR)/patches/. ; \
	  else true; fi; \
	else true; fi

rcs_update: rcs_ver rcs_tar rcs_patch
	$(RM) /tmp/$(VERSION_NAME)
	$(LN) -s `pwd` /tmp/$(VERSION_NAME)
	cd /tmp; if [ $(PATCH_LEVEL) -gt 50 ] ; then \
	  tupload -fvvr $(ARCHIVE).*.gz $(ALPHA_DIR) ; \
	else \
	  tupload -fvvr $(ARCHIVE).*.gz $(BETA_DIR) ; \
	fi
	cd /tmp; $(CHMOD) ugo-w $(ARCHIVE).*.gz

rcs_remote: rcs_tar
	$(RM) /tmp/$(VERSION_NAME)
	$(LN) -s `pwd` /tmp/$(VERSION_NAME)
	cd /tmp; tupload -fvvr $(ARCHIVE).tar.gz /tmp
	trsh -s 'cd /tmp;zcat $(VERSION_NAME).tar.gz|tar xvvf -'
	trsh -s 'cd /tmp/$(VERSION_NAME);./configure --user;make install'

rcs_spell: distclean rcs_extract
	ispell -p $(HOME)/.term_dict `find . -type f -not -name \*,v -not -name \*.gz`

dummy:

checksum.o : checksum.c 
client.o : client.c includes.h term_main.h config.h client.h terminal.h 
compress.o : compress.c includes.h term_main.h config.h client.h terminal.h debug.h 
do_connect.o : do_connect.c includes.h term_main.h config.h client.h terminal.h 
utils.o : utils.c includes.h term_main.h config.h client.h terminal.h debug.h 
linecheck.o : linecheck.c includes.h term_main.h config.h client.h terminal.h 
do_link.o : do_link.c includes.h term_main.h config.h client.h terminal.h debug.h 
main.o : main.c includes.h term_main.h config.h client.h terminal.h debug.h 
meta.o : meta.c includes.h term_main.h config.h client.h terminal.h debug.h 
misc.o : misc.c includes.h term_main.h config.h client.h terminal.h debug.h 
pty.o : pty.c includes.h term_main.h config.h client.h terminal.h debug.h 
redir.o : redir.c includes.h term_main.h config.h client.h terminal.h 
udpredir.o : udpredir.c includes.h term_main.h config.h client.h terminal.h 
do_select.o : do_select.c includes.h term_main.h config.h client.h terminal.h 
serial.o : serial.c includes.h term_main.h config.h client.h terminal.h debug.h 
server.o : server.c includes.h term_main.h config.h client.h terminal.h 
sevenbit.o : sevenbit.c includes.h term_main.h config.h client.h terminal.h debug.h 
shutdown.o : shutdown.c includes.h term_main.h config.h client.h terminal.h 
sockets.o : sockets.c includes.h term_main.h config.h client.h terminal.h 
spipe.o : spipe.c includes.h term_main.h config.h client.h terminal.h
statistics.o : statistics.c includes.h term_main.h config.h client.h terminal.h 
tclient.o : tclient.c includes.h term_main.h config.h client.h terminal.h 
term_getopt.o : term_getopt.c includes.h term_main.h config.h client.h terminal.h 
term_herror.o : term_herror.c includes.h term_main.h config.h client.h terminal.h 
term_putenv.o : term_putenv.c includes.h term_main.h config.h client.h terminal.h 
term_spair.o : term_spair.c includes.h term_main.h config.h client.h terminal.h 
terminal.o : terminal.c includes.h term_main.h config.h client.h terminal.h 
termnet.o : termnet.c includes.h term_main.h config.h client.h terminal.h 
termtest.o : termtest.c includes.h term_main.h config.h client.h terminal.h 
tmon.o : tmon.c includes.h term_main.h config.h client.h terminal.h 
trdate.o : trdate.c includes.h term_main.h config.h client.h terminal.h 
trshell.o : trshell.c includes.h term_main.h config.h client.h terminal.h 
upload.o : upload.c includes.h term_main.h config.h client.h terminal.h 
download.o : download.c includes.h term_main.h config.h client.h terminal.h 
xconn.o : xconn.c includes.h term_main.h config.h client.h terminal.h

