我有一個帶有以下內容的 Perl 腳本Makefile.PL:
# Load the Module::Install bundled in ./inc/
use lib '.'; # added since from Perl 5.26 '.' is no more in @INC
use inc::Module::Install;
##############################################################################
# Define metadata (we read it from the binary)
name 'check_updates';
version_from 'check_updates';
perl_version_from 'check_updates';
all_from 'check_updates.pod';
##############################################################################
# Specific dependencies
include 'version';
my %prereqs = (
'Carp' => 0,
'English' => 0,
'POSIX' => 0,
'Readonly' => 0,
'Monitoring::Plugin' => 0,
'Monitoring::Plugin::Threshold' => 0,
'Monitoring::Plugin::Getopt' => 0,
);
install_script 'check_updates';
auto_install;
tests 't/*.t';
test_requires 'Test::More' => 0;
test_requires 'File::Spec' => 0;
# https://metacpan.org/pod/release/DAGOLDEN/CPAN-Meta-2.142690/lib/CPAN/Meta/Spec.pm#license
license 'gpl_3';
WriteMakefile(
PREREQ_PM => \%prereqs,
INSTALLSCRIPT => '/usr/lib/nagios/plugins/contrib',
INSTALLSITESCRIPT => '/usr/lib/nagios/plugins/contrib',
MAN1PODS => { 'check_updates.pod' => 'blib/man1/check_updates.1', },
MAN3PODS => { },
);
我還想將 bash 完成腳本(即check_updates.completion)復制到正確的目錄(由pkg-config --variable=completionsdir bash-completion, 例如給出/opt/local/share/bash-completion/completions)
有沒有辦法生成一個 Makefile 規則來將檔案復制到目錄中?
pkg-config --variable=completionsdir bash-completion也可以在Makefile.PL生成帶有硬編碼規則的 Makefile 時執行。
uj5u.com熱心網友回復:
根據檔案Module::AutoInstall:_
從 0.43 版開始,
Module::AutoInstall支持MY::postamble在Makefile.PL. user-definedMY::postamble(如果存在)負責呼叫Module::AutoInstall::postamble并將輸出包含在其回傳值中。
我用這個簡單的測驗了這個Makefile.PL:
use strict;
use warnings;
use inc::Module::Install;
name 'My-Module';
all_from 'lib/My/Module.pm';
include 'Module::AutoInstall';
my %prereqs = (
'Carp' => 0,
'English' => 0,
'POSIX' => 0,
'Readonly' => 0,
);
install_script 'myscript';
auto_install;
WriteMakefile(
PREREQ_PM => \%prereqs,
);
sub MY::postamble {
my $dest_path = "/opt/local/share/bash-completion/completions";
my $script_name = "check_updates.completion";
my $str = "install::\n\t\$(CP) ${script_name} ${dest_path}\n";
return &Module::AutoInstall::postamble . $str;
}
它似乎在這里作業正常(它在你運行時將給定的檔案復制到指定的路徑sudo make install)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/435091.html
標籤:perl
上一篇:使用標量參考子程式
