#
# Copyright (c) 1983 Regents of the University of California.
# All rights reserved. The Berkeley Software License Agreement
# specifies the terms and conditions for redistribution.
#
#$Header:Makefile 12.1$
#$ACIS:Makefile 12.1$
#$Source: /ibm/acis/usr/src/ucb/dbx/RCS/Makefile,v $
#
# make file for debugger "dbx"
#
# The file "defs.h" is included by all.
#

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

AOUT	= tdbx
DEST	= ${DESTDIR}/usr/ucb/dbx

CC	= cc
AS	= as
#
# if you want gripes
# CFLAGS = '-DMAINTAINER="linton@shasta"'
#
CFLAGS = 


LD = cc
LDFLAGS	=
LIBRARIES = -lm # -lPW for IRIS (System V)

# Define symbolic links to be made to machine dependent files.
# % make links	    # to create these.
#	coredump.c -> machine/coredump.c
#	decode.c -> machine/decode.c
#	frame.c -> machine/frame.c
#	machine -> ibmrt
#	machine.h -> decode.h
#	ops.c -> machine/ops.c
#	procinfo.c -> machine/procinfo.c
LINKS = coredump.c decode.c frame.c ops.c procinfo.c

# Define default machine
MACHINE = ibmrt

OBJ = \
    y.tab.o \
    asm.o \
    events.o \
    c.o \
    cerror.o \
    check.o \
    coredump.o \
    debug.o \
    decode.o \
    eval.o \
    examine.o \
    execute.o \
    fortran.o \
    frame.o \
    keywords.o \
    languages.o \
    library.o \
    lists.o \
    main.o \
    mappings.o \
    modula-2.o \
    names.o \
    object.o \
    operators.o \
    ops.o \
    pascal.o \
    printsym.o \
    process.o \
    procinfo.o \
    runtime.o \
    scanner.o \
    source.o \
    stabstring.o \
    symbols.o \
    tree.o \
    version.o

HDR = \
    asm.h \
    events.h \
    c.h \
    check.h \
    coredump.h \
    debug.h \
    decode.h \
    eval.h \
    examine.h \
    execute.h \
    fortran.h \
    frame.h \
    keywords.h \
    languages.h \
    lists.h \
    main.h \
    mappings.h \
    modula-2.h \
    names.h \
    object.h \
    operators.h \
    ops.h \
    pascal.h \
    printsym.h \
    process.h \
    procinfo.h \
    runtime.h \
    scanner.h \
    source.h \
    stabstring.h \
    symbols.h \
    tree.h \
    version.h

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

.s.o:
	rm -f tmp
	/lib/cpp $*.s | grep -v "^#" > tmp
	${AS} -o $*.o tmp
	rm -f tmp

.c.h:
	@rm -f $*.h
	./makedefs -f $*.c $*.h
	@chmod 444 $*.h

${AOUT} all: makedefs mkdate ${HDR} ${OBJ}
	@rm -f date.c
	@./mkdate > date.c
	@echo "linking"
	@${CC} ${CFLAGS} -c date.c
	@${LD} ${LDFLAGS} date.o ${OBJ} ${LIBRARIES} -o ${AOUT}

# Someone has to setup the initial machine symbolic link
links:
	-@if [ ! -r machine ]; then echo 'Warning - linking machine to ${MACHINE}' >&2; \
		ln -s ${MACHINE} machine;fi
	-for i in ${LINKS};do if [ ! -r $$i ]; then ln -s $i machine/$$i ; fi ; done
	-if [ ! -r machine.h ]; then ln -s decode.h machine.h; fi

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

y.tab.c: commands.y
	yacc -d commands.y

cerror.o: machine/cerror.s

makedefs: makedefs.c library.o cerror.o
	${CC} makedefs.c library.o cerror.o -o makedefs

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

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 date.o core mon.out prof.out make.out

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

testinstall: ${AOUT} test install

test:
	@cd tests; make

install: ${AOUT}
	install -s -c ${AOUT} ${DEST}

#
# 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
