build: Create dependencies for Goalfile itself.
[goals.git] / Goalfile.in
index 0bc2550..88e0684 100644 (file)
@@ -1,4 +1,4 @@
-# Goalfile parser
+# Goalfile
 # Copyright (C) 2019 Richard W.M. Jones
 # Copyright (C) 2019 Red Hat Inc.
 #
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
+include "ocaml.gl"
+
+let MENHIR = "@MENHIR@"
+let OCAMLDEP = "@OCAMLDEP@"
+let OCAMLFIND = "@OCAMLFIND@"
+let OCAMLLEX = "@OCAMLLEX@"
+# XXX
+let OCAMLFLAGS = [ "-g", "-safe-string", "-warn-error", "CDEFLMPSUVYZX+52-3" ]
+let OCAMLPACKAGES = [ "-package", "str,unix", "-I", "src" ]
+#let OCAMLFLAGS = "@OCAMLFLAGS@"
+#let OCAMLPACKAGES = "@OCAMLPACKAGES@"
+
+let objects = [
+    "src/config.cmx",
+    "src/utils.cmx",
+    "src/cmdline.cmx",
+    "src/ast.cmx",
+    "src/eval.cmx",
+    "src/run.cmx",
+    "src/parser.cmx",
+    "src/lexer.cmx",
+    "src/parse.cmx",
+    "src/main.cmx"
+]
+
+let subdirs = [ "m4", "src", "stdlib", "tests" ]
+
+goal all = : "Goalfile", ocaml_link ("src/goals", objects)
+
+goal clean = {
+    for d in %subdirs; do
+        pushd $d
+        rm -f *~
+        rm -f *.cmi *.cmo *.cmx *.o
+        popd
+    done
+    rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
+
+    # We don't delete src/goals because it is required to do builds.
+    # If you want to really delete it, use the maintainer-clean rule.
+}
+
+goal maintainer-clean = : clean {
+    rm -f src/goals
+}
+
+"src/parser.mli", "src/parser.ml" : "src/parser.mly" {
+    %MENHIR --explain %<
+    # Hack required to get includes working.
+    echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' \
+        >> src/parser.mli
+}
+
+"src/lexer.ml" : "src/lexer.mll" {
+    %OCAMLLEX %<
+}
+
+# XXX Goalfile itself depends on this and we should probably have a
+# way to reevaluate it.
+# XXX Atomic output.
+goal depend () =
+"src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
+    rm -f %@ %@-t
+    # Like many existing tools, ocamldep produces make-compatible
+    # output which doesn't work directly in goals.
+    %OCAMLDEP -all -one-line -I src %< |
+        sed 's|[./[:alnum:]]\+|"&"|g' |
+        sed 's|" "|", "|g' |
+        sed 's|.*|& ;|' > %@-t
+    mv %@-t %@
+}
+
+-include "src/.depend";
+
+"Goalfile": "Goalfile.in", "config.status" {
+    ./config.status %@
+}
+"src/config.ml" : "src/config.ml.in", "config.status" {
+    ./config.status %@
+}