d38e70f8ac73ba0540ff61d10812fae82b7233c5
[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 CC = "@CC@"
55 let OCAMLLIB = "@OCAMLLIB@"
56 let MENHIR = "@MENHIR@"
57 let OCAMLDEP = "@OCAMLDEP@"
58 let OCAMLFIND = "@OCAMLFIND@"
59 let OCAMLLEX = "@OCAMLLEX@"
60 # XXX
61 let CFLAGS = [ "-g", "-O2", "-I%OCAMLLIB", "-I." ]
62 #let CFLAGS = "@CFLAGS@ -I%OCAMLLIB -I."
63 let OCAMLFLAGS = [ "-g", "-safe-string", "-warn-error", "CDEFLMPSUVYZX+52-3" ]
64 let OCAMLPACKAGES = [ "-package", "str,unix,threads", "-I", "src", "-thread" ]
65 #let OCAMLFLAGS = "@OCAMLFLAGS@"
66 #let OCAMLPACKAGES = "@OCAMLPACKAGES@"
67
68 let objects = [
69     # These must be in dependency order.
70     "src/config.cmx",
71     "src/utils-c.o",
72     "src/utils.cmx",
73     "src/cmdline.cmx",
74     "src/jobs.cmx",
75     "src/ast.cmx",
76     "src/parser.cmx",
77     "src/lexer.cmx",
78     "src/parse.cmx",
79     "src/eval.cmx",
80     "src/deps.cmx",
81     "src/run.cmx",
82     "src/main.cmx"
83 ]
84
85 goal tool = : ocaml_link ("src/goals", objects) ;
86
87 # C code.
88 "src/utils-c.o" : "src/utils-c.c" {
89     %CC %CFLAGS -c %< -o %@
90 }
91
92 # Parser.
93 "src/parser.mli", "src/parser.ml" : "src/parser.mly" {
94     %MENHIR --explain %<
95     # Hack required to break circular dependencies.
96     echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
97     echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
98 }
99
100 "src/lexer.ml" : "src/lexer.mll" {
101     %OCAMLLEX %<
102 }
103
104 # XXX Goalfile itself depends on this and we should probably have a
105 # way to reevaluate it.
106 # XXX Atomic output.
107 goal depend =
108 "src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
109     rm -f %@ %@-t
110     # Like many existing tools, ocamldep produces make-compatible
111     # output which doesn't work directly in goals.
112     %OCAMLDEP -all -one-line -I src %< |
113         sed 's|[./[:alnum:]]\+|"&"|g' |
114         sed 's|" "|", "|g' |
115         sed 's|.*|& ;|' > %@-t
116     mv %@-t %@
117 }
118
119 -include "src/.depend";
120
121 #----------------------------------------------------------------------
122 # Documentation.
123
124 let POD2MAN = "@POD2MAN@"
125
126 goal documentation = : pod2man ("goals", "1"),
127                        pod2man ("Goalfile", "5"),
128                        pod2man ("goals-reference", "5")
129
130 goal pod2man (page, section) =
131 "man/%page.%section" : "docs/%page.pod" {
132     rm -f %@ %@-t
133     mkdir -p man
134     %POD2MAN \
135         -u \
136         -c "goals" \
137         --release "@PACKAGE_NAME@-@PACKAGE_VERSION@" \
138         --section %section %< > %@-t
139     mv %@-t %@
140 }
141
142 #----------------------------------------------------------------------
143 # Tests.
144
145 let tests = wrap ("test", wildcard ("tests/*.sh"))
146
147 goal check () = : tests
148
149 goal test (name) = @{
150     t=`basename %name`
151     cd tests
152     if ../run ./$t > $t.log 2>&1; then
153         start_green
154         echo -n "PASS: "
155         end_colour
156         echo $t
157     else
158         start_red
159         echo -n "FAIL: "
160         end_colour
161         echo $t
162         exit 1
163     fi
164 }