# Kit of the case study mcfsi0_factorial1: the C algorithm generated by eb2pcal from Event-B
CC      ?= cc
CFLAGS  ?= -std=c99 -Wall -Wextra -O1
FRAMAC  ?= frama-c
PROVERS ?= alt-ergo,z3

run: mcfsi0_factorial1.c mcfsi0_factorial1_spec.c main.c mcfsi0_factorial1.h
	$(CC) $(CFLAGS) -o run mcfsi0_factorial1.c mcfsi0_factorial1_spec.c main.c

# run the algorithm on the examples of main.c (or with given parameters: make test ARGS="5")
test: run
	./run $(ARGS)

WP      = $(FRAMAC) -wp -wp-prover $(PROVERS) -wp-timeout 10 -wp-prop=-@lemma

# proof of the contract and of the annotations with Frama-C/WP
wp:
	$(WP) mcfsi0_factorial1.c

# only the verification conditions that are not proved (hypotheses, goal, provers)
wp-unproved:
	$(WP) -wp-status mcfsi0_factorial1.c 2>&1 | sed -n '/^Goal /,$$p'

# one line per verification condition that is not proved
wp-list:
	@$(WP) mcfsi0_factorial1.c 2>&1 | grep -E '\[(Timeout|Unknown|Failed)\]' || echo "every verification condition is proved"

# status of every property in vc.csv; prints those that are not proved
wp-report:
	@$(WP) mcfsi0_factorial1.c -then -report -report-csv vc.csv > /dev/null 2>&1; \
	  awk -F'\t' 'NR>1 && $$6=="Unknown"' vc.csv | cut -f3,5,6,7

# text of every verification condition (proved or not)
wp-print:
	$(WP) -wp-print -wp-status-all mcfsi0_factorial1.c

clean:
	rm -f run *.o vc.csv
