#**************************************************************************
#*                                                                        *
#*                                 OCaml                                  *
#*                                                                        *
#*                 Xavier Clerc, SED, INRIA Rocquencourt                  *
#*                                                                        *
#*   Copyright 2010 Institut National de Recherche en Informatique et     *
#*     en Automatique.                                                    *
#*                                                                        *
#*   All rights reserved.  This file is distributed under the terms of    *
#*   the GNU Lesser General Public License version 2.1, with the          *
#*   special exception on linking described in the file LICENSE.          *
#*                                                                        *
#**************************************************************************

.PHONY: default
default: compile

# See run-file in Makefile.several for the use of mktemp
.PHONY: compile
compile:
	@for file in *.ml; do \
	  printf " ... testing '$$file'"; \
	  if [ `echo $$file | grep principal` ]; \
	  then PRIN="-principal -w +18+19 -warn-error A"; \
	  else PRIN=""; fi; \
	  if [ `echo $$file | grep bad` ]; then \
	    $(OCAMLC) -c -w a $$PRIN $$file 2>/dev/null \
            && echo " => failed" || echo " => passed"; \
	  else \
	    F="`basename $$file .ml`"; \
	    test -f $$F.mli && $(OCAMLC) -c -w a $$PRIN $$F.mli; \
	    $(OCAMLC) -c -w a $$PRIN $$file 2>/dev/null \
	    && if [ -f $$F.reference ]; then \
	         test -e program.byte.exe && { \
	           T="`mktemp -p .`"; \
	           mv -f program.byte.exe "$$T"; \
	           rm -f "$$T"; \
	         } ; \
	         rm -f program.byte program.byte.exe; \
	         $(OCAMLC) $$F.cmo -o program.byte$(EXE) \
	         && $(OCAMLRUN) program.byte$(EXE) >$$F.result \
	         && $(DIFF) $$F.reference $$F.result >/dev/null; \
	       fi \
	    && echo " => passed" || echo " => failed"; \
	  fi; \
	done

.PHONY: promote
promote: defaultpromote

.PHONY: clean
clean: defaultclean
	@rm -f program.byte program.byte.exe *.cm* *.result
