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