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

THIS_DIR = mmc_make

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

# Any program added here should also be added to the `.cvsignore' file.

MMAKE_USE_MMC_MAKE=yes

PROGS =	\
		complex_test \
		hello \
		linkage_test \
		rebuild

# These tests only work if the workspace was compiled with `--use-subdirs'.
ifneq ($(origin WORKSPACE),undefined)
    ifeq ($(shell [ -d $(WORKSPACE)/library/Mercury ] || echo cannot_run),cannot_run)
	PROGS =
    endif
endif

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

%.runtest: %.res ;

complex_test.log: install_libs

linkage_test.log: install_libs_linkage_test2

# Just test that the executable is rebuilt.
rebuild.runtest:
	$(MCM) --rebuild rebuild
	$(MCM) --rebuild --verbose-make rebuild > rebuild.err2 2>&1
	grep '^Making rebuild\($$\|\.\)' rebuild.err2

# The compiler used to fail when invoked as `mmc --make build_object.o'.
build_object.runtest: build_object.o

.PHONY: install_libs
install_libs: start_runtests_local
	$(MMAKE) TESTS_FLAGS
	( cd lib; \
	$(MCM) --no-libgrade --install-prefix $(shell pwd)/install \
			libcomplex_numbers.install ) \
	|| touch complex_test.failed

.PHONY: install_libs_linkage_test2
install_libs_linkage_test2: start_runtests_local
	$(MMAKE) TESTS_FLAGS
	( cd lib; \
	$(MCM) --no-libgrade --install-prefix $(shell pwd)/install \
			liblinkage_test2.install --lib-linkage static ) \
	|| touch linkage_test.failed

# Copy/symlink TESTS_FLAGS into the current directory for when
# we change into the `lib' subdirectory.
TESTS_FLAGS: ../TESTS_FLAGS
	ln -s $< $@ || cp $< $@

realclean_local: TESTS_FLAGS
	rm -rf install rebuild.err2
	# ./TESTS_FLAGS is expected by the following line.
	cd lib; $(MCM) complex_numbers.realclean linkage_test2.realclean
	rm -f TESTS_FLAGS

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