# WARNING! This file is automatically overwritten by the
# Configure shell script.  Anything you change in here will
# be lost the next time you get an update to the debugger.
#
SYSNAME = Plexus running System V.2
CPU	= 68
OS	= V
MAN	= man1
LIBS	= 
O_EXTRAS	= 
C_EXTRAS	= 
GRAMMARS	=  cgram.o
 
##########  END OF CONFIGURATION PARAMETERS ##########
 
 
# $Header: Make.Cdb,v 6.3 86/09/15 09:32:15 peter Exp $
# (C) Copyright 1984 by Third Eye Software, Inc. - All Rights Reserved

# This file contains information for MAKEing various flavors of
# Third Eye Software's CDB debugger.
# It is used by the Configure shell script to create the file "Makefile".

.SUFFIXES: .o .s .a .c .y

# DANGER - we have evidence that the 4.2 VAX optimizer generates bad code.
# Do NOT compile CDB with the -O flag on a VAX 4.2 (and possibly others!)
# CFLAGS		= -O -c

CFLAGS		= -c
DEBUGFLAGS	= -g -c
#DEBUGFLAGS	= -gx -c	# use this line for PYRAMID systems
# Un-comment the next line to debug the debuggers themselves
CFLAGS		= $(DEBUGFLAGS)

# This is where directory hierarchies start from
BASE = 	../
DEMO_BASE = 	../

# ################################# #
# Files that compose the debuggers  #
# ################################# #

OPTIONS =	cpu68.c dis68.c \
		cpuVax.c disVax.c \
		cpuCci.c disCci.c \
		cpu3b2.c dis3b2.c \
		cpuPy9x.c disPy9x.c \
		cpu386.c dis386.c \
		cpu32.c dis32.c \
		cpuPdn.c disPdn.c \
		osV.c osBsd.c osEncore.c osSiemens.c \
		xptrace.h xptrace.c xremote.c \
		fsupport.c ww.c \
		waitSingle.c waitMulti.c 

#		cpuElxsi.c disElxsi.c
#		cpuF32.c disF32.c

GENERIC =	cpu.c dis.c os.c

HFILES =	config.h cdb.h sym.h tokens.h

CFILES =	main.c access.c assert.c bp.c\
		cmd.c cmdline.c cpulib.c csupport.c dummy.c \
		cdbend.c expr.c files.c format.c help.c history.c \
		list.c lib.c math.c \
		procedure.c process.c pt.c \
		signal.c single.c sym.c tk.c valid.c var.c \
		$(C_EXTRAS)

# grammars are done first so that tk.h (y.tab.h) is correct
OFILES =	$(GRAMMARS) $(O_EXTRAS) $(SYS_O_EXTRAS) \
		cpu.o dis.o os.o\
		main.o access.o assert.o bp.o\
		cmd.o cmdline.o cpulib.o\
		csupport.o expr.o\
		files.o format.o\
		help.o history.o\
		list.o lib.o math.o\
		procedure.o process.o pt.o\
		signal.o single.o sym.o tk.o\
		valid.o var.o

# These are the documentation files (and other random stuff) for CDB
OTHERFILES =	cdb.1 cdbtrans.1 names cdbhelp.text cdb.defs\
		cgram.y wdb newvers.sh \
		READ_ME Porting loe.c ext.sed\
		Configure Make.Cdb config.awk config.db\
		DEMO_HDR READ_ME_DEMO cdbdemo.c cdbdemo.script dodemo\
		demovalid.c demo.h demotime.c demo.c

ALLFILES =	$(CFILES) $(HFILES) $(OTHERFILES) $(OPTIONS)


# ###############################
#  ------ Start of Rules ------ #
# ###############################

all:	Makefile Message debug cdbtrans cdbdemo $(WM)

# Normal way to make cdb
debug:	ext.h cdb rdb kdb

# if you modify (or add) any procedure formals, execute this rule.
ext.h:	$(GENERIC) $(CFILES)
	grep '^[ 	]*export' $(GENERIC) $(CFILES) | sed -f ext.sed > ext.h

# Single process, native
cdb:	Makefile $(OFILES) waitSingle.o libcdb.a
	make "DUMMYFLAGS=" dummy.o
	$(CC) -o $@ $(OFILES) waitSingle.o dummy.o libcdb.a $(LIBS)
	@rm dummy.o

# Single process, remote
rdb:	Makefile $(OFILES) waitSingle.o rptrace.o libcdb.a cdbremote
	make "DUMMYFLAGS=-DREMOTE" dummy.o
	$(CC) -o $@ $(OFILES) rptrace.o waitSingle.o dummy.o libcdb.a $(LIBS)
	@rm dummy.o

kdb:	Makefile $(OFILES) waitSingle.o kptrace.o libcdb.a 
	make "DUMMYFLAGS=-DREMOTE" dummy.o
	$(CC) -o $@ $(OFILES) kptrace.o waitSingle.o dummy.o libcdb.a $(LIBS)
	@rm dummy.o

# Multiple processes, native
mdb:	Makefile $(OFILES) waitMulti.o libcdb.a
	make "DUMMYFLAGS=-DMULTI" dummy.o
	$(CC) -o $@ $(OFILES) waitMulti.o dummy.o libcdb.a $(LIBS)
	@rm dummy.o

# dummy module is ALWAYS recompiled.
# It contains stub routines for missing options.
# It also contains version info.
dummy.o:
	sh newvers.sh
	$(CC) $(CFLAGS) $(DUMMYFLAGS) dummy.c

# Remote debug server
remote:	xremote.o
	$(CC) -o $@ xremote.o
cdbremote: cdbremote.o
	$(CC) -o $@ cdbremote.o

# Symbol table translator
TRANSDIR=	../trans$(OS)
cdbtrans:	SYS.h config.h sym.h
	cd $(TRANSDIR); rm -f SYS.h config.h sym.h
	ln SYS.h config.h sym.h $(TRANSDIR)
	cd $(TRANSDIR); make $(MFLAGS) all
	rm -f cdbtrans
	ln $(TRANSDIR)/cdbtrans .

# Ascii window manager
WMDIR=	../wm
wm:
	cd $(WMDIR); make $(MFLAGS) all
	rm -f wm
	ln $(WMDIR)/wm .

wminstall:	wm
	strip wm
	rm -f $(BASE)usr/bin/wm
	cp wm $(BASE)usr/bin
	chmod 555 $(BASE)usr/bin/wm

Message:
	@echo This makefile is currently setup for a
	@echo $(SYSNAME)
	@echo CPU = $(CPU), OS = $(OS).
	@echo If this is incorrect, run the Configure script.

# demotime is used for setting the magic time on demo copies of the debugger
demotime:	demotime.o
	$(CC) -o demotime demotime.o

dodemo:
	echo "cdb -Z0 -p cdbdemo.script cdbdemo" > dodemo
	chmod 555 dodemo

cdbdemo:	cdbdemo.c
	$(CC) -g -o $@ $@.c libcdb.a

cdb.demo:	cdb demovalid.o
	mv cdb cdb.save
	mv valid.o valid.save
	mv demovalid.o valid.o
	make cdb
	mv cdb cdb.demo
	mv valid.o demovalid.o
	mv valid.save valid.o
	mv cdb.save cdb

reset:	demotime cdb.demo $(TRANS)	# TES local command
	echo "rm -f $(DEMO_BASE)usr/bin/cdb*" | su2 
	cp cdb.demo $(DEMO_BASE)usr/bin/cdb
	cp cdbtrans $(DEMO_BASE)usr/bin
	demotime - $(DEMO_BASE)usr/bin/cdb*
	touch demo

DIRS:
	@echo "You *must* be ROOT to do the installation."
	-cd $(BASE);mkdir usr usr/bin usr/lib usr/lib/cdb usr/man usr/man/$(MAN)

cdbinstall:	all
	strip cdb cdbtrans
	rm -f $(BASE)usr/bin/cdb $(BASE)usr/bin/cdbtrans
	cp cdb cdbtrans $(BASE)usr/bin
	chmod 111 $(BASE)usr/bin/cdb $(BASE)usr/bin/cdbtrans
	rm -f $(BASE)usr/man/$(MAN)/cdb.1 $(BASE)usr/man/$(MAN)/cdbtrans.1
	cp cdb.1 cdbtrans.1 $(BASE)usr/man/$(MAN)
	chmod 444 $(BASE)usr/man/$(MAN)/cdb.1 $(BASE)usr/man/$(MAN)/cdbtrans.1
	rm -f $(BASE)usr/lib/cdbhelp.text $(BASE)usr/lib/libcdb.a \
			$(BASE)usr/lib/cdbend.c
	cp cdbhelp.text libcdb.a cdbend.c $(BASE)usr/lib
	chmod 444 $(BASE)usr/lib/cdbhelp.text $(BASE)usr/lib/libcdb.a \
			$(BASE)usr/lib/cdbend.c
	rm -f $(BASE)usr/lib/cdb/cdbdemo $(BASE)usr/lib/cdb/cdbdemo.c \
		    $(BASE)usr/lib/cdb/cdbdemo.script $(BASE)usr/lib/cdb/dodemo
	cp dodemo cdbdemo cdbdemo.c cdbdemo.script $(BASE)usr/lib/cdb
	chmod 555 $(BASE)usr/lib/cdb/cdbdemo $(BASE)usr/lib/cdb/dodemo
	chmod 444 $(BASE)usr/lib/cdb/cdbdemo.c $(BASE)usr/lib/cdb/cdbdemo.script

demoinstall:	cdb.demo demotime
	@echo "You *must* be ROOT to do the installation."
	mv cdb cdb.save
	mv cdb.demo cdb
	-make "BASE=$(DEMO_BASE)" install
	mv cdb cdb.demo
	mv cdb.save cdb
	demotime $(DEMO_BASE)usr/bin/cdb*

# Move things to interesting places
install:	DIRS cdbinstall $(WMINSTALL)

demo.tar: demoinstall
	cd $(DEMO_BASE); rm -f cdb.demo.tar; tar vcf cdb.demo.tar usr
	@echo ""
	@echo "Make a print of DEMO_HDR to give to customer"

.c.o:	$*.c
	$(CC) $(CFLAGS) $*.c

.y.c:
	cat tokens.h $*.y > Y.y
	yacc -d Y.y
	sed -e '/}/ s/YYSTYPE/NOTUSED/' -e '/extern/ s/YYSTYPE/SER/' \
	     -e '/prec/d' < y.tab.h > tk.h
	grep -v "^#.*line" y.tab.c |\
	  sed -e 's/yy/$*y/g' -e 's/$*ylex/yylex/g' -e 's/$*ylval/yylval/g'\
	      -e 's/YY/$*Y/g' > $*.c
	rm y.tab.h y.tab.c Y.y

cdbend.o:
	$(CC) $(DEBUGFLAGS) cdbend.c

libcdb.a:	cdbend.o
	ld -o libcdb.a -r cdbend.o

TEST:	loe fib

# "loe" is a liitle-of-everything file used for testing/playing with cdb
# "fib" is the world's worst implementation of a fibonaci number computer
loe fib:	FRC
	$(CC) -g -o $@ $@.c libcdb.a

# Link the appropriate files to the GENERIC ones
os.c:
	ln os$(OS).c os.c
cpu.c:
	ln cpu$(CPU).c cpu.c
dis.c:
	ln dis$(CPU).c dis.c

Makefile:	config.db Make.Cdb
	@echo "The configuration information and/or master makefile"
	@echo "has changed. You should run the shell script"
	@echo "'Configure' again.  This will be your only warning."
	touch Makefile

tags:	FRC
	ctags -w $(HFILES) $(CFILES) $(GENERIC)

clean:
	rm -f *.o *.cdb cdb rdb cdbremote remote mdb loe cdb.demo cdbdemo\
		cdbtrans libcdb.a mkerr tk.h cgram.c vers.h kdb
	cd ../transV; make clean

allfiles:	Makefile
	@echo "$(ALLFILES)" >allfiles

FRC:

# These two rules are used by Third Eye's BACKUP mechanism
.PRECIOUS:	SAVE
SAVE:	$(ALLFILES)
	BACKUP $?
	rm -f SAVE os.c cpu.c dis.c
	touch SAVE
	chmod 0 SAVE

# The following will create a list of first-level dependecies for cdb.
# It should be run if you add any non-system include files to cdb.
depend:	$(CFILES) $(HFILES)
	echo '# start of automatic dependencies' > .X1
	grep '^#[ 	]*include' $(CFILES) $(GENERIC) | grep '"' > .X2
	sed -e 's/#[ 	]*include//' -e 's/"//g' -e 's/\.c/.o/' -e 's/\/\*.*\*\///' <.X2 >> .X1
	cp Makefile newMake
	(echo '/^# start of auto/,$$d'; echo '$$r .X1'; echo w; echo q) | /bin/ed - newMake
	mv Makefile oldMake
	mv newMake Makefile
	rm oldMake
	@rm .X1 .X2
	@echo DONE with depend

# start of static dependencies
ww.o: cdb.h
fsupport.o: cdb.h
cpu.o: cdb.h
dis.o: cdb.h
os.o: cdb.h
cgram.c: tokens.h
fgram.c: tokens.h
cgram.o: cdb.h cgram.c
fgram.o: cdb.h fgram.c
demovalid.o: cdb.h demo.h

# Don't put anything below the following line!
# It is manipulated by the automatic dependency rule above.

# start of automatic dependencies
main.o: cdb.h
access.o: cdb.h
assert.o: cdb.h
bp.o: cdb.h
cmd.o: cdb.h
cmdline.o: cdb.h
cpulib.o: cdb.h
csupport.o: cdb.h
dummy.o: cdb.h
cdbend.o: config.h
expr.o: cdb.h
files.o: cdb.h
format.o: cdb.h
help.o: cdb.h
list.o: cdb.h
lib.o: cdb.h
math.o: cdb.h
procedure.o: cdb.h
process.o: cdb.h
pt.o: cdb.h
signal.o: cdb.h
single.o: cdb.h
sym.o: cdb.h
tk.o: cdb.h
valid.o: cdb.h
var.o: cdb.h
xptrace.o: cdb.h
xptrace.o: xptrace.h
xremote.o: xptrace.h
waitSingle.o: cdb.h
waitMulti.o: cdb.h
