Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use modules with js_of_ocaml?

I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o -linkpkg -o file.byte file.ml but I would like to include several modules in my project. How can I do that ?

The other modules are actually a lexer and a parser poduced by ocamllex and menhir. I have read a tutorial on how to use ocamllex and menhir with js_of_ocaml but it makes wrong assumptions on where js_of_ocaml is installed (I installed it with opam) and it uses ocamlbuild and I want to know how to do it by hand without using an automated tool such as ocamlbuild.

like image 669
Thomash Avatar asked Jan 17 '13 16:01

Thomash


1 Answers

I found the solution by trying to understand the makefiles for the official examples.

Here is my Makefile :

OBJS=file1.cmo file2.cmo file3.cmo
NAME=projectname
OCAMLC=ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax -syntax camlp4o

$(NAME).byte: $(OBJS)
        $(OCAMLC) -linkpkg -o $@ $(OBJS)

$(NAME).js: $(NAME).byte
        js_of_ocaml $<

%.cmo: %.ml
        $(OCAMLC) -c $<
...
like image 134
Thomash Avatar answered Sep 23 '22 06:09

Thomash