# environment dependent variables; change these to their appropriate
# directory paths for the X11 and tcl/tk library and header paths
# Solaris paths
# TCL_LIB = /usr/local/lib
# TCL_INC = /usr/local/include
# X_LIB = /opt/x11r5/lib
# X_INC = /usr/local/X11R5/include
# Linux paths
TCL_LIB = /usr/lib
TCL_INC = /usr/include
X_LIB = /usr/X11R6/lib
X_INC = /usr/X11R6/include

# change this to point to the existing directory where you would like
# the package installed; no change is necessary for testing
DEST = .

# Uncomment this if you are using Tk4.0.
# CPPFLAGS = -DTK40

# Solaris may need the -lsocket and -lnsl flags added.  Tk4.1 and newer
# also require the -ldl flag.
# LLIBS = ${TCL_LIB}/libtcl7.6.a ${TCL_LIB}/libtk4.2.a -L${X_LIB} -lX11 -lnsl -lsocket -lm -ldl
LLIBS = ${TCL_LIB}/libtcl.so ${TCL_LIB}/libtk.so -L${X_LIB} -lX11 -lm -ldl
# LLIBS = ${TCL_LIB}/libtcl.a ${TCL_LIB}/libtk.a -L${X_LIB} -lX11 -lm


###########################################################################
# user should not change anything below this line
###########################################################################

CC = gcc
CFLAGS = ${CPPFLAGS} -O -I. -I${TCL_INC} -I${X_INC}
TARGET = dlxview

OBJS = asm.o cop0.o getput.o io.o issue.o main.o script.o sim.o stop.o sym.o trap.o

# source files
SRC = ${OBJS:.o=.c} 

# header files
# HDR = asm.h cop0.h dlx.h gp.h io.h purdue.h script.h sym.h traps.h 
HDR = cop0.h dlx.h io.h purdue.h script.h sym.h 

# TCL script files
SCRIPT = disc.tcl mkDisc.tcl mkBasicPipe.tcl mkConfigure.tcl \
	 mkEdit.tcl mkGoStep.tcl mkLoad.tcl mkReset.tcl \
	 mkScoreboard.tcl mkStop.tcl mkTomasulo.tcl mkTrace.tcl

# test files
TEST = f.d f.s f305.i f305.s f347.d f347.i f347.s bas sco tom

PACKAGE = Makefile Makefile.solaris Makefile.linux README.1st \
          help.html images $(HDR) $(SRC) $(TEST) 

all:
#	@$(MAKE) $(TARGET) "CFLAGS=$(CFLAGS) -DSCRIPT"
	@$(MAKE) $(TARGET) "CFLAGS=$(CFLAGS)"

$(TARGET): $(OBJS)  
	rm -f $(TARGET)
	$(CC) ${OBJS} ${LLIBS} -o $(TARGET)

dist: 
	-@mkdir dlxview0.9
	-@cd dlxview0.9
	-@for i in $(PACKAGE) \
	    ; do \
	  cp -r $$i dlxview0.9; \
	done
	-@cd ..
	tar -cvf - dlxview0.9 | gzip > dlxview0.9.tar.gz
	-@rm -rf dlxview0.9

linux_dist: $(TARGET)
	-@mkdir dlxview0.9
	-@cd dlxview0.9
	-@for i in $(PACKAGE) $(TARGET) \
	    ; do \
	  cp -r $$i dlxview0.9; \
	done
	-@cd ..
	tar -cvf - dlxview0.9 | gzip > dlxview0.9.linux-elf.tar.gz
	-@rm -rf dlxview0.9

solaris_dist: $(TARGET)
	-@mkdir dlxview0.9
	-@cd dlxview0.9
	-@for i in $(PACKAGE) $(TARGET) \
	    ; do \
	  cp -r $$i dlxview0.9; \
	done
	-@cd ..
	tar -cvf - dlxview0.9 | gzip > dlxview0.9.solaris2.5.tar.gz
	-@rm -rf dlxview0.9

hardfile:
	enscript -fCourier8 -2Gr -phardcopy.src Makefile $(HDR) $(SRC) 
	  
install: 
	-@chmod 755 $(TARGET)
	cp $(TARGET) $(DEST)
	-@chmod 644 $(TEST) 
	-@for i in $(TEST); do \
	   cp $$i $(DEST); \
        done

clean:
#	for i in $(PACKAGE); do \
#	   chmod 644 $$i; \
#	done
	-@rm -rf ${OBJS} dlxview core hardcopy.src *.BAK

realclean:
	-@$(MAKE) clean
	-@rm $(TARGET)


asm.o : asm.c dlx.h sym.h
cop0.o : cop0.c dlx.h
getput.o : getput.c dlx.h sym.h
io.o : io.c dlx.h
issue.o: issue.c dlx.h
main.o : main.c dlx.h
script.o : script.c script.h
sim.o : sim.c dlx.h sym.h 
stop.o : stop.c dlx.h sym.h
sym.o : sym.c dlx.h sym.h
trap.o : trap.c dlx.h sym.h 
