#
# 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: /var/home/larus/SPIM/RCS/Makefile,v 3.11 1991/05/10 15:44:13 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\"
TRAP_PATH = \"/usr/local/lib/spim/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 = /usr/local/bin/flex
#MYYACC= /usr/local/bin/bison -y

# 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 =
MYYACC = yacc

# Location of X11 root directory.
#TOPDIR = /usr/misc/X11
TOPDIR = /usr/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
#


#IFLAGS = -I/usr/misc/X11
IFLAGS = -I/usr/X11/include
CFLAGS = $(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


XOBJS = textact.o xutils.o windows.o buttons.o


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


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


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


mem.o:	mem.c spim.h reg.h inst.h mem.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
	$(MYYACC) $(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


textact.o:  textact.c

xutils.o: xutils.c xspim.h

windows.o:  windows.c xspim.h

buttons.o:  buttons.c xspim.h


#
# Test spim with the torture test.
#

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


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


FILES = BLURB README COPYING Makefile *.c *.h *.y *.l trap.handler 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:
	make TRAP_PATH='\"/var/scratch/lib/trap.handler\"' xspim
	mv xspim /var/scratch/bin.MIPS/

install:
	install -c -o root -g root -m 755 spim /usr/local/bin
	install -c -o root -g root -m 755 xspim /usr/local/bin
	install -c -o root -g root -m 644 trap.handler /usr/local/lib/spim

#
# 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 = textact.c xutils.c windows.c buttons.c

saber_src:
	#load $(CFLAGS) -DDEFAULT_TRAP_HANDLER='"\"./trap.handler\""' -DSPIM_VERSION='"\"saber\""' $(SRC) $(XSRC) xspim.c $(XLDFLAGS)

