#
# SPIM S20 MIPS Simulator.
# Makefile for SPIM.
# Copyright (C) 1990-1992 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.
#
# NOTES ON AMIGA VERSION:
#   Amiga modifications by Kjetil Jacobsen / Ymir's Thoughts
#   The distributed binaries were compiled with gcc2.3.3, using gmake and flex.
#   You need ixemul v39.47 (or later) to run SPIM.
#   This Amiga version is based on spim/xspim version 5.4
#
# To make spim, type:
#
#   make spim
#
# To make xpsim, type:
#
#   make xspim
#

#
# To make cl-spim (cycle level SPIM simulator), type:
#
#   make cl-spim
#
# To make cl-xpsim, type:
#
#   make cl-xspim
#

# This is amiga specific, so it's got an unique vesion number.
ENDIAN = BIGENDIAN
AMIGAVER = 1

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

# Location of X11 root directory.
TOPDIR = gcc:


# Full path for directory that will hold the trap handler file:
TRAP_DIR = spim:lib

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

# Full path for the directory that will hold the man files:
MAN_DIR = doc:

# Full path for the trap handler file:
TRAP_PATH = \"$(TRAP_DIR)/trap.handler\"

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


CC = gcc
OPTFLAGS = 
AMIFLAGS = -Damiga -D_ANSI_SOURCE
IFLAGS = -Igcc:include
CL_FLAG =
CFLAGS = -c $(OPTFLAGS) $(IFLAGS) -D$(ENDIAN) $(AMIFLAGS) $(MEM_SIZES) -I$(X_INCLUDE_DIR) $(EXTRA_C_FLAGS) $(CL_FLAG)
YFLAGS = -d
YCFLAGS =
LDFLAGS = -lnet -lamy -lm
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 mips-syscall.o


XOBJS = windows.o buttons.o


CLOBJS = cl-cache.o cl-except.o cl-tlb.o cl-cycle.o


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

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


cl-spim: $(OBJS) $(CLOBJS) spim.o
	$(CC) -o cl-spim $(OBJS) $(CLOBJS) spim.o $(LDFLAGS)

cl-xspim: $(OBJS) $(CLOBJS) $(XOBJS) xspim.o
	$(CC) -o cl-xspim $(OBJS) $(CLOBJS) $(XOBJS) xspim.o $(XLDFLAGS) $(LDFLAGS) 


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


clean:
	delete spim xspim cl-spim cl-xspim *.o y.output *.bak core a.out \
	  .spim-made .cl-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 trap.handler $(TRAP_DIR)
	install -c -m 0444 spim.man $(MAN_DIR)
	install -c -m 0444 xspim.man $(MAN_DIR)

very-clean: clean
	delete 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 \
       read-aout.c mips-syscall.c

XSRC = windows.c buttons.c


#
# Dependences not handled well by makedepend:
#

spim-utils.o: spim-utils.c spim.h inst.h mem.h reg.h y.tab.h 
	$(CC) $(CFLAGS) -DDEFAULT_TRAP_HANDLER=$(TRAP_PATH) -DSPIM_VERSION=$(AMIGAVER) -c spim-utils.c


y.tab.h: y.tab.c

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

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


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

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

