#
# SPIM S20 MIPS Simulator.
# Makefile for SPIM.
#
# Copyright (C) 1990-2004 by James Larus (larus@cs.wisc.edu).
# ALL RIGHTS RESERVED.
#
# SPIM is distributed under the following conditions:
#
#   You may make copies of SPIM for your own use and modify those copies.
#
#   All copies of SPIM must retain my name and copyright notice.
#
#   You may not sell SPIM or distributed SPIM in conjunction with a commerical
#   product or service without the expressed written consent of James Larus.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE.
#
# $Header: $


#
# To make spim, type:
#
#   make spim
#
# To make xpsim, type:
#
#   make xspim
#

#
# To verify spim works, type:
#
#   make test
#


#
# The following parameters must be set for the target machine:
#
#


# Full path for directory containing X11 include files:
X_INCLUDE_DIR=/usr/X11/include


# Location of X11 root directory.
TOPDIR = /usr/X11


# Full path for directory that will hold the exception handler file:
EXCEPTION_DIR = .

# Full path for the directory that will hold the executable files:
BIN_DIR = /usr/unsup/bin

# Full path for the directory that will hold the man files:
MAN_DIR = /usr/unsup/man


# Full path for the exception handler file:
EXCEPTION_PATH = \"$(EXCEPTION_DIR)/exceptions.s\"

# If you have flex, use it instead of lex.  If you use flex, define this
# variable and set LEXFLAGS.
MYLEX = flex

# SPIM needs flex's -I flag since the scanner is used interactively.
# You can set the -8 flag so that funny characters do not hang the scanner.
LEXFLAGS = -I -8


# If you use lex, set the variables this way:
#MYLEX = lex
#LEXFLAGS =


# Size of the segments when spim starts up (data segment must be >= 64K).
# (These sizes are fine for most users since SPIM dynamically expands
# the memory as necessary.)
MEM_SIZES = -DTEXT_SIZE=65536 -DDATA_SIZE=131072 -DK_TEXT_SIZE=65536


#
# End of parameters
#


DEFINES = $(ENDIAN) $(MEM_SIZES) -DDEFAULT_EXCEPTION_HANDLER=$(EXCEPTION_PATH) -DSPIM_VERSION="\"`cat VERSION`\""

CC = cc
CFLAGS = $(DEFINES)
IFLAGS = -I$(X_INCLUDE_DIR)
YFLAGS = -d
YCFLAGS =
LDFLAGS = -lm
XLDFLAGS = -L$(TOPDIR)/lib -lXaw -lXmu -lXt -lXext -lX11
CSH = csh

# lex.yy.c is usually compiled with -O to speed it up.

LEXCFLAGS = -O



OBJS = spim-utils.o run.o mem.o inst.o data.o sym-tbl.o y.tab.o lex.yy.o \
       syscall.o display-utils.o string-stream.o


XOBJS = windows.o buttons.o


ENDIAN=`cat configuration`


spim:   force
	@touch .spim-made
	make -f Makefile.std spim2

spim2:	$(OBJS) spim.o
	$(CC) -g $(OBJS) spim.o $(LDFLAGS) -o spim -lm


xspim:  force
	@touch .spim-made
	make -f Makefile.std xspim2

xspim2:	$(OBJS) $(XOBJS) xspim.o
	$(CC) -g $(OBJS) $(XOBJS) xspim.o $(LDFLAGS) $(XLDFLAGS) -o xspim -lm

force:	configuration

configuration:
	Configure

#

test:	spim
	@echo
	@echo "Testing tt.bare.s:"
	$(CSH) -c "./spim -delayed_branches -delayed_loads -noexception -file Tests/tt.bare.s >& test.out"
	@tail -2 test.out
	@echo

	@if [ ! -f $(EXCEPTION_DIR)/exceptions.s ]; then echo "Exception Handler not installed; do make install"; exit 1; else true; fi
	@if diff exceptions.s $(EXCEPTION_DIR)/exceptions.s > /dev/null ; then true ; else echo "Old exception_handler installed.  Type: make install" ; exit 1; fi

	@echo
	@echo "Testing tt.core.s:"
	$(CSH) -c "./spim -file Tests/tt.core.s < Tests/tt.in >& test.out"
	@tail -2 test.out
	@echo

	@echo
	@echo "Testing tt.endian.s:"
	$(CSH) -c "./spim -file Tests/tt.endian.s >& test.out"
	@tail -2 test.out
	@echo
	@echo

# This test currently only works for little-endian machines.  The file
# tt.alu.bare.s needs to be converted in places for big-endian machines.

test_bare: spim
	@echo
	@echo "Testing tt.alu.bare.s:"
	$(CSH) -c "./spim -bare -noexception -file Tests/tt.alu.bare.s >& test.out"
	@tail -2 test.out
	@echo

	@echo
	@echo "Testing tt.fpt.bare.s:"
	$(CSH) -c "./spim -bare -noexception -file Tests/tt.fpu.bare.s >& test.out"
	@tail -2 test.out
	@echo
	@echo

#

TAGS:	*.c *.h *.l *.y
	etags *.l *.y *.c *.h


clean:
	rm -f spim xspim *.o y.output core a.out TAGS \
	  .spim-made  \
	  spim.tar.* spim.aux spim.log spim.dvi spim.shar*

install: spim xspim
	install -c -s  spim $(BIN_DIR)
	install -c -s  xspim $(BIN_DIR)
	install -c -m 0444 exceptions.s $(EXCEPTION_DIR)
	install -c -m 0444 spim.man $(MAN_DIR)
	install -c -m 0444 xspim.man $(MAN_DIR)

very-clean: clean
	rm -f y.tab.h y.tab.c lex.yy.c spim.tar* Documentation/spim.ps


SRC = spim-utils.c run.c mem.c inst.c data.c sym-tbl.c y.tab.o lex.yy.o \
      syscall.c

XSRC = windows.c buttons.c


#
# Dependences not handled well by makedepend:
#


y.tab.h: y.tab.c

y.tab.c: parser.y
	yacc $(YFLAGS) parser.y

y.tab.o: y.tab.c
	$(CC) $(IFLAGS) $(CFLAGS) $(YCFLAGS) -c y.tab.c


lex.yy.c: scanner.l
	$(MYLEX) $(LEXFLAGS) scanner.l

lex.yy.o: lex.yy.c
	$(CC) $(IFLAGS) $(LEXCFLAGS) -c lex.yy.c


#
# DO NOT DELETE THIS LINE -- make depend depends on it.

buttons.o: spim.h
buttons.o: spim-utils.h
buttons.o: xspim.h
buttons.o: inst.h
buttons.o: mem.h
buttons.o: reg.h
buttons.o: scanner.h
buttons.o: sym-tbl.h
buttons.o: buttons.h
data.o: spim.h
data.o: spim-utils.h
data.o: inst.h
data.o: mem.h
data.o: reg.h
data.o: sym-tbl.h
data.o: parser.h
data.o: run.h
data.o: data.h
inst.o: spim.h
inst.o: spim-utils.h
inst.o: inst.h
inst.o: mem.h
inst.o: reg.h
inst.o: sym-tbl.h
inst.o: y.tab.h
inst.o: parser.h
inst.o: scanner.h
inst.o: data.h
inst.o: op.h
lex.yy.o: spim.h
lex.yy.o: spim-utils.h
lex.yy.o: inst.h
lex.yy.o: sym-tbl.h
lex.yy.o: y.tab.h
lex.yy.o: parser.h
lex.yy.o: scanner.h
lex.yy.o: op.h
mem.o: spim.h
mem.o: spim-utils.h
mem.o: inst.h
mem.o: mem.h
mem.o: reg.h
syscall.o: spim.h
syscall.o: inst.h
syscall.o: mem.h
syscall.o: reg.h
syscall.o: sym-tbl.h
syscall.o: spim-syscall.h
syscall.o: syscall.h
run.o: spim.h
run.o: spim-utils.h
run.o: inst.h
run.o: mem.h
run.o: reg.h
run.o: sym-tbl.h
run.o: y.tab.h
run.o: syscall.h
run.o: run.h
spim-utils.o: spim.h
spim-utils.o: spim-utils.h
spim-utils.o: inst.h
spim-utils.o: data.h
spim-utils.o: mem.h
spim-utils.o: reg.h
spim-utils.o: scanner.h
spim-utils.o: parser.h
spim-utils.o: y.tab.h
spim-utils.o: run.h
spim-utils.o: sym-tbl.h
spim.o: spim.h
spim.o: spim-utils.h
spim.o: inst.h
spim.o: mem.h
spim.o: reg.h
spim.o: parser.h
spim.o: sym-tbl.h
spim.o: scanner.h
spim.o: y.tab.h
sym-tbl.o: spim.h
sym-tbl.o: spim-utils.h
sym-tbl.o: inst.h
sym-tbl.o: mem.h
sym-tbl.o: data.h
sym-tbl.o: parser.h
sym-tbl.o: sym-tbl.h
windows.o: spim.h
windows.o: spim-utils.h
windows.o: buttons.h
windows.o: xspim.h
windows.o: windows.h
xspim.o: spim.h
xspim.o: spim-utils.h
xspim.o: inst.h
xspim.o: mem.h
xspim.o: reg.h
xspim.o: y.tab.h
xspim.o: buttons.h
xspim.o: windows.h
xspim.o: xspim.h
y.tab.o: spim.h
y.tab.o: spim-utils.h
y.tab.o: inst.h
y.tab.o: mem.h
y.tab.o: reg.h
y.tab.o: sym-tbl.h
y.tab.o: data.h
y.tab.o: scanner.h
y.tab.o: parser.h
parser.o: spim.h
parser.o: spim-utils.h
parser.o: inst.h
parser.o: mem.h
parser.o: reg.h
parser.o: sym-tbl.h
parser.o: data.h
parser.o: scanner.h
parser.o: parser.h
scanner.o: spim.h
scanner.o: spim-utils.h
scanner.o: inst.h
scanner.o: sym-tbl.h
scanner.o: y.tab.h
scanner.o: parser.h
scanner.o: scanner.h
scanner.o: op.h
