FRAMAC_TOPLEVEL = @FRAMAC@
FRAMAC_SHARE  = @FRAMAC_SHARE@
FRAMAC_LIBDIR = @FRAMAC_LIBDIR@

PLUGIN_NAME   = Jessie3
MODULES       = literals ACSLtoWhy3 register
TESTS	      = basic demo

WHYLIB  = ../../lib/why3

INCLUDE = -I $(FRAMAC_LIBDIR) -I $(FRAMAC_LIBDIR)/plugins -I +ocamlgraph @ZIPINCLUDE@ @MENHIRINCLUDE@ -I $(WHYLIB)
FLAGS = -w +a-3-4-6-9-41-44-45-48 -annot -bin-annot  -g
OCAMLLEX  = @OCAMLLEX@

all:: Jessie3.cma Jessie3.cmxs

Makefile: Makefile.in ../../config.status
	(cd ../../ ; ./config.status chmod --file src/jessie/Makefile)

literals.ml: literals.mll
	$(OCAMLLEX) $<

Jessie3.cma: $(addsuffix .cmo, $(MODULES))
	ocamlc.opt -a $(FLAGS) $(INCLUDE) -o $@ nums.cma unix.cma dynlink.cma str.cma menhirLib.cmo $(addsuffix .cma, @ZIPLIB@) $(WHYLIB)/why3.cma $^

Jessie3.cmx: $(addsuffix .cmx, $(MODULES))
	ocamlopt.opt $(FLAGS) $(INCLUDE) -o $@ -pack $^

Jessie3.cmxs: Jessie3.cmx
	ocamlopt.opt -shared $(FLAGS) $(INCLUDE) -o $@ nums.cmxa menhirLib.cmx $(addsuffix .cmxa, @ZIPLIB@) $(WHYLIB)/why3.cmxa $^

%.cmi: %.mli
	ocamlc.opt $(FLAGS) $(INCLUDE) -c $^

%.cmo: %.ml
	ocamlc.opt $(FLAGS) $(INCLUDE) -c $^

%.cmx: %.ml
	ocamlopt.opt $(FLAGS) $(INCLUDE) -for-pack Jessie3 -c $^

test.byte:
	frama-c.byte -load-module ./Jessie3.cma -jessie3 tests/basic/forty-two.c
# -kernel-debug 2

test.opt:
	frama-c -load-module ./Jessie3.cmxs -jessie3 tests/basic/forty-two.c
# -kernel-debug 2

.PHONY: tests

tests: tests/ptests_config
	time -p ptests.opt
	grep 'Task\|Ergo' tests/basic/result/*.res.log  tests/demo/result/*.res.log

tests/ptests_config: Makefile
	rm -rf tests/ptests_config
	echo "DEFAULT_SUITES="$(TESTS) > tests/ptests_config
	echo "TOPLEVEL_PATH=$(FRAMAC_TOPLEVEL) -load-module ./Jessie3.cma" >> tests/ptests_config
	echo "FRAMAC_SHARE="$(FRAMAC_SHARE) >> tests/ptests_config
	echo "FRAMAC_PLUGIN=." >> tests/ptests_config
	echo "FRAMAC_PLUGIN_GUI=./gui" >> tests/ptests_config
	echo "FRAMAC_LIB="$(FRAMAC_LIBDIR) >> tests/ptests_config
	echo "OCAMLRUNPARAM=" >> tests/ptests_config
	chmod a-w tests/ptests_config

clean:
	rm -f $(addsuffix .cmi, $(MODULES))
	rm -f $(addsuffix .cmo, $(MODULES))
	rm -f $(addsuffix .cmx, $(MODULES))
	rm -f Jessie3.cma Jessie3.cmxs

register.cmx: ACSLtoWhy3.cmx

register.cmo: ACSLtoWhy3.cmo
