How to use `make depend` in the OCaml project?

Are there instructions (or known tricks/tips) for using make depend?

Through trial and error, I was able to use make depend to add 2 library functions to Gc, which IIRC required doing a make clean, though I forget whether it was before or after the make depend.

However, when I tried adding a third very similar function to Gc I couldn’t get it to work–I spent more than an hour trying, with various issues.

This was on 4.10. (I wanted maximum stability for my first Ocaml code change.)

If there are tips, I can submit a PR to add that info in, say the top-level CONTRIBUTING.md. I can also submit a simple example of the problem on 4.10 or 4.11 as an issue if that’s needed.

Thanks.

Not sure what you’re asking, but [clarifying, just to be sure] for most Makefiles, if “make” doesn’t work, repeated passes “make -k” usually do. And then eventually when everything is built, “make depend” should update dependencies so that "make clean ; make " should work. Is that process not working?

There isn’t much to it really: typically if you start from a freshly built tree (ie you need to do make or at least build ocamlrun) you can do make depend and it should work.

That said, if you are adding a new function to Gc which does not refer to another module of the stdlib then there is no need to run make depend.

On the other hand, if the function you are adding does refer to another module of the stdlib you need to take care that it does not introduce a dependency cycle and that it is compatible with the linking order of the stdlib modules. In general dependencies between stdlib modules are kept to a minimum to avoid these kind of problems as much as possible.

Other than that, if you would like help with a specific problem, you will need to provide more details :slight_smile:

Cheers,
Nicolás

I didn’t try to reproduce my earlier problems, but here are two things I ran into today that were unexpected:

  1. make clean; make depend fails with this message:
runtime/ocamlrun tools/make_opcodes -opcodes < runtime/caml/instruct.h > bytecomp/opcodes.ml
/bin/sh: 1: runtime/ocamlrun: not found
Makefile:1280: recipe for target 'bytecomp/opcodes.ml' failed

I did the clean just in case the make depend doesn’t update everything in some cases (after I did a make depend by itself that didn’t include my newly added files).

  1. I wanted to create a new file runtime/reachable.c. I had to edit runtime/Makefile, adding my file to NATIVE_C_SOURCES, then do a make depend in the reachable directory.

I could put in a PR adding this info to one of the .md files, though I’m not sure which file it should go in.

Just FYI, uh, I’m not really surprised that “make depend” fails after a “make clean”. I mean, “ocamldep” is an Ocaml program, right? Have you tried to run “make -k” repeatedly to get the whole thing built?

And then run “make depend” (without cleaning beforehand)?

Yeah, I can get things to compile but it’s hit or miss when I add dependencies for new files.

Does ocamldep update dependencies for the C files, too? I thought those at least would be updated or perhaps that depend would come from the protected bootstrap copy (right term?) of OCaml. The make -k is worth mentioning somewhere; I’ve not had to do that on other open source projects I’ve worked on.

Here’s another quirk: make clean;make depend; make fails as shown below. It’s natural to think that a make would fix the make depend failure. But in fact, you have to do another make clean before the make. Then you can do a make depend.

File "/mnt/c/proj/ocaml/bytecomp/emitcode.ml", line 192, characters 13-17:
192 | | Ceq -> out opEQ    | Cne -> out opNEQ
                   ^^^^
Error: Unbound value opEQ
Makefile:1303: recipe for target 'bytecomp/emitcode.cmo' failed
make[4]: *** [bytecomp/emitcode.cmo] Error 2
./boot/ocamlrun ./boot/ocamlc -g -nostdlib -I boot -use-prims runtime/primitives -strict-sequence -principal -absname -w +a-4-9-40-41-42-44-45-48-66 -warn-error A -bin-annot -safe-string -strict-formats -I utils -I parsing -I typing -I bytecomp -I file_formats -I lambda -I middle_end -I middle_end/closure -I middle_end/flambda -I middle_end/flambda/base_types -I asmcomp -I asmcomp/debug -I driver -I toplevel -c bytecomp/bytelink.ml
File "/mnt/c/proj/ocaml/bytecomp/bytelink.ml", line 364, characters 27-41:
364 |        output_byte outchan Opcodes.opSTOP;
                                 ^^^^^^^^^^^^^^
Error: Unbound value Opcodes.opSTOP
Makefile:1303: recipe for target 'bytecomp/bytelink.cmo' failed

It would shock me if it did.

In general, you do not want to do make clean before make depend. make depend needs to have a number of things already built in order to work: the runtime runtime/ocamlrun (so that it can run boot/ocamlc to compute dependencies), and also it needs to be able to build all generated files so that dependencies are accurate. Some of these generated files are built themselves with boot/ocamlc, so again the runtime needs to be available.

This seems about right. Note that in the current trunk dependencies for C files are no longer stored in the repository, so there is no need to do make depend in the runtime directory anymore.

No.

This is again because make clean should not be used before make depend. In general you want to be in a stable state (ie after a successful make) before doing make depend.

Best wishes,
Nicolás