parser: Fix longstanding bug where "()" was required after CLI targets.
[goals.git] / Goalfile.in
1 # Goalfile
2 # Copyright (C) 2019 Richard W.M. Jones
3 # Copyright (C) 2019 Red Hat Inc.
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 include "ocaml.gl"
20
21 let subdirs = [ "m4", "src", "stdlib", "docs", "man", "tests" ]
22
23 goal all = : "Goalfile", tool, documentation;
24
25 "Goalfile": "Goalfile.in", "config.status" {
26     ./config.status %@
27 }
28 "src/config.ml" : "src/config.ml.in", "config.status" {
29     ./config.status %@
30 }
31
32 goal clean = {
33     for d in %subdirs; do
34         pushd $d
35         rm -f *~
36         rm -f *.cmi *.cmo *.cmx *.o
37         popd
38     done
39     rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
40     rm -f man/*.1 man/*.5
41     rm -f tests/*.log
42
43     # We don't delete src/goals because it is required to do builds.
44     # If you want to really delete it, use the maintainer-clean rule.
45 }
46
47 goal maintainer-clean = : clean {
48     rm -f src/goals
49 }
50
51 #----------------------------------------------------------------------
52 # Build the goals tool itself.
53
54 let MENHIR = "@MENHIR@"
55 let OCAMLDEP = "@OCAMLDEP@"
56 let OCAMLFIND = "@OCAMLFIND@"
57 let OCAMLLEX = "@OCAMLLEX@"
58 # XXX
59 let OCAMLFLAGS = [ "-g", "-safe-string", "-warn-error", "CDEFLMPSUVYZX+52-3" ]
60 let OCAMLPACKAGES = [ "-package", "str,unix,threads", "-I", "src", "-thread" ]
61 #let OCAMLFLAGS = "@OCAMLFLAGS@"
62 #let OCAMLPACKAGES = "@OCAMLPACKAGES@"
63
64 let objects = [
65     # These must be in dependency order.
66     "src/config.cmx",
67     "src/utils.cmx",
68     "src/cmdline.cmx",
69     "src/jobs.cmx",
70     "src/ast.cmx",
71     "src/parser.cmx",
72     "src/lexer.cmx",
73     "src/parse.cmx",
74     "src/eval.cmx",
75     "src/deps.cmx",
76     "src/run.cmx",
77     "src/main.cmx"
78 ]
79
80 goal tool = : ocaml_link ("src/goals", objects) ;
81
82 # Parser.
83 "src/parser.mli", "src/parser.ml" : "src/parser.mly" {
84     %MENHIR --explain %<
85     # Hack required to break circular dependencies.
86     echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
87     echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
88 }
89
90 "src/lexer.ml" : "src/lexer.mll" {
91     %OCAMLLEX %<
92 }
93
94 # XXX Goalfile itself depends on this and we should probably have a
95 # way to reevaluate it.
96 # XXX Atomic output.
97 goal depend =
98 "src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
99     rm -f %@ %@-t
100     # Like many existing tools, ocamldep produces make-compatible
101     # output which doesn't work directly in goals.
102     %OCAMLDEP -all -one-line -I src %< |
103         sed 's|[./[:alnum:]]\+|"&"|g' |
104         sed 's|" "|", "|g' |
105         sed 's|.*|& ;|' > %@-t
106     mv %@-t %@
107 }
108
109 -include "src/.depend";
110
111 #----------------------------------------------------------------------
112 # Documentation.
113
114 let POD2MAN = "@POD2MAN@"
115
116 goal documentation = : pod2man ("goals", "1"),
117                        pod2man ("Goalfile", "5"),
118                        pod2man ("goals-reference", "5")
119
120 goal pod2man (page, section) =
121 "man/%page.%section" : "docs/%page.pod" {
122     rm -f %@ %@-t
123     mkdir -p man
124     %POD2MAN \
125         -u \
126         -c "goals" \
127         --release "@PACKAGE_NAME@-@PACKAGE_VERSION@" \
128         --section %section %< > %@-t
129     mv %@-t %@
130 }
131
132 #----------------------------------------------------------------------
133 # Tests.
134
135 let tests = wrap ("test", wildcard ("tests/*.sh"))
136
137 goal check () = : tests
138
139 goal test (name) = @{
140     t=`basename %name`
141     cd tests
142     if ../run ./$t > $t.log 2>&1; then
143         start_green
144         echo -n "PASS: "
145         end_colour
146         echo $t
147     else
148         start_red
149         echo -n "FAIL: "
150         end_colour
151         echo $t
152         exit 1
153     fi
154 }