[m-users.] How to Specify Compile Time Defines??

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Mar 18 06:10:05 AEDT 2019



On Sun, 17 Mar 2019 07:54:55 -0500, Charles Shuller <charles.shuller at gmail.com> wrote:
> Is there a mechanism in Mercury for specifying compile time defines, or
> something with analogous functionality?

No, because it is that is a piece of functionality that is rarely needed,
which is easy to achieve without special support within Mercury itself.

> I want to specify the version number in the build system, and then
> reference it in source (for answering the --version flag mostly).

Have something like a file named version.m.in containing

  :- module version.

  :- interface.
  :- func version = string.

  :- implementation.
  version = "@VERSION@".

and then have a shell or sed script that constructs version.m from
version.m.in by replacing @VERSION@ with the actual version string.
If you want  the version string to change without human intervention
(e.g. to reflect the current date), you would then add an mmake rule
to construct version.m from version.m.in automatically at appropriate
points in time.

Zoltan.


More information about the users mailing list