#-----------------------------------------------------------------------------#

THIS_DIR = warnings

#-----------------------------------------------------------------------------#

COMPILE_PROGS=	\
	arg_order_rearrangment \
	foreign_term_invalid \
	non_term_user_special \
	pragma_term_conflict \
	term_indirect_warning \
	warn_dead_procs

ERRORCHECK_PROGS= \
	ambiguous_overloading \
	bug257 \
	det_infer_warning \
	double_underscore \
	duplicate_call \
	duplicate_const \
	inf_recursion_lambda \
	inference_test \
	infinite_recursion \
	inst_with_no_type \
	missing_if \
	non_stratification \
	pragma_source_file \
	purity_warnings \
	simple_code \
	singleton_test \
	spurious_obsolete \
	state_vars_test \
	table_with_inline \
	unify_f_g \
	unused_args_test \
	unused_import \
	unused_interface_import \
	warn_contiguous_foreign \
	warn_non_contiguous \
	warn_non_contiguous_foreign \
	warn_non_contiguous_foreign_group \
	warn_return \
	warn_succ_ind \
	warn_stubs

# We don't yet pass (or even have a .exp file for) this test.
#	trace_goal_dupl_defn

ifeq ($(MMAKE_USE_MMC_MAKE),yes)
ERRORCHECK_PROGS += unused_args_analysis
endif

PROGS=$(COMPILE_PROGS) $(ERRORCHECK_PROGS) up_to_date

TESTS = $(sort $(PROGS))
SUBDIRS =
TESTS_DIR = ..
include $(TESTS_DIR)/Mmake.common

# Module-specific options should go in Mercury.options so they
# can be found by `mmc --make'.
include Mercury.options

# With `mmc --make', the errors should only go to the 
# `.err' files, not stderr.
MCFLAGS += --output-compile-error-lines 0

MCFLAGS += --infer-all

$(COMPILE_PROGS:%=%.runtest): %.runtest: %.res_compile ;

$(ERRORCHECK_PROGS:%=%.runtest): %.runtest: %.res_error ;

# Build the `.analysis' file for unused_args_analysis2
# before building unused_args_analysis.c.
unused_args_analysis.c: unused_args_analysis2.c
unused_args_analysis.err: unused_args_analysis.c

# Check that `mmc --make up_to_date.m' generates a warning.
up_to_date.runtest:
	$(MCM) up_to_date.m > up_to_date.err_make 2>&1
	diff $(DIFF_OPTS) up_to_date.exp up_to_date.err_make \
		> up_to_date.res_make || \
		{ cat up_to_date.err_make; cat up_to_date.res_make; exit 1; }

#-----------------------------------------------------------------------------#

%.res_error:	%.exp %.err
	-rm -f $@
	diff $(DIFF_OPTS) $*.exp $*.err > $@ || \
                { [ -f $*.exp2 ] && \
                  diff $(DIFF_OPTS) $*.exp2 $*.err > $@; } || \
                { [ -f $*.exp3 ] && \
                  diff $(DIFF_OPTS) $*.exp3 $*.err > $@; } || \
                { [ -f $*.exp4 ] && \
                  diff $(DIFF_OPTS) $*.exp4 $*.err > $@; } || \
                { cat $*.err; cat $@; exit 1; }

%.res_compile:	%.exp %.c
	-rm -f $@
	diff $(DIFF_OPTS) $*.exp $*.err > $@ || \
                { [ -f $*.exp2 ] && \
                  diff $(DIFF_OPTS) $*.exp2 $*.err > $@; } || \
                { [ -f $*.exp3 ] && \
                  diff $(DIFF_OPTS) $*.exp3 $*.err > $@; } || \
                { [ -f $*.exp4 ] && \
                  diff $(DIFF_OPTS) $*.exp4 $*.err > $@; } || \
                { cat $*.err; cat $@; exit 1; }

ifeq ($(MMAKE_USE_MMC_MAKE),yes)
%.c: %.m
	$(MCM) $@
endif

#-----------------------------------------------------------------------------#

clean_local:	clean_err clean_res

clean_err:
	rm -f *.err up_to_date.err_make

#-----------------------------------------------------------------------------#
