sub run_test($$;$) {
my ($what, $result, $adjective) = @_;
$adjective //= 'available';
- print_format "Checking whether <|GREEN $what|> is $adjective ... ";
- print_format $result ? "<|GREEN yes|>\n" : "<|RED no|>\n";
+ print console_format "Checking whether <|GREEN $what|> is $adjective ... ";
+ say console_format $result ? "<|GREEN yes|>" : "<|RED no|>";
return $result;
}
sub write_configure_cache(%) {
unless (-e CONFIGURE_DIRECTORY) {
- print_format "Creating <|GREEN ${\abs2rel CONFIGURE_DIRECTORY, CONFIGURE_ROOT}|> ...\n";
+ say console_format "Creating <|GREEN ${\abs2rel CONFIGURE_DIRECTORY, CONFIGURE_ROOT}|> ...";
create_directory CONFIGURE_DIRECTORY, 0750 or print_error "unable to create ${\CONFIGURE_DIRECTORY}: $!";
}
- print_format "Writing <|GREEN ${\abs2rel CONFIGURE_CACHE_FILE, CONFIGURE_ROOT}|> ...\n";
+ say console_format "Writing <|GREEN ${\abs2rel CONFIGURE_CACHE_FILE, CONFIGURE_ROOT}|> ...";
my %config = @_;
write_config_file CONFIGURE_CACHE_FILE, %config;
}
# Iterate through files in make/template.
foreach my $template (<${\CONFIGURE_ROOT}/make/template/*>) {
- print_format "Parsing <|GREEN ${\abs2rel $template, CONFIGURE_ROOT}|> ...\n";
+ say console_format "Parsing <|GREEN ${\abs2rel $template, CONFIGURE_ROOT}|> ...";
open(my $fh, $template) or print_error "unable to read $template: $!";
my (@lines, $mode, @platforms, @targets);
# Create the directory if it doesn't already exist.
my $directory = dirname $target;
unless (-e $directory) {
- print_format "Creating <|GREEN ${\abs2rel $directory, CONFIGURE_ROOT}|> ...\n";
+ say console_format "Creating <|GREEN ${\abs2rel $directory, CONFIGURE_ROOT}|> ...";
create_directory $directory, 0750 or print_error "unable to create $directory: $!";
};
# Write the template file.
- print_format "Writing <|GREEN ${\abs2rel $target, CONFIGURE_ROOT}|> ...\n";
+ say console_format "Writing <|GREEN ${\abs2rel $target, CONFIGURE_ROOT}|> ...";
open(my $fh, '>', $target) or print_error "unable to write $target: $!";
foreach (@lines) {
say $fh $_;
our @EXPORT = qw(command
execute_command
console_format
- print_format
print_error
print_warning
prompt_bool
return $message;
}
-sub print_format($;$) {
- my $message = shift;
- my $stream = shift // *STDOUT;
- print { $stream } console_format $message;
-}
-
sub print_error {
print STDERR console_format "<|RED Error:|> ";
for my $line (@_) {
my ($interactive, $question, $default) = @_;
return $default unless $interactive;
say console_format $question;
- say console_format "[<|GREEN $default|>] => ";
+ print console_format "[<|GREEN $default|>] => ";
chomp(my $answer = <STDIN>);
say '';
return $answer ? $answer : $default;
sub execute_command(@) {
my $command = defined $_[0] ? lc shift : 'help';
if ($command eq 'help') {
- print_format "<|GREEN Usage:|> $0 <<|UNDERLINE COMMAND|>> [<|UNDERLINE OPTIONS...|>]\n\n";
- print_format "<|GREEN Commands:|>\n";
+ say console_format "<|GREEN Usage:|> $0 <<|UNDERLINE COMMAND|>> [<|UNDERLINE OPTIONS...|>]";
+ say '';
+ say console_format "<|GREEN Commands:|>";
for my $key (sort keys %commands) {
next unless defined $commands{$key}->description;
my $name = sprintf "%-15s", $key;
my $description = $commands{$key}->description;
- print_format " <|BOLD $name|> # $description\n";
+ say console_format " <|BOLD $name|> # $description";
}
exit 0;
} elsif (!$commands{$command}) {
# Try to execute the command...
chomp(my $result = `$command ${\DIRECTIVE_ERROR_PIPE}`);
unless ($?) {
- print_format "Execution of `<|GREEN $command|>` succeeded: <|BOLD $result|>\n";
+ say console_format "Execution of `<|GREEN $command|>` succeeded: <|BOLD $result|>";
return $result;
}
if (defined $environment && $environment ne '') {
$environment = __environment 'INSPIRCD_', $environment;
if (defined $ENV{$environment}) {
- print_format "Execution of `<|GREEN $command|>` failed; using the environment: <|BOLD $ENV{$environment}|>\n";
+ say console_format "Execution of `<|GREEN $command|>` failed; using the environment: <|BOLD $ENV{$environment}|>";
return $ENV{$environment};
}
}
# If all else fails then look for the defaults..
if (defined $defaults) {
- print_format "Execution of `<|GREEN $command|>` failed; using the defaults: <|BOLD $defaults|>\n";
+ say console_format "Execution of `<|GREEN $command|>` failed; using the defaults: <|BOLD $defaults|>";
return $defaults;
}
# Try to look up the compiler flags with pkg-config...
chomp(my $flags = `pkg-config --cflags $name ${\DIRECTIVE_ERROR_PIPE}`);
unless ($?) {
- print_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|> using pkg-config: <|BOLD $flags|>\n";
+ say console_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|> using pkg-config: <|BOLD $flags|>";
return $flags;
}
# If looking up with pkg-config fails then check the environment...
my $key = __environment 'INSPIRCD_CXXFLAGS_', $name;
if (defined $ENV{$key}) {
- print_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>\n";
+ say console_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>";
return $ENV{$key};
}
# If all else fails then look for the defaults..
if (defined $defaults) {
- print_format "Using the default <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|>: <|BOLD $defaults|>\n";
+ say console_format "Using the default <|GREEN $name|> compiler flags for <|GREEN ${\module_shrink $file}|>: <|BOLD $defaults|>";
return $defaults;
}
# Try to look up the linker flags with pkg-config...
chomp(my $flags = `pkg-config --libs $name ${\DIRECTIVE_ERROR_PIPE}`);
unless ($?) {
- print_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|> using pkg-config: <|BOLD $flags|>\n";
+ say console_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|> using pkg-config: <|BOLD $flags|>";
return $flags;
}
# If looking up with pkg-config fails then check the environment...
my $key = __environment 'INSPIRCD_CXXFLAGS_', $name;
if (defined $ENV{$key}) {
- print_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>\n";
+ say console_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>";
return $ENV{$key};
}
# If all else fails then look for the defaults..
if (defined $defaults) {
- print_format "Using the default <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|>: <|BOLD $defaults|>\n";
+ say console_format "Using the default <|GREEN $name|> linker flags for <|GREEN ${\module_shrink $file}|>: <|BOLD $defaults|>";
return $defaults;
}
# Try to look the directory up in the environment...
my $key = __environment 'INSPIRCD_VENDOR_', $name;
if (defined $ENV{$key}) {
- print_format "Found the <|GREEN $name|> vendor directory for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>\n";
+ say console_format "Found the <|GREEN $name|> vendor directory for <|GREEN ${\module_shrink $file}|> using the environment: <|BOLD $ENV{$key}|>";
return $ENV{$key};
}
my $directory = catdir(VENDOR_DIRECTORY, $name);
if (-d $directory) {
- print_format "Using the default <|GREEN $name|> vendor directory for <|GREEN ${\module_shrink $file}|>: <|BOLD $directory|>\n";
+ say console_format "Using the default <|GREEN $name|> vendor directory for <|GREEN ${\module_shrink $file}|>: <|BOLD $directory|>";
return $directory;
}