OK, I have investigated, and now know what the problem is, as well as how to fix it. Also, why there is no easy workaround except to apply the patch. So ….. here we go.
First, here’s the PR for lablgl: A fix to make the camlp5 build work. by chetmurthy · Pull Request #13 · garrigue/lablgl · GitHub
What was the problem
BTW, all of this is documented in CHANGES for the 8.03.00 release of Camlp5, which came out with OCaml 5.2.0 support. It was at that time that lablgl.1.07 stopped being supported (via a conflicts stanza in opam).
The problem is that OCaml 5.2.0 introduced raw identifiers, and this required changing Camlp5’s pretty-printers. Camlp5 has multiple syntaxes, and each syntax has different keywords. So when you emit in some syntax, you need to tell the printing apparatus the keywords; then if an identifier is a keyword, it is printed as a raw-identifier. Remember that Camlp5 can parse in one syntax, and pretty-print in another. So this situation can happen.
The solution was to add a module that contained the list of keywords for that syntax. So there are r_keywords.cmo and o_keywords.cmo. These need to be loaded before pr_r.cmo and pr_o.cmo respectively.
What is the fix (to lablgl)
Camlp5 has supported both using ocamlfind packages to load its preprocessors when compiling, AND using a small extension of ocamlfind called not-ocamlfind in order to do preprocessing only. So instead of writing something like
camlp5 pa_r.cmo .... pr_o.cmo
you can write
not-ocamlfind preprocess -syntax camlp5r -package ....,camlp5.pr_o
So making this change to lablgl fixes the problem.
NOTE: Notice that in that first camlp5 … invocation, depending on the version of camlp5, you might need to use pr_o.cmo or o_keywords.cmo pr_o.cmo. But with the second invocation, camlp5.pr_o always works, b/c the findlib package contains the required filenames.
Why this bug is somewhat pernicious and weird (and not obvious)
lablgl.1.07 has two files that need to be processed by camlp5: src/var2switch.ml4 and src/var2def.ml4. the postprocessed files are included in the package source, and the last-modified times are what you would expect so that Make will not try to recompile (.ml4 → .ml) (hence needing camlp5). And it works as expected, IF YOU RUN MAKE in the source-directory.
So why doesn’t it work when we do opam install ….? Well, after numerous runs, I conclude that the process of COPYING the source-tree into the opam-controlled build-directory does not preserve last-modified times (HAHAHA) so when you run make over in the build-directory, SOMETIMES the last-mod times cause Make to want to regenerate the .ml files from the .ml4 files, and BOOM you need camlp5 for that.
So: if you try to install with opam install, it might work, and it might not. All depends on the mod-time-stamps, it seems.