4a613c426568f15f3ef183dc29c60cb3b2cc9c45
[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 let CFLAGS = join (split ("@CFLAGS@"), ["-I%OCAMLLIB", "-I."])
63 let OCAMLFLAGS = split ("@OCAMLFLAGS@")
64 let OCAMLPACKAGES = join (split ("@OCAMLPACKAGES@"), ["-I", "src"])
65
66 let objects = [
67     # These must be in dependency order.
68     "src/config.cmx",
69     "src/utils-c.o",
70     "src/utils.cmx",
71     "src/cmdline.cmx",
72     "src/jobs.cmx",
73     "src/ast.cmx",
74     "src/parser.cmx",
75     "src/lexer.cmx",
76     "src/parse.cmx",
77     "src/eval.cmx",
78     "src/deps.cmx",
79     "src/run.cmx",
80     "src/main.cmx"
81 ]
82
83 goal tool = : ocaml_link ("src/goals", objects) ;
84
85 # C code.
86 "src/utils-c.o" : "src/utils-c.c" {
87     %CC %CFLAGS -c %< -o %@
88 }
89
90 # Parser.
91 "src/parser.mli", "src/parser.ml" : "src/parser.mly" {
92     %MENHIR --explain %<
93     # Hack required to break circular dependencies.
94     echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
95     echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
96 }
97
98 "src/lexer.ml" : "src/lexer.mll" {
99     %OCAMLLEX %<
100 }
101
102 # XXX Goalfile itself depends on this and we should probably have a
103 # way to reevaluate it.
104 # XXX Atomic output.
105 goal depend =
106 "src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
107     rm -f %@ %@-t
108     # Like many existing tools, ocamldep produces make-compatible
109     # output which doesn't work directly in goals.
110     %OCAMLDEP -all -one-line -I src %< |
111         sed 's|[./[:alnum:]]\+|"&"|g' |
112         sed 's|" "|", "|g' |
113         sed 's|.*|& ;|' > %@-t
114     mv %@-t %@
115 }
116
117 -include "src/.depend";
118
119 #----------------------------------------------------------------------
120 # Documentation.
121
122 let POD2MAN = "@POD2MAN@"
123
124 goal documentation = : pod2man ("goals", "1"),
125                        pod2man ("Goalfile", "5")
126
127 goal pod2man (page, section) =
128 "man/%page.%section" : "docs/%page.pod" {
129     rm -f %@ %@-t
130     mkdir -p man
131     %POD2MAN \
132         -u \
133         -c "goals" \
134         --release "@PACKAGE_NAME@-@PACKAGE_VERSION@" \
135         --section %section %< > %@-t
136     mv %@-t %@
137 }
138
139 #----------------------------------------------------------------------
140 # Tests.
141
142 let tests = wrap ("test", wildcard ("tests/*.sh"))
143
144 goal check () = : tests
145
146 goal test (name) = @{
147     t=`basename %name`
148     cd tests
149     if ../run ./$t > $t.log 2>&1; then
150         print_green "PASS:" $t
151     else
152         print_red "FAIL:" $t
153         exit 1
154     fi
155 }
156
157 #----------------------------------------------------------------------
158 # Install.
159
160 # DESTDIR can be overridden on the command line to install into
161 # a subdirectory.
162 let DESTDIR = ""
163
164 let stdlibfiles = [wildcard ("stdlib/*.gl"), wildcard ("stdlib/*.sh")]
165
166 goal install = {
167     # exec_prefix die die die
168     bindir="@prefix@/bin"
169     datadir="@prefix@/share"
170     mkdir -p %DESTDIR/"$bindir"
171     mkdir -p %DESTDIR/"$datadir/goals"
172     install src/goals %DESTDIR/"$bindir" -m 0755
173     install %stdlibfiles %DESTDIR/"$datadir"/goals -m 644
174 }
175
176 #----------------------------------------------------------------------
177 # Distribution.
178
179 let sources = [
180     "src/ast.ml",
181     "src/ast.mli",
182     "src/cmdline.ml",
183     "src/cmdline.mli",
184     "src/config.ml.in",
185     "src/config.mli",
186     "src/deps.ml",
187     "src/deps.mli",
188     "src/eval.ml",
189     "src/eval.mli",
190     "src/jobs.ml",
191     "src/jobs.mli",
192     "src/lexer.mli",
193     "src/lexer.mll",
194     "src/main.ml",
195     "src/parse.ml",
196     "src/parse.mli",
197     "src/parser.mly",
198     "src/run.ml",
199     "src/run.mli",
200     "src/utils-c.c",
201     "src/utils.ml",
202     "src/utils.mli",
203 ]
204
205 let distfiles = [
206     ".gitignore",
207     "COPYING",
208     "Goalfile.in",
209     "Makefile.in",
210     "README",
211     "TODO",
212     "autogen.sh",
213     "config.h.in",
214     "configure",
215     "configure.ac",
216     wildcard ("docs/*.pod"),
217     "install-sh",
218     "m4/ocaml.m4",
219     "run.in",
220     sources,
221     "stamp-h.in",
222     wildcard ("stdlib/*.gl"),
223     wildcard ("stdlib/*.sh"),
224     wildcard ("tests/*.data"),
225     wildcard ("tests/*.data[0-9]"),
226     wildcard ("tests/*.expected"),
227     wildcard ("tests/*.gl"),
228     wildcard ("tests/*.sh"),
229     wildcard ("tests/10-function-wildcard.d/*"),
230 ]
231
232 let tarfile = "@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz"
233
234 goal dist = {
235     d="@PACKAGE_NAME@-@PACKAGE_VERSION@"
236     o=%tarfile
237     rm -rf "$d"
238     rm -f "$o" "$o-t"
239
240     mkdir "$d"
241     for f in %distfiles; do
242         subdir="$(dirname "$f")"
243         mkdir -p "$d/$subdir"
244         cp -a "$f" "$d/$subdir"
245     done
246     tar zcf "$o-t" "$d"
247     mv "$o-t" "$o"
248     rm -rf "$d"
249 }