##
## Makefile for Mixbug monitor (trivial application)
##
export OR1K=1



SWROOT  = ../../openrisc/sw
HWROOT  = ../../openrisc

include $(SWROOT)/Makefile.def

PROGRAM =  hltest2
#  periphtest
# coproctest
# hltest2
# coproctest
#
# hltest
CFLAGS  = -DOR1K -mhard-div -O2 -DHEAPEND=$(HEAPEND)  -DHEAPBASE=$(HEAPBASE) -I$(SWROOT)/prlibc 
# -I$(SOCDAMOR1K)/btlm-baseline/support


OR1KSIM = $(HWROOT)/testbench/or1ksmp -tracelevel 0
# -verilated
# 4 -verilated

NEEDED= \
    $(PROGRAM).o \
    $(SWROOT)/uart64_cbg/device_driver/uart64_driver.o 

# cancel internal .c -> .o rule that does not have sufficient dependecies
%.o: %.c

%.o: %.s
	$(AS) -o $@ $<

%.s: %.c
	$(CC1) -o $@ $(CFLAGS)  $<


all:$(PROGRAM) disassembles
	time $(OR1KSIM) -cores 1 -image $(PROGRAM) -uart-input "help\rmd 80 2\r\q"
# -global-qk-us 100 
# -tracelevel 32 | head -1000

$(PROGRAM):$(NEEDED) $(SWROOT)/prlibc/liblibcor1k.a
	$(LD) -o $(PROGRAM) $(LDFLAGS) -Ttext 0x0 -Tdata 0x8000 -Tbss 0x10000 $(SWROOT)/prlibc/mycrt.o $(NEEDED) -L$(SWROOT)/prlibc -llibcor1k
	$(OBJD) -D $(PROGRAM) > $(PROGRAM).dump

disassembles:
	$(NM) $(PROGRAM) > $(PROGRAM).nm
	$(OBJD) -D $(PROGRAM) > $(PROGRAM).dump
	readelf -a $(PROGRAM) > $(PROGRAM).readelf

clean:
	rm -f $(PROGRAM)  *.o *.a


$(SWROOT)/prlibc/liblibcor1k.a:
	cd $(SWROOT)/prlibc; make

$(SWROOT)/uart64_cbg/device_driver/uart64_driver.o:
	cd /uart64_cbg/device_driver; make

# eof
