include $(ROOT)/usr/include/make/NGdefs

OPTIMIZER = -O2

TESTS= \
	  thrd.elf \
	  tmr.elf \
	  tmr1.elf \
	  tmr2.elf \
	  tmr_chk.elf\
	  tmr_periodic.elf\
	  aes.elf \
	  mq.elf \
	  msg.elf \
	  dd.elf  \
	  sha.elf\
	  alloc.elf \
	  fl.elf \
	  stm.elf \
	  ipcrm.elf\
	  iob_tests.elf\
	  rm_iob.elf\
	  heap0.elf\
	  dcache.elf\
	  delay.elf\
	  dicheck.elf\
	  alloc2.elf\
      launch.elf\
      launchOS.elf\
      launchPPC.elf\
	  align.elf\
	  usleep.elf\
	  dump.elf \
	  iob_2583.elf\
	  setver.elf\
	  setppcperms.elf\
	  di_syscalls.elf\
	  getcoreclk.elf\
	  memperf.elf\
	  memtest_perf.elf \
	  memtest_correctness.elf\
	  memset_perf.elf \
	  memset_correctness.elf \
	  memclear_correctness.elf \
	  pri.elf\
	  ipcmax.elf\
	  ipcsysmax.elf\
	  memchk.elf \
	  fsdev_chk.elf

ASFILES += memclear.s

TARGETS = $(TESTS)

default: $(TARGETS)

SUBDIRS = iosc eeprom

include $(COMMONRULES)

LLDLIBS = -lsys -liosc -lioslibc -lios
LDIRT += *.bin *.elf

DDR_LDFLAGS =  $(LDLIBS) $(LDFLAGS) -T$(ROOT)/usr/lib/rvl/ddr.link  -Ttext=$(MK_APPS_START)
MEMCHK_LDFLAGS =  $(LDLIBS) $(LDFLAGS) -T$(ROOT)/usr/lib/rvl/ddr.link  -Ttext=$(MK_OH1_TXT_START)
MEMCHK_CFLAGS = -DFS_VIRT_START=$(MK_FS_VIRT_START) -DDI_VIRT_START=$(MK_DI_VIRT_START) -DES_VIRT_START=$(MK_ET_VIRT_START)

memchk.o: memchk.c
	$(CC) $(CFLAGS) $(MEMCHK_CFLAGS) -c -o $@ $^ 

memchk.elf: $(CRT0) memchk.o
	$(CC) $(CFLAGS) -o $@ $^ $(MEMCHK_LDFLAGS)


memclear_correctness.elf: $(CRT0)  memclear_correctness.o memclear.o 
	$(CC) $(CFLAGS) -o $@ $^ $(DDR_LDFLAGS)

%.elf: $(CRT0)  %.o 
	$(CC) $(CFLAGS) -o $@ $^ $(DDR_LDFLAGS)

install_src:
	-mkdir -p $(ROOT)/usr/src/os/tests
	$(INSTALL) *.c $(ROOT)/usr/src/os/tests
	$(INSTALL) Makefile.example $(ROOT)/usr/src/os/tests/Makefile

exports: $(TESTS)
	$(INSTALL) $(TESTS) $(ROOT)/usr/bin/rvl/tests

install: exports install_src

