361dd07bd7f01791f47280d496ee51365dfc74b6
[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 let POD2TEXT = "@POD2TEXT@"
124
125 goal documentation = : pod2man ("goals", "1"), pod2man ("Goalfile", "5"),
126                        pod2text ("goals", "1"), pod2text ("Goalfile", "5")
127
128 goal pod2man (page, section) =
129 "man/%page.%section" : "docs/%page.pod" {
130     rm -f %@ %@-t
131     mkdir -p man
132     %POD2MAN \
133         -u \
134         -c "goals" \
135         --release "@PACKAGE_NAME@-@PACKAGE_VERSION@" \
136         --section %section %< > %@-t
137     mv %@-t %@
138 }
139
140 goal pod2text (page, section) =
141 "man/%page.%section.txt" : "docs/%page.pod" {
142     rm -f %@ %@-t
143     mkdir -p man
144     %POD2TEXT -u %< > %@-t
145     mv %@-t %@
146 }
147
148 #----------------------------------------------------------------------
149 # Tests.
150
151 let tests = wrap ("test", wildcard ("tests/*.sh"))
152
153 goal check () = : tests
154
155 goal test (name) = @{
156     t=`basename %name`
157     cd tests
158     if ../run ./$t > $t.log 2>&1; then
159         print_green "PASS:" $t
160     else
161         print_red "FAIL:" $t
162         exit 1
163     fi
164 }
165
166 #----------------------------------------------------------------------
167 # Install.
168
169 # DESTDIR can be overridden on the command line to install into
170 # a subdirectory.
171 let DESTDIR = ""
172
173 let stdlibfiles = [wildcard ("stdlib/*.gl"), wildcard ("stdlib/*.sh")]
174
175 goal install = {
176     # exec_prefix die die die
177     bindir="@prefix@/bin"
178     datadir="@prefix@/share"
179     mkdir -p %DESTDIR"$bindir"
180     mkdir -p %DESTDIR"$datadir/goals"
181     install src/goals %DESTDIR"$bindir" -m 0755
182     install %stdlibfiles %DESTDIR"$datadir"/goals -m 644
183 }
184
185 #----------------------------------------------------------------------
186 # Distribution.
187
188 let sources = [
189     "src/ast.ml",
190     "src/ast.mli",
191     "src/cmdline.ml",
192     "src/cmdline.mli",
193     "src/config.ml.in",
194     "src/config.mli",
195     "src/deps.ml",
196     "src/deps.mli",
197     "src/eval.ml",
198     "src/eval.mli",
199     "src/jobs.ml",
200     "src/jobs.mli",
201     "src/lexer.mli",
202     "src/lexer.mll",
203     "src/main.ml",
204     "src/parse.ml",
205     "src/parse.mli",
206     "src/parser.mly",
207     "src/run.ml",
208     "src/run.mli",
209     "src/utils-c.c",
210     "src/utils.ml",
211     "src/utils.mli",
212 ]
213
214 let distfiles = [
215     ".gitignore",
216     "COPYING",
217     "Goalfile.in",
218     "Makefile.in",
219     "README",
220     "TODO",
221     "autogen.sh",
222     "config.h.in",
223     "configure",
224     "configure.ac",
225     wildcard ("docs/*.pod"),
226     "goals.spec.in",
227     "install-sh",
228     "m4/ocaml.m4",
229     "run.in",
230     "src/.depend",
231     sources,
232     "stamp-h.in",
233     wildcard ("stdlib/*.gl"),
234     wildcard ("stdlib/*.sh"),
235     wildcard ("tests/*.data"),
236     wildcard ("tests/*.data[0-9]"),
237     wildcard ("tests/*.expected"),
238     wildcard ("tests/*.gl"),
239     wildcard ("tests/*.sh"),
240     wildcard ("tests/10-function-wildcard.d/*"),
241 ]
242
243 let tarfile = "@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz"
244
245 goal dist = "%tarfile" : {
246     d="@PACKAGE_NAME@-@PACKAGE_VERSION@"
247     o=%tarfile
248     rm -rf "$d"
249     rm -f "$o" "$o-t"
250
251     mkdir "$d"
252     for f in %distfiles; do
253         subdir="$(dirname "$f")"
254         mkdir -p "$d/$subdir"
255         cp -a "$f" "$d/$subdir"
256     done
257     tar zcf "$o-t" "$d"
258     mv "$o-t" "$o"
259     rm -rf "$d"
260 }
261
262 goal distcheck = : dist {
263     d="@PACKAGE_NAME@-@PACKAGE_VERSION@"
264     tar zxf %tarfile
265     pushd "$d"
266     ./configure
267     make
268     make check
269     popd
270     rm -rf "$d"
271     print_green "PASS: distcheck"
272 }
273
274 #----------------------------------------------------------------------
275 # Maintainer rules.
276
277 # Check no files are missing from distfiles above by unpacking the
278 # distribution tarball and comparing it to git.
279 goal maintainer-check-extra-dist = : dist @{
280     tar ztf %tarfile | sort |
281         sed 's,^@PACKAGE_NAME@-@PACKAGE_VERSION@/,,' > tarfiles
282     git ls-files | sort > gitfiles
283     comm -13 tarfiles gitfiles > comm.out
284     cat comm.out
285     [ ! -s comm.out ]
286     rm tarfiles gitfiles comm.out
287     print_green "PASS: distfiles"
288 }
289
290 # XXX This should also do a Fedora build.
291 goal maintainer-release = : dist,
292                             maintainer-check-extra-dist,
293                             distcheck,
294                             maintainer-upload,
295                             maintainer-srpm,
296                             maintainer-fedora-copr
297
298 let websitedir = "%HOME/d/websites/people.redhat.com/goals"
299
300 # XXX Should actually use the *url tactic here.
301 goal maintainer-upload = : distcheck {
302     [ -d %websitedir ]
303     cp %tarfile %websitedir/files
304     cp README %websitedir/README
305     cp man/goals.1.txt man/Goalfile.5.txt %websitedir
306     cd %websitedir
307     git add files/%tarfile README goals.1.txt Goalfile.5.txt
308     git commit -m "@PACKAGE_NAME@ @PACKAGE_VERSION@"
309     cd ..
310     ./.rsync
311 }
312
313 pure function get-fedora-dist () returning string = @{
314     rpm --eval '%%dist'
315 }
316 let fedora-dist = get-fedora-dist ()
317 let srpm = "goals-@PACKAGE_VERSION@%fedora-dist.src.rpm"
318
319 goal maintainer-srpm =
320 "%srpm" : tarfile, "goals.spec" {
321     rpmbuild -bs \
322         --define "%%_sourcedir $PWD" \
323         --define "%%_srcrpmdir $PWD" \
324         goals.spec
325 }
326
327 goal maintainer-fedora-copr = : maintainer-upload, srpm {
328     copr build rjones/goals %srpm
329 }