Commit | Line | Data |
---|---|---|
d6ce1786 C |
1 | #! /bin/sh -e |
2 | ||
3 | set -e | |
feec80c3 C |
4 | |
5 | # If you don't have menhir installed, but you do have the generated files, then | |
6 | # this script fakes menhir by providing the generated files as the result of the | |
7 | # menhir invocation. | |
8 | ||
9 | STATE=0 | |
10 | base= | |
11 | reqml= | |
12 | reqmli= | |
13 | ||
14 | for arg in "$@"; do | |
d6ce1786 | 15 | if test "x$STATE" = x0 -a "x$arg" = "x--base" -o "x$arg" = "x-b"; then |
feec80c3 | 16 | STATE=1 |
d6ce1786 | 17 | elif test "x$STATE" = x1; then |
feec80c3 C |
18 | base="$arg" |
19 | STATE=0 | |
20 | else | |
21 | filename="$arg" | |
22 | basename="${filename%.*}" | |
23 | extension="${filename##*.}" | |
24 | ||
25 | # assumes that all commandline parameters ending in .mly are files to be processed by menhir | |
d6ce1786 | 26 | if test "x$extension" = xmly; then |
feec80c3 C |
27 | reqml="${basename}.ml" |
28 | reqmli="${basename}.mli" | |
29 | ||
30 | # do we have a preprocessed ml file? | |
31 | if test ! -f "$reqml"; then | |
32 | echo "error: the file $reqml is needed, which requires preprocessing by menhir to obtain it from ${filename}. However, menhir is not enabled." 1>&2 | |
33 | exit 1 | |
34 | fi | |
35 | ||
36 | # do we have a preprocessed mli file? | |
37 | if test ! -f "$reqmli"; then | |
38 | echo "error: the files ${basename}.mli is needed, which requires preprocessing by menhir to obtain it from ${filename}. However, menhir is not enabled." 1>&2 | |
39 | exit 1 | |
40 | fi | |
41 | ||
42 | # is the preprocessed file not older than the original source? | |
43 | if test "$reqml" -ot "$filename" -o "$reqmli" -ot "$filename"; then | |
44 | echo "error: ${basename}.ml(i) is older than $filename, which requires preprocessing by menhir to update them from ${filename}. However, menhir is not enabled." 1>&2 | |
45 | exit 1 | |
46 | fi | |
47 | ||
48 | if test -z "$base"; then | |
49 | base="$basename" | |
50 | fi | |
51 | fi | |
52 | fi | |
53 | done | |
54 | ||
55 | if test -n "$reqml" -a -n "$reqmli" -a -n "$base"; then | |
56 | if test "$reqml" != "${base}.ml"; then | |
57 | cp -f "$reqml" "${base}.ml" | |
58 | fi | |
59 | ||
60 | if test "$reqmli" != "${base}.mli"; then | |
61 | cp -f "$reqmli" "${base}.mli" | |
62 | fi | |
63 | ||
64 | touch "${base}.ml" | |
65 | touch "${base}.mli" | |
66 | exit 0 | |
67 | else | |
68 | echo "error: do not know how to handle: $@" 1>&2 | |
69 | exit 1 | |
70 | fi |