stdlib/fedora: Use rpmdev-bumpspec -r flag for < Rawhide builds.
[goals.git] / Goalfile.in
index 2fcf7dd..711016e 100644 (file)
@@ -1,6 +1,7 @@
 # Goalfile
-# Copyright (C) 2019 Richard W.M. Jones
-# Copyright (C) 2019 Red Hat Inc.
+# @configure_input@
+# Copyright (C) 2019-2020 Richard W.M. Jones
+# Copyright (C) 2019-2020 Red Hat Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 
 include "ocaml.gl"
 
+let version = "@PACKAGE_VERSION@"
+
+let subdirs = [ "m4", "src", "stdlib", "docs", "man", "tests" ]
+
+goal all = : "Goalfile", tool, documentation;
+
+"Goalfile": "Goalfile.in", "config.status" {
+    ./config.status %@
+}
+"src/config.ml" : "src/config.ml.in", "config.status" {
+    ./config.status %@
+}
+
+goal clean = : wrap ("clean-subdir", subdirs), clean-subdir ("."), clean-other
+
+goal clean-subdir (dir) = {
+    cd %dir
+    rm -f *~
+    rm -f *.cmi *.cmo *.cmx *.o
+}
+
+goal clean-other = {
+    rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
+    rm -f man/*.1 man/*.5
+    rm -f tests/*.log
+
+    # We don't delete src/goals because it is required to do builds.
+    # If you want to really delete it, use the maintainer-clean rule.
+}
+
+goal maintainer-clean = : clean {
+    rm -f src/goals
+}
+
+#----------------------------------------------------------------------
+# Build the goals tool itself.
+
+let CC = "@CC@"
+let OCAMLLIB = "@OCAMLLIB@"
 let MENHIR = "@MENHIR@"
 let OCAMLDEP = "@OCAMLDEP@"
 let OCAMLFIND = "@OCAMLFIND@"
 let OCAMLLEX = "@OCAMLLEX@"
-# XXX
-let OCAMLFLAGS = [ "-g", "-safe-string", "-warn-error", "CDEFLMPSUVYZX+52-3" ]
-let OCAMLPACKAGES = [ "-package", "str,unix", "-I", "src" ]
-#let OCAMLFLAGS = "@OCAMLFLAGS@"
-#let OCAMLPACKAGES = "@OCAMLPACKAGES@"
+let CFLAGS = join (split ("@CFLAGS@"), ["-I%OCAMLLIB", "-I."])
+let OCAMLFLAGS = split ("@OCAMLFLAGS@")
+let OCAMLPACKAGES = join (split ("@OCAMLPACKAGES@"), ["-I", "src"])
 
 let objects = [
+    # These must be in dependency order.
     "src/config.cmx",
+    "src/utils-c.o",
     "src/utils.cmx",
     "src/cmdline.cmx",
+    "src/jobs.cmx",
     "src/ast.cmx",
-    "src/eval.cmx",
-    "src/run.cmx",
     "src/parser.cmx",
     "src/lexer.cmx",
     "src/parse.cmx",
+    "src/eval.cmx",
+    "src/deps.cmx",
+    "src/run.cmx",
     "src/main.cmx"
 ]
 
-goal all = : ocaml_link ("src/goals", objects)
-
-goal clean = {
-    for d in `find -type d`; do
-        pushd $d
-        rm -f *~
-        rm -f *.cmi *.cmo *.cmx *.o
-    done
-    rm -f src/parser.ml src/parser.mli src/lexer.ml src/parser.conflicts
-
-    # We don't delete src/goals because it is required to do builds.
-    # If you want to really delete it, use the maintainer-clean rule.
-}
+goal tool = : ocaml_link ("src/goals", objects) ;
 
-goal maintainer-clean = : clean {
-    rm -f src/goals
+# C code.
+"src/utils-c.o" : "src/utils-c.c" {
+    %CC %CFLAGS -c %< -o %@
 }
 
+# Parser.
 "src/parser.mli", "src/parser.ml" : "src/parser.mly" {
     %MENHIR --explain %<
+    # Hack required to break circular dependencies.
+    echo 'val lexer_read : (Lexing.lexbuf -> token) option ref' >> src/parser.mli
+    echo 'val eval_substitute : (Ast.env -> Ast.loc -> Ast.substs -> string) option ref' >> src/parser.mli
 }
 
 "src/lexer.ml" : "src/lexer.mll" {
     %OCAMLLEX %<
 }
 
-# XXX Depends on *.ml *.mli, but we don't have a function for this yet.
 # XXX Goalfile itself depends on this and we should probably have a
 # way to reevaluate it.
 # XXX Atomic output.
-# XXX GNU sed: https://unix.stackexchange.com/a/13704
-"src/.depend" : {
+goal depend =
+"src/.depend" : wildcard ("src/*.ml"), wildcard ("src/*.mli") {
     rm -f %@ %@-t
     # Like many existing tools, ocamldep produces make-compatible
     # output which doesn't work directly in goals.
-    %OCAMLDEP src/*.ml src/*.mli |
-        sed ':x; /\\$/ { N; s/\\\n//; tx }' |
-        sed 's,[./[:alnum:]]\+,"&",g' |
-        sed 's,.*,& ;,' > %@-t
+    %OCAMLDEP -all -one-line -I src %< |
+        sed 's|[./[:alnum:]]\+|"&"|g' |
+        sed 's|" "|", "|g' |
+        sed 's|.*|& ;|' > %@-t
+    mv %@-t %@
+}
+
+-include "src/.depend";
+
+#----------------------------------------------------------------------
+# Documentation.
+
+let POD2MAN = "@POD2MAN@"
+let POD2TEXT = "@POD2TEXT@"
+
+goal documentation = : pod2man ("goals", "1"), pod2man ("Goalfile", "5"),
+                       pod2text ("goals", "1"), pod2text ("Goalfile", "5")
+
+goal pod2man (page, section) =
+"man/%page.%section" : "docs/%page.pod" {
+    rm -f %@ %@-t
+    mkdir -p man
+    %POD2MAN \
+        -u \
+        -c "goals" \
+        --release goals-%version \
+        --section %section %< > %@-t
     mv %@-t %@
 }
 
--include "src/.depend"
+goal pod2text (page, section) =
+"man/%page.%section.txt" : "docs/%page.pod" {
+    rm -f %@ %@-t
+    mkdir -p man
+    %POD2TEXT -u %< > %@-t
+    mv %@-t %@
+}
+
+#----------------------------------------------------------------------
+# Tests.
+
+let tests = wrap ("test", wildcard ("tests/*.sh"))
+
+goal check () = : tests
+
+goal test (name) = @{
+    t=`basename %name`
+    cd tests
+    if ../run ./$t > $t.log 2>&1; then
+        print_green "PASS:" $t
+    else
+        print_red "FAIL:" $t
+        exit 1
+    fi
+}
+
+#----------------------------------------------------------------------
+# Install.
+
+# DESTDIR can be overridden on the command line to install into
+# a subdirectory.
+let DESTDIR = ""
+
+let stdlibfiles = [wildcard ("stdlib/*.gl"), wildcard ("stdlib/*.sh")]
+
+goal install = {
+    # exec_prefix die die die
+    bindir="@prefix@/bin"
+    datadir="@prefix@/share"
+    mandir="$datadir/man"
+    mkdir -p %DESTDIR"$bindir"
+    mkdir -p %DESTDIR"$datadir/goals/stdlib"
+    mkdir -p %DESTDIR"$mandir/man1" %DESTDIR"$mandir/man5"
+    install src/goals %DESTDIR"$bindir" -m 0755
+    install %stdlibfiles %DESTDIR"$datadir"/goals/stdlib -m 644
+    install man/*.1 %DESTDIR"$mandir"/man1/ -m 644
+    install man/*.5 %DESTDIR"$mandir"/man5/ -m 644
+}
+
+#----------------------------------------------------------------------
+# Distribution.
+
+let sources = [
+    "src/ast.ml",
+    "src/ast.mli",
+    "src/cmdline.ml",
+    "src/cmdline.mli",
+    "src/config.ml.in",
+    "src/config.mli",
+    "src/deps.ml",
+    "src/deps.mli",
+    "src/eval.ml",
+    "src/eval.mli",
+    "src/jobs.ml",
+    "src/jobs.mli",
+    "src/lexer.mli",
+    "src/lexer.mll",
+    "src/main.ml",
+    "src/parse.ml",
+    "src/parse.mli",
+    "src/parser.mly",
+    "src/run.ml",
+    "src/run.mli",
+    "src/utils-c.c",
+    "src/utils.ml",
+    "src/utils.mli",
+]
+
+let distfiles = [
+    ".gitignore",
+    "COPYING",
+    "Goalfile.in",
+    "Makefile.am",
+    "Makefile.in",
+    "README",
+    "TODO",
+    "aclocal.m4",
+    "autogen.sh",
+    "compile",
+    "config.h.in",
+    "configure",
+    "configure.ac",
+    wildcard ("docs/*.pod"),
+    "goals.spec.in",
+    "install-sh",
+    "m4/ocaml.m4",
+    "missing",
+    "run.in",
+    "src/.depend",
+    sources,
+    "stamp-h.in",
+    wildcard ("stdlib/*.gl"),
+    wildcard ("stdlib/*.sh"),
+    wildcard ("tests/*.data"),
+    wildcard ("tests/*.data[0-9]"),
+    wildcard ("tests/*.expected"),
+    wildcard ("tests/*.gl"),
+    wildcard ("tests/*.sh"),
+    wildcard ("tests/10-function-wildcard.d/*"),
+]
+
+let tarfile = "goals-%version.tar.gz"
+
+goal dist = "%tarfile" : {
+    d=goals-%version
+    o=%tarfile
+    rm -rf "$d"
+    rm -f "$o" "$o-t"
+
+    mkdir "$d"
+    for f in %distfiles; do
+        subdir="$(dirname "$f")"
+        mkdir -p "$d/$subdir"
+        cp -a "$f" "$d/$subdir"
+    done
+    # Replace $d/install-sh with a real file
+    if [ -L "$d/install-sh" ]; then
+        rm "$d/install-sh"
+        cp -L "install-sh" "$d/install-sh"
+    fi
+    tar zcf "$o-t" "$d"
+    mv "$o-t" "$o"
+    rm -rf "$d"
+}
+
+goal distcheck = : dist {
+    d=goals-%version
+    tar zxf %tarfile
+    pushd "$d"
+    ./configure
+    make
+    make check
+    popd
+    rm -rf "$d"
+    print_green "PASS: distcheck"
+}
+
+#----------------------------------------------------------------------
+# Maintainer rules.
+
+# Easy way to commit and tag a release.
+goal maintainer-commit = {
+    git commit -a -m "Version "%version"."
+}
+
+goal maintainer-tag = {
+    git tag -a v%version -m "Version "%version -f
+}
+
+# Check no files are missing from distfiles above by unpacking the
+# distribution tarball and comparing it to git.
+goal maintainer-check-extra-dist = : dist @{
+    tar ztf %tarfile | sort |
+        sed 's,^goals-'%version'/,,' > tarfiles
+    git ls-files | sort > gitfiles
+    comm -13 tarfiles gitfiles > comm.out
+    cat comm.out
+    [ ! -s comm.out ]
+    rm tarfiles gitfiles comm.out
+    print_green "PASS: distfiles"
+}
+
+# XXX This should also do a Fedora build.
+goal maintainer-release = : dist,
+                            maintainer-check-extra-dist,
+                            distcheck,
+                            maintainer-upload,
+                            maintainer-srpm,
+                            maintainer-fedora-copr
+
+let websitedir = "%HOME/d/websites/people.redhat.com/goals"
+
+# XXX Should actually use the is-url predicate here.
+goal maintainer-upload = : distcheck {
+    [ -d %websitedir ]
+    cp %tarfile %websitedir/files
+    cp README %websitedir/README
+    cp man/goals.1.txt man/Goalfile.5.txt %websitedir
+    cd %websitedir
+    git add files/%tarfile README goals.1.txt Goalfile.5.txt
+    git commit -m "goals "%version
+    cd ..
+    ./.rsync
+}
+
+pure function get-fedora-dist () returning string = @{
+    rpm --eval '%%dist'
+}
+let fedora-dist = get-fedora-dist ()
+# XXX Replace autoconf macro with %{version} in future.
+let srpm = "goals-@PACKAGE_VERSION@-1%fedora-dist.src.rpm"
+
+goal maintainer-srpm =
+"%srpm" : tarfile, "goals.spec" {
+    rpmbuild -bs \
+        --define "%%_sourcedir $PWD" \
+        --define "%%_srcrpmdir $PWD" \
+        goals.spec
+}
 
-# XXX The Goalfile itself needs rules to rebuild it.
-#Makefile: Makefile.in ../config.status
-#        ../config.status $@
-#config.ml: config.ml.in ../config.status
-#        ../config.status $@
+goal maintainer-fedora-copr = : maintainer-upload, srpm {
+    copr build rjones/goals %srpm
+}
\ No newline at end of file