简体   繁体   English

如何在Mercury中指定编译时间定义?

[英]How do I specify compile time defines in Mercury?

How do I specify compile time defines in Mercury? 如何在Mercury中指定编译时间定义?

I would like to have the build system read the version number out of a configuration file and pass it into the module for access by predicates and functions. 我希望构建系统从配置文件中读取版本号,并将其传递到模块中,以供谓词和函数访问。

For example, in C I'd do something like: gcc -DVERSION="1.2.0", and then use the newly defined macro VERSION in the source. 例如,在C语言中,我将执行以下操作:gcc -DVERSION =“ 1.2.0”,然后在源代码中使用新定义的宏VERSION。

Zoltan Somogyi on the Mercury Users Mailing List Responded with: Zoltan Somogyi在Mercury用户邮件列表上的回复:

[Compile time defines, like in C, aren't possible in Mercury], because it is that is a piece of functionality that is rarely needed, which is easy to achieve without special support within Mercury itself. [像在C中一样,在Mercury中无法定义编译时],因为这是很少需要的功能,如果没有Mercury本身的特殊支持,就很容易实现。

.... ....

[For your specific need, pushing in the version number from the build system] Have something like a file named version.m.in containing [根据您的特定需要,从构建系统中输入版本号]有一个名为version.m.in的文件,其中包含

:- module version. :-模块版本。

:- interface. :-界面。 :- func version = string. :-func版本=字符串。

:- implementation. :-实施。 version = "@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. 然后使用shell或sed脚本,通过将@ VERSION @替换为实际的版本字符串,从version.m.in构造version.m。 If you want the version string to change without human intervention (eg 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. 如果要在没有人为干预的情况下更改版本字符串(例如,反映当前日期),则可以添加mmake规则,以在适当的时间点自动从version.m.in构造version.m。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM