#ident "$Id: Makefile,v 1.50 2006/06/23 03:00:14 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 test_dvd_enable.elf di_boot.img

PRODUCTS = di_boot.elf

TARGETS = $(PROGS)

default: $(TARGETS)

include $(COMMONRULES)

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

CFLAGS += -std=c99

LCINCS += -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 += -fno-strict-aliasing
#OPTIMIZER += -O0
LCFLAGS += -DSTACK_PRINT
LCFLAGS += -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)

test_dvd_enable.elf: $(CRT0) test_dvd_enable.o app_open_mem.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 $@

exports install: $(PRODUCTS)
	$(INSTALL) $(PRODUCTS) $(ROOT)/usr/bin/rvl

# Expect a bunch of warnings when running this.
depend:
	makedepend -Y -f Makefile $(LCINCS) $(SRCS)

dvd_low.o dvd_driver.o dvd_low_rvl.o: dvd_hw_reg.i

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

di_boot.o: arm_stdint.h stack.h ./stdbool.h
dvd_driver.o: ./assert.h ./stdbool.h dvd_mem.h dvd.h dvd_hw.h dvd_driver.h
dvd_driver.o: dvd_low.h dvd_command.h dvd_low_rvl.h dvd_hw_reg.i debug.h
dvd_driver.o: md5.h stack.h
dvd_rvl_mem.o: arm_stdint.h dvd_driver.h debug.h md5.h
dvd_low.o: ./assert.h ./stdbool.h dvd.h dvd_hw.h dvd_driver.h dvd_low.h
dvd_low.o: dvd_command.h dvd_low_rvl.h dvd_hw_reg.i debug.h md5.h flush.i
dvd_low.o: ../../../tools/dvd/disk_format.h dvd_mem.h
dvd_low_rvl.o: ./assert.h ./stdbool.h aes.h dvd_hw.h dvd.h dvd_driver.h
dvd_low_rvl.o: dvd_low_rvl.h ../../../tools/dvd/disk_format.h crypto_stub.h
dvd_low_rvl.o: sha1.h dvd_mem.h debug.h md5.h flush.i dvd_low.h dvd_command.h
sha1.o: sha1.h
aes_api.o: aes_api.h aes_imp.h
aes.o: bsstypes.h aes.h aes_api.h
aes_imp.o: aes_imp.h
