#-----------------------------------------------------------------------------#
# Copyright (C) 1997-2002 The University of Melbourne.
# This file may only be copied under the terms of the GNU Library General
# Public License - see the file COPYING.LIB in the Mercury distribution.
#-----------------------------------------------------------------------------#

MAIN_TARGET = all

# We need to use a grade with trailing
GRADEFLAGS += --use-trail

MCFLAGS = --infer-all

# Enable C debugging
CFLAGS=-g
MLFLAGS=-g

# Link in the trailed_update library from ..
MCFLAGS += -I..
CFLAGS += -I..
MLFLAGS += --mercury-libs static
MLOBJS = ../libtrailed_update.a
VPATH = ..:$(MMAKE_VPATH)
C2INITARGS = ../trailed_update.init

# We need the following to use shared libraries on Linux
#CFLAGS += -DPIC_REG
#MLFLAGS += --shared

DIFF_OPTS=-c

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

# The Mmake.params file can be used to override definitions in this file
-include ../../Mmake.params

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

# The "vqueens" program does not work in ".rt" grades,
# since it uses the "var" module which does not work in ".rt" grades.
# The "interpreter" program does not work in ".rt" grades either,
# due to a bug with unification of values of type "store__mutvar" in ".rt"
# grades.
ifeq "$(findstring .rt,$(GRADE))" ".rt"
PROGS	=	
else
PROGS	=	interpreter vqueens
endif

DEPENDS =	$(PROGS:%=%.depend)
CS	=	$(PROGS:%=%.c)
RESS	=	$(PROGS:%=%.res)

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

$(PROGS): ../libtrailed_update.a

%.out: %
	./$< > $@ 2>&1;

%.res: %.exp %.out
	diff $(DIFF_OPTS) $*.exp $*.out > $@

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

interpreter.out: interpreter interpreter.inp
	./interpreter interpreter.m < interpreter.inp > interpreter.out

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

.PHONY: depend
depend: $(DEPENDS)

.PHONY: all
all: $(PROGS)

.PHONY: check
check: $(RESS)

.PHONY: cs
cs: $(CS)

.PHONY: clean_local
clean_local:
	rm -f *.out *.res

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