# $Id: Makefile.std,v 1.71 1994/06/20 14:08:32 christos Exp $
#	Makefile.std	4.3	6/11/83
#
# C Shell with process control; VM/UNIX VAX Makefile
# Bill Joy UC Berkeley; Jim Kulp IIASA, Austria
#
# With an input editor, command completion, etc. and ported to all sorts of
# things; Paul Placeway, CIS Dept., Ohio State University
#
SHELL=/bin/sh
VERSION=6.05
BUILD=tcsh

#
# These are the default suffixes from .c to .o and -c to get there
# but to use the global optimizer on the mips boxes, see below
#
SUF=o
CF=-c

INCLUDES=-I.

LFLAGS=$(INCLUDES)

CFLAGS=-O2 -m68020 -m68881 -Wa,-m68030,-m68881 -mint $(INCLUDES)

DFLAGS=

################################################################
## LDFLAGS.  Define something here if you need to
################################################################
LDFLAGS=

################################################################
## LIBES.  Pick one, or roll your own.
################################################################
#LIBES=-lmtermcap -lmiio -lmint020
LIBES=-lmcurses -lmiio -lmint020

#CC=	gcc
ED=	ed
AS=	as
RM=	rm
#CXREF=	/usr/ucb/cxref
#VGRIND=	csh /usr/ucb/vgrind
#CTAGS=	/usr/ucb/ctags
#XSTR= /usr/ucb/xstr
#SCCS=	/usr/local/sccs
#PARALLEL=12				# Make the multi-max run fast.
#P=&					# Use Sequent's parallel make
P=
#DESTDIR=/usr/local
#MANSECT=1
#DESTBIN=${DESTDIR}/bin
#DESTMAN=${DESTDIR}/man/man${MANSECT}
# DESTMAN=${DESTDIR}/catman/man${MANSECT}	 # A/UX
# DESTMAN=${DESTDIR}/usr/share/man/man${MANSECT} # Stardent Vistra (SysVR4)
# DESTMAN=/usr/catman/1l			 # Amiga unix (SysVR4)
FTPAREA=/usr/spool/ftp

ASSRCS=	sh.c sh.dir.c sh.dol.c sh.err.c sh.exec.c sh.char.c \
	sh.exp.c sh.file.c sh.func.c sh.glob.c sh.hist.c sh.init.c \
	sh.lex.c sh.misc.c sh.parse.c sh.print.c sh.proc.c sh.sem.c \
	sh.set.c sh.time.c sh.char.h sh.dir.h sh.proc.h sh.h 
PSSRCS= sh.decls.h glob.c glob.h mi.termios.c mi.wait.h mi.varargs.h ma.setp.c \
	vms.termcap.c
SHSRCS= ${ASSRCS} ${PSSRCS}
SHOBJS=	sh.${SUF} sh.dir.${SUF} sh.dol.${SUF} sh.err.${SUF} sh.exec.${SUF} \
	sh.char.${SUF} sh.exp.${SUF} sh.func.${SUF} sh.glob.${SUF} \
	sh.hist.${SUF} sh.init.${SUF} sh.lex.${SUF} sh.misc.${SUF} \
	sh.parse.${SUF} sh.print.${SUF} sh.proc.${SUF} sh.sem.${SUF} \
	sh.set.${SUF} sh.time.${SUF} glob.${SUF}

TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c \
	tw.comp.c
TWOBJS=	tw.help.${SUF} tw.init.${SUF} tw.parse.${SUF} tw.spell.${SUF} \
	tw.comp.${SUF}

EDSRCS= ed.chared.c ed.decls.h ed.defns.c ed.h ed.init.c ed.inputl.c \
	ed.refresh.c ed.screen.c ed.xmap.c ed.term.c ed.term.h
EDOBJS=	ed.chared.${SUF} ed.refresh.${SUF} ed.screen.${SUF} ed.init.${SUF} \
	ed.inputl.${SUF} ed.defns.${SUF} ed.xmap.${SUF} ed.term.${SUF}

TCSRCS= tc.alloc.c tc.bind.c tc.const.c tc.decls.h tc.disc.c \
	tc.func.c tc.os.c tc.os.h tc.printf.c tc.prompt.c \
	tc.sched.c tc.sig.c tc.sig.h tc.str.c sh.types.h tc.vers.c tc.wait.h \
	tc.who.c tc.h
TCOBJS=	tc.alloc.${SUF} tc.bind.${SUF} tc.const.${SUF} tc.defs.${SUF} \
	tc.disc.${SUF} tc.func.${SUF} tc.os.${SUF} tc.printf.${SUF} \
	tc.prompt.${SUF} tc.sched.${SUF} tc.sig.${SUF} tc.str.${SUF} \
	tc.vers.${SUF} tc.who.${SUF} 

PVSRCS= Makefile.std Makefile.vms
AVSRCS= Fixes MAKEDIFFS MAKESHAR NewThings README FAQ \
	WishList config_f.h eight-bit.me glob.3 patchlevel.h \
	pathnames.h tcsh.man Ported src.desc Imakefile imake.config \
	README.imake complete.tcsh vmsreadme.txt termcap.vms snames.h \
	host.defs gethost.c tcsh.man2html

VHSRCS=${PVSRCS} ${AVSRCS}

CONFSRCS=config/* 

ALLSRCS=  ${SHSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${VHSRCS}
DISTSRCS= ${PSSRCS} ${TWSRCS} ${EDSRCS} ${TCSRCS} ${AVSRCS}


OBJS= ${SHOBJS} ${TWOBJS} ${EDOBJS} ${TCOBJS}


all: ${BUILD}

tcsh:$(P) ${OBJS} 
#	rm -f tcsh core
	${CC} -o tcsh ${LDFLAGS} ${CFLAGS} ${OBJS} ${LIBES} ${EXTRALIBS}
	fixstk 20k tcsh
	xstrip -k tcsh
	chmod +x tcsh
#	mv tcsh xtcsh

gethost:  gethost.c sh.err.h tc.const.h sh.h
#	rm -f gethost
	${CC} -o gethost ${LDFLAGS} ${CFLAGS} ${DFLAGS} gethost.c ${LIBES} ${EXTRALIBS}
	chmod +x $@

tc.defs.c:	gethost host.defs
	@rm -f $@
	@echo "/* Do not edit this file, make creates it */" > $@
	./gethost host.defs >> $@

#tcsh.ps: tcsh.man
#	rm -f tcsh.ps
#	-ptroff -man tcsh.man > tcsh.ps


.c.${SUF}:
	${CC} ${CF} ${CFLAGS} ${DFLAGS} ${EXTRAFLAGS} $<


#ed.defns.h: ed.defns.c
#	@rm -f $@
#	@echo '/* Do not edit this file, make creates it. */' > $@
#	@echo '#ifndef _h_ed_defns' >> $@
#	@echo '#define _h_ed_defns' >> $@
#	grep '[FV]_' ed.defns.c | grep \#define >> $@
#	@echo '#endif /* _h_ed_defns */' >> $@

sh.err.h: sh.err.c
	@rm -f $@
	@echo '/* Do not edit this file, make creates it. */' > $@
	@echo '#ifndef _h_sh_err' >> $@
	@echo '#define _h_sh_err' >> $@
	grep 'ERR_' sh.err.c | grep \#define >> $@
	@echo '#endif /* _h_sh_err */' >> $@

tc.const.h: tc.const.c sh.char.h config.h config_f.h sh.types.h sh.err.h
	@rm -f $@
	@echo '/* Do not edit this file, make creates it. */' > $@
	@echo '#ifndef _h_tc_const' >> $@
	@echo '#define _h_tc_const' >> $@
	${CC} -E $(INCLUDES) ${DFLAGS} -D_h_tc_const tc.const.c | \
	    grep 'Char STR' | \
	    sed -e 's/Char \([a-zA-Z0-9_]*\)\[\].*/extern Char \1[];/' >> $@
	@echo '#endif /* _h_tc_const */' >> $@

csh.prof: ${OBJS} sh.prof.${SUF} mcrt0.${SUF}
	rm -f csh.prof
	ld -X mcrt0.${SUF} ${OBJS} -o csh.prof ${LIBES} -lc

sh.prof.${SUF}:
	cp sh.c sh.prof.c
	${CC} ${CF} ${CFLAGS} -DPROF sh.prof.c


clean:
	${RM} -f a.out strings x.c xs.c tcsh tcsh.a _MAKE_LOG core gethost
	${RM} -f *.${SUF} \#* xtcsh

store : clean
	gtar -cv * -f tcsh.tar
	gzip tcsh.tar
	rm -r -f [A-Z]* [a-s]* [u-z]* *.c *.h 

veryclean: clean
	${RM} -f *~ \#*

tags:	/tmp
	${CTAGS} sh*.c


#
# Dependencies
#
config.h: config_f.h

TCH=tc.h tc.const.h tc.decls.h tc.os.h tc.sig.h
SHH=sh.h sh.types.h sh.char.h sh.err.h sh.dir.h sh.proc.h pathnames.h \
    sh.decls.h ${TCH}
TWH=tw.h tw.decls.h
EDH=ed.h ed.decls.h

# EDH
EDINC=sh.${SUF} sh.func.${SUF} sh.lex.${SUF} sh.print.${SUF} sh.proc.${SUF} \
      sh.set.${SUF} tc.bind.${SUF} tc.os.${SUF} tc.prompt.${SUF} \
      tc.sched.${SUF} tw.parse.${SUF}
${EDOBJS} ${EDINC} : ${EDH}

# SHH
${OBJS}: config.h ${SHH}

# TWH
TWINC=ed.chared.${SUF} ed.inputl.${SUF} sh.exec.${SUF} sh.func.${SUF} \
      sh.set.${SUF} tc.func.${SUF}
${TWOBJS} ${TWINC}: ${TWH}

# glob.h
glob.${SUF} sh.glob.${SUF}: glob.h

# ed.defns.h
EDDINC=tc.bind.${SUF} tc.func.${SUF} tc.os.${SUF}
${EDOBJS} ${EDDINC}: ed.defns.h

# tc.defs.o
tc.defs.${SUF}:	tc.defs.c sh.h
