X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Fdirective.pm;h=b178228fd67014db3f274ca73ad51ac5ed8709aa;hb=b2ac8cc0a6405946a388b80df3be21bc276a61f3;hp=c490135fd872aac147436d0a04b1793c169e9cd7;hpb=806e57433a38193ae14942ee60f573fe47f4b643;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/directive.pm b/make/directive.pm index c490135fd..b178228fd 100644 --- a/make/directive.pm +++ b/make/directive.pm @@ -27,13 +27,15 @@ use feature ':5.10'; use strict; use warnings FATAL => qw(all); -use File::Basename qw(basename); -use Exporter qw(import); +use File::Basename qw(basename dirname); +use File::Spec::Functions qw(catdir); +use Exporter qw(import); use make::configure; use make::console; use constant DIRECTIVE_ERROR_PIPE => $ENV{INSPIRCD_VERBOSE} ? '' : '2>/dev/null'; +use constant VENDOR_DIRECTORY => catdir(dirname(dirname(__FILE__)), 'vendor'); our @EXPORT = qw(get_directive execute_functions); @@ -41,16 +43,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 +82,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 +151,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}; @@ -165,25 +174,25 @@ sub __function_find_compiler_flags { # 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 compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using pkg-config: <|BOLD $flags|>\n"; + print_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using pkg-config: <|BOLD $flags|>\n"; return $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"; + print_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n"; return $ENV{$key}; } # If all else fails then look for the defaults.. if (defined $defaults) { - print_format "Found the compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using the defaults: <|BOLD $defaults|>\n"; + print_format "Using the default <|GREEN $name|> compiler flags for <|GREEN ${\basename $file, '.cpp'}|>: <|BOLD $defaults|>\n"; return $defaults; } # We can't find it via pkg-config, via the environment, or via the defaults so give up. - __error $file, "unable to find the compiler flags for <|GREEN ${\basename $file, '.cpp'}|>!"; + __error $file, "unable to find the <|GREEN $name|> compiler flags for <|GREEN ${\basename $file, '.cpp'}|>!"; } sub __function_find_linker_flags { @@ -192,25 +201,25 @@ sub __function_find_linker_flags { # 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 linker flags for <|GREEN ${\basename $file, '.cpp'}|> using pkg-config: <|BOLD $flags|>\n"; + print_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\basename $file, '.cpp'}|> using pkg-config: <|BOLD $flags|>\n"; return $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"; + print_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n"; return $ENV{$key}; } # If all else fails then look for the defaults.. if (defined $defaults) { - print_format "Found the linker flags for <|GREEN ${\basename $file, '.cpp'}|> using the defaults: <|BOLD $defaults|>\n"; + print_format "Using the default <|GREEN $name|> linker flags for <|GREEN ${\basename $file, '.cpp'}|>: <|BOLD $defaults|>\n"; return $defaults; } # We can't find it via pkg-config, via the environment, or via the defaults so give up. - __error $file, "unable to find the linker flags for <|GREEN ${\basename $file, '.cpp'}|>!"; + __error $file, "unable to find the <|GREEN $name|> linker flags for <|GREEN ${\basename $file, '.cpp'}|>!"; } sub __function_require_system { @@ -244,7 +253,7 @@ sub __function_require_version { # If pkg-config isn't installed then we can't do anything here. if (system "pkg-config --exists $name ${\DIRECTIVE_ERROR_PIPE}") { - print_warning "unable to look up the version of $name using pkg-config!"; + print_warning "unable to look up the version of <|GREEN $name|> using pkg-config!"; return undef; } @@ -256,6 +265,26 @@ sub __function_require_version { return ""; } +sub __function_vendor_directory { + my ($file, $name) = @_; + + # 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 ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n"; + return $ENV{$key}; + } + + my $directory = catdir(VENDOR_DIRECTORY, $name); + if (-d $directory) { + print_format "Using the default <|GREEN $name|> vendor directory for <|GREEN ${\basename $file, '.cpp'}|>: <|BOLD $directory|>\n"; + return $directory; + } + + # We can't find it via the environment or via the filesystem so give up. + __error $file, "unable to find the <|GREEN $name|> vendor directory for <|GREEN ${\basename $file, '.cpp'}|>!"; +} + sub __function_warning { my ($file, @messages) = @_; print_warning @messages;