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

TARGETS = devmon.bwf devmon_small.bwf

CFILES = mon.c cmd.c escmd.c diag/audtone.c diag/audrecord.c diag.c

default: $(TARGETS)

include $(COMMONRULES)

LLDLIBS = -liosc -lios -lioslibc -lvio_usb 
LLDOPTS = -T $(SDRAM_LINK) -L$(ROOT)/usr/lib/sc
LDIRT += ncdevmon.elf
FSAPI = $(ROOT)/usr/lib/sc/libisfs.a
ESAPI = $(ROOT)/usr/lib/sc/libes.a
BUILD_TIME := $(shell date +"%D %r")
LCDEFS = -DBUILD_TIME='"$(BUILD_TIME)"'

headers: shell.h
	$(INSTALL) shell.h $(ROOT)/usr/include/sc

exports: ncdevmon.elf
	$(INSTALL) ncdevmon.elf $(ROOT)/usr/bin/sc

install: $(TARGETS)
	$(INSTALL) $(TARGETS) $(ROOT)/usr/bin/sc

ncdevmon.elf: $(CRT0) $(OBJECTS) $(FSAPI) $(ESAPI) $(SC_ADDR_MAP)
	$(CC) $(CFLAGS) -Ttext $(MK_DEVMON_START) $(LDFLAGS) -o $@ \
		 $(CRT0) $(OBJECTS) $(FSAPI) $(ESAPI) $(LDLIBS)  

#
# We need two versions of devmon:  one without p2p and one with p2p.
#
# The reason is that devmon+p2p is too big to be loaded by the 1.15 or
# earlier devmon.  So the user needs to load the small one first, which
# has the bigger buffer and then reboot and load the full devmon.
#
devmon.mrg : ncdevmon.elf $(ROOT)/usr/bin/sc/sk.elf $(ROOT)/usr/bin/sc/usb.elf \
		$(ROOT)/usr/bin/sc/fs.elf $(ROOT)/usr/bin/sc/es.elf \
		$(ROOT)/usr/bin/sc/aud.elf $(ROOT)/usr/bin/sc/mediafs.elf \
		$(ROOT)/usr/bin/sc/socp.elf
	$(MERGE) -o $@ -s $(MK_SHARED_START) -z 0x100000 \
		-d ncdevmon.elf \
		-k $(ROOT)/usr/bin/sc/sk.elf \
		-u $(ROOT)/usr/bin/sc/usb.elf \
		-f $(ROOT)/usr/bin/sc/fs.elf \
		-e $(ROOT)/usr/bin/sc/es.elf \
		-a $(ROOT)/usr/bin/sc/aud.elf \
		-n $(ROOT)/usr/bin/sc/mediafs.elf \
		-p $(ROOT)/usr/bin/sc/socp.elf

devmon.bwf : devmon.mrg
	$(PUBLISH) -b -n devmon -l devmon.mrg

devmon_small.mrg : ncdevmon.elf $(ROOT)/usr/bin/sc/sk.elf $(ROOT)/usr/bin/sc/usb.elf \
		$(ROOT)/usr/bin/sc/fs.elf $(ROOT)/usr/bin/sc/es.elf
	$(MERGE) -o $@ -s $(MK_SHARED_START) -z 0x100000 \
		-d ncdevmon.elf \
		-k $(ROOT)/usr/bin/sc/sk.elf \
		-u $(ROOT)/usr/bin/sc/usb.elf \
		-f $(ROOT)/usr/bin/sc/fs.elf \
		-e $(ROOT)/usr/bin/sc/es.elf

devmon_small.bwf : devmon_small.mrg
	$(PUBLISH) -b -n devmon_small -l devmon_small.mrg
