#
#  Linux Makefile for XC for use with GNU Make
#  
.PHONY	: all bin clean clobber distclean eline install spotless uninstall zmodem

SHELL	= /bin/sh

#WARN 	= -Wall
#machine = -m486
CC	= gcc 
CFLAGS	= $(WARN) -O2 -fomit-frame-pointer $(machine) -DRLINE

prefix	= /usr/local
bindir	= $(prefix)/bin
libdir	= $(prefix)/lib/xc 
mandir	= /usr/man/man1
catdir	= /var/catman/cat1
manown	= -o daemon -g daemon
binown	= -o bin -g bin

export CC CFLAGS manown binown

INSTALL	= install
LDFLAGS	= -ltermcap editline/libedit.a
NROFF 	= groff -man
CXDEFS = -D__linux__ -Dlinux -D__i386__ -D__i386 -D__GNUC_MINOR__=5 -Di386\
	-D__unix -D__unix__ -D__GNUC__=2 -D__linux -Dunix

# you should have all of these files:
SRCS =	xcb+.c xcdbglog.c xcdial.c xcmain.c xcport.c \
               xcscrpt.c xcsubs.c xcterm.c xcxmdm.c

OBJS =	xcb+.o xcdbglog.o xcdial.o xcmain.o xcport.o \
               xcscrpt.o xcsubs.o xcterm.o xcxmdm.o

all:	xc zmodem xc.1 bin
	@echo "All targets are up to date"
	@echo "Now you may execute 'make install'"

xc:	$(OBJS) eline
	$(CC) $(CFLAGS) $(OBJS) -o xc $(LDFLAGS) 

zmodem: 
	cd rzsz ;  $(MAKE) all

uninstall:
	rm -f $(bindir)/xc $(mandir)/xc.1 $(catdir)/xc.1.*
	cd rzsz ; $(MAKE) uninstall

install: ./bin/xc ./bin/rz ./bin/sz ./bin/crc xc.1
	@echo " "
	$(INSTALL) $(binown) -m 755 -s ./bin/xc $(bindir) 
	$(INSTALL) $(manown) -m 644 xc.1 $(mandir)
	cd rzsz ; $(MAKE) binstall
	@echo " "
	@echo " "
	@echo "You will want to manually install 'phonelist' and"
	@echo "the 'xc.init' files in $(libdir). Or alternatively they"
	@echo "may be installed in your home directory. Be careful not"
	@echo "to clobber your old versions!"
	@echo " "
	@echo "See the 'dotfiles' directory for sample scripts."
	@echo "The sample xc scripts (.aus .autocis .callhq .cisdial .exrc"
	@echo ".pass .phonelist .rz .sz .temp_opt .uni .xc) should be manually"
	@echo "moved to the $(libdir) directory.  The shell scripts (call"
	@echo "callback cisdownload) should be moved to the $(INSDIR) directory."
	@echo
	@echo "We do not do this automatically, as you may want to recompile xc"
	@echo "with different options, yet not touch these scripts once you've"
	@echo "personalized them with your own passwords and telephone numbers."
	@echo " "

xc.1:	xc.nro
	cp xc.nro xc.1

clean:
	rm -f $(OBJS) xc core erro xc.1

clobber: clean
	rm -f $(OBJS) xc core tags erro xc.out xc.man
	cd editline ; $(MAKE) clean 
	cd rzsz ; $(MAKE) clean

distclean:
	$(MAKE) clobber

spotless: clobber
	rm -f ./bin/crc ./bin/rz ./bin/sz ./bin/xc

$(OBJS): xc.h

eline:
	cd editline ; $(MAKE) all

protos:
	cextract +a -c -P +p -s -DRLINE $(CXDEFS) -o xcxtr.h $(SRCS)

bin: 
	cp -a ./xc ./bin
	cp -a ./rzsz/crc ./rzsz/rz ./rzsz/sz ./bin

#########################################
##  mostly unused stuff below here ... ##
#########################################

xc.man:	myman xc.nro
	cat myman xc.nro | grep -v '^\.tm ' | tbl -C >xc.man

xc.out:	xc.man
	if [ -d $(catdir) ]; then \
		$(NROFF) xc.man > xc.out; \
	else \
			cat xc.man >xc.out; \
	fi

shar:
	shar -awF -L51 -nXC -oXC -s jpr@jpr.com $(MANIFEST)
	@ls -l XC.??

taz:
	tar cf - $(MANIFEST) | compress > XC.TAR.Z
	@ls -l *.Z

tah:
	tar cf - $(MANIFEST) | compress -H > XC.TAR.Z
	@ls -l *.Z

lha:
	lha c XC $(MANIFEST)
	@ls -L XC.A XC.lha

shark:
	shark $(MANIFEST) > XC.SHK
	@ls -l *SHK

manifest:
	ls -al * >Manifest	
	chmod a+w Manifest

