summaryrefslogtreecommitdiff
path: root/perl/Build.PL
blob: 86562330a8b48cab8d63b621af7582dc8cf99706 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
#
# Build script for the Net::Remctl distribution.
#
# Written by Russ Allbery <eagle@eyrie.org>
# Copyright 2007, 2012-2013
#     The Board of Trustees of the Leland Stanford Junior University
#
# SPDX-License-Identifier: MIT

use 5.008;
use strict;
use warnings;

use Module::Build;

# Create a command script that will be run by remctld during the test suite.
# These scripts will be stored in the t/data directory.
#
# $build - Module::Build object
# $name  - Name of command
# $code  - Perl code, as a string, to put into the script
#
# Returns: undef
#  Throws: Text exceptions on I/O failures
sub create_command {
    my ($build, $name, $code) = @_;
    my $path = File::Spec->catfile(qw(t data), $name);

    # Create the file.
    open(my $command, q{>}, $path)
      or die "Cannot create $path: $!\n";
    print {$command} "#!/usr/bin/perl\nuse strict;\nuse warnings;\n"
      or die "Cannot write to $path: $!\n";
    print {$command} $code, "\n"
      or die "Cannot write to $path: $!\n";
    close($command)
      or die "Cannot write to $path: $!\n";

    # Fix the shebang line.
    $build->fix_shebang_line($path);

    # Set permissions, which seems to be un-done by fix_shebang_ling.
    chmod(0755, $path)
      or die "Cannot set permissions on $path: $!\n";
    return;
}

# Basic package configuration.
my $build = Module::Build->new(
    module_name          => 'Net::Remctl',
    dist_author          => 'Russ Allbery <eagle@eyrie.org>',
    license              => 'mit',
    recursive_test_files => 1,
    add_to_cleanup       => [qw(cover_db t/data/cmd-hello t/data/cmd-sleep)],

    # XS configuration.  For in-tree builds, we override this to add the full
    # list of dependency libraries, which will work on more systems.
    extra_linker_flags => [qw(-lremctl)],

    # Other package relationships.
    configure_requires => { 'Module::Build' => 0.28 },
    requires           => { perl            => '5.008' },
);

# Work around a bug in the version of Module::Build that shipped with RHEL 5.
if ($Module::Build::VERSION <= 0.2807) {
    for my $param (qw(extra_compiler_flags extra_linker_flags)) {
        my $value = $build->$param;
        if (ref($value) eq 'ARRAY' && @{$value} == 1) {
            $build->$param($build->split_like_shell($value->[0]));
        }
    }
}

# Generate the build script.
$build->create_build_script;

# Generate the commands that will be run by remctld during the test suite.
## no critic (ValuesAndExpressions::RequireInterpolationOfMetachars)
create_command($build, 'cmd-hello', 'print "hello world\n" or die "fail\n"');
create_command($build, 'cmd-sleep', 'sleep 3;');