#
# Makefile for building wand program
#
# Copyright (C) 2006  Nathan (Acorn) Pooley
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License (gpl.txt) for more details. 
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# 
# You can contact the author, Nathan (Acorn) Pooley, by writing
# to Nathan (Acorn) Pooley, 949 Buckeye Drive, Sunnyvale, CA  94086, USA
# or through the form at http://www.rawbw.com/~acorn/wand/feedback.html
# 

TARGETS		:=	kernel.hex \
				kload.hex \
				wand.hex \
				wchars.inc \
				statecheck_test \
				tags \

SRC			:=	wand.asm \
				kload.asm

COM_HDR		:=	chip.inc \
				kernel.inc \
				wiohw1.inc \
				wiohw2.inc \
				kernel.inc \
				d182525.inc \
				d182620.inc \
				d18252.inc \

#				$(HOME)/Software/gputils-0.13.3/header/p18f2525.inc

WAND_HDR	:=	$(COM_HDR) \
				rspells.inc \
				wand_str.inc \
				wchars.inc \
				wparse.inc \
				wstrings.inc \
				wmspells.inc \
				wmspells2.inc \
				wspell_info.inc \
				wspell_str.inc \
				

ALL_HDR		:=	$(WAND_HDR)

default:	$(TARGETS)	;
	
help:
	@echo "  Targets"
	@echo "  -------"
	@echo "  (default)  - make all targets"
	@echo "  clean      - remove stuff"
	@echo "  save       - copy current kernel to Archive dir"

save: FORCE
	./savekern

kernel.hex: kernel.asm $(COM_HDR)
	gpasm -g -a inhx32 -o $@ $<
	./checkvars $@ $+ || rm -f $@
	cat $@ > /dev/null

kload.hex: kload.asm $(COM_HDR)
	gpasm -g -a inhx32 -o $@ $<
	./checkvars $@ $+ || rm -f $@
	cat $@ > /dev/null

wand.hex: wand.asm $(WAND_HDR)
	gpasm -g -a inhx32 -o $@ $<
	./checkvars $@ $+ || rm -f $@
	cat $@ > /dev/null

statecheck_test: statecheck_test.c
	gcc -o $@ $<

wchars.inc: wchars.sh
	bash $< > $@

wand_str.inc: wand_str.str
	echo ";" > $@
	echo "; DO NOT EDIT - GENERATED FROM $< " >> $@
	echo ";" >> $@
	cat $< >> $@

wparse.inc: ../server/wparse.inc
	-cp  $< $@

wmspells.inc: ../server/wmspells.inc
	-cp  $< $@

wmspells2.inc: ../server/wmspells2.inc
	-cp  $< $@

../server/wmspells.inc ../server/wmspells2.inc ../server/wparse.inc:
	@echo ""
	@echo "ERROR: You must create $@ by running 'make' in ../server before"
	@echo "running make here."
	exit 1

tags: $(SRC) $(HDR) Makefile
	-ctags $(CTAGS_OPTS) $^

dist_files:
	\ls Makefile *.asm *.sh *.str *.h *.txt *.c 
	\ls ggg wand.mcp wand.mcs wand.mcw savekern checkvars showtimes
	\ls *.inc \
		| grep -v wchars.inc \
		| grep -v wmspells.inc \
		| grep -v wmspells2.inc \
		| grep -v wparse.inc

clean:
	\rm -f *.cod *.hex *.lst $(TARGETS) tags wchars.inc wand_str.txt

FORCE:	; 

.PHONY: FORCE clean dist_files

CTAGS_OPTS	:=	-h +.inc \
				--langmap=Asm:+.inc.asm
