caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David Allsopp <dra-news@metastack.com>
To: "Julien Signoles" <julien.signoles@gmail.com>,
	"Étienne André" <Etienne.Andre@univ-paris13.fr>
Cc: Caml List <caml-list@inria.fr>
Subject: RE: [Caml-list] Build number and date in OCaml?
Date: Wed, 10 Apr 2013 09:08:41 +0000	[thread overview]
Message-ID: <E51C5B015DBD1348A1D85763337FB6D9CC59260F@Remus.metastack.local> (raw)
In-Reply-To: <CAPczgCCt_Tki79V5p1T0Z0cWXnfmFBZ5gTtghk-dH93X4iF++w@mail.gmail.com>

Julien Signoles wrote:
> 2013/4/9 Étienne André <Etienne.Andre@univ-paris13.fr>
> I've been using OCaml for a couple of years, but without using any advanced feature;
> so my question may be a little naive. Is there any way to insert easily the current 
> date and time of compiling, as well as, e.g., an incremental build number in an OCaml
> program? So that it is printed at runtime, e.g., in the program header.
>
> This kind of information is part of your build process and are not directly accessible
> in OCaml. If you want to access it in your OCaml program, you have to pass them from 
> the build environment to the program environment. As Jeremie Dimino said, the usual way
> is to general a small OCaml file at build time and to link it to your program.
> For instance, if you use 'make', you could have the following lines in your Makefile:
> VERSION=...
> config.ml: Makefile

NB - if you want the build stamp ever to be updated, it'll need to depend on more than Makefile. You can either have it depend on all of your ML source files or, if using GNU make, you could declare config.ml as .PHONY (which means it will be rebuilt at every invocation of make).

<snip>

> CMO_FILES = config.cmo ... (* other cmo files *)

There's a further subtlety which can come into play if your build has more than one output, which is to place config.cmo / config.cmx as an order-only dependency. For example, suppose your build system has two programs whose sources are Foo.ml and Bar.ml both of which depend on Common.ml. If you structure your Makefile as:

Config.ml: Foo.ml Bar.ml Common.ml
	...

foo.exe: Common.cmx Foo.cmx | Config.cmx
	...

bar.exe: Common.cmx Bar.cmx | Config.cmx
	...

then updates to Foo.ml will not cause bar.exe to be rebuilt. The advantage of this approach is that the generating of the build stamp does not interfere with make - i.e. you don't get any additional recompilations. Of course, there are times where you do want all output programs to have the same build stamp but most of the time (i.e. while developing!) you don't want a change in one small part of the system to force recompilation/linking of the whole system... 

HTH,


David

  reply	other threads:[~2013-04-10  9:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-09 11:38 Étienne André
2013-04-09 12:18 ` Jeremie Dimino
2013-04-10  8:49 ` Julien Signoles
2013-04-10  9:08   ` David Allsopp [this message]
2013-04-11 13:00 ` Alain Frisch
2013-04-12 14:38   ` Daniel Weil

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=E51C5B015DBD1348A1D85763337FB6D9CC59260F@Remus.metastack.local \
    --to=dra-news@metastack.com \
    --cc=Etienne.Andre@univ-paris13.fr \
    --cc=caml-list@inria.fr \
    --cc=julien.signoles@gmail.com \
    /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).