#
# define      description
# ------      ------------------------------------------------------
# DEBUG       enable debugging statements
# DEBUG_ERROR enable only error messages
# DUMP_PACKET display receive/transmit packet contents

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

OPTIMIZER = -O2

# enable debugging support
ifdef DEBUG
LCDEFS += -DNIF_DEBUG
endif

ifdef DEBUG_ERROR
LCDEFS += -DNIF_DEBUG_ERROR
endif

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

#

TARGETS += usbeth_basic.img usbeth_cable.img usbeth_dongle.img

COMMON_CFILES += net_if.c
COMMON_OBJECTS = $(COMMON_CFILES:.c=.o)

CFILES  += usbeth_basic.c usbeth_cable.c $(COMMON_CFILES)
HFILES  += net_if.h

LCFLAGS += -DIOP_OS -O2

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

LDIRT += $(TARGETS:.img=.elf) $(TARGETS:.img=.mrg) usbeth_cable.c

default: $(TARGETS)

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

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

usbeth_dongle.c: usbeth_cable.c
	-rm -f $@
	echo "#define DONGLE" > $@
	cat $< >> $@

usbeth_cable.c: usbeth_basic.c
	-rm -f $@
	echo "#define CABLE" > $@
	cat $< >> $@

%.elf: $(CRT0) %.o $(COMMON_OBJECTS)
	$(CC) $(CFLAGS) -Ttext $(MK_NET_START) -o $@ $^ $(LDFLAGS) $(LDLIBS) 

install: $(TARGETS) # install_src
	$(INSTALL) $(TARGETS) $(ROOT)/usr/bin/rvl/tests

#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

include $(COMMONRULES)

