@SET_MAKE@

srcdir = @srcdir@
VPATH = @srcdir@

top_srcdir = @top_srcdir@

include ../config.make

PRE_CPPFLAGS = -I.. -I$(top_srcdir)
PRE_LDFLAGS = -L..

TS_NETTLE_SOURCES = aes-test.c arcfour-test.c arctwo-test.c \
		    blowfish-test.c cast128-test.c \
	            base16-test.c base64-test.c \
		    camellia-test.c \
		    des-test.c des3-test.c des-compat-test.c \
		    md2-test.c md4-test.c md5-test.c md5-compat-test.c \
		    memxor-test.c \
		    ripemd160-test.c \
		    sha1-test.c sha224-test.c sha256-test.c \
		    sha384-test.c sha512-test.c \
		    serpent-test.c twofish-test.c \
		    knuth-lfib-test.c \
		    cbc-test.c ctr-test.c gcm-test.c hmac-test.c \
		    meta-hash-test.c meta-cipher-test.c meta-armor-test.c \
		    buffer-test.c yarrow-test.c

TS_HOGWEED_SOURCES = sexp-test.c sexp-format-test.c \
		     rsa2sexp-test.c sexp2rsa-test.c \
		     bignum-test.c random-prime-test.c \
		     pkcs1-test.c \
		     rsa-test.c rsa-encrypt-test.c rsa-keygen-test.c \
		     dsa-test.c dsa-keygen-test.c

TS_SOURCES = $(TS_NETTLE_SOURCES) @IF_HOGWEED@ $(TS_HOGWEED_SOURCES)

TS_NETTLE = $(TS_NETTLE_SOURCES:.c=$(EXEEXT))
TS_HOGWEED = $(TS_HOGWEED_SOURCES:.c=$(EXEEXT))
TS_C = $(TS_NETTLE) @IF_HOGWEED@ $(TS_HOGWEED)
TS_CXX = @CXX_TESTS@
TARGETS = $(TS_C) $(TS_CXX)
TS_SH = sexp-conv-test pkcs1-conv-test symbols-test
TS_ALL = $(TARGETS) $(TS_SH)
EXTRA_SOURCES = sha1-huge-test.c
EXTRA_TARGETS = $(EXTRA_SOURCES:.c=$(EXEEXT))

SOURCES = $(TS_SOURCES) testutils.c

DISTFILES = $(SOURCES) $(EXTRA_SOURCES) cxx-test.cxx Makefile.in .test-rules.make \
	$(TS_SH) run-tests teardown-env \
	gold-bug.txt testutils.h

all: $(TARGETS) $(EXTRA_TARGETS)

.c.$(OBJEXT):
	$(COMPILE) -c $< && $(DEP_PROCESS)

.SUFFIXES: .cxx
.cxx.$(OBJEXT):
	$(COMPILE_CXX) -c $< && $(DEP_PROCESS)

# BSD (and Solaris) make doesn't allow extra dependencies together one
# single-suffix rules, which makes it impossible or almost impossible
# to use suffix rules to build the test executables. So we use an
# explicit rule for each and every executable.

LIB_HOGWEED = @IF_HOGWEED@ -lhogweed
TEST_OBJS = testutils.$(OBJEXT) $(LIB_HOGWEED) -lnettle $(LIBS)

.PHONY: test-rules
test-rules:
	(for f in $(TS_NETTLE) $(TS_HOGWEED) $(EXTRA_TARGETS) ; do \
	  echo $$f'$$(EXEEXT): '$$f'.$$(OBJEXT)' ; \
	  echo '	$$(LINK) '$$f'.$$(OBJEXT) $$(TEST_OBJS) -o '$$f'$$(EXEEXT)' ; \
	  echo ; \
	done ; \
	for f in $(TS_CXX) ; do \
	  echo $$f'$$(EXEEXT): '$$f'.$$(OBJEXT)' ; \
	  echo '	$$(LINK_CXX) '$$f'.$$(OBJEXT) $$(TEST_OBJS) -o '$$f'$$(EXEEXT)' ; \
	  echo ; \
	done) > $(srcdir)/.test-rules.make

include $(srcdir)/.test-rules.make

$(TARGETS) $(EXTRA_TARGETS): testutils.$(OBJEXT) \
	../libnettle.a @IF_HOGWEED@ ../libhogweed.a

# The PATH update is for locating dlls on w*ndows.
check: $(TS_ALL) $(srcdir)/run-tests
	LD_LIBRARY_PATH=../.lib PATH="../.lib:$$PATH" srcdir="$(srcdir)" \
	  $(srcdir)/run-tests $(TS_ALL)


Makefile: $(srcdir)/Makefile.in ../config.status
	cd .. && $(SHELL) ./config.status testsuite/$@

install uninstall:
	true

distdir: $(DISTFILES)
	cp $? $(distdir)

clean:
	-rm -f $(TARGETS) $(EXTRA_TARGETS) *.o test.in test1.out test2.out

distclean: clean
	-rm -f Makefile *.d

tags:
	etags -o $(srcdir)/TAGS --include $(top_srcdir) $(srcdir)/*.c $(srcdir)/*.h

@DEP_INCLUDE@ $(SOURCES:.c=.$(OBJEXT).d)
