# $Id: checkrules,v 1.5 2010/05/06 16:24:18 alanh Exp $
#
# These are some standard rules common to all Makefiles that perform
# tests.  If you change this file please read README.tests in the
# toplevel directory first.

include $(top_srcdir)/configvars

# The variable "type" will be appended to "lib" when searching for
# libraries.  Thus, to test the library with fpu code and >=m68020, 
# set type to 16020.  If you change this you must run "make checkclean".
type=

# These are additional CFLAGS passed to the compiler and the linker.
# For fpu/m68020 libs:
#	cflags=-m68020-60
# If you change this you must run "make checkclean".
cflags=

CRT0 = $(top_srcdir)/startup/crt0.o
libs = $(libs-$(@F)) $(top_srcdir)/lib$(type)/libc.a
LIBS = -lgcc $(LIBS-$(@F)) $(libs) -lgcc

TESTPRGS = $(addprefix test-, $(TESTS))
TESTCFILES = $(addsuffix .c, $(TESTPRGS) $(EXTRAPRGS))
TESTOBJS = $(TESTCFILES:.c=.o)
DEP_FILES = $(addprefix $(srcdir)/.deps/, $(patsubst %.c,%.P,$(TESTCFILES)))

TESTCFLAGS = $(cflags) $(EXTRACFLAGS)
TESTLDFLAGS = $(cflags) -s -nostartfiles -nostdlib
TESTDEFS = -D_GNU_SOURCE -D_REENTRANT

INCLUDES = -nostdinc -I$(shell cat $(top_srcdir)/includepath) \
-I$(top_srcdir)/include -I$(srcdir) -I$(top_srcdir) -I$(top_srcdir)/time
COMPILE = $(CC) $(TESTCFLAGS) $(CFLAGS-$(<F)) $(DEFS) $(DEFS-$(<F)) $(TESTDEFS)\
$(INCLUDES)

check: check-local $(libs) $(TESTPRGS)
	$(top_srcdir)/do_test $(TESTS)

checkclean:
	rm -f $(srcdir)/*.o $(TESTPRGS) 
	rm -rf $(srcdir)/.deps

$(TESTPRGS) $(EXTRAPRGS): %: %.o $(libs) $(CRT0)
	$(CC) $(LDFLAGS) $(TESTLDFLAGS) $(CRT0) $< -o $@ $(LIBS)

.SUFFIXES:
.SUFFIXES: .o .c

.c.o:
	@echo '$(COMPILE) -c $< -o $@'; \
	$(COMPILE) -Wp,-MD,.deps/$(@:.o=.P) -c $< -o $@

DEPS_MAGIC := $(shell mkdir $(srcdir)/.deps > /dev/null 2>&1 || :)

-include $(DEP_FILES) /dev/null

