#-----------------------------------------------------------------------------#
# vim: ts=8 sw=8 noexpandtab ft=make
#-----------------------------------------------------------------------------#

TESTS_DIR = ..
THIS_DIR = invalid_submodule
MAYBE_J1 = -j1

# This directory contains tests for errors in programs in which at least
# one source file contains more than one nested module. We disable
# parallel make with the -j1 above, because if we didn't, we would get
# intermittent failures caused by interface files of nested submodules
# not being ready when another job, executed in parallel by mmake,
# wants to read them.
#
# For multi-module tests (which includes all the tests in this directory)
# we normally need to make the dependencies. However, multi-module tests
# where the error is detected when building the dependencies
# (e.g. duplicate_module_test.m) should be included in DO_NOT_MAKE_DEP_PROGS,
# not MAKE_DEP_PROGS, because we have a specific make rule for them below.

MAKE_DEP_PROGS = \
	exported_unify3 \
	undef_mod_qual \
	unresolved_overloading

DO_NOT_MAKE_DEP_PROGS = \
	duplicate_module_test \
	func_class \
	nested_impl_in_int

# XXX The test cases import_in_parent and subtype_submodule are
# currently disabled, because
#
# - we now discover the errors they reports when making .int files,
#   which would require moving them to invalid_make_int, but
# - this would require adding support for nested submodules to
#   invalid_make_int, and
# - this is not warranted, because the errors they report are tested for
#   elsewhere.

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

PROGS = $(MAKE_DEP_PROGS) $(DO_NOT_MAKE_DEP_PROGS)
TESTS = $(sort $(MAKE_DEP_PROGS) $(DO_NOT_MAKE_DEP_PROGS:%=%-nodepend))
include ../Mmake.common

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

%.runtest: %.err_res ;

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

ifneq ($(MMAKE_USE_MMC_MAKE),yes)

%.err: %.m
	if $(MC) --errorcheck-only $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) $* \
		> $*.err 2>&1; \
	then false; \
	else true; \
	fi

else

% XXX: with `mmake --use-mmc-make' the ".DEFAULT:" rule seems to take
# precedence over "%.err: %.m" rules.
% XXX: the reason we run the $(MCM) command twice is to avoid doubled up
# error messages, once while making interface files, then the module proper.
# The second time the command is run, only one set of error messages
# should appear.
$(addsuffix .err,$(PROGS)):
	-$(MCM) $@
	if $(MCM) -r $@ > /dev/null 2>&1 ; \
	then false; \
	else true; \
	fi

endif

# For these test cases, the bug is caught when generating dependencies,
# so it is easiest just to do that step.
$(addsuffix .err,$(DO_NOT_MAKE_DEP_PROGS)): %.err: %.m
	if $(MC) $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
		--generate-dependencies $* > $*.err 2>&1; \
	then false; \
	else true; \
	fi

$(dates_subdir)undef_mod_qual.date: $(int0s_subdir)undef_mod_qual.int0

clean_local: clean_invalid_submodules

clean_invalid_submodules:
	rm -f *dep_err *.err *.err_res

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