X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=make%2Fdirective.pm;h=2e9e7ed6182fb3c2fdd55b7060b317c47964b4c5;hb=bb4aa10ed82612624da45d0c9592ddf7f2f51ab5;hp=c490135fd872aac147436d0a04b1793c169e9cd7;hpb=05953e35b03a8136f5906e0add89412f02bfca36;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/directive.pm b/make/directive.pm index c490135fd..2e9e7ed61 100644 --- a/make/directive.pm +++ b/make/directive.pm @@ -41,16 +41,16 @@ our @EXPORT = qw(get_directive sub get_directive($$;$) { my ($file, $property, $default) = @_; - open(MODULE, $file) or return $default; + open(my $fh, $file) or return $default; my $value = ''; - while () { + 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; @@ -80,6 +80,13 @@ sub execute_functions($$$) { 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, ''; @@ -142,7 +149,7 @@ sub __function_execute { # 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}; @@ -170,7 +177,7 @@ sub __function_find_compiler_flags { } # 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}; @@ -197,7 +204,7 @@ sub __function_find_linker_flags { } # 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};