#
-# This makefile take each "at*" file, extracts it's part name
-# And compile it into an ELF binary.
-# It also disassemble it for debugging purposes.
+# This makefile takes each "at*" file, extracts it's part name
+# And compiles it into an ELF binary.
+# It also disassembles it for debugging purposes.
#
-# The code is compiled "optimized" to the max.
-#
-# The wierd "-Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000"
-# is used to tell the linker not to discard the .mmcu section,
-# otherwise the --gc-sections will delete it.
-#
-# Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
+# Copyright 2008-2012 Michel Pollet <buserror@gmail.com>
#
# This file is part of simavr.
#
# You should have received a copy of the GNU General Public License
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
-ifeq (${shell uname}, Darwin)
-AVR_ROOT := "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/"
-else
-AVR_ROOT :=
-endif
-AVR := ${AVR_ROOT}avr-
-SHELL = /bin/bash
+SHELL = /bin/bash
sources := $(wildcard at*.c)
+simavr = ..
+
+IPATH += ${simavr}/include
+IPATH += ${simavr}/simavr/sim
+
+tests_src = ${wildcard test_*.c}
+tests = ${patsubst %.c, ${OBJ}/%.tst, ${tests_src}}
-all : ${sources:.c=.axf} ${sources:.c=.hex} ${sources:.c=.s}
+all: obj axf tests
include ../Makefile.common
-clean:
- rm -f *.hex *.o *.axf *.s
+tests: ${tests}
+
+axf: ${sources:.c=.axf}
+
+
+${OBJ}/%.tst: tests.c %.c
+ifeq ($(V),1)
+ $(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
+else
+ @echo TST $@
+ @$(CC) -MMD ${CFLAGS} ${LFLAGS} -o $@ $^ $(LDFLAGS)
+endif
+
+run_tests: all
+ @export LD_LIBRARY_PATH=${simavr}/simavr/${OBJ} ;\
+ num_failed=0 ;\
+ num_run=0 ;\
+ for test in ${OBJ}/test_*.tst; do \
+ num_run=$$(($$num_run+1)) ;\
+ if ! $$test; then \
+ echo "$$test returned with exit value $$?." ;\
+ num_failed=$$(($$num_failed+1)) ;\
+ fi ;\
+ done ;\
+ echo "Tests run: $$num_run Successes: $$(($$num_run-$num_failed)) Failures: $$num_failed"
+
+clean: clean-${OBJ}
+ rm -f *.axf