使用 ExtUtils::MakeMaker 时如何更改脚本/模块中的变量字符串
我在用 perl 编写的应用程序中有一些模块和脚本。对于其分发,我使用 ExtUtils::MakeMaker
。
模块和脚本的目标操作系统是Linux。重点是,我期望最终用户将模块/脚本安装在非标准目录中,也许在他们自己的目录中,然后他们安装如下:
perl Makefile.PL PREFIX='/YOUR/DIRECTORY'
make
make test
make install
ExtUtils::MakeMaker 解决了模块/脚本时的问题安装目录不是标准的,并且通过 PREFIX
变量。
如何将 PREFIX
字符串的值复制或替换到脚本中?例如,而不是硬代码:
use lib '/YOUR/DIRECTORY';
我想将其替换为如下模板:
use lib '%%PREFIX%%';
其中 %%PREFIX%%
在“编译”时间被替换,并且没有设置环境变量($ENV{'PREFIX'}
)
感谢您的回答!
I have some modules and scripts in an application written in perl. For its distribution I am using ExtUtils::MakeMaker
.
The modules and scripts' target OS is Linux. The point is than I expect the final users will install the modules/scripts in non standard directories and maybe in their own directory, then they install like:
perl Makefile.PL PREFIX='/YOUR/DIRECTORY'
make
make test
make install
ExtUtils::MakeMaker
solves the problem when the modules/scritps instalation directory are not standard and by PREFIX
variable.
How can I copy or replace the PREFIX
string' value into the scripts? for example, instead of hard code:
use lib '/YOUR/DIRECTORY';
I would like to replace it for a template like:
use lib '%%PREFIX%%';
where %%PREFIX%%
is replaced in "compiling" time, and without set an environment variable ($ENV{'PREFIX'}
)
Thank for your answers!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要使用的是 PM_FILTER:
它适用于 Linux 和除 Windows 之外的几乎所有操作系统(正如您可以从注释中看到的)。
[更新以包含更多使用细节:]
(正如评论所指出的,您可以尝试在 PM_FILTER 中调用 perl 本身,这样您就不需要 Windows 检查;在上面的示例中,但是,我发现 perl 不在 exec 路径中并且 /usr 的现有 PREFIX 路径已经可以的情况...如果需要,您可以直接在正常的 WriteMakefile 参数列表中定义 PM_FILTER 。
The thing to use is the PM_FILTER:
Which works on linux and pretty much everything but windows (as you can see by the comments).
[Updated to include more usage detail:]
(and as is pointed out the comments, you can try to call perl itself in the PM_FILTER so you don't need the windows check; in my example above, however, I found instances where perl wasn't in the exec path and the existing PREFIX path of /usr was already ok... You can define the PM_FILTER directly in the normal WriteMakefile argument list if you want.