build: Add distcheck, maintainer-check-extra-dist and maintainer-release.
[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     "install-sh",
227     "m4/ocaml.m4",
228     "run.in",
229     "src/.depend",
230     sources,
231     "stamp-h.in",
232     wildcard ("stdlib/*.gl"),
233     wildcard ("stdlib/*.sh"),
234     wildcard ("tests/*.data"),
235     wildcard ("tests/*.data[0-9]"),
236     wildcard ("tests/*.expected"),
237     wildcard ("tests/*.gl"),
238     wildcard ("tests/*.sh"),
239     wildcard ("tests/10-function-wildcard.d/*"),
240 ]
241
242 let tarfile = "@PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz"
243
244 goal dist = {
245     d="@PACKAGE_NAME@-@PACKAGE_VERSION@"
246     o=%tarfile
247     rm -rf "$d"
248     rm -f "$o" "$o-t"
249
250     mkdir "$d"
251     for f in %distfiles; do
252         subdir="$(dirname "$f")"
253         mkdir -p "$d/$subdir"
254         cp -a "$f" "$d/$subdir"
255     done
256     tar zcf "$o-t" "$d"
257     mv "$o-t" "$o"
258     rm -rf "$d"
259 }
260
261 goal distcheck = : dist {
262     d="@PACKAGE_NAME@-@PACKAGE_VERSION@"
263     tar zxf %tarfile
264     pushd "$d"
265     ./configure
266     make
267     make check
268     popd
269     rm -rf "$d"
270     print_green "PASS: distcheck"
271 }
272
273 #----------------------------------------------------------------------
274 # Maintainer rules.
275
276 # Check no files are missing from distfiles above by unpacking the
277 # distribution tarball and comparing it to git.
278 goal maintainer-check-extra-dist = : dist @{
279     tar ztf %tarfile | sort |
280         sed 's,^@PACKAGE_NAME@-@PACKAGE_VERSION@/,,' > tarfiles
281     git ls-files | sort > gitfiles
282     comm -13 tarfiles gitfiles > comm.out
283     cat comm.out
284     [ ! -s comm.out ]
285     rm tarfiles gitfiles comm.out
286     print_green "PASS: distfiles"
287 }
288
289 # XXX This should also do a Fedora build.
290 goal maintainer-release = : dist,
291                             maintainer-check-extra-dist,
292                             distcheck,
293                             maintainer-upload
294
295 let websitedir = "%HOME/d/websites/people.redhat.com/goals"
296
297 # XXX Should actually use the *url tactic here.
298 goal maintainer-upload = {
299     [ -d %websitedir ]
300     cp %tarfile %websitedir/files
301     cp README %websitedir/README
302     cp man/goals.1.txt man/Goalfile.5.txt %websitedir
303     cd %websitedir
304     git add files/%tarfile README goals.1.txt Goalfile.5.txt
305     git commit -m "@PACKAGE_NAME@ @PACKAGE_VERSION@"
306     cd ..
307     ./.rsync
308 }