# 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 m68020.  If you change this you must run "make checkclean".
type=m68000

# 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=$(CFLAGS_$(type))

CRT0 = $(top_srcdir)/build/$(type)/crt0.o
libs = $(libs-$(@F)) $(top_srcdir)/build/$(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 $(top_srcdir)/build/$(type)/$(subdir)/.deps/,$(patsubst %.c,%.P,$(TESTCFILES)))

TESTCFLAGS = $(cflags) $(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 $(top_srcdir)/build/$(type)/$(subdir)/*.o $(TESTPRGS) 
	rm -rf $(top_srcdir)/build/$(type)/$(subdir)/.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,$(top_srcdir)/build/$(type)/$(subdir)/.deps/$(@:.o=.P) -c $< -o $@

DEPS_MAGIC := $(shell mkdir -p $(top_srcdir)/build/$(type)/$(subdir)/.deps > /dev/null 2>&1 || :)

-include $(DEP_FILES) /dev/null
