【问题标题】:Module::Install and bash completion scriptsModule::Install 和 bash 完成脚本
【发布时间】:2022-02-27 04:39:28
【问题描述】:

我有一个带有以下 Makefile.PL 的 Perl 脚本:

# 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。

【问题讨论】:

标签: perl


【解决方案1】:

根据Module::AutoInstall中的documentation

从 0.43 版开始,Module::AutoInstall 支持的模块 在他们的Makefile.PL 中需要一个MY::postamble 子例程。这 用户定义的MY::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时,它会将给定的文件复制到指定的路径)

【讨论】:

    猜你喜欢
    • 2012-03-09
    • 2016-07-27
    • 1970-01-01
    • 2017-12-20
    • 2012-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多