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

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
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)

17
18
# Some tests involve several input files. The naming convention for
# these tests is /name/-[1-9].mly.
19
TESTS=$(shell ls *.mly | egrep '.*([1]|[^2-9]).mly')
20
RESULTS=$(TESTS:.mly=.opp.out)
21
22

test: clean $(RESULTS)
23
24
25
26
	@ if test -e warnings; then \
	  echo WARNINGS: ; \
	  cat warnings; \
	fi
27
28
29
30
31
	@ if test -e failures; then \
	  echo FAILURES: ; \
	  cat failures;	\
	  exit 1; \
	fi
32

33
34
# The file %.opp.out   stores the output of menhir --only-preprocess.
# The file %.opp.exp stores its expected output.
35
# The file %.out      stores the output of menhir.
36
# The file %.exp      stores its expected output.
37

38
%.opp.out: %.mly
39
	@ if echo $< | grep -e "-1.mly" &> /dev/null; then		\
40
41
42
	  export BASE=`echo $< | sed s/"-1.mly"/""/`;			\
	  export FILES=`echo $$BASE-[1-9].mly`;				\
	  export CMD="$$FILES --base $$BASE";				\
43
	else								\
44
45
46
	  export FILES="$<";						\
	  export BASE=`echo $< | sed s/".mly"/""/`;			\
	  export CMD="$<";						\
47
48
49
	fi;								\
	$(SHELL) -c '$(MENHIR) --only-preprocess $$CMD >& $@';		\
	if [ x$$CREATE_EXPECTED == x"1" ]; then				\
50
	  cp $@ $*.opp.exp;						\
51
	fi;								\
52
53
	if test -e $*.opp.exp; then					\
	  if diff $@ $*.opp.exp >& /dev/null; then			\
54
	    if $(MENHIR) --explain $$CMD >& $*.out; then		\
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
	      if [ x$$CREATE_EXPECTED == x"1" ]; then			\
		cp $*.out $*.exp;					\
	      fi;							\
	      if test -e $*.exp; then					\
	        if ! diff $*.exp $*.out >& /dev/null; then (		\
		  echo "-> [KO] $$FILES:";				\
		  echo "   menhir produced wrong output.";		\
	          echo "   diff $*.exp $*.out";				\
	        ) | tee -a failures;					\
	        else							\
	          echo "[OK] $$FILES";					\
	        fi;							\
	      else							\
	        echo "Warning: missing file: $*.exp" | tee -a warnings; \
	      fi;							\
70
71
72
73
74
	    else							\
	      if ! grep $* 00KNOWN_FAILURES >& /dev/null; then (	\
	        echo "-> [KO] $$FILES:";				\
	        echo "   menhir --only-preprocess succeeded,"; 		\
	        echo "   but menhir failed."; 				\
75
	        echo "   more $*.out";					\
76
77
78
79
80
	      ) | tee -a failures; 					\
	      else                                                      \
	        echo "-> [KO] $$FILES:";				\
	        echo "   known failure.";				\
	      fi;							\
81
82
83
84
	    fi;								\
	  else (							\
	    echo "-> [KO] $$FILES:";					\
	    echo "   menhir --only-preprocess produced wrong output."; 	\
85
	    echo "   diff $*.opp.exp $@";				\
86
87
	  ) | tee -a failures;						\
	  fi;								\
88
	else								\
89
	  echo "Warning: missing file: $*.opp.exp" | tee -a warnings; 	\
90
91
92
	fi;								\

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

100
clean::
101
102
	rm -f *~
	rm -f *.ml *.mli *.conflicts *.automaton
103
	rm -f *.out failures warnings
104

105
106
107
# ------------------------------------------------------------------------------
# Testing LRijkstra, that is, menhir --list-errors.

108
ifeq ($(shell hostname),teraram)
POTTIER Francois's avatar
POTTIER Francois committed
109
110
  TIMEOUT  := 1200
  PARALLEL := -j30
111
112
113
114
else
  TIMEOUT  := 2
  PARALLEL := -j4
endif
115
116
117
118
119
120
121
122

SINGLE    = $(shell ls *.mly | egrep -v '.*-([1-9]).mly')

%.log: %.mly
	@ echo "Now dealing with: $<" | tee -a $@
	@ if (timeout $(TIMEOUT) $(MENHIR) --list-errors -la 2 --lalr $<) >>$@ 2>&1 ; then \
	    echo "$<: success." | tee -a $@ ; \
          else \
POTTIER Francois's avatar
POTTIER Francois committed
123
	    echo "$<: TIMEOUT (or failure)." | tee -a $@ ; \
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
	  fi

list:
# Compile Menhir.
#	make -C $(SRC) clean
	make -C $(SRC) bootstrap
# Remove any leftover output files.
	rm -f *.log lr.csv
# Print the header of lr.csv. (This should be kept in sync with LRijkstra.ml.)
	echo "grammar,terminals,nonterminals,size,states,trie,facts,edges,time,heap" > lr.csv
# Try every grammar. (Only the single-file grammars, that is.)
# This can proceed in parallel, for a reasonable number of processes.
# Each process appends one line of data to lr.csv when it finishes.
# Hopefully the final content of lr.csv will be a reasonable interleaving
# of these lines.
139
	@ time $(MAKE) $(PARALLEL) $(patsubst %.mly,%.log,$(SINGLE))
140
141
142
143
144
# Finished.
	@ echo "Number of grammars that could not be handled in $(TIMEOUT) seconds:"
	@ grep TIMEOUT *.log | wc -l
	@ echo "Number of grammars that were successfully handled:"
	@ tail -n +2 lr.csv  | wc -l
145
146
147
148
149

clean::
	rm -f *.log
#	rm -f lr.csv