#
# SPIM S20 MIPS Simulator.
# Makefile for SPIM.
# Copyright (C) 1990 by James Larus (larus@cs.wisc.edu).
#
# SPIM is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 1, or (at your option) any
# later version.
#
# SPIM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU CC; see the file COPYING.  If not, write to James R.
# Larus, Computer Sciences Department, University of Wisconsin--Madison,
# 1210 West Dayton Street, Madison, WI 53706, USA or to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# $Header: /home/primost/larus/RCS/Makefile,v 3.16 1992/01/13 18:40:46 larus Exp larus $
#
# 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:
#
# Note: SPIM does not work when compiled by a compiler that does
# not distinguish floats from doubles (e.g., pcc and pcc-compatible compilers
# on the VAX).
#
# Full path for the trap handler file:
TRAP_PATH = \"`pwd`/trap.handler\"

# If host computer is big-endian (e.g. 68000's (i.e. Sun 3, HP Bobcats), RT/PC,
# SPARC, some MIPS boxes), define this:
# ENDIAN=-DBIGENDIAN

# If host computer is little-endian (e.g. DECstation, Sequent Symmetry),
# define this:
ENDIAN=-DLITTLEENDIAN

# Use tt.be for big-endian systems
# Use tt.le for little-endian systems:
TEST_FILE = tt.le

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

# SPIM needs the -I flag to flex 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 =


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

# Size of the segments when spim starts up (data segment must be >= 64K).
MEM_SIZES = -DTEXT_SIZE=65536 -DDATA_SIZE=131072 -DK_TEXT_SIZE=65536


# Define these flags if your operating system libraries are missing these:
#
# -DNEED_VSPRINTF   If your system doesn't have vsprintf
# -DNEED_STRTOL     If your system doesn't have strtol
#
# Note: Ultrix and SunOS do not need any flags.
#       Sequent requires both flags.
#	PC/RTs requires -DNEED_VSPRINTF
#	BSD4.3 requires -DNEED_STRTOL
SYS_FLAGS =


#
# End of parameters
#

CC=cc
IFLAGS = -I/usr/misc/X11
CFLAGS = -g $(IFLAGS) $(ENDIAN) $(MEM_SIZES) $(SYS_FLAGS)
YFLAGS = -d
YCFLAGS =
LDFLAGS =
XLDFLAGS = -L$(TOPDIR)/lib -lXaw -lXmu -lXt -lXext -lX11


# 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 \
       read-aout.o except.o cache.o

XOBJS = windows.o buttons.o

#all: spim xspim

spim:	$(OBJS) spim.o
	$(CC) -g $(OBJS) spim.o $(LDFLAGS) -o spim -lm
xspim:	$(OBJS) $(XOBJS) xspim.o
	$(CC) -g $(OBJS) $(XOBJS) xspim.o $(LDFLAGS) $(XLDFLAGS) -o xspim -lm
spim.o:	spim.c spim.h reg.h mem.h y.tab.h
xspim.o: xspim.c xspim.h spim.c spim.h reg.h mem.h y.tab.h
spim-utils.o: spim-utils.c spim.h inst.h mem.h reg.h y.tab.h VERSION
	$(CC) $(IFLAGS) $(CFLAGS) -DDEFAULT_TRAP_HANDLER=$(TRAP_PATH) -DSPIM_VERSION="\"`cat VERSION`\"" -c spim-utils.c
run.o:	run.c spim.h reg.h y.tab.h inst.h mem.h sym_tbl.h spim-syscall.h mips-syscall.h
except.o:	except.c spim.h reg.h inst.h mem.h sym_tbl.h spim-syscall.h mips-syscall.h
mem.o:	mem.c spim.h reg.h inst.h mem.h
cache.o:	cache.c reg.h inst.h mem.h cache.h
inst.o: inst.c spim.h reg.h inst.h mem.h sym_tbl.h y.tab.h op.h
data.o: data.c spim.h mem.h reg.h sym_tbl.h
sym_tbl.o: sym_tbl.c spim.h inst.h mem.h sym_tbl.h
read_aout.o: read_aout.c inst.h mem.h
y.tab.h: y.tab.c
y.tab.c: parser.y spim.h inst.h mem.h reg.h sym_tbl.h
	yacc $(YFLAGS) parser.y
y.tab.o: y.tab.c
	$(CC) $(IFLAGS) $(CFLAGS) $(YCFLAGS) -c y.tab.c
lex.yy.c: scanner.l y.tab.h op.h
	$(MYLEX) $(LEXFLAGS) scanner.l
lex.yy.o: lex.yy.c
	$(CC) $(IFLAGS) $(LEXCFLAGS) -c lex.yy.c
windows.o:  windows.c xspim.h
buttons.o:  buttons.c xspim.h

#
# Test spim with the torture test.
#
test:	spim
	/bin/rm -f Tests/tt.out
	csh -c "./spim -bare -notrap -file Tests/tt.bare.s >& Tests/tt.out"
	@echo The next command should not produce any output:
	diff Tests/tt.out Tests/tt.bare.OK
	/bin/rm -f Tests/tt.out

	@echo
	csh -c "./spim -file Tests/$(TEST_FILE).s >& Tests/tt.out"
	@echo The next command should not produce any output:
	diff Tests/tt.out Tests/$(TEST_FILE).OK
	/bin/rm -f Tests/tt.out
# 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:
	csh -c "./spim -bare -notrap -file Tests/tt.alu.bare.s >& Tests/tt.out"
	@echo The next command should not produce any output:
	diff Tests/tt.out Tests/tt.alu.bare.OK
	/bin/rm -f Tests/tt.out

	@echo
	csh -c "./spim -bare -notrap -file Tests/tt.fpu.bare.s >& Tests/tt.out"
	@echo The next command should not produce any output:
	diff Tests/tt.out Tests/tt.fpu.bare.OK
	/bin/rm -f Tests/tt.out
TAGS:	*.c *.h *.l *.y
	etags *.l *.y *.c *.h
clean:
	rm -f spim xspim *.o y.output core a.out TAGS spim.tar.* spim.aux spim.log spim.dvi spim.shar* *~ y.tab.h y.tab.c lex.yy.c spim.tar* spim.ps

FILES = BLURB README COPYING Makefile *.c *.h *.y *.l trap.handler Tests/tt.* \
	ChangeLog VERSION spim.tex mips.id xinterface.id mem.id stack-frame.id
spim.ps: spim.tex
	latex spim.tex
	latex spim.tex
	dvips spim.dvi
	rm -f spim.aux spim.log spim.dvi
tar:	spim.ps
	tar cvf spim.tar $(FILES) spim.ps
tar.Z:	tar
	compress spim.tar
shar:
	mv -f y.tab.c y.tab.c.xx
	mv -f lex.yy.c lex.yy.c.xx
	rm -f spim.shar spim.shar0?
	makekit -n spim.shar $(FILES)
	mv -f y.tab.c.xx y.tab.c
	mv -f lex.yy.c.xx lex.yy.c
local:
	rm spim-utils.o
	make TRAP_PATH='\"/var/scratch/lib/trap.handler\"' spim xspim
	mv spim xspim /var/scratch/bin.MIPS/
	rm spim-utils.o
#
# Saber C rules
#
saber_obj: $(OBJS) $(XOBJS) xspim.o
	#load  $(OBJS) $(XOBJS) xspim.o $(XLDFLAGS)
SRC = spim-utils.c run.c mem.c inst.c data.c sym_tbl.c y.tab.o lex.yy.o \
       read-aout.c
XSRC = windows.c buttons.c
saber_src:
	#load $(CFLAGS) -DDEFAULT_TRAP_HANDLER='"\"./trap.handler\""' -DSPIM_VERSION='"\"saber\""' $(SRC) $(XSRC) xspim.c $(XLDFLAGS)

