While I haven't found any straightforward way to include or directly link a source file, I've come up with a way to effectively include a module from a sibling directory.
Once again, here is the structure of the project:
project/
|
|-- subproject1
| |
| |-- module.ml
|
|-- subproject2
|
|-- main.ml
From the project
directory, the following ocamlbuild
command will compile the whole project, with subproject2/main.ml
as target, and subproject2/_build/
as output build directory:
ocamlbuild -I subproject1 subproject2/_build/ subproject2/main.byte
The expected main.byte
file will however be output as subproject2/_build/subproject2/main.byte
, so manual link editing will be necessary to end up with the usual main.byte
symlink in subproject2
.
Since I like being able to use make
, I wrote the following Makefile
in subproject2/
, so as to compile subproject2/
by simply running make
from the inside, as make
is supposed to work.
all:
# Move to project/
cd ..;\
# Run the ocamlbuild command
ocamlbuild -I subproject1 subproject2/_build/ subproject2/main.byte\
# Go back into subproject2
cd subproject2;\
# Try to remove the existing symlink, mute stderr, and continue on error
rm main.byte 2> /dev/null || true;\
# Create the desired symlink
ln -s _build/subproject2/main.byte main.byte