# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# See the COPYRIGHT file distributed with this work for additional
# information regarding copyright ownership.

srcdir =	@srcdir@
VPATH =		@srcdir@
top_srcdir =	@top_srcdir@

VERSION=@BIND9_VERSION@

@BIND9_MAKE_INCLUDES@

CINCLUDES =	-I. -Iinclude ${DNS_INCLUDES} ${ISC_INCLUDES} \
		${OPENSSL_CFLAGS} @CMOCKA_CFLAGS@
CDEFINES =	-DTESTS="\"${top_builddir}/lib/dns/tests/\""

ISCLIBS =	../../isc/libisc.@A@ ${OPENSSL_LIBS} ${JSON_C_LIBS} ${LIBXML2_LIBS}
ISCDEPLIBS =	../../isc/libisc.@A@
DNSLIBS =	../libdns.@A@ ${MAXMINDDB_LIBS} @DNS_CRYPTO_LIBS@
DNSDEPLIBS =	../libdns.@A@

LIBS =		@LIBS@ @CMOCKA_LIBS@

OBJS =		dnstest.@O@
SRCS =		acl_test.c \
		db_test.c \
		dbdiff_test.c \
		dbiterator_test.c \
		dh_test.c \
		dispatch_test.c \
		dnstap_test.c \
		dst_test.c \
		dnstest.c \
		geoip_test.c \
		keytable_test.c \
		master_test.c \
		name_test.c \
		nsec3_test.c \
		peer_test.c \
		private_test.c \
		rbt_test.c \
		rbt_serialize_test.c \
		rdata_test.c \
		rdataset_test.c \
		rdatasetstats_test.c \
		resolver_test.c \
		result_test.c \
		rsa_test.c \
		sigs_test.c \
		time_test.c \
		tkey_test.c \
		tsig_test.c \
		update_test.c \
		zonemgr_test.c \
		zt_test.c

SUBDIRS =
TARGETS =	acl_test@EXEEXT@ \
		db_test@EXEEXT@ \
		dbdiff_test@EXEEXT@ \
		dbiterator_test@EXEEXT@ \
		dbversion_test@EXEEXT@ \
		dh_test@EXEEXT@ \
		dispatch_test@EXEEXT@ \
		dnstap_test@EXEEXT@ \
		dst_test@EXEEXT@ \
		geoip_test@EXEEXT@ \
		keytable_test@EXEEXT@ \
		master_test@EXEEXT@ \
		name_test@EXEEXT@ \
		nsec3_test@EXEEXT@ \
		peer_test@EXEEXT@ \
		private_test@EXEEXT@ \
		rbt_test@EXEEXT@ \
		rbt_serialize_test@EXEEXT@ \
		rdata_test@EXEEXT@ \
		rdataset_test@EXEEXT@ \
		rdatasetstats_test@EXEEXT@ \
		resolver_test@EXEEXT@ \
		result_test@EXEEXT@ \
		rsa_test@EXEEXT@ \
		sigs_test@EXEEXT@ \
		time_test@EXEEXT@ \
		tkey_test@EXEEXT@ \
		tsig_test@EXEEXT@ \
		update_test@EXEEXT@ \
		zonemgr_test@EXEEXT@ \
		zt_test@EXEEXT@

@BIND9_MAKE_RULES@

LD_WRAP_TESTS=@LD_WRAP_TESTS@

acl_test@EXEEXT@: acl_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ acl_test.@O@ dnstest.@O@ ${DNSLIBS} \
		${ISCLIBS} ${LIBS}

db_test@EXEEXT@: db_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ db_test.@O@ dnstest.@O@ ${DNSLIBS} \
		${ISCLIBS} ${LIBS}

dbdiff_test@EXEEXT@: dbdiff_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dbdiff_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dbiterator_test@EXEEXT@: dbiterator_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dbiterator_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dbversion_test@EXEEXT@: dbversion_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dbversion_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dh_test@EXEEXT@: dh_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dh_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dispatch_test@EXEEXT@: dispatch_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dispatch_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dnstap_test@EXEEXT@: dnstap_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dnstap_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

dst_test@EXEEXT@: dst_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ dst_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

geoip_test@EXEEXT@: geoip_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ geoip_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

keytable_test@EXEEXT@: keytable_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ keytable_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

master_test@EXEEXT@: master_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	test -d testdata || mkdir testdata
	test -d testdata/master || mkdir testdata/master
	${PERL} ${srcdir}/mkraw.pl < ${srcdir}/testdata/master/master12.data.in \
		> testdata/master/master12.data
	${PERL} ${srcdir}/mkraw.pl < ${srcdir}/testdata/master/master13.data.in \
		> testdata/master/master13.data
	${PERL} ${srcdir}/mkraw.pl < ${srcdir}/testdata/master/master14.data.in \
		> testdata/master/master14.data
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ master_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

name_test@EXEEXT@: name_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ name_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

nsec3_test@EXEEXT@: nsec3_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ nsec3_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

peer_test@EXEEXT@: peer_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ peer_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

private_test@EXEEXT@: private_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ private_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rbt_serialize_test@EXEEXT@: rbt_serialize_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rbt_serialize_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rbt_test@EXEEXT@: rbt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rbt_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rdata_test@EXEEXT@: rdata_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rdata_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rdataset_test@EXEEXT@: rdataset_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rdataset_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rdatasetstats_test@EXEEXT@: rdatasetstats_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rdatasetstats_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

resolver_test@EXEEXT@: resolver_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ resolver_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

result_test@EXEEXT@: result_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ result_test.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

rsa_test@EXEEXT@: rsa_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ rsa_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

sigs_test@EXEEXT@: sigs_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ sigs_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

time_test@EXEEXT@: time_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ time_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

WRAP_OPTIONS = -Wl,--wrap=isc__mem_put,--wrap=isc__mem_get,--wrap=isc_mem_attach,--wrap=isc_mem_detach
tkey_test@EXEEXT@: tkey_test.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	if test "${LD_WRAP_TESTS}" = true; then WRAP="${WRAP_OPTIONS}"; fi; \
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
			${LDFLAGS} ${WRAP} -o $@ tkey_test.@O@ \
			${DNSLIBS} ${ISCLIBS} ${LIBS}

tsig_test@EXEEXT@: tsig_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ tsig_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

update_test@EXEEXT@: update_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ update_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

zonemgr_test@EXEEXT@: zonemgr_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ zonemgr_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
	${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} \
		${LDFLAGS} -o $@ zt_test.@O@ dnstest.@O@ \
		${DNSLIBS} ${ISCLIBS} ${LIBS}

unit::
	sh ${top_builddir}/unit/unittest.sh

clean distclean::
	rm -f ${TARGETS}
	rm -f atf.out
	rm -f testdata/master/master12.data testdata/master/master13.data \
		testdata/master/master14.data
	rm -f zone.bin
