# $Copyright:	$
# Copyright (c) 1984, 1985, 1986, 1987 Sequent Computer Systems, Inc.
# All rights reserved
#  
# This software is furnished under a license and may be used
# only in accordance with the terms of that license and with the
# inclusion of the above copyright notice.   This software may not
# be provided or otherwise made available to, or used by, any
# other person.  No title to or ownership of the software is
# hereby transferred.
#

# $Header: Makefile 1.9 87/07/14 $

#
# Make file for debugger "dbx"
#
# The file "defs.h" is included by all.
#
VPATH	=../common
C	=../common

.SUFFIXES:
.SUFFIXES: .h .c .s .o

# production/v2.0
AOUT		= zdbx
CFLAGS	= -O -DDBX -I. -I$C ${INCLUDE} ${CEFLAGS}
LDFLAGS	= -h
LIBRARIES	= -lseq -lm
SPECIAL	=

OBJ = main.o y.tab.o asm.o events.o c.o cerror.o check.o coredump.o \
    debug.o dbgparse.o dbgsym.o eval.o fortran.o keywords.o languages.o \
    library.o lists.o machine.o mappings.o multi-p.o names.o object.o \
    operators.o pascal.o pio.o printsym.o queue.o runtime.o scanner.o \
    source.o stabstring.o symbols.o tree.o tty.o fpu387.o

HDR = asm.h events.h c.h check.h coredump.h debug.h eval.h fortran.h \
    dbgparse.h dbgsym.h keywords.h languages.h library.h lists.h \
    machine.h multi-p.h main.h mappings.h \
    names.h object.h operators.h pascal.h pio.h printsym.h runtime.h \
    scanner.h source.h stabstring.h symbols.h tree.h tty.h

SRC = $C/defs.h $C/commands.y $C/asm.c $C/events.c $C/c.c $C/cerror.c \
    $C/check.c $C/coredump.c $C/dbgparse.c $C/dbgsym.c $C/debug.c \
    $C/eval.c $C/fortran.c $C/keywords.c $C/languages.c $C/library.c \
    $C/lists.c machine.c $C/main.c $C/mappings.c $C/multi-p.c \
    $C/names.c $C/object.c $C/operators.c $C/pascal.c $C/pio.c \
    $C/printsym.c $C/queue.c runtime.c $C/scanner.c $C/source.c \
    $C/stabstring.c $C/symbols.c $C/tree.c $C/tty.c fpu387.s

TSRC = $C/defs.h $C/asm.c $C/events.c $C/c.c $C/cerror.c \
    $C/check.c $C/coredump.c $C/dbgparse.c $C/dbgsym.c $C/debug.c \
    $C/eval.c $C/fortran.c $C/keywords.c $C/languages.c $C/library.c \
    $C/lists.c machine.c $C/main.c $C/mappings.c $C/multi-p.c \
    $C/names.c $C/object.c $C/operators.c $C/pascal.c $C/pio.c \
    $C/printsym.c $C/queue.c runtime.c $C/scanner.c $C/source.c \
    $C/stabstring.c $C/symbols.c $C/tree.c $C/tty.c fpu387.s

.c.o:
	${CC} ${CFLAGS} -c $*.c

.s.o:
	${CC}  -c $*.s

.c.h:
	./makedefs -f $*.c $*.h

${AOUT}: makedefs mkdate hdrs objs
	rm -f date.c
	./mkdate > date.c
	${CC} ${CFLAGS} -c date.c
	${CC} ${LDFLAGS} date.o ${OBJ} ${SPECIAL} ${LIBRARIES} -o ${AOUT}

hdrs:&	${HDR}
objs:&	${OBJ} ${SPECIAL}

malloc.o:	$C/malloc.c
	${CC} -g -c -Ddebug -DRCHECK -DMSTATS $C/malloc.c

profile: ${HDR} ${OBJ}
	rm -f date.c
	./mkdate > date.c
	${CC} ${LDFLAGS} -p date.c ${OBJ} ${LIBRARIES} -o ${AOUT}

y.tab.c: $C/commands.y
	@echo "	expect 2 shift/reduce conflicts"
	$(YACC) -d $C/commands.y

makedefs: $C/makedefs.c $C/library.c cerror-native.o
	cc $C/makedefs.c $C/library.c cerror-native.o -o makedefs
	rm -f library.o cerror.o

cerror-native.o: $C/cerror.c
	cc -O -SO $C/cerror.c | sed -e "s/_cerror/cerror/g" >cerror-native.s
	cc -c cerror-native.s && rm -f cerror-native.s

cerror.o: $C/cerror.c
	$(CC) $(CFLAGS) -SO $C/cerror.c | sed -e "s/_cerror/cerror/g" >cerror.s
	$(CC) $(CFLAGS) -c cerror.s && rm -f cerror.s

mkdate: $C/mkdate.c
	cc $C/mkdate.c -o mkdate

tags:
	ctags -tm ${TSRC}

lint:	y.tab.c
	lint -I. -I$C ${INCLUDE} $C/defs.h y.tab.c \
	$C/asm.c $C/events.c $C/c.c $C/cerror.c $C/check.c $C/coredump.c \
	$C/dbgparse.c $C/dbgsym.c \
	$C/debug.c $C/eval.c $C/fortran.c $C/keywords.c $C/languages.c \
	$C/library.c $C/lists.c machine.c $C/main.c $C/mappings.c \
	$C/multi-p.c $C/names.c $C/object.c $C/operators.c $C/pascal.c \
	$C/pio.c $C/printsym.c runtime.c $C/scanner.c $C/source.c \
	$C/stabstring.c $C/symbols.c $C/tree.c

print:
	@echo "	don't print it, it's too long"

#
# Don't worry about the removal of header files, they're created from
# the source files.
#

clean:
	rm -f ${HDR} ${OBJ} y.tab.c y.tab.h ${AOUT} mkdate mkdate.o \
	    makedefs makedefs.o date.c core mon.out prof.out make.out \
	    cerror.s cerror.o cerror-native.o cerror-native.s \
	    date.o yacc.*

cleandefs:
	rm -f ${HDR} y.tab.h

testinstall: ${AOUT} test install

test:
	@chdir tests; make

install:
	install -s $(AOUT) $(DESTDIR)/usr/ucb/pdbx
	rm -f $(DESTDIR)/usr/ucb/dbx
	ln $(DESTDIR)/usr/ucb/pdbx $(DESTDIR)/usr/ucb/dbx
	cd ../demo && install -c -m 644 * $(DESTDIR)/usr/sequent/pdbx.demo

#
# Create a tar file called "tape" containing relevant files.
#

TAPE = tape

tape:
	@tar cf ${TAPE} \
	    Makefile History version READ_ME ${SRC} \
	    makedefs.c mkdate.c tests pchanges ptests

#
# Header dependencies are purposely incomplete since header files
# are "written" every time the accompanying source file changes even if
# the resulting contents of the header don't change.  The alternative is
# to force a "makedefs" to be invoked for every header file each time dbx
# is made.
#
# Also, there should be a dependency of scanner.o and keywords.o on y.tab.h
# but misfortunately silly make does a "makedefs y.tab.c y.tab.h" which
# destroys y.tab.h.
#

symbols.o tree.o check.o eval.o events.o: operators.h

# ----------------------------------------------------------------------
# dependency rule:
#
depend: ${SRC}
	/bin/grep '^#[ 	]*include' ${SRC} \
		| sed '/<.*>/d' \
		| sed '/y\.tab/d' \
		| sed 's/:[^"]*"\([^"]*\)".*/: \1/' \
		| sed 's/\.c/.o/' >>makedep
	echo '/^# DO NOT DELETE THIS LINE/+2,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	cp Makefile Makefile.bak
	ed - Makefile < eddep
	rm eddep makedep
	echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile
	echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile
	echo '# see make depend above' >> Makefile

# DO NOT DELETE THIS LINE -- make depend uses it


