sub get_directive($$;$)
{
my ($file, $property, $default) = @_;
- open(MODULE, $file) or return $default;
+ open(my $fh, $file) or return $default;
my $value = '';
- while (<MODULE>) {
+ while (<$fh>) {
if ($_ =~ /^\/\* \$(\S+): (.+) \*\/$/ || $_ =~ /^\/\/\/ \$(\S+): (.+)/) {
next unless $1 eq $property;
$value .= ' ' . execute_functions($file, $1, $2);
}
}
- close(MODULE);
+ close $fh;
# Strip all extraneous whitespace.
$value =~ s/^\s+|\s+$//g;
return $line;
}
+sub __environment {
+ my ($prefix, $suffix) = @_;
+ $suffix =~ s/[-.]/_/g;
+ $suffix =~ s/[^A-Za-z0-9_]//g;
+ return $prefix . uc $suffix;
+}
+
sub __error {
my ($file, @message) = @_;
push @message, '';
# If looking up with pkg-config fails then check the environment...
if (defined $environment && $environment ne '') {
- $environment = sprintf('INSPIRCD_%s', uc $environment);
+ $environment = __environment 'INSPIRCD_', $environment;
if (defined $ENV{$environment}) {
print_format "Execution of `<|GREEN $command|>` failed; using the environment: <|BOLD $ENV{$environment}|>\n";
return $ENV{$environment};
}
# If looking up with pkg-config fails then check the environment...
- my $key = sprintf('INSPIRCD_CXXFLAGS_%s', uc $name);
+ my $key = __environment 'INSPIRCD_CXXFLAGS_', $name;
if (defined $ENV{$key}) {
print_format "Found the compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n";
return $ENV{$key};
}
# If looking up with pkg-config fails then check the environment...
- my $key = sprintf('INSPIRCD_LDFLAGS_%s', uc $name);
+ my $key = __environment 'INSPIRCD_CXXFLAGS_', $name;
if (defined $ENV{$key}) {
print_format "Found the linker flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n";
return $ENV{$key};