+# If src/goals doesn't exist then brute-force build it. Once we have
+# src/goals we can rebuild it and other parts of the project using
+# goals itself (see Goalfile.in).
+
+MENHIR = @MENHIR@
+OCAMLDEP = @OCAMLDEP@
+OCAMLFIND = @OCAMLFIND@
+OCAMLLEX = @OCAMLLEX@
+OCAMLFLAGS = @OCAMLFLAGS@
+OCAMLPACKAGES = @OCAMLPACKAGES@
+
+src/goals:
+ $(MENHIR) --explain src/parser.mly
+# Hack required to break circular dependencies.
+ echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
+ echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
+ $(OCAMLLEX) src/lexer.mll
+ $(OCAMLFIND) opt $(OCAMLFLAGS) $(OCAMLPACKAGES) -I src \
+ $$($(OCAMLDEP) -sort src/*.mli src/*.ml) \
+ -linkpkg -o $@
+
+# These rules are required by autoconf.