# $Id: Makefile,v 1.42 2006/06/07 23:28:45 craig Exp $
include $(ROOT)/usr/include/make/NGdefs

vpath %.c ../../../tools/dvd

PROGS= di_boot.elf test_id_iop.elf test_read_iop.elf stress_raw_read.elf \
       test_read_rvl.elf stress_read_rvl.elf dump_bytes.elf \
       dump_rvl_bytes.elf di_boot.img

TARGETS = $(PROGS)

default: $(TARGETS)

include $(COMMONRULES)

LLDLIBS = -lsys -lioslibc -liossyscall -liosc
LDIRT += *.bin *.elf *.mrg *.img

CFLAGS += -std=c99 -I../../../tools/iose/os/di -I../../../tools/dvd \
          -I. -I../../../common/include

#CFLAGS += -DDEBUG
CFLAGS += -DERR_DEBUG
#FIXME - see if you can get change code so that
#no-struct-aliasing isn't needed
# Compiling -O2 saves space over -O0
OPTIMIZER += -O2 -fno-strict-aliasing
#OPTIMIZER += -O0
#LCFLAGS += -DSTACK_PRINT
CFLAGS += -DNEW_CODE


# Size of the unprotected heap usable by applications and not
# the driver - in K bytes.
CFLAGS += -DAPP_HEAP_OPEN_SIZE=32

SRCS        = di_boot.c dvd_driver.c dvd_rvl_mem.c dvd_low.c dvd_low_rvl.c \
              crypto_stub.o sha1.c aes_api.c aes.c aes_imp.c key.c

DI_BOOT_LDFLAGS =  $(LDLIBS) $(LDFLAGS) -les -T$(ROOT)/usr/lib/rvl/ddr.link \
               -Ttext=$(MK_DI_START)

APP_LDFLAGS =  $(LDLIBS) $(LDFLAGS) -T$(ROOT)/usr/lib/rvl/ddr.link \
               -Ttext=$(MK_APPS_START)
DRIVER_SRC = di_boot.c dvd_driver.c dvd_rvl_mem.c dvd_low.c dvd_low_rvl.c \
             stack.c

#Files are needed only when doing MD5 sums
#DRIVER_SRC += debug.o md5.o

#Files are needed only when doing software decrypt
#DRIVER_SRC += crypto_stub.o sha1.o aes_api.o aes.o aes_imp.o key.o
             
DRIVER_OBJ = $(DRIVER_SRC:.c=.o)
di_boot.elf: $(CRT0) $(DRIVER_OBJ)
	$(CC) $(CFLAGS) -o $@ $^ $(DI_BOOT_LDFLAGS)

test_id_iop.elf: $(CRT0) test_id_iop.o app_open_mem.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

test_read_iop.elf: $(CRT0) test_read_iop.o common_test.o app_open_mem.o md5.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

stress_raw_read.elf: $(CRT0) stress_raw_read.o md5.o rand.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

stress_read_rvl.elf: $(CRT0) stress_read_rvl.o md5.o rand.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

test_read_rvl.elf: $(CRT0) test_read_rvl.o md5.o rand.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

dump_bytes.elf: $(CRT0) dump_bytes.o common_test.o app_open_mem.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

test_open_part.elf: $(CRT0) test_open_part.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

dump_rvl_bytes.elf: $(CRT0) dump_rvl_bytes.o app_open_mem.o test_funcs.o
	$(CC) $(CFLAGS) -o $@ $^ $(APP_LDFLAGS)

TEST_APP = dump_bytes

di_boot.mrg: di_boot.elf ../ios/ios_real.elf $(ROOT)/usr/bin/rvl/es.elf \
	     $(ROOT)/usr/bin/rvl/fs.elf $(TEST_APP).elf
	     $(MERGE)   -o $@					\
	     		-k ../ios/ios_real.elf			\
	                -s $(MK_SHARED_START)			\
			-z $(MK_SHARED_SIZE)			\
			-f $(ROOT)/usr/bin/rvl/fs.elf		\
			-e $(ROOT)/usr/bin/rvl/es.elf		\
			-d di_boot.elf				\
			-d $(TEST_APP).elf

di_boot.img: $(ROOT)/usr/bin/rvl/loader.bin di_boot.mrg
	$(OSMERGE) -b $(ROOT)/usr/bin/rvl/loader.bin -m di_boot.mrg -o $@

install: $(PROGS)
	$(INSTALL) $(PROGS) $(ROOT)/usr/bin/rvl

#This is broken (for now)
depend:
	makedepend -f Makefile $(CFLAGS) $(SRCS)

# DO NOT DELETE THIS LINE -- make depend depends on it.
