How to arrange source files in Ocsigen project

112 Views Asked by At

I have created a simple Ocsigen project from basic template. Everything was fine until I decided I'd like to put all my source files in src directory and create more subdirectiories inside it too, so that my source code is partitioned into modules and arranged nicely.

Unfortunately when I try to compile the project, only the files in the main directory get compiled and the src directory is not searched for source files. I have read the makefiles generated by the project template and tried to figure out a way to make it work, but with no success. Specifically it's not sufficient just to change values of CLIENT_FILES and SERVER_FILES in Makefile.options. I tried to impose recursive search like so:

SERVER_FILES := $(shell find src -name "*.eliom" -or -name "*.eliomi")

but it didn't work. Makefile apparently requires much more changes to accept that. I also tried with flat structure using $(wildcard src/*.eliom), but that didn't work either.

So is there any way to achieve what I need without making changes to half the template Makefile, which is quite magical for me, difficult to modify, and even more difficult to completely comprehend and rewrite.

1

There are 1 best solutions below

0
On

I can refer you to this very helpful post from Danny Willems Ocsigen: how to compile an Eliom project. Understand the compilation process in deep. If you want, you can make it automated with any framework for example if you want to use ocamlbuild you can create a Makefile yourself and put in it these lines

SOURCE_FILES = src
OCB_FLAGS = -plugin-tags "package(eliom.ocamlbuild)" -use-ocamlfind -I $(SOURCE_FILES)
OCB = ocamlbuild $(OCB_FLAGS)
...
$(PATH_YOU_WANT)$(YOUR_PROJECT_NAME).js:
  $(OCB) -no-hygiene $@

and then in a _tags file write:

true: eliom_ppx
<*/server/*>: package(eliom.server), thread
<*/client/*>: package(eliom.client)

First line is needed if you used ppx extension of eliom in your code that is sometimes necessary. Issuing make in a shell, ocamlbuild will compile your code into _build/src/server and _build/src/client