#	Makefile	4.5	2022/10/2
#
# 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.00
BUILD=tcsh

LFLAGS=-I.

SYSDEFINE=pdp11
CFLAGS= -I. -O -D${SYSDEFINE}

LDFLAGS=-i -X

LIBES= -ltermcap		## BSD style things

CC=	cc
ED=	-ed
AS=	-as
RM=	-rm
CXREF=	/usr/ucb/cxref
CTAGS=	/usr/ucb/ctags
XSTR= /usr/ucb/xstr
MKSTR=	./mkprstr
DESTDIR=
BINDIR=/bin
CATSECT=0
MANSECT=1
DESTMAN=/usr/man/man${MANSECT}
DESTCAT=/usr/man/cat${MANSECT}

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
SHSRCS= ${ASSRCS} ${PSSRCS}
SHOBJS=	sh.o sh.dir.o sh.dol.o sh.err.o sh.exec.o \
	sh.char.o sh.exp.o sh.func.o sh.glob.o \
	sh.hist.o sh.init.o sh.lex.o sh.misc.o \
	sh.parse.o sh.print.o sh.proc.o sh.sem.o \
	sh.set.o sh.time.o glob.o

TWSRCS= tw.decls.h tw.h tw.help.c tw.init.c tw.parse.c tw.spell.c
TWOBJS=	tw.help.o tw.init.o tw.parse.o tw.spell.o

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
EDOBJS=	ed.chared.o ed.refresh.o ed.screen.o ed.init.o \
	ed.inputl.o ed.defns.o ed.xmap.o

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.o tc.bind.o tc.const.o tc.disc.o \
	tc.func.o tc.os.o tc.printf.o \
	tc.prompt.o tc.sched.o tc.sig.o tc.str.o \
	tc.vers.o tc.who.o 

PVSRCS= Makefile
AVSRCS= Fixes MAKEDIFFS NewThings README FAQ WishList \
	 config_f.h eight-bit.me glob.3 patchlevel.h \
	 pathnames.h tcsh.man
VHSRCS=${PVSRCS} ${AVSRCS}

CONFSRCS=config/config.*

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


# STRINGS must be last, to keep in sync with mkstr and xstr ouput 
OBJS= ${SHOBJS} ${TWOBJS} ${EDOBJS} ${TCOBJS} ${ALLOC} ${ERROBJ} ${STRINGS}

################################################################
## ERROBJS.  File for mkstr error processing
################################################################
ERROBJ=jpnerror.o
STRINGDIR=/etc
STRINGFILE=tcsh${VERSION}strgs
STRINGS=strings.o

ALLOC=tc.alloc.o alloc11.o

all: mkprstr tcsh tcsh.${CATSECT}

mkprstr:  mkprstr.c
	${CC} -O -o  mkprstr  mkprstr.c

BASE=			\
	${ALLOC}	\
	${ERROBJ}	\
	${STRINGS}	\
	ed.defns.o	\
	ed.init.o	\
	ed.inputl.o	\
	ed.xmap.o	\
	glob.o		\
	sh.char.o	\
	sh.exp.o	\
	sh.hist.o	\
	sh.init.o	\
	sh.misc.o	\
	sh.print.o	\
	sh.time.o	\
	tc.const.o	\
	tc.disc.o	\
	tc.os.o		\
	tc.printf.o	\
	tc.sched.o	\
	tc.sig.o	\
	tc.str.o	\
	tc.who.o	\
	tc.vers.o	\
	tw.help.o	\
	tw.init.o	\
	tw.spell.o

OV1=			\
	ed.chared.o	\
	ed.refresh.o	\
	sh.err.o	\
	sh.dol.o

OV2=			\
	ed.screen.o	\
	sh.dir.o	\
	sh.exec.o	\
	sh.parse.o

OV3=			\
	sh.func.o	\
	tw.parse.o

OV4=			\
	sh.lex.o	\
	sh.o

OV5=			\
	sh.proc.o	\
	sh.sem.o	\
	sh.set.o	\
	tc.prompt.o

OV6=			\
	sh.glob.o	\
	tc.bind.o	\
	tc.func.o

OV7=

tcsh: $(OBJS)
	rm -f $@
	/bin/ld -i -X -o tcsh /lib/crt0.o \
	$(BASE) \
	-Z $(OV1) -Z $(OV2) -Z $(OV3) -Z $(OV4) \
	-Z $(OV5) -Z $(OV6) -Z $(OV7) \
	-Y -ltermcap -lc
	@-size $@

.c.o: ${MKSTR}
	${MKSTR} - ${STRINGFILE} x $*.c
	${CC} -E ${CFLAGS} x$*.c | ${XSTR} -c -
	rm -f x$*.c
	${CC} ${CFLAGS} -c x.c 
	mv x.o $*.o
	rm -f x.c

strings.o: strings
	${XSTR}
	${CC} -c xs.c
	mv -f xs.o strings.o
	rm -f xs.c

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' >> $@
	egrep '[FV]_' ed.defns.c | egrep '^#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' >> $@
	-unifdef -D${SYSDEFINE} sh.err.c | egrep 'ERR_' | egrep '^#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. */' > $@
	${CC} -E -I. tc.const.c | egrep 'Char STR' | \
	    sed -e 's/Char \([a-zA-Z0-9_]*\)\(.*\)/extern Char \1[];/' | \
	    sort >> $@

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

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

lint: tc.const.h ed.defns.h
	lint ${LFLAGS} sh*.c tw*.c ed*.c tc.*.c ${LIBES}

print:
	@pr READ_ME
	@pr makefile makefile.*
	@(size -l a.out; size *.o) | pr -h SIZES
	@${CXREF} sh*.c | pr -h XREF
	@ls -l | pr 
	@pr sh*.h [a-rt-z]*.h sh*.c alloc.c

# tcsh  tcsh.${CATSECT}
install: all
	-mv -f ${DESTDIR}${BINDIR}/tcsh  ${DESTDIR}${BINDIR}/tcsh.old
	install -s -m 555 -o bin -g bin tcsh ${DESTDIR}${BINDIR}/tcsh
	install -c -m 444 -o bin -g bin  ${STRINGFILE} ${DESTDIR}${STRINGDIR}
	install -c -m 444 -o bin -g bin tcsh.${CATSECT} ${DESTDIR}${DESTCAT}

tcsh.${CATSECT}:  tcsh.man
	/usr/man/manroff tcsh.man > tcsh.${CATSECT}

clean:
	${RM} -f a.out strings x.c xs.c tcsh _MAKE_LOG core ./mkprstr
	${RM} -f *.o sh.prof.c ed.defns.h tc.const.h sh.err.h
	${RM} -f ${STRINGFILE} tcsh.${CATSECT}

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

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


#
# Dependencies
#
config.h: config_f.h

tc.h: tc.const.h tc.decls.h tc.os.h tc.sig.h
sh.h: sh.types.h sh.char.h sh.err.h sh.dir.h sh.proc.h pathnames.h \
      sh.decls.h tc.h
tw.h: tw.decls.h
ed.h: ed.decls.h

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

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

# tw.h:
TWINC=ed.chared.o ed.inputl.o sh.exec.o sh.func.o \
      sh.set.o tc.func.o
${TWOBJS} ${TWINC}: tw.h

# glob.h
glob.o sh.glob.o: glob.h

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