# Copyright (c) 2000-1 by Wayne C. Gramlich.
# All rights reserved.

# Permission to use, copy, modify, distribute, and sell this software
# for any purpose is hereby granted without fee provided that the above
# copyright notice and this permission are retained.  The author makes
# no representations about the suitability of this software for any purpose.
# It is provided "as is" without express or implied warranty.

ROOT = ../..

include $(ROOT)/Makefile_common.mk
include $(ROOT)/Makefile_private.mk

UCL_DIRECTORY = ..
UCL = $(UCL_DIRECTORY)/ucl

ERROR_BASES :=			\
	mismatch1		\
	empty1			\
	processor1		\
	processor2		\
	processor3		\
	processor4		\
	processor5		\
	processor6		\
	processor7		\
	port1			\
	port2			\
	port3			\
	port4			\
	port5			\
	port6			\
	register1		\
	register2		\
	register3		\
	register4		\
	bind1			\
	bind2			\
	bind3			\
	bind4			\
	bind5			\
	bind6			\
	bind7			\
	switch1
GOOD_BASES :=			\
	assemble1		\
	array1			\
	array2			\
	array3			\
	array4			\
	bank1			\
	bank2			\
	bank3			\
	bank4			\
	bank5			\
	bank6			\
	basic1			\
	basic_main_loop1	\
	brace1			\
	global1			\
	bit1			\
	call1			\
	call2			\
	call3			\
	compare1		\
	compare2		\
	compare3		\
	compare4		\
	compare5		\
	compare6		\
	constant1		\
	equals1			\
	equals2			\
	equals3			\
	equals4			\
	equals5			\
	equals6			\
	equals7			\
	equals8			\
	minimal1		\
	minimal2		\
	minimal3		\
	minimal4		\
	minimal5		\
	origin1			\
	origin2			\
	origin3			\
	origin4			\
	pic12bit1		\
	pic12bit2		\
	pic12bit3		\
	pic16f876_1		\
	register1		\
	register2		\
	register_array1		\
	bind1			\
	incr1			\
	incr2			\
	incr3			\
	incr4			\
	if1			\
	if2			\
	if3			\
	if4			\
	if5			\
	if6			\
	if7			\
	if8			\
	if9			\
	select1			\
	select2			\
	select3			\
	cond_and1		\
	cond_and2		\
	cond_and3		\
	cond_and4		\
	cond_and5		\
	cond_and6		\
	cond_and7		\
	cond_or1		\
	cond_or2		\
	and1			\
	or1			\
	xor1			\
	shift1			\
	shift2			\
	shift3			\
	shift4			\
	shift5			\
	shift6			\
	shift7			\
	expr1			\
	expr2			\
	expr3			\
	expr4			\
	expr5			\
	expr6			\
	expr7			\
	expr8			\
	return1			\
	switch1			\
	switch2			\
	switch3			\
	string_constants1	\
	string_constants2	\
	string_constants3	\
	string_constants4	\
	string_constants5	\
	watch_dog_reset1	\
	while1			\
	while2			\
	uniform_count_down1	\
	uniform_delay1		\
	uniform_if1		\
	uniform_if2		\
	uniform_if3		\
	uniform_if4		\
	uniform_if5		\
	uniform_if6		\
	uniform_if7		\
	uniform_switch1		\
	uniform_switch2		\
	uniform_switch3		\
	uniform_switch4
BASES := ${ERROR_BASES:%=error_%} ${GOOD_BASES}
UCLS := ${BASES:%=%.ucl}
OUTS := ${BASES:%=%.out}
ASMS := ${BASES:%=%.asm}
HEXS := ${BASES:%=%.hex}
LSTS := ${BASES:%=%.lst}

FOO := array1 array2 array3

BAR := expr3 and1 or1 incr4 equals7

# Some pattern rules:

%.out: %.ucl
	@echo -n "Test $(@:%.out=%) ... " ;			\
	$(UCL) -c w $(@:%.out=%) > $@ 2>&1 ;			\
	if [ ! -s $@ ] ;					\
	  then							\
	    cat $(@:%.out=%.asm) | 				\
	      sed "s,[0-9]* ; random number,0r1,g" |		\
	      fgrep -v ";" > $@ ;				\
	  fi ;							\
	if diff $@ `basename $@ .out`.golden ;			\
	  then							\
	    echo "Passed" ;					\
	    rm -f $(@:%.out=%.asm) ;				\
	    rm -f $(@:%.out=%.hex) ;				\
	    rm -f $(@:%.out=%.lst) ;				\
	  else							\
	    echo "Failed" ;					\
	  fi

# Some targets:

.PHONY: all

all: ${OUTS}

foo:
	rm -f ${FOO:%=%.out}

bar:
	rm -f ${BAR:%=%.out}

# Programs:

clean:
	rm -f ${OUTS} ${ASMS} ${HEXS} ${LSTS}
	$(CLEAN)


