]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Convert the build system to Perl 5.10.
authorPeter Powell <petpow@saberuk.com>
Sat, 21 Mar 2015 20:04:03 +0000 (20:04 +0000)
committerPeter Powell <petpow@saberuk.com>
Wed, 25 Mar 2015 19:01:33 +0000 (19:01 +0000)
Thanks to Kross for the heads up on "use feature".

configure
make/common.pm
make/configure.pm
make/console.pm
tools/genssl
tools/test-build

index 1ff38bad12b4947075f0f08363c892e7a776ef4c..ab2d50a8676820f316e4f499c6beb8c3fa852147 100755 (executable)
--- a/configure
+++ b/configure
 
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
 }
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -137,7 +138,7 @@ if ($interactive) {
        }
 }
 
-$config{CXX} = find_compiler($config{CXX} || $ENV{CXX});
+$config{CXX} = find_compiler($config{CXX} // $ENV{CXX});
 unless ($config{CXX}) {
        print "A suitable C++ compiler could not be detected on your system!\n";
        print "Set the CXX environment variable to the compiler binary path if this is incorrect.\n";
@@ -149,24 +150,24 @@ $config{HAS_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX},
 $config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
 
 if ($config{HAS_EPOLL} = run_test 'epoll', test_header($config{CXX}, 'sys/epoll.h')) {
-       $config{SOCKETENGINE} ||= 'epoll';
+       $config{SOCKETENGINE} //= 'epoll';
 }
 
 if ($config{HAS_KQUEUE} = run_test 'kqueue', test_file($config{CXX}, 'kqueue.cpp')) {
-       $config{SOCKETENGINE} ||= 'kqueue';
+       $config{SOCKETENGINE} //= 'kqueue';
 }
 
 if ($config{HAS_PORTS} = run_test 'Solaris IOCP', test_header($config{CXX}, 'port.h')) {
-       $config{SOCKETENGINE} ||= 'ports';
+       $config{SOCKETENGINE} //= 'ports';
 }
 
 if ($config{HAS_POLL} = run_test 'poll', test_header($config{CXX}, 'poll.h')) {
-       $config{SOCKETENGINE} ||= 'poll';
+       $config{SOCKETENGINE} //= 'poll';
 }
 
 # Select is available on all platforms
 $config{HAS_SELECT} = 1;
-$config{SOCKETENGINE} ||= 'select';
+$config{SOCKETENGINE} //= 'select';
 
 if (defined $opt_socketengine) {
        my $cfgkey = 'HAS_' . uc $opt_socketengine;
@@ -191,21 +192,21 @@ if (defined $opt_distribution_label) {
 }
 
 if (defined $opt_system) {
-       $config{BASE_DIR}   = $opt_prefix     || '/var/lib/inspircd';
-       $config{BINARY_DIR} = $opt_binary_dir || '/usr/sbin';
-       $config{CONFIG_DIR} = $opt_config_dir || '/etc/inspircd';
-       $config{DATA_DIR}   = $opt_data_dir   || '/var/inspircd';
-       $config{LOG_DIR}    = $opt_module_dir || '/var/log/inspircd';
-       $config{MANUAL_DIR} = $opt_manual_dir || '/usr/share/man/man1';
-       $config{MODULE_DIR} = $opt_module_dir || '/usr/lib/inspircd';
+       $config{BASE_DIR}   = $opt_prefix     // '/var/lib/inspircd';
+       $config{BINARY_DIR} = $opt_binary_dir // '/usr/sbin';
+       $config{CONFIG_DIR} = $opt_config_dir // '/etc/inspircd';
+       $config{DATA_DIR}   = $opt_data_dir   // '/var/inspircd';
+       $config{LOG_DIR}    = $opt_module_dir // '/var/log/inspircd';
+       $config{MANUAL_DIR} = $opt_manual_dir // '/usr/share/man/man1';
+       $config{MODULE_DIR} = $opt_module_dir // '/usr/lib/inspircd';
 } else {
-       $config{BASE_DIR}   = $opt_prefix     || $config{BASE_DIR}   || rel2abs 'run';
-       $config{BINARY_DIR} = $opt_binary_dir || $config{BINARY_DIR} || rel2abs $config{BASE_DIR} . '/bin';
-       $config{CONFIG_DIR} = $opt_config_dir || $config{CONFIG_DIR} || rel2abs $config{BASE_DIR} . '/conf';
-       $config{DATA_DIR}   = $opt_data_dir   || $config{DATA_DIR}   || rel2abs $config{BASE_DIR} . '/data';
-       $config{LOG_DIR}    = $opt_log_dir    || $config{LOG_DIR}    || rel2abs $config{BASE_DIR} . '/logs';
-       $config{MANUAL_DIR} = $opt_manual_dir || $config{MANUAL_DIR} || rel2abs $config{BASE_DIR} . '/manuals';
-       $config{MODULE_DIR} = $opt_module_dir || $config{MODULE_DIR} || rel2abs $config{BASE_DIR} . '/modules';
+       $config{BASE_DIR}   = $opt_prefix     // $config{BASE_DIR}   // rel2abs 'run';
+       $config{BINARY_DIR} = $opt_binary_dir // $config{BINARY_DIR} // rel2abs $config{BASE_DIR} . '/bin';
+       $config{CONFIG_DIR} = $opt_config_dir // $config{CONFIG_DIR} // rel2abs $config{BASE_DIR} . '/conf';
+       $config{DATA_DIR}   = $opt_data_dir   // $config{DATA_DIR}   // rel2abs $config{BASE_DIR} . '/data';
+       $config{LOG_DIR}    = $opt_log_dir    // $config{LOG_DIR}    // rel2abs $config{BASE_DIR} . '/logs';
+       $config{MANUAL_DIR} = $opt_manual_dir // $config{MANUAL_DIR} // rel2abs $config{BASE_DIR} . '/manuals';
+       $config{MODULE_DIR} = $opt_module_dir // $config{MODULE_DIR} // rel2abs $config{BASE_DIR} . '/modules';
 }
 
 # Parse --gid=123 or --gid=foo and extract the group id.
@@ -214,7 +215,7 @@ if (defined $opt_gid) {
        @group = $opt_gid =~ /^\d+$/ ? getgrgid($opt_gid) : getgrnam($opt_gid);
        print_error "there is no '$opt_gid' group on this system!" unless @group;
 } else {
-       @group = $opt_system ? getgrnam('irc') : getgrgid($config{GID} || getgid());
+       @group = $opt_system ? getgrnam('irc') : getgrgid($config{GID} // getgid());
        print_error "you need to specify a group to run as using '--gid [id|name]'!" unless @group;
 }
 $config{GROUP} = $group[0];
@@ -226,7 +227,7 @@ if (defined $opt_uid) {
        @user = $opt_uid =~ /^\d+$/ ? getpwuid($opt_uid) : getpwnam($opt_uid);
        print_error "there is no '$opt_uid' user on this system!" unless @user;
 } else {
-       @user = $opt_system ? getpwnam('irc') : getpwuid($config{UID} || getuid());
+       @user = $opt_system ? getpwnam('irc') : getpwuid($config{UID} // getuid());
        print_error "you need to specify a user to run as using '--uid [id|name]'!" unless @user;
 }
 $config{USER} = $user[0];
@@ -246,8 +247,8 @@ version instead.
 You can obtain the latest stable version from http://www.inspircd.org/ or by
 running `git checkout insp20` if you are installing from Git.
 EOW
-       if (!prompt_bool $interactive, 'I understand this warning and want to continue anyway.', $opt_development || 0) {
-               print STDERR "If you understand this warning and still want to continue pass the --development flag.\n" unless $interactive;
+       if (!prompt_bool $interactive, 'I understand this warning and want to continue anyway.', $opt_development // 0) {
+               say STDERR 'If you understand this warning and still want to continue pass the --development flag.' unless $interactive;
                exit 1;
        }
 }
@@ -322,7 +323,7 @@ EOM
 
 for my $file (<src/modules/m_*>) {
        my $module = basename $file, '.cpp';
-       print "  * $module\n" if -l $file;
+       say "  * $module" if -l $file;
 }
 
 print_format <<"EOM";
index 24ef599ce9ced47ce617f453d8db44aa18980b22..638cc668ae3fd9d53a2e33c4a38ba069726769c3 100644 (file)
 
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
 }
 
 package make::common;
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -33,9 +34,8 @@ our @EXPORT = qw(get_cpu_count
                  get_version
                  module_installed);
 
-my %version;
-
 sub get_version {
+       state %version;
        return %version if %version;
 
        # Attempt to retrieve version information from src/version.sh
@@ -47,22 +47,22 @@ sub get_version {
        # Attempt to retrieve missing version information from Git
        chomp(my $gr = `git describe --tags 2>/dev/null`);
        if ($gr =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\d+-g(\w+))?$/) {
-               $version{MAJOR} = $1 unless defined $version{MAJOR};
-               $version{MINOR} = $2 unless defined $version{MINOR};
-               $version{PATCH} = $3 unless defined $version{PATCH};
+               $version{MAJOR} //= $1;
+               $version{MINOR} //= $2;
+               $version{PATCH} //= $3;
                $version{LABEL} = $4 if defined $4;
        }
 
        # The user is using a stable release which does not have
        # a label attached.
-       $version{LABEL} = 'release' unless defined $version{LABEL};
+       $version{LABEL} //= 'release';
 
        # If any of these fields are missing then the user has deleted the
        # version file and is not running from Git. Fill in the fields with
        # dummy data so we don't get into trouble with undef values later.
-       $version{MAJOR} = '0' unless defined $version{MAJOR};
-       $version{MINOR} = '0' unless defined $version{MINOR};
-       $version{PATCH} = '0' unless defined $version{PATCH};
+       $version{MAJOR} //= '0';
+       $version{MINOR} //= '0';
+       $version{PATCH} //= '0';
 
        return %version;
 }
index 84f076483c6b7322a24cbb5633fc4d417aa6e141..9a53221a8667abe2f27cb4e3974f4157dcba1234 100644 (file)
 
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
 }
 
 package make::configure;
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -175,18 +176,18 @@ EOH
 
 sub cmd_update {
        print_error "You have not run $0 before. Please do this before trying to update the generated files." unless -f CONFIGURE_CACHE_FILE;
-       print "Updating...\n";
+       say 'Updating...';
        my %config = read_configure_cache();
        my %compiler = get_compiler_info($config{CXX});
        my %version = get_version();
        parse_templates(\%config, \%compiler, \%version);
-       print "Update complete!\n";
+       say 'Update complete!';
        exit 0;
 }
 
 sub run_test($$;$) {
        my ($what, $result, $adjective) = @_;
-       $adjective ||= 'available';
+       $adjective //= 'available';
        print_format "Checking whether <|GREEN $what|> is $adjective ... ";
        print_format $result ? "<|GREEN yes|>\n" : "<|RED no|>\n";
        return $result;
@@ -195,7 +196,7 @@ sub run_test($$;$) {
 sub test_file($$;$) {
        my ($compiler, $file, $args) = @_;
        my $status = 0;
-       $args ||= '';
+       $args //= '';
        $status ||= system "$compiler -o __test_$file make/test/$file $args >/dev/null 2>&1";
        $status ||= system "./__test_$file >/dev/null 2>&1";
        unlink "./__test_$file";
@@ -204,7 +205,7 @@ sub test_file($$;$) {
 
 sub test_header($$;$) {
        my ($compiler, $header, $args) = @_;
-       $args ||= '';
+       $args //= '';
        open(COMPILER, "| $compiler -E - $args >/dev/null 2>&1") or return 0;
        print COMPILER "#include <$header>";
        close(COMPILER);
@@ -228,8 +229,8 @@ sub write_configure_cache(%) {
        my %config = @_;
        open(CACHE, '>', CONFIGURE_CACHE_FILE) or print_error "unable to write ${\CONFIGURE_CACHE_FILE}: $!";
        while (my ($key, $value) = each %config) {
-               $value = '' unless defined $value;
-               print CACHE "$key=\"$value\"\n";
+               $value //= '';
+               say CACHE "$key=\"$value\"";
        }
        close(CACHE);
 }
@@ -251,7 +252,7 @@ sub get_compiler_info($) {
 
 sub find_compiler {
        my @compilers = qw(c++ g++ clang++ icpc);
-       foreach my $compiler (shift || @compilers) {
+       foreach my $compiler (shift // @compilers) {
                return $compiler if __test_compiler $compiler;
                return "xcrun $compiler" if $^O eq 'darwin' && __test_compiler "xcrun $compiler";
        }
@@ -269,7 +270,7 @@ sub get_property($$;$)
                }
        }
        close(MODULE);
-       return defined $default ? $default : '';
+       return $default // '';
 }
 
 sub parse_templates($$$) {
@@ -418,7 +419,7 @@ sub parse_templates($$$) {
                                print_format "Writing <|GREEN $target|> ...\n";
                                open(TARGET, '>', $target) or print_error "unable to write $_: $!";
                                foreach (@final_lines) {
-                                       print TARGET $_, "\n";
+                                       say TARGET $_;
                                }
                                close(TARGET);
 
index 045df8a704c61afd2b6e15c398df597c0447e4c7..4e7b32d4963b01185923830b612d330d3933b0f9 100644 (file)
 package make::console;
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
 }
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -55,7 +56,7 @@ sub __console_format($$) {
 
 sub print_format($;$) {
        my $message = shift;
-       my $stream = shift || *STDOUT;
+       my $stream = shift // *STDOUT;
        while ($message =~ /(<\|(\S+)\s(.+?)\|>)/) {
                my $formatted = __console_format $2, $3;
                $message =~ s/\Q$1\E/$formatted/;
@@ -106,7 +107,7 @@ sub prompt_string($$$) {
        print_format "$question\n";
        print_format "[<|GREEN $default|>] => ";
        chomp(my $answer = <STDIN>);
-       print "\n";
+       say '';
        return $answer ? $answer : $default;
 }
 
index 13b1f01fc9d6d1f928c6b99654633c19453740bd..739f7fc7d82adc3ffd200fa3d85397d1f816ff9f 100755 (executable)
 
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
 }
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -36,15 +37,15 @@ use File::Temp();
 sub prompt($$) {
        my ($question, $default) = @_;
        return prompt_string(1, $question, $default) if eval 'use make::console; 1';
-       print "$question\n";
+       say $question;
        print "[$default] => ";
        chomp(my $answer = <STDIN>);
-       print "\n";
+       say '';
        return $answer ? $answer : $default;
 }
 
 if ($#ARGV != 0 || $ARGV[0] !~ /^(?:auto|gnutls|openssl)$/i) {
-       print "Syntax: genssl <auto|gnutls|openssl>\n";
+       say 'Syntax: genssl <auto|gnutls|openssl>';
        exit 1;
 }
 
@@ -65,14 +66,14 @@ if ($tool eq 'auto') {
        } elsif ($has_openssl) {
                $tool = 'openssl';
        } else {
-               print STDERR "SSL generation failed: could not find $certtool or openssl in the PATH!\n";
+               say STDERR "SSL generation failed: could not find $certtool or openssl in the PATH!";
                exit 1;
        }
 } elsif ($tool eq 'gnutls' && !$has_gnutls) {
-       print STDERR "SSL generation failed: could not find '$certtool' in the PATH!\n";
+       say STDERR "SSL generation failed: could not find '$certtool' in the PATH!";
        exit 1;
 } elsif ($tool eq 'openssl' && !$has_openssl) {
-       print STDERR "SSL generation failed: could not find 'openssl' in the PATH!\n";
+       say STDERR 'SSL generation failed: could not find \'openssl\' in the PATH!';
        exit 1;
 }
 
@@ -138,13 +139,14 @@ __OPENSSL_END__
 }
 
 if ($status) {
-       print STDERR "SSL generation failed: $tool exited with a non-zero status!\n";
+       say STDERR "SSL generation failed: $tool exited with a non-zero status!";
        exit 1;
 }
 
 if (defined $dercert && eval 'use Digest::SHA; 1') {
        my $hash = Digest::SHA->new(256);
        $hash->add($dercert);
-       print "\nAdd this TLSA record to your domain for DANE support:\n";
-       print "_6697._tcp." . $common_name . " TLSA 3 0 1 " . $hash->hexdigest . "\n";
+       say '';
+       say 'Add this TLSA record to your domain for DANE support:';
+       say "_6697._tcp." . $common_name . " TLSA 3 0 1 " . $hash->hexdigest;
 }
index 1b0192e31b959a204f0f09333dbed822b9079660..b0eb255c02c744b4e8a95627aa72d4079ae670b2 100755 (executable)
 
 
 BEGIN {
-       require 5.8.0;
+       require 5.10.0;
        unless (-f 'configure') {
                print "Error: $0 must be run from the main source directory!\n";
                exit 1;
        }
 }
 
+use feature ':5.10';
 use strict;
 use warnings FATAL => qw(all);
 
@@ -39,7 +40,7 @@ system 'git', 'clean', '-dfx';
 my @compilers = $#ARGV >= 0 ? @ARGV : qw(g++ clang++ icpc);
 foreach my $compiler (@compilers) {
        if (system "$compiler -v > /dev/null 2>&1") {
-               print "Skipping $compiler as it is not installed on this system!\n";
+               say "Skipping $compiler as it is not installed on this system!";
                next;
        }
        $ENV{CXX} = $compiler;
@@ -49,23 +50,23 @@ foreach my $compiler (@compilers) {
        push @socketengines, 'poll' if test_header $compiler, 'poll.h';
        push @socketengines, 'ports' if test_header $compiler, 'ports.h';
        foreach my $socketengine (@socketengines) {
-               print "Attempting to build using the $compiler compiler and the $socketengine socket engine...\n";
+               say "Attempting to build using the $compiler compiler and the $socketengine socket engine...";
                system './configure', '--enable-extras', $ENV{TEST_BUILD_MODULES} if defined $ENV{TEST_BUILD_MODULES};
                if (system './configure', '--development', '--socketengine', $socketengine) {
-                       print "Failed to configure using the $compiler compiler and the $socketengine socket engine!\n";
+                       say "Failed to configure using the $compiler compiler and the $socketengine socket engine!";
                        exit 1;
                }
                $ENV{PURE_STATIC} = 1;
                if (system 'make', '-j'.get_cpu_count, 'install') {
-                       print "Failed to compile with static modules using the $compiler compiler and the $socketengine socket engine!\n";
+                       say "Failed to compile with static modules using the $compiler compiler and the $socketengine socket engine!";
                        exit 1;
                }
                delete $ENV{PURE_STATIC};
                if (system 'make', '-j'.get_cpu_count, 'install') {
-                       print "Failed to compile with dynamic modules using the $compiler compiler and the $socketengine socket engine!\n";
+                       say "Failed to compile with dynamic modules using the $compiler compiler and the $socketengine socket engine!";
                        exit 1;
                }
-               print "Building using the $compiler compiler and the $socketengine socket engine succeeded!\n";
+               say "Building using the $compiler compiler and the $socketengine socket engine succeeded!";
        }
 
        system 'git', 'clean', '-dfx';