X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Fdirective.pm;h=76ba72907d8d477068042b1d09da13435dd4774f;hb=5d8dc98dfad1e13e840ea0322fb624dc8397fddd;hp=2e9e7ed6182fb3c2fdd55b7060b317c47964b4c5;hpb=7851faac62d7a83c94cd5d37e0109b5d0a152bf9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/directive.pm b/make/directive.pm index 2e9e7ed61..76ba72907 100644 --- a/make/directive.pm +++ b/make/directive.pm @@ -1,7 +1,7 @@ # # InspIRCd -- Internet Relay Chat Daemon # -# Copyright (C) 2016 Peter Powell +# Copyright (C) 2016-2019 Sadie Powell # # This file is part of InspIRCd. InspIRCd is free software: you can # redistribute it and/or modify it under the terms of the GNU General Public @@ -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); @@ -87,6 +89,13 @@ sub __environment { return $prefix . uc $suffix; } +sub __module { + my $file = shift; + my $name = basename $file, '.cpp'; + $name =~ s/^m_//; + return $name; +} + sub __error { my ($file, @message) = @_; push @message, ''; @@ -122,6 +131,9 @@ sub __error { } else { push @message, 'If you believe this error to be a bug then you can file a bug report'; push @message, 'at https://github.com/inspircd/inspircd/issues'; + push @message, ''; + push @message, 'You can also refer to the documentation page for this module at'; + push @message, "https://docs.inspircd.org/3/modules/${\__module $file}"; } push @message, ''; @@ -162,7 +174,7 @@ sub __function_execute { return $defaults; } - # Executing the command failed and we don't have any defaults so give up. + # Executing the command failed and we don't have any defaults so give up. __error $file, "`<|GREEN $command|>` exited with a non-zero exit code!"; } @@ -172,25 +184,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 ${\__module $file}|> using pkg-config: <|BOLD $flags|>\n"; 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 compiler flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n"; + print_format "Found the <|GREEN $name|> compiler flags for <|GREEN ${\__module $file}|> 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 ${\__module $file}|>: <|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 ${\__module $file}|>!"; } sub __function_find_linker_flags { @@ -199,25 +211,41 @@ 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 ${\__module $file}|> using pkg-config: <|BOLD $flags|>\n"; 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 linker flags for <|GREEN ${\basename $file, '.cpp'}|> using the environment: <|BOLD $ENV{$key}|>\n"; + print_format "Found the <|GREEN $name|> linker flags for <|GREEN ${\__module $file}|> 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 ${\__module $file}|>: <|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 ${\__module $file}|>!"; +} + +sub __function_require_compiler { + my ($file, $name, $minimum, $maximum) = @_; + + # Look up information about the compiler. + return undef unless $ENV{CXX}; + my %compiler = get_compiler_info($ENV{CXX}); + + # Check whether the current compiler is suitable. + return undef unless $compiler{NAME} eq $name; + return undef if defined $minimum && $compiler{VERSION} < $minimum; + return undef if defined $maximum && $compiler{VERSION} > $maximum; + + # Requirement directives don't change anything directly. + return ""; } sub __function_require_system { @@ -251,7 +279,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; } @@ -263,6 +291,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 ${\__module $file}|> 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 ${\__module $file}|>: <|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 ${\__module $file}|>!"; +} + sub __function_warning { my ($file, @messages) = @_; print_warning @messages;