1

プロジェクトに応じて含める特定のディレクトリとCライブラリをリストするトップレベルの define.mk ファイルがあります。

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"},
);

それは私が望むことをするように見えます。ありがとう!

4

1 に答える 1

0

メソッドをオーバーライドしてpost_initialize、追加の定義を含めます。

sub MY::post_initialize {
    open my $defs, '<', 'defines.mk';
    my $extra_defines = join '', <$defs>;
    close $defs;
    return $extra_defines;
}

これらはMakefileの上部に表示されるため、後の定義(たとえばLIBS、それらを使用できます)。

次の問題は、MakeMakerにLIBSINCパラメータの「無効な」エントリをMakefileに渡させることです。

:nosearchWindowsでは、次のように配置できます。

LIBS => ['-lm', ':nosearch $(OTHER_LIBS)']

そしてそれは通過します(ドキュメントを参照してくださいExtUtils::Liblist)。動作しないUnix-yシステムでは、オーバーライドのようなもっと根本的なことをする必要があるかもしれませんinit_others

sub MM::init_others {      # MM package is a subclass of ExtUtils::MM_Unix and will
                           # get called instead of ExtUtils::MM_Unix::init_others
    my $self = shift;
    $self->SUPER::init_others(@_); # invoke ExtUtils::MM_Unix::init_others

    # now repair the attributes that ExtUtils::MM_Any::init_others didn't set
    $self->{EXTRALIBS} = '-lkdev $(KERNEL_LIB) -lrt $(DRIVER_LIB)';
    $self->{BSLOADLIBS} = $self->{LDLOADLIBS} = $self->{EXTRALIBS};
    1; 
}

私はこれをテストしておらず、これは完全に機能するソリューションではない可能性があります。うまくいけば、それはあなたが正しい方向に進むようになるでしょう(あなたがまだここまで読んでいるなら)。

于 2010-11-19T01:04:42.000 に答える