# ###################################################################
#
# ${ZOG}/Makefile
#
# This makefile provides a way to build all programs in the source tree.
# Single application demos can also be built from here.
#
# ###################################################################

# the first port found in /dev/ttyUSB* for make operations
# if your serial port is not on the first device, reassign
# PORT=<your port> for your needs.
#
PORT=`ls /dev/ttyUSB* | awk '{print $1}'`

# the list of directories to build for $ make all
#
SUBDIRS = lib test loader spin

#
# $ make all
#
# Builds everything in lib, test, loader, and spin
#
all: $(SUBDIRS)

#
# $ make tv
#
# Will build Tv2Text demo program.
# Will store .bin file on SDCARD as main.bin.
# Will not program EEPROM.
#
tv: tools
	@echo "Load and run Tv2Text/main.bin using $(PORT)"
	@cd test/Tv2Text && make
	@./load.sh test/Tv2Text/main.bin $(PORT)
	@cd spin && make program

#
# $ make tv
#
# Will build Tv2Text demo program.
# Will store .bin file on SDCARD as main.bin.
# Will not program EEPROM.
#
fibo: tools
	@echo "Load and run fibo.bin using $(PORT)"
	@cd test/fibo && make
	@./load.sh test/fibo/fibo.bin $(PORT)
	@cd spin && make program
	@nanocom $(PORT) -b 115200

tools: lib loader spin

#
# $ make program
#
# Will build debug_zog.spin and load in Propeller HUB RAM
#
program:
	cd spin && make program

#
# $ make progee
#
# Will build debug_zog.spin and save in Propeller EEPROM
#
progee:
	cd spin && make progee

#
# $ make install
#
# Will build uploadsd.spin, debug_zog.spin and
# save debug_zog in Propeller EEPROM.
#
install:
	cd spin && make install

#
# $ make all
#
# recurively builds all lib, loader, spin, and test
#
$(SUBDIRS):
	cd $@ && make && cd ..
.PHONY : all $(SUBDIRS)

#
# $ make clean
#
# recurively cleans all lib, loader, spin, and test
#
clean: FORCE
	for dir in $(SUBDIRS); do cd $$dir && make clean; cd ..; done
FORCE:


