#!/usr/bin/make -f

CPPFLAGS = -std=gnu++11 -DNDEBUG -DSTD_RECINT_SIZE=8
LIBS = $(shell pkg-config givaro --libs)

TESTS = test-random    \
	test-ifactor   \
	test-ffarith   \
	test-ringarith \
	test-mod       \
	test-modsqroot \
	test-trunc     \
	test-poly       \
	test-crt       \
	test-geom      \
	test-integer   \
	test-conversion \
	test-ratrecon \
	test-modularmulprecomp \
	test-rmint_arith_addmul_mg   \
	test-rmint_arith_addmul      \
	test-ruint_arith_addmul      \
	test-rmint_arith_add_mg      \
	test-rmint_arith_add         \
	test-ruint_arith_add         \
	test-rint_arith_add          \
	test-rmint_arith_sub_mg      \
	test-rmint_arith_sub         \
	test-ruint_arith_sub         \
	test-rint_arith_sub          \
	test-rmint_arith_mul_mg      \
	test-rmint_arith_mul         \
	test-ruint_arith_mul         \
	test-rint_arith_mul          \
	test-rmint_arith_mod_mg      \
	test-rmint_arith_mod         \
	test-ruint_arith_div         \
	test-rint_arith_mod          \
	test-rmint_inv_div_mg        \
	test-rmint_inv_div           \
	test-rmint_constructors_mg   \
	test-rmint_constructors      \
	test-rmint_neg_mg            \
	test-rmint_neg               \
	test-rmint_comparisons_mg    \
	test-rmint_comparisons       \
	test-rmint_complex_mg        \
	test-rmint_complex           \
	test-recint_rand_mg          \
	test-recint_rand             \
	test-recint_exp_mg           \
	test-recint_exp              \
	test-recint_extra_mg         \
	test-recint_extra            \
	test-recint_convert_mg       \
	test-recint_convert          \
	test-recint_cast             \
	test-rmint_montgomery        \
	test-ruint_arazi             \
	test-ruint_comparisons       \
	test-ruint_complex           \
	test-ruint_constructors      \
	test-ruint_fiddling          \
	test-ruint_lmul              \
	test-ruint_operators         \
	test-ruint_shift             \
	test-ruint_square

test-random_SOURCES   = test-random.C
test-ifactor_SOURCES  = test-ifactor.C
test-ffarith_SOURCES  = test-ffarith.C
test-ringarith_SOURCES= test-ringarith.C
test-modularmulprecomp_SOURCES= test-modularmulprecomp.C
test-mod_SOURCES      = test-mod.C
test-modsqroot_SOURCES= test-modsqroot.C
test-trunc_SOURCES    = test-trunc.C
test-poly_SOURCES    = test-poly.C
test-crt_SOURCES      = test-crt.C
test-geom_SOURCES     = test-geom.C
test-integer_SOURCES  = test-integer.C
test-ratrecon_SOURCES = test-ratrecon.C
test-conversion_SOURCES = test-conversion.C

test-rmint_arith_addmul_mg_SOURCES   = test-rmint_arith.C
test-rmint_arith_addmul_SOURCES      = test-rmint_arith.C
test-ruint_arith_addmul_SOURCES      = test-ruint_arith.C
test-rmint_arith_add_mg_SOURCES      = test-rmint_arith.C
test-rmint_arith_add_SOURCES         = test-rmint_arith.C
test-ruint_arith_add_SOURCES         = test-ruint_arith.C
test-rint_arith_add_SOURCES          = test-rint_arith.C
test-rmint_arith_sub_mg_SOURCES      = test-rmint_arith.C
test-rmint_arith_sub_SOURCES         = test-rmint_arith.C
test-ruint_arith_sub_SOURCES         = test-ruint_arith.C
test-rint_arith_sub_SOURCES          = test-rint_arith.C
test-rmint_arith_mul_mg_SOURCES      = test-rmint_arith.C
test-rmint_arith_mul_SOURCES         = test-rmint_arith.C
test-ruint_arith_mul_SOURCES         = test-ruint_arith.C
test-rint_arith_mul_SOURCES          = test-rint_arith.C
test-rmint_arith_mod_mg_SOURCES      = test-rmint_arith.C
test-rmint_arith_mod_SOURCES         = test-rmint_arith.C
test-ruint_arith_div_SOURCES         = test-ruint_arith.C
test-rint_arith_mod_SOURCES          = test-rint_arith.C

test-rmint_inv_div_mg_SOURCES        = test-rmint_inv_div.C
test-rmint_inv_div_SOURCES           = test-rmint_inv_div.C
test-rmint_constructors_mg_SOURCES   = test-rmint_constructors.C
test-rmint_constructors_SOURCES      = test-rmint_constructors.C
test-rmint_neg_mg_SOURCES            = test-rmint_neg.C
test-rmint_neg_SOURCES               = test-rmint_neg.C
test-rmint_comparisons_mg_SOURCES    = test-rmint_comparisons.C
test-rmint_comparisons_SOURCES       = test-rmint_comparisons.C
test-rmint_complex_mg_SOURCES        = test-rmint_complex.C
test-rmint_complex_SOURCES           = test-rmint_complex.C
test-recint_rand_mg_SOURCES          = test-recint_rand.C
test-recint_rand_SOURCES             = test-recint_rand.C
test-recint_exp_mg_SOURCES           = test-recint_exp.C
test-recint_exp_SOURCES              = test-recint_exp.C
test-recint_extra_mg_SOURCES         = test-recint_extra.C
test-recint_extra_SOURCES            = test-recint_extra.C
test-recint_convert_mg_SOURCES       = test-recint_convert.C
test-recint_convert_SOURCES          = test-recint_convert.C

test-recint_cast_SOURCES         = test-recint_cast.C
test-rmint_montgomery_SOURCES    = test-rmint_montgomery.C
test-ruint_arazi_SOURCES         = test-ruint_arazi.C
test-ruint_comparisons_SOURCES   = test-ruint_comparisons.C
test-ruint_complex_SOURCES       = test-ruint_complex.C
test-ruint_constructors_SOURCES  = test-ruint_constructors.C
test-ruint_fiddling_SOURCES      = test-ruint_fiddling.C
test-ruint_lmul_SOURCES          = test-ruint_lmul.C
test-ruint_operators_SOURCES     = test-ruint_operators.C
test-ruint_shift_SOURCES         = test-ruint_shift.C
test-ruint_square_SOURCES        = test-ruint_square.C

test-rmint_arith_addmul_mg_CPPFLAGS  = -DMG_DEFAULT=MG_ACTIVE -DNOT_IN_PLACE -DRI_OP=addmul -DGMP_OP=mpz_addmul -DGMP_OPUI=mpz_addmul_ui
test-rmint_arith_addmul_CPPFLAGS     = -DNOT_IN_PLACE -DRI_OP=addmul -DGMP_OP=mpz_addmul -DGMP_OPUI=mpz_addmul_ui
test-ruint_arith_addmul_CPPFLAGS     = -DNOT_IN_PLACE -DRI_OP=addmul -DGMP_OP=mpz_addmul -DGMP_OPUI=mpz_addmul_ui
test-rmint_arith_add_mg_CPPFLAGS     = -DMG_DEFAULT=MG_ACTIVE -DRI_OP=add -DGMP_OP=mpz_add -DGMP_OPUI=mpz_add_ui
test-rmint_arith_add_CPPFLAGS        = -DRI_OP=add -DGMP_OP=mpz_add -DGMP_OPUI=mpz_add_ui
test-ruint_arith_add_CPPFLAGS        = -DRI_OP=add -DGMP_OP=mpz_add -DGMP_OPUI=mpz_add_ui
test-rint_arith_add_CPPFLAGS         = -DRI_OP=add -DGMP_OP=mpz_add -DGMP_OPUI=mpz_add_ui
test-rmint_arith_sub_mg_CPPFLAGS     = -DMG_DEFAULT=MG_ACTIVE -DRI_OP=sub -DGMP_OP=mpz_sub -DGMP_OPUI=mpz_sub_ui
test-rmint_arith_sub_CPPFLAGS        = -DRI_OP=sub -DGMP_OP=mpz_sub -DGMP_OPUI=mpz_sub_ui
test-ruint_arith_sub_CPPFLAGS        = -DRI_OP=sub -DGMP_OP=mpz_sub -DGMP_OPUI=mpz_sub_ui
test-rint_arith_sub_CPPFLAGS         = -DRI_OP=sub -DGMP_OP=mpz_sub -DGMP_OPUI=mpz_sub_ui
test-rmint_arith_mul_mg_CPPFLAGS     = -DMG_DEFAULT=MG_ACTIVE -DRI_OP=mul -DGMP_OP=mpz_mul -DGMP_OPUI=mpz_mul_ui
test-rmint_arith_mul_CPPFLAGS        = -DRI_OP=mul -DGMP_OP=mpz_mul -DGMP_OPUI=mpz_mul_ui
test-ruint_arith_mul_CPPFLAGS        = -DRI_OP=mul -DGMP_OP=mpz_mul -DGMP_OPUI=mpz_mul_ui
test-rint_arith_mul_CPPFLAGS         = -DRI_OP=mul -DGMP_OP=mpz_mul -DGMP_OPUI=mpz_mul_ui
test-rmint_arith_mod_mg_CPPFLAGS     = -DMG_DEFAULT=MG_ACTIVE -DRI_OP=mod -DGMP_OP=mpz_mod -DGMP_OPUI=mpz_mod_ui
test-rmint_arith_mod_CPPFLAGS        = -DRI_OP=mod -DGMP_OP=mpz_mod -DGMP_OPUI=mpz_mod_ui
test-ruint_arith_div_CPPFLAGS        = -DNOT_IN_PLACE -DRI_OP=div_q -DGMP_OP=mpz_fdiv_q -DGMP_OPUI=mpz_fdiv_q_ui
test-rint_arith_mod_CPPFLAGS         = -DARITH_MOD -DNOT_IN_PLACE -DRI_OP=div_r -DGMP_OP=mpz_tdiv_r

test-rmint_inv_div_mg_CPPFLAGS        = -DMG_DEFAULT=MG_ACTIVE
test-rmint_constructors_mg_CPPFLAGS   = -DMG_DEFAULT=MG_ACTIVE
test-rmint_neg_mg_CPPFLAGS            = -DMG_DEFAULT=MG_ACTIVE
test-rmint_comparisons_mg_CPPFLAGS    = -DMG_DEFAULT=MG_ACTIVE
test-rmint_complex_mg_CPPFLAGS        = -DMG_DEFAULT=MG_ACTIVE
test-recint_rand_mg_CPPFLAGS          = -DMG_DEFAULT=MG_ACTIVE
test-recint_exp_mg_CPPFLAGS           = -DMG_DEFAULT=MG_ACTIVE
test-recint_extra_mg_CPPFLAGS         = -DMG_DEFAULT=MG_ACTIVE
test-recint_convert_mg_CPPFLAGS       = -DMG_DEFAULT=MG_ACTIVE


all: $(TESTS)
	@PASS=0; \
	FAIL=0; \
	for TEST in $(TESTS); \
	do \
		./$$TEST > /dev/null ; \
		if [ $$? = 0 ]; \
		then \
		echo "PASS: $$TEST"; \
		PASS=$$(($$PASS+1)); \
	else \
		echo "FAIL: $$TEST"; \
		FAIL=$$(($$FAIL+1)); \
	fi; \
	done; \
	echo "========"; \
	echo "Summary:"; \
	echo "========"; \
	echo "PASS: $$PASS"; \
	echo "FAIL: $$FAIL"; \
	rm -f $(TESTS) *.o; \
	exit $$FAIL

$(TESTS):
	g++ $(CPPFLAGS) $($@_CPPFLAGS) tests/$($@_SOURCES) $(LIBS) -o $@
