#
# Makefile for to make stuffs
# Created by goddess of chaos
# OpenWii - YOLD 3173
#

chip=chiip

COMDIRS = $(chip)

#these are phoney targets
.PHONY: subs $(COMDIRS)

all: checkargs mn10200rule subs

checkargs:
#check for required arguments
ifndef chip
	@$(MAKE) -s help
	@false
else
ifdef withbootloader
	@echo "Make with boot loader..."
endif
	@echo "Here we go..."
endif

mn10200rule:
	$(MAKE) -C mn10200 $(MAKEARGS) chip=$(chip) drive=dms
	$(MAKE) -C mn10200 $(MAKEARGS) chip=$(chip) drive=d2b

subs: $(COMDIRS)

#rules for building anything in the subdirs (in this case make stuff!)
$(COMDIRS):
	@$(MAKE) -C $@ $(MAKEARGS) chip=$(chip)
	@$(MAKE) -C $@ $(MAKEARGS) chip=$(chip) withbootloader=yes

help:
	@echo "How to use me blah blah"
	@echo "make chip=chiip"
	@echo "make chip=msp430"
	@echo "make chip=msp430 clean"
	@echo "add withbootloader=yes if you want to include the bootloader in the firmware"
	@echo "etc etc"

cleanchip: MAKEARGS = clean
cleanchip: checkargs $(chip)
	@echo "cleaned up a bit"

clean: MAKEARGS = clean
clean: checkargs subs
	@echo "cleaned up a bit"
