OCaml spec file support macros
by Jerry James
Hi all,
I've been experimenting with adding some macros to make OCaml
packaging a bit easier. You can see what I have so far here:
https://src.fedoraproject.org/fork/jjames/rpms/ocaml-srpm-macros/c/9554c8...
With these macros, the main part of a spec file for a package that
builds with dune can be as simple as this:
```
%build
%dune_build
%install
%dune_install
%check
%dune_check
%files -f .ofiles
%doc README.md
%license LICENSE.md
%files devel -f .ofiles-devel
```
Packages that do not use dune to build can still use the %ocaml_files
macro at the end of %install to generate .ofiles and .ofiles-devel
files to pass to %files.
New macros:
- %ocamldir: shorter replacement for %{_libdir}/ocaml
- %odoc_package: inspired by %javadoc_package, everything you need in one
place to declare a package that contains odoc documentation.
- %relink_stublibs: automatically locate any dll*.so files created by
ocamlmklib and relink them with Fedora linker flags
- %_add_release_func: internal macro to add `--release` to flags passed to
%dune_build or %dune_check if neither `--release` nor `-p` has been given.
I should probably rewrite it in lua.
- %dune_build: invoke `dune build` with a standard set of flags, followed by
%relink_stublibs. Arguments can be passed to dune, e.g.,
`%dune_build @install`.
- %dune_check: invoke `dune runtest` with a standard set of flags. Arguments
can be passed to dune, e.g., `%dune_check -p foobar`.
- %ocaml_files: generate .ofiles* files to pass to %files from files installed
in the buildroot. Use of this macro requires python3 to be installed in the
chroot. By default, files are split into a main package (.ofiles) and a
devel package (.ofiles-devel). Use `%ocaml_files -n` to ump all files
together into .ofiles. Use `%ocaml_files -s` to generate files with the
OCaml module name embedded in them; e.g., .ofiles-module1,
.ofiles-module1-devel, .ofiles-module2, .ofiles-module2-devel, etc.
- %dune_install: invoke `dune install` with a standard set of flags, then:
- Remove any .dune-keep markers left over from running odoc
- Remove anything installed into /usr/doc
- Remove all *.ml files that have matching *.mli files installed
- Invoke %ocaml_files, with the same -s or -n options passed to
%dune_install itself
I would appreciate any feedback you can offer. My questions:
1. Is ocaml-srpm-macros the best place for this?
2. Is the python dependency for %ocaml_files / %dune_install okay? I thought
about writing it in lua to avoid the external dependency, but then the
entire %install script has to be written in lua. If the entire %install
script is just %dune_install, then that's okay, but it seems like a
significant barrier otherwise.
3. Can you think of any other macros that would be useful?
4. I wonder if it would be useful to allow overrides for the logic used by
%ocaml_files to split files into the main and devel packages. Perhaps
something like this:
-d file1,file2,...: comma-separated list of files to put in the devel
package, even if they would normally go in the main package
-m file1,file2,...: comma-separated list of files to put in the main
package, even if they would normally go in the devel package
Too bad for you if you want to do this to a file with a comma in its name.
:-) Of course, one can always do surgery on the .ofiles* files after they
are created, so maybe this would be overkill.
I was working on making a bunch of spec files for everyone to look at
when the package notes feature derailed me. Sigh. I'm going to get
that cleaned up first, then I hope to get back to making examples.
Regards,
--
Jerry James
http://www.jamezone.org/
11 months