#
-# 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.
#
# along with simavr. If not, see <http://www.gnu.org/licenses/>.
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: obj axf tests
+
+include ../Makefile.common
+
+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"
-all : ${sources:.c=.axf} ${sources:.c=.hex} ${sources:.c=.s}
-
-%.hex: %.axf
- @avr-objcopy -j .text -j .data -O ihex ${<} ${@}
-
-%.s: %.axf
- @avr-objdump -j .text -j .data -j .bss -d ${<} > ${@}
-
-%.axf: %.c
- @echo CC ${<}
- @part=${<} ; part=$${part/_*}; \
- avr-gcc -Wall -g -Os -std=gnu99 \
- -mmcu=$$part \
- -DF_CPU=8000000 \
- -mcall-prologues -fno-inline-small-functions \
- -ffunction-sections -fdata-sections \
- -Wl,--relax,--gc-sections \
- -Wl,--undefined=_mmcu,--section-start=.mmcu=0x910000 \
- -I../include \
- ${<} -o ${@}
- @avr-size ${@}|sed '1d'
-
-clean:
- rm -f *.hex *.o *.axf *.s
+clean: clean-${OBJ}
+ rm -f *.axf