#
# define      description
# ------      ------------------------------------------------------
# TEST        compile in test program, testProc.c
# DEBUG       enable debugging statements
# DEBUG_ERROR enable only error messages
# DUMP_PACKET display receive/transmit packet contents

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

# enable internal test program
ifdef TEST
LCDEFS += -DTEST_PROC
CFILES += usbeth_boot.c
endif

# enable debugging support
ifdef DEBUG
LCDEFS += -DUE_DEBUG -DAX_DEBUG
endif

ifdef DEBUG_ERROR
LCDEFS += -DUE_DEBUG_ERROR -DAX_DEBUG_ERROR
endif

# enable packet dumping
ifdef DUMP_PACKET
LCDEFS += -DDUMP_PACKET
endif

#

TARGETS = usbeth.elf

CFILES  += usbeth.c ax.c
HFILES  += ax.h ax_defs.h

LCFLAGS += -mthumb -DIOP_OS -O2

LLDLIBS += -lusb -lioslibc -lios	
LLDOPTS += -Tddr.link

default: $(TARGETS)

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

usbeth.mrg: $(ROOT)/usr/bin/rvl/ios_real.elf $(ROOT)/usr/bin/rvl/ohci0.elf usbeth.elf
	$(MERGE) -k $(ROOT)/usr/bin/rvl/ios_real.elf -u $(ROOT)/usr/bin/rvl/ohci0.elf -c usbeth.elf -s $(MK_SHARED_START) -z $(MK_SHARED_SIZE) -o $@

usbeth.elf: $(CRT0) $(OBJECTS)
	$(CC) $(CFLAGS) -Ttext $(MK_USBETH_START) -o $@ $^ $(LDFLAGS) $(LDLIBS) 

install: exports install_src

install_src: $(SRCS)
	-mkdir -p $(ROOT)/usr/src/os/usbeth
	$(INSTALL) -m 644 $(CFILES) $(HFILES) $(ROOT)/usr/src/os/usbeth
	$(INSTALL) -m 644 Makefile.example $(ROOT)/usr/src/os/usbeth/Makefile

exports: $(TARGETS)
	$(INSTALL) $(TARGETS) $(ROOT)/usr/bin/rvl

include $(COMMONRULES)

