stdlib: Fix %branch -> %fedora-branch.
[goals.git] / Goalfile.in
1 # Goalfile
2 # @configure_input@
3 # Copyright (C) 2019-2020 Richard W.M. Jones
4 # Copyright (C) 2019-2020 Red Hat Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with this program; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 include "ocaml.gl"
21
22 let version = "@PACKAGE_VERSION@"
23
24 let subdirs = [ "m4", "src", "stdlib", "docs", "man", "tests" ]
25
26 goal all = : "Goalfile", tool, documentation;
27
28 "Goalfile": "Goalfile.in", "config.status" {
29     ./config.status %@
30 }
31 "src/config.ml" : "src/config.ml.in", "config.status" {
32     ./config.status %@
33 }
34
35 goal clean = : wrap ("clean-subdir", subdirs), clean-subdir ("."), clean-other
36
37 goal clean-subdir (dir) = {
38     cd %dir
39     rm -f *~
40     rm -f *.cmi *.cmo *.cmx *.o
41 }
42
43 goal clean-other = {
44     rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
45     rm -f man/*.1 man/*.5
46     rm -f tests/*.log
47
48     # We don't delete src/goals because it is required to do builds.
49     # If you want to really delete it, use the maintainer-clean rule.
50 }
51
52 goal maintainer-clean = : clean {
53     rm -f src/goals
54 }
55
56 #----------------------------------------------------------------------
57 # Build the goals tool itself.
58
59 let CC = "@CC@"
60 let OCAMLLIB = "@OCAMLLIB@"
61 let MENHIR = "@MENHIR@"
62 let OCAMLDEP = "@OCAMLDEP@"
63 let OCAMLFIND = "@OCAMLFIND@"
64 let OCAMLLEX = "@OCAMLLEX@"
65 let CFLAGS = join (split ("@CFLAGS@"), ["-I%OCAMLLIB", "-I."])
66 let OCAMLFLAGS = split ("@OCAMLFLAGS@")
67 let OCAMLPACKAGES = join (split ("@OCAMLPACKAGES@"), ["-I", "src"])
68
69 let objects = [
70     # These must be in dependency order.
71     "src/config.cmx",
72     "src/utils-c.o",
73     "src/utils.cmx",
74     "src/cmdline.cmx",
75     "src/jobs.cmx",
76     "src/ast.cmx",
77     "src/parser.cmx",
78     "src/lexer.cmx",
79     "src/parse.cmx",
80     "src/eval.cmx",
81     "src/deps.cmx",
82     "src/run.cmx",
83     "src/main.cmx"
84 ]
85
86 goal tool = : ocaml_link ("src/goals", objects) ;
87
88 # C code.
89 "src/utils-c.o" : "src/utils-c.c" {
90     %CC %CFLAGS -c %< -o %@
91 }
92
93 # Parser.
94 "src/parser.mli", "src/parser.ml" : "src/parser.mly" {
95     %MENHIR --explain %<
96     # Hack required to break circular dependencies.
97     echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
98     echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
99 }
100
101 "src/lexer.ml" : "src/lexer.mll" {
102     %OCAMLLEX %<
103 }
104
105 # XXX Goalfile itself depends on this and we should probably have a
106 # way to reevaluate it.
107 # XXX Atomic output.
108 goal depend =
109 "src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
110     rm -f %@ %@-t
111     # Like many existing tools, ocamldep produces make-compatible
112     # output which doesn't work directly in goals.
113     %OCAMLDEP -all -one-line -I src %< |
114         sed 's|[./[:alnum:]]\+|"&"|g' |
115         sed 's|" "|", "|g' |
116         sed 's|.*|& ;|' > %@-t
117     mv %@-t %@
118 }
119
120 -include "src/.depend";
121
122 #----------------------------------------------------------------------
123 # Documentation.
124
125 let POD2MAN = "@POD2MAN@"
126 let POD2TEXT = "@POD2TEXT@"
127
128 goal documentation = : pod2man ("goals", "1"), pod2man ("Goalfile", "5"),
129                        pod2text ("goals", "1"), pod2text ("Goalfile", "5")
130
131 goal pod2man (page, section) =
132 "man/%page.%section" : "docs/%page.pod" {
133     rm -f %@ %@-t
134     mkdir -p man
135     %POD2MAN \
136         -u \
137         -c "goals" \
138         --release goals-%version \
139         --section %section %< > %@-t
140     mv %@-t %@
141 }
142
143 goal pod2text (page, section) =
144 "man/%page.%section.txt" : "docs/%page.pod" {
145     rm -f %@ %@-t
146     mkdir -p man
147     %POD2TEXT -u %< > %@-t
148     mv %@-t %@
149 }
150
151 #----------------------------------------------------------------------
152 # Tests.
153
154 let tests = wrap ("test", wildcard ("tests/*.sh"))
155
156 goal check () = : tests
157
158 goal test (name) = @{
159     t=`basename %name`
160     cd tests
161     if ../run ./$t > $t.log 2>&1; then
162         print_green "PASS:" $t
163     else
164         print_red "FAIL:" $t
165         exit 1
166     fi
167 }
168
169 #----------------------------------------------------------------------
170 # Install.
171
172 # DESTDIR can be overridden on the command line to install into
173 # a subdirectory.
174 let DESTDIR = ""
175
176 let stdlibfiles = [wildcard ("stdlib/*.gl"), wildcard ("stdlib/*.sh")]
177
178 goal install = {
179     # exec_prefix die die die
180     bindir="@prefix@/bin"
181     datadir="@prefix@/share"
182     mandir="$datadir/man"
183     mkdir -p %DESTDIR"$bindir"
184     mkdir -p %DESTDIR"$datadir/goals/stdlib"
185     mkdir -p %DESTDIR"$mandir/man1" %DESTDIR"$mandir/man5"
186     install src/goals %DESTDIR"$bindir" -m 0755
187     install %stdlibfiles %DESTDIR"$datadir"/goals/stdlib -m 644
188     install man/*.1 %DESTDIR"$mandir"/man1/ -m 644
189     install man/*.5 %DESTDIR"$mandir"/man5/ -m 644
190 }
191
192 #----------------------------------------------------------------------
193 # Distribution.
194
195 let sources = [
196     "src/ast.ml",
197     "src/ast.mli",
198     "src/cmdline.ml",
199     "src/cmdline.mli",
200     "src/config.ml.in",
201     "src/config.mli",
202     "src/deps.ml",
203     "src/deps.mli",
204     "src/eval.ml",
205     "src/eval.mli",
206     "src/jobs.ml",
207     "src/jobs.mli",
208     "src/lexer.mli",
209     "src/lexer.mll",
210     "src/main.ml",
211     "src/parse.ml",
212     "src/parse.mli",
213     "src/parser.mly",
214     "src/run.ml",
215     "src/run.mli",
216     "src/utils-c.c",
217     "src/utils.ml",
218     "src/utils.mli",
219 ]
220
221 let distfiles = [
222     ".gitignore",
223     "COPYING",
224     "Goalfile.in",
225     "Makefile.in",
226     "README",
227     "TODO",
228     "autogen.sh",
229     "config.h.in",
230     "configure",
231     "configure.ac",
232     wildcard ("docs/*.pod"),
233     "goals.spec.in",
234     "install-sh",
235     "m4/ocaml.m4",
236     "run.in",
237     "src/.depend",
238     sources,
239     "stamp-h.in",
240     wildcard ("stdlib/*.gl"),
241     wildcard ("stdlib/*.sh"),
242     wildcard ("tests/*.data"),
243     wildcard ("tests/*.data[0-9]"),
244     wildcard ("tests/*.expected"),
245     wildcard ("tests/*.gl"),
246     wildcard ("tests/*.sh"),
247     wildcard ("tests/10-function-wildcard.d/*"),
248 ]
249
250 let tarfile = "goals-%version.tar.gz"
251
252 goal dist = "%tarfile" : {
253     d=goals-%version
254     o=%tarfile
255     rm -rf "$d"
256     rm -f "$o" "$o-t"
257
258     mkdir "$d"
259     for f in %distfiles; do
260         subdir="$(dirname "$f")"
261         mkdir -p "$d/$subdir"
262         cp -a "$f" "$d/$subdir"
263     done
264     # Replace $d/install-sh with a real file
265     if [ -L "$d/install-sh" ]; then
266         rm "$d/install-sh"
267         cp -L "install-sh" "$d/install-sh"
268     fi
269     tar zcf "$o-t" "$d"
270     mv "$o-t" "$o"
271     rm -rf "$d"
272 }
273
274 goal distcheck = : dist {
275     d=goals-%version
276     tar zxf %tarfile
277     pushd "$d"
278     ./configure
279     make
280     make check
281     popd
282     rm -rf "$d"
283     print_green "PASS: distcheck"
284 }
285
286 #----------------------------------------------------------------------
287 # Maintainer rules.
288
289 # Easy way to commit and tag a release.
290 goal maintainer-commit = {
291     git commit -a -m "Version "%version"."
292 }
293
294 goal maintainer-tag = {
295     git tag -a v%version -m "Version "%version -f
296 }
297
298 # Check no files are missing from distfiles above by unpacking the
299 # distribution tarball and comparing it to git.
300 goal maintainer-check-extra-dist = : dist @{
301     tar ztf %tarfile | sort |
302         sed 's,^goals-'%version'/,,' > tarfiles
303     git ls-files | sort > gitfiles
304     comm -13 tarfiles gitfiles > comm.out
305     cat comm.out
306     [ ! -s comm.out ]
307     rm tarfiles gitfiles comm.out
308     print_green "PASS: distfiles"
309 }
310
311 # XXX This should also do a Fedora build.
312 goal maintainer-release = : dist,
313                             maintainer-check-extra-dist,
314                             distcheck,
315                             maintainer-upload,
316                             maintainer-srpm,
317                             maintainer-fedora-copr
318
319 let websitedir = "%HOME/d/websites/people.redhat.com/goals"
320
321 # XXX Should actually use the *url tactic here.
322 goal maintainer-upload = : distcheck {
323     [ -d %websitedir ]
324     cp %tarfile %websitedir/files
325     cp README %websitedir/README
326     cp man/goals.1.txt man/Goalfile.5.txt %websitedir
327     cd %websitedir
328     git add files/%tarfile README goals.1.txt Goalfile.5.txt
329     git commit -m "goals "%version
330     cd ..
331     ./.rsync
332 }
333
334 pure function get-fedora-dist () returning string = @{
335     rpm --eval '%%dist'
336 }
337 let fedora-dist = get-fedora-dist ()
338 # XXX Replace autoconf macro with %{version} in future.
339 let srpm = "goals-@PACKAGE_VERSION@-1%fedora-dist.src.rpm"
340
341 goal maintainer-srpm =
342 "%srpm" : tarfile, "goals.spec" {
343     rpmbuild -bs \
344         --define "%%_sourcedir $PWD" \
345         --define "%%_srcrpmdir $PWD" \
346         goals.spec
347 }
348
349 goal maintainer-fedora-copr = : maintainer-upload, srpm {
350     copr build rjones/goals %srpm
351 }