2

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.

Sventimir
  • 1,996
  • 3
  • 14
  • 25
  • In https://github.com/ocsigen/ocsigen-start/issues/365 , the ocsigen devs seem to say they'd rather have people develop external libraries and keep the website code as small as possible. – PatJ Jan 16 '17 at 14:39
  • Well, perhaps. But still my whole team including myself prefers to separate source code from various configs, readmes and makefiles. Besides a website code could and should be small indeed. But not that small as to fit in a single file. Especially if you consider all the HTML that needs to be generated. I see no point in making that a separate library. – Sventimir Jan 16 '17 at 15:08
  • Maybe you can create a directory just for building with symbolic links to the actual files. – PatJ Jan 16 '17 at 15:41
  • Then I pollute the main directory with symbolic links to files instead of files themselves, which seems even worse to me. – Sventimir Jan 17 '17 at 07:33
  • Did you ever figure out how to do this ? I'm going nuts compiling my files by hand, there has to be a way to get a Makefile working with a clean src/ directory at the very least – Ulrar Apr 25 '17 at 10:43
  • Unfortunately, not. What I have done in the end was to start rewriting the Makefile from scratch, adding new features as I needed them. One thing I could never do right was to automatically figure out dependencies between source files. There is a tool in the OCaml compiler to do that, but it goes nuts when a cyclic dependency occurs. This happens quite often accidentally and should be treated as an error, but unfortuantely is not. Instead the project compiles well and produces a binary that crashes on startup. Also I have never implemented compilation to native machine code. – Sventimir Apr 25 '17 at 15:51

1 Answers1

1

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

Community
  • 1
  • 1
Morin
  • 93
  • 7