caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Martin DeMello <martindemello@gmail.com>
Cc: Marek Kubica <marek@xivilization.net>,
	r.3@libertysurf.fr,  "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] which ocaml build system
Date: Fri, 26 Jul 2013 06:49:04 +0200	[thread overview]
Message-ID: <CAPFanBHUkqxmcEdtRb45_XNE9Uocc2vcE8R-8GGBfgAj62KEVA@mail.gmail.com> (raw)
In-Reply-To: <CAFrFfuGD-gzfZx6Z44qo5z_3WQohvnJ8YuRU40w74Nkt-2fCjA@mail.gmail.com>

> You can see the pretty simple makefile here:
> https://github.com/martindemello/varix/blob/master/makefile - I can't
> remember exactly what difficulties I had with ocamlbuild and omake
> now.

We all love ocamlbuild exercises in the morning!

First, I was unable to build your project using the makefile on my
machine (simple 3.12.1 OCaml with Debian package), because of the mix
of libs that now use Camlp4, and Ledit code integrated into your
project. I took the quick route, removed dependency on ledit code
(by removing the relevant target from your makefile) and replaced the
code of the "let readline prompt" function of varix.ml by an "assert
false". Then your makefile succeeded in compiling the program
(that is, once I added a META file to the aurochs sources for
aurochs_lib).

Porting this working makefile to ocamlbuild was then extremely easy.

(1) You use the following ocamlfind packages:

  PACKS = unix bigarray str mikmatch_pcre pcre batteries aurochs_lib

to which correspond the following line in a _tags file:

  true: package(unix), package(bigarray), package(str), \
        package(mikmatch_pcre), package(pcre), package(batteries), \
        package(aurochs_lib)

(remember to compile with "ocamlbuild -use-ocamlfind" to enable direct
ocamlfind use; otherwise you'll get a build error with these)

(you may want to be a tad more specific about which modules of your
code use which packages; or at least you now have the possibility to
be more specific.)

(2) I had to ask ocamlbuild not to look into the ledit/ directory to
avoid hygiene complaints. Again in _tags

  "ledit": -traverse

(3) You use camlp4 preprocessing. Again in _tags:

  true: syntax(camlp4o)

(4) You have a rule to build a .ml from a .peg:

  vx.ml: vx.peg
  	aurochs -target ml vx.peg

ocamlbuild doesn't support aurochs out-of-the-box, so we need to add
a new rule in a myocamlbuild.ml plugin. This looks like the beginning
of bad news (nobody likes to write myocamlbuild.ml plugins), but the
Google link for "ocamlbuild plugin" brought me to

  http://brion.inria.fr/gallium/index.php/Using_alphaCaml_with_ocamlbuild

which is *exactly* your use-case (building a .ml/.mli pair from an
external tool). I copy-pasted the plugin code in the link above,
adapting it lightly:

  open Ocamlbuild_plugin;;
  open Command;;

  let alphaCaml = A"aurochs";;

  dispatch begin function
    | After_rules ->
        rule "aurochs: peg -> ml"
          ~prods:["%.ml"; "%.mli"]
          ~dep:"%.peg"
        begin fun env _build ->
          Cmd(S[alphaCaml; A"-target"; A"ml"; P(env "%.peg")])
        end;
    | _ -> ()
  end

Note that the makefile rule says you only produce a .ml, but aurochs
in fact produce a .ml and .mli. I initially only had ~prods:["%.ml"]
because I believed the makefile, and that caused a build failure.

(5) Voilà:

  ocamlbuild -use-ocamlfind varix.native

If you're tired of adding -use-ocamlfind each time, you can also add

  Options.use_ocamlfind := true;;

to myocamlbuild.ml



The META I added to aurochs and the changes I did to varix are
available at:
  https://github.com/gasche/aurochs
  https://github.com/gasche/varix

Note that I have no particular opinion on which build system *you*
should be using -- probably the one that you find most convenient.

On Thu, Jul 25, 2013 at 11:45 PM, Martin DeMello
<martindemello@gmail.com> wrote:
> On Tue, Jul 23, 2013 at 6:39 AM, Marek Kubica <marek@xivilization.net> wrote:
>>
>>> I would like to gather thoughts on that in the ocaml.org website,
>>> because actually its advice is 'make + OcamlMakefile' and 'Omake',
>>> and I am not sure it is the best advice.
>>
>> I suppose this advice used to be good, but today maybe not as much
>> anymore.
>
> I have an old (and fairly small) project that I've tried at least
> thrice to migrate off OcamlMakefile to something more
> modern/ocaml-specific, and failed each time (after spending 1-2
> evenings on it). I'll give it another go and report back on my
> experience, but at least historically OCamlMakefile was the easiest
> thing to get up and running.
>
> You can see the pretty simple makefile here:
> https://github.com/martindemello/varix/blob/master/makefile - I can't
> remember exactly what difficulties I had with ocamlbuild and omake
> now.
>
> martin
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  parent reply	other threads:[~2013-07-26  4:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <51ECF4EB.1060301@libertysurf.fr>
2013-07-22  9:07 ` r.3
2013-07-22 15:11   ` Ashish Agarwal
2013-07-23 13:39   ` Marek Kubica
2013-07-25 21:45     ` Martin DeMello
2013-07-26  1:10       ` Francois Berenger
2013-07-26  5:01         ` Malcolm Matalka
2013-07-26  5:46           ` Adrien Nader
2013-07-26  6:49             ` rixed
2013-07-26  7:07               ` David Allsopp
2013-07-26  4:49       ` Gabriel Scherer [this message]
2013-08-05 17:34         ` [Caml-list] character syntax error '^M' r.3
2013-08-05 17:38           ` David Allsopp
2013-08-05 20:23             ` William R
2013-08-06 10:52               ` David Allsopp
2013-07-27  9:51       ` [Caml-list] which ocaml build system Goswin von Brederlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPFanBHUkqxmcEdtRb45_XNE9Uocc2vcE8R-8GGBfgAj62KEVA@mail.gmail.com \
    --to=gabriel.scherer@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=marek@xivilization.net \
    --cc=martindemello@gmail.com \
    --cc=r.3@libertysurf.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).