ExtUtils::MakeMaker 包括外部 *.mk 并使用 *.mk 文件中的定义来定义 WriteMakefile 中的 LIBS 和 INC 参数
我有一个顶级的 Defines.mk 文件,其中列出了要包含的某些目录和 C 库,具体取决于项目,如下所示。
KERNEL_LIB = -lkdev
DRIVER_LIB = -ldriver -lutil -linit $(KERNEL_LIB)
DRIVER_INCLUDE = -I../../include
我使用 XS 允许 perl 脚本访问这些库,并使用 MakeMaker 生成将链接这些库的 Makefile。我希望在生成 Makefile 时,它会引入这些定义。
给定一个像这样的 WriteMakefile,
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/app/lib -lkdev -lpthread -lrt -ldriver -lutil -linit'],
DEFINE => '',
INC => '-I../../include',
clean => {FILES=>"*.o"},
);
我想实现这个目标
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/dx/lib $(KERNEL_LIB) -lpthread -lrt $(DRIVER_LIB)'],
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
来自 @mobrule 我现在有了这个 Makefile.PL
use 5.008008;
use ExtUtils::MakeMaker;
use ExtUtils::MM_Unix;
use ExtUtils::MM;
sub MY::post_initialize {
open my $defs, '<', 'defines.mk';
my $extra_defines = join '', <$defs>;
close $defs;
return $extra_defines;
}
sub MM::init_others {
my $self = shift;
$self->ExtUtils::MM_Unix::init_others(@_);
$self->{EXTRALIBS} = '-L/usr/local/app/lib $(DRIVER_LIB) -lpthread -lrt';
$self->{BSLOADLIBS} = $self->{LDLOADLIBS} = $self->{EXTRALIBS};
}
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
看起来它可以满足我的要求。谢谢!
I have a top level defines.mk file which lists certain directories and C libraries to include depending on the project like so.
KERNEL_LIB = -lkdev
DRIVER_LIB = -ldriver -lutil -linit $(KERNEL_LIB)
DRIVER_INCLUDE = -I../../include
I use XS to allow perl scripts to access these libraries and MakeMaker to generate the Makefile which will link these libraries in. I want to make it such that when the Makefile is generated, it pulls in these defines.
Given a WriteMakefile like this
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/app/lib -lkdev -lpthread -lrt -ldriver -lutil -linit'],
DEFINE => '',
INC => '-I../../include',
clean => {FILES=>"*.o"},
);
I want to achieve this
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
LIBS => ['-L/usr/local/dx/lib $(KERNEL_LIB) -lpthread -lrt $(DRIVER_LIB)'],
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
From @mobrule I now have this Makefile.PL
use 5.008008;
use ExtUtils::MakeMaker;
use ExtUtils::MM_Unix;
use ExtUtils::MM;
sub MY::post_initialize {
open my $defs, '<', 'defines.mk';
my $extra_defines = join '', <$defs>;
close $defs;
return $extra_defines;
}
sub MM::init_others {
my $self = shift;
$self->ExtUtils::MM_Unix::init_others(@_);
$self->{EXTRALIBS} = '-L/usr/local/app/lib $(DRIVER_LIB) -lpthread -lrt';
$self->{BSLOADLIBS} = $self->{LDLOADLIBS} = $self->{EXTRALIBS};
}
WriteMakefile(
NAME => 'generic_scripts',
VERSION_FROM => 'generic_scripts.pm',
DEFINE => '',
INC => '$(DRIVER_INCLUDE)',
clean => {FILES=>"*.o"},
);
Which looks like it does what I want. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖
post_initialize
方法以包含其他定义:这些定义将出现在 Makefile 的顶部,因此以后的定义(例如
LIBS
)可以使用它们。下一个问题是让 MakeMaker 让 LIBS 和 INC 参数中的“无效”条目传递到 Makefile。
在 Windows 上,我认为您只需放置一个
:nosearch
即可通过(请参阅
ExtUtils::Liblist
的文档)。在 Unix-y 系统上,这不起作用,您可能需要做一些更激进的事情,例如覆盖init_others
:我还没有对此进行测试,这可能不是一个完整的工作解决方案。希望它能让您朝着正确的方向前进(如果您仍在阅读本文)。
Override the
post_initialize
method to include your additional definitions:These will appear at the top of the Makefile, so later definitions (e.g.
LIBS
, can use them).The next problem is getting MakeMaker to let the "invalid" entries in the
LIBS
andINC
parameters passed through to the Makefile.On Windows I think you can just put a
:nosearch
, likeand it will pass through (consult the docs to
ExtUtils::Liblist
). On Unix-y systems that doesn't work, and you may need to do something more radical like overridinginit_others
:I haven't tested this and this might not be a complete working solution. Hopefully it will get you going in the right direction (if you are still reading this far).