# $Id: $
# University of Cambridge, Computer Laboratory.
# SoC D/M Classes - OR1K Reference Design
#
CC=g++



# Use one or other of the next two lines:
# ORSIM= -L ../verilatedcpp  -lVor1200
ORSIM=  -L../orsim -lorsim 


BOOST=/usr/groups/han/clteach/boost_1_42_0
CXXFLAGS = -O3 -g -I $(SYSTEMC)/include/ -I $(TLM_HOME)/include/tlm/ -I$(BOOST) -I../hw 
LFLAGS = -L $(SYSTEMC)/lib-linux/ -lsystemc  $(ORSIM)
CLFLAGS=-DSC_INCLUDE_DYNAMIC_PROCESSES

# Using Verilator, uncomment the following:
#CXXFLAGS += -I $(VER) -I$(VERILATOR_ROOT)/include/

targets: iss main run

BACKDOORS=backdoor_nops.C backdoor_reads.C backdoor_writes.C



run: main withlocal
	./main -image ../sw/mixbug-or1k/mixbug -cores 2 -- test1 test2  
# | head -1000000

iss:
	cd ../orsim; make

Vor1200:
	cd $(VER) && $(MAKE) all

cbgram.o: cbgram.cpp cbgram.h
	$(CC) $(CLFLAGS) $(CXXFLAGS) -c cbgram.cpp

cbguart.o: cbguart.cpp cbguart.h
	$(CC) $(CLFLAGS) $(CXXFLAGS) -c cbguart.cpp


# Fast, ISS version:
orsim_sc.o:orsim_sc.cpp orsim_sc.h $(BACKDOORS)
	$(CC) $(CLFLAGS) $(CXXFLAGS) -c orsim_sc.cpp

# Verilated version:
OR1200.o: OR1200.cpp OR1200.h $(BACKDOORS)
	$(CC) $(CLFLAGS) $(CXXFLAGS) -I $(VER) -I$(VERILATOR_ROOT)/include/ -c OR1200.cpp	


busmux.o: busmux.cpp busmux.h
	$(CC) $(CLFLAGS) $(CXXFLAGS) -c busmux.cpp	

main.o: main.cpp
	$(CC) $(CLFLAGS) $(CXXFLAGS) -I SCmodules/ -c main.cpp

withlocal.o: withlocal.cpp
	$(CC) $(CLFLAGS) $(CXXFLAGS) -I SCmodules/ -c withlocal.cpp

#ORCORE=OR1200.o
ORCORE=orsim_sc.o

main: main.o  cbgram.o busmux.o $(ORCORE) cbguart.o
	$(CC) $(CLFLAGS)  main.o cbgram.o $(ORCORE) busmux.o cbguart.o $(LFLAGS) -o main -lpthread

withlocal: withlocal.o  cbgram.o busmux.o $(ORCORE) cbguart.o orsim_sc.o
	$(CC) $(CLFLAGS)  withlocal.o cbgram.o $(ORCORE) busmux.o cbguart.o $(LFLAGS) -o withlocal -lpthread

software:
	cd ../sw/mysoft/ && $(MAKE) all
	rm -f flash.in
	ln ../flash.in flash.in
clean:
	rm -f *.o main *~ test *.vcd

zip:
	zip zip.zip *.cpp *.h Makefile

reverilate:
	cd $(VER) && $(MAKE) clean
	cd $(VER) && $(MAKE) all

