Makefile 2.3 KB
Newer Older
1
2
.PHONY: clean test expected

3
4
5
6
7
# Note that there is potential confusion between src/_stage1/menhir
# and src/_stage2/menhir. Here, we use the latter (built by "make
# bootstrap" in the src/ directory). But typing "make" in the src/
# directory re-builds only the former.

8
9
SHELL=/bin/bash
SRC=../../src
10
MENHIR=$(SRC)/_stage2/menhir.native --dump --explain --stdlib $(SRC)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
CAMLC           := $(shell if ocamlfind ocamlc -v >/dev/null 2>&1 ; \
                       then echo ocamlfind ocamlc ; \
		       elif ocamlc.opt -v >/dev/null 2>&1 ; \
                       then echo ocamlc.opt ; \
		       else echo ocamlc ; fi)

# La convention de nommage des tests multi-grammaires
# est : /nom/-[1-9].mly
TESTS=$(shell ls | egrep '*([1]|[^2-9]).mly')
RESULTS=$(TESTS:.mly=.result)

test: clean $(RESULTS)
	@ if test -e failed_files; then		\
		echo FAILED ON: ;		\
		cat failed_files;		\
		exit 1;				\
	 fi

29
30
31
# The file %.result   stores the output of menhir --only-preprocess.
# The file %.expected stores its expected output.

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%.result: %.mly
	@ if echo $< | grep -e "-1.mly" &> /dev/null; then		\
		export BASE=`echo $< | sed s/"-1.mly"/""/`;		\
		export FILES=`echo $$BASE-[1-9].mly`;			\
		export CMD="$$FILES --base $$BASE";			\
	else								\
		export FILES="$<";					\
		export BASE=`echo $< | sed s/".mly"/""/`;		\
		export CMD="$<";					\
	fi;								\
	$(SHELL) -c '$(MENHIR) --only-preprocess $$CMD >& $@';		\
	if [ x$$CREATE_EXPECTED == x"1" ]; then				\
		cp $@ $*.expected;					\
	fi;								\
	if test -e $*.expected; then					\
	   if diff $@ $*.expected >& /dev/null; then			\
		if $(MENHIR) $$CMD >& /dev/null; then			\
			echo "[OK] $$FILES";				\
		else							\
51
			echo "-> [KO] menhir failed on $$FILES";	\
52
53
54
55
56
57
58
			export FAILED_FILES="$$FAILED_FILES $$FILES";	\
		fi;							\
	   else								\
		echo "-> [KO] menhir front-end failed on $$FILES";	\
		echo "  $$FILES" >> failed_files;			\
	   fi;								\
	else								\
59
	  echo "Warning: missing file $*.expected"; 			\
60
61
62
63
64
65
66
67
68
69
70
71
72
	fi;								\

expected:
	@ echo "Are you sure ? (this will erase *.expected) [Press ENTER]"
	@ read
	@ mkdir -p /tmp/mini-expected
	@ cp *.expected /tmp/mini-expected >& /dev/null || true
	@ CREATE_EXPECTED=1 $(MAKE) -s test
	@ echo "Expected output re-generated."

clean:
	rm -f *.ml *.mli *.conflicts *.automaton *.cmi *.cmo *.cmx *.o *.s *.result *~ failed_files