I'm trying to build an ocaml project which requires a camlp4 extension (pa_deriving in this case). Here's my Makefile:

include ./Makefile.config

OCAMLC     := ${OCAMLFIND} ocamlc
OCAMLOPT   := ${OCAMLFIND} ocamlopt
OCAMLDEP   := ${OCAMLFIND} ocamldep
PP         := -package camlp4 -ppopt /home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen/pa_deriving.cma -syntax camlp4o
LIBS       := -I /home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen  -package unix -package oUnit

OCAMLFLAGS   = -w Aef

SOURCES = logic.ml          \
      fsm.ml            \
      test_logic.ml         


 test_logic: ${SOURCES:.ml=.cmo}
  ${OCAMLC} -o $@ ${LIBS} -linkpkg deriving.cma $^

 # Common rules

 %.cmi: %.mli
  ${OCAMLC} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<
 %.cmo: %.ml
  ${OCAMLC} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<
 %.cmx: %.ml
  ${OCAMLOPT} ${OCAMLFLAGS} ${PP} ${LIBS} -c $<

 # Clean up
 clean:
  -rm -f *.cm[ioax] *.cmxa *.cmxs *${OBJEXT} *${LIBEXT} *.annot
  -rm -f tests${EXEEXT}
 distclean: clean
  -rm -f *~ \#* .\#*

 # Dependencies
 depend:
   ${OCAMLDEP} ${PP} *.ml *.mli > .depend

 -include .depend

This Makefile works; it gets the job done, but the problem is that I've got hardcoded paths above, like: /home/p/godi-3.12.1.0/lib/ocaml/site-lib/deriving-ocsigen/pa_deriving.cma which refers to my godi installation of OCaml. I want to get rid of those so that I can distribute the code & Makefile so anyone can build with it.

Should I be using omake or ocamlbuild for this? I'd like to use omake and I've played with an OMakefile for this, but couldn't get anything working - any suggestions would be appreciated.

Update: I tried to use ocamlbuild with the following _tags file:

<*.ml>: package(unix), package(oUnit), package(deriving-ocsigen.syntax), syntax(camlp4o)

using the following ocamlbuild command: ocamlbuild -use-ocamlfind test_logic.native -classic-display

And I get:

/home/phil/godi-3.12.1.0/bin/ocamlfind ocamldep -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -modules fsm.ml > fsm.ml.depends  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamldep -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -modules logic.ml > logic.ml.depends  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlc -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o logic.cmo logic.ml 
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlc -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o fsm.cmo fsm.ml  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o logic.cmx logic.ml  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -c -package deriving-ocsigen.syntax -package oUnit -package unix -syntax camlp4o -o fsm.cmx fsm.ml  
/home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg logic.cmx fsm.cmx   test_logic.cmx -o test_logic.native  
+ /home/phil/godi-3.12.1.0/bin/ocamlfind ocamlopt -linkpkg -linkpkg logic.cmx fsm.cmx test_logic.cmx -o test_logic.native  
File "_none_", line 1, characters 0-1:  
Error: No implementations provided for the following modules:  
         Deriving_Show referenced from test_logic.cmx  
         Deriving_Enum referenced from test_logic.cmx  
         OUnit referenced from test_logic.cmx  

What would I need to add to the _tags file to correct this?

2

There are 2 best solutions below

0
On

I got this working using ocamlbuild. Here is the secret sauce:

_tags file:

<*.ml> or "test_logic.native": package(unix), package(oUnit), package(deriving-ocsigen), package(deriving-ocsigen.syntax), syntax(camlp4o)

NOTE: the *or "test_logic.native"* is very important for the linking phase.

Then run:

ocamlbuild -use-ocamlfind test_logic.native -classic-display

So I'll probably stick with this ocamlbuild solution. If anyone knows how to get this going in omake it would be great to see the answer for that as well.

0
On

I see that you solved your solution with ocamlbuild, which is fine. In the general case, you can use ocamlfind query from your scripts/Makefile as a command-line interface to query information about findlib packages, and in particular avoid hardcoded path.

$ ocamlfind query deriving-ocsigen 
/usr/lib/ocaml/deriving-ocsigen
$ ocamlfind query deriving-ocsigen -i-format
-I /usr/lib/ocaml/deriving-ocsigen
$ ocamlfind query deriving-ocsigen -predicates byte -a-format
deriving_num.cma
$ ocamlfind query deriving-ocsigen.syntax -predicates syntax,preprocessor -a-format
pa_deriving.cma
$ ocamlfind query deriving-ocsigen.syntax -predicates syntax,preprocessor -format "-I %d %a"
-I /usr/lib/ocaml/deriving-ocsigen pa_deriving.cma