X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Fconfigure.pm;h=d04a0b645d83fc87777df090025492344173e13b;hb=11f4d02e7020cb5775d2b89af0e652e53cd90ed7;hp=de49bd53cf4df176acd399f6b5e9efcfac081e98;hpb=8692ce1b65bd38c41f36fdbb7fa2000b1ce03639;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/configure.pm b/make/configure.pm index de49bd53c..d04a0b645 100644 --- a/make/configure.pm +++ b/make/configure.pm @@ -1,7 +1,7 @@ # # InspIRCd -- Internet Relay Chat Daemon # -# Copyright (C) 2012 Peter Powell +# Copyright (C) 2012-2014 Peter Powell # Copyright (C) 2008 Robin Burchell # Copyright (C) 2007-2008 Craig Edwards # Copyright (C) 2008 Thomas Stagner @@ -21,42 +21,198 @@ # -package make::configure; +BEGIN { + require 5.8.0; +} -require 5.8.0; +package make::configure; use strict; use warnings FATAL => qw(all); +use Cwd 'getcwd'; use Exporter 'import'; -use POSIX; +use File::Basename 'basename'; + +use make::console; use make::utilities; -our @EXPORT = qw(get_compiler_info find_compiler test_file test_header promptnumeric dumphash getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic yesno showhelp promptstring_s module_installed); -my $revision; +our @EXPORT = qw(cmd_clean cmd_help cmd_update + read_configure_cache write_configure_cache + get_compiler_info find_compiler + run_test test_file test_header + dump_hash get_property parse_templates); + +sub __get_socketengines() { + my @socketengines; + foreach () { + s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/; + push @socketengines, $1; + } + return @socketengines; +} + +# TODO: when buildtool is done this can be mostly removed with +# the remainder being merged into parse_templates. +sub __get_template_settings($$) { + + # These are actually hash references + my ($config, $compiler) = @_; + + # Start off by populating with the config + my %settings = %$config; + + # Compiler information + while (my ($key, $value) = each %{$compiler}) { + $settings{'COMPILER_' . $key} = $value; + } + + # Version information + my %version = get_version(); + while (my ($key, $value) = each %version) { + $settings{'VERSION_' . $key} = $value; + } + + # Miscellaneous information + $settings{SYSTEM_NAME} = lc $^O; + chomp($settings{SYSTEM_NAME_VERSION} = `uname -sr 2>/dev/null`); + + return %settings; +} + +sub cmd_clean { + unlink '.config.cache'; +} + +sub cmd_help { + my $PWD = getcwd(); + my $SELIST = join ', ', __get_socketengines(); + print <) { + next if $line =~ /^\s*($|\#)/; + my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/); + $cfg{$key} = $value; + } + close(CACHE); + return %cfg; +} + +sub write_configure_cache(%) { + my %cfg = @_; + open(CACHE, ">.config.cache") or return 0; + while (my ($key, $value) = each %cfg) { + $value = "" unless defined $value; + print CACHE "$key=\"$value\"\n"; + } + close(CACHE); + return 1; +} sub get_compiler_info($) { - my %info = (NAME => shift, VERSION => '0.0'); - my $version = `$info{NAME} -v 2>&1`; - return (ERROR => 1) if $?; - if ($version =~ /(?:clang|llvm)\sversion\s(\d+\.\d+)/i) { - $info{NAME} = 'Clang'; - $info{VERSION} = $1; - $info{UNSUPPORTED} = $1 lt '3.0'; - $info{REASON} = 'Clang 2.9 and older do not have adequate C++ support.'; - } elsif ($version =~ /gcc\sversion\s(\d+\.\d+)/i) { - $info{NAME} = 'GCC'; - $info{VERSION} = $1; - $info{UNSUPPORTED} = $1 lt '4.1'; - $info{REASON} = 'GCC 4.0 and older do not have adequate C++ support.'; - } elsif ($version =~ /(?:icc|icpc)\sversion\s(\d+\.\d+).\d+\s\(gcc\sversion\s(\d+\.\d+).\d+/i) { - $info{NAME} = 'ICC'; - $info{VERSION} = $1; - $info{UNSUPPORTED} = $2 lt '4.1'; - $info{REASON} = "ICC $1 (GCC $2 compatibility mode) does not have adequate C++ support." - } - return %info; -} + my $binary = shift; + my $version = `$binary -v 2>&1`; + if ($version =~ /(?:clang|llvm)\sversion\s(\d+\.\d+)/i) { + return ( + NAME => 'Clang', + VERSION => $1, + UNSUPPORTED => $1 lt '3.0', + REASON => 'Clang 2.9 and older do not have adequate C++ support.' + ); + } elsif ($version =~ /gcc\sversion\s(\d+\.\d+)/i) { + return ( + NAME => 'GCC', + VERSION => $1, + UNSUPPORTED => $1 lt '4.1', + REASON => 'GCC 4.0 and older do not have adequate C++ support.' + ); + } elsif ($version =~ /(?:icc|icpc)\sversion\s(\d+\.\d+).\d+\s\(gcc\sversion\s(\d+\.\d+).\d+/i) { + return ( + NAME => 'ICC', + VERSION => $1, + UNSUPPORTED => $2 lt '4.1', + REASON => "ICC $1 (GCC $2 compatibility mode) does not have adequate C++ support." + ); + } + return ( + NAME => $binary, + VERSION => '0.0' + ); +} sub find_compiler { foreach my $compiler ('c++', 'g++', 'clang++', 'icpc') { @@ -68,6 +224,13 @@ sub find_compiler { return ""; } +sub run_test($$) { + my ($what, $result) = @_; + print "Checking whether $what is available... "; + print $result ? "yes\n" : "no\n"; + return $result; +} + sub test_file($$;$) { my ($cc, $file, $args) = @_; my $status = 0; @@ -87,166 +250,22 @@ sub test_header($$;$) { return !$?; } -sub yesno { - my ($flag,$prompt) = @_; - print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> "; - chomp(my $tmp = ); - if ($tmp eq "") { $tmp = $main::config{$flag} } - if (($tmp eq "") || ($tmp =~ /^y/i)) - { - $main::config{$flag} = "y"; - } - else - { - $main::config{$flag} = "n"; - } - return; -} - -sub getrevision { - return $revision if defined $revision; - chomp(my $tags = `git describe --tags 2>/dev/null`); - $revision = $tags || 'release'; - return $revision; -} - -sub getcompilerflags { - my ($file) = @_; - open(FLAGS, $file) or return ""; - while () { - if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) { - my $x = translate_functions($1, $file); - next if ($x eq ""); - close(FLAGS); - return $x; - } - } - close(FLAGS); - return ""; -} - -sub getlinkerflags { - my ($file) = @_; - open(FLAGS, $file) or return ""; - while () { - if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) { - my $x = translate_functions($1, $file); - next if ($x eq ""); - close(FLAGS); - return $x; - } - } - close(FLAGS); - return ""; -} - -sub getdependencies { - my ($file) = @_; - open(FLAGS, $file) or return ""; - while () { - if ($_ =~ /^\/\* \$ModDep: (.+) \*\/$/) { - my $x = translate_functions($1, $file); - next if ($x eq ""); - close(FLAGS); - return $x; - } - } - close(FLAGS); - return ""; -} - -sub nopedantic { - my ($file) = @_; - open(FLAGS, $file) or return ""; - while () { - if ($_ =~ /^\/\* \$NoPedantic \*\/$/) { - my $x = translate_functions($_, $file); - next if ($x eq ""); - close(FLAGS); - return 1; - } - } - close(FLAGS); - return 0; -} - -sub getmodules -{ - my ($silent) = @_; - - my $i = 0; - - if (!$silent) - { - print "Detecting modules "; - } - - opendir(DIRHANDLE, "src/modules") or die("WTF, missing src/modules!"); - foreach my $name (sort readdir(DIRHANDLE)) - { - if ($name =~ /^m_(.+)\.cpp$/) - { - my $mod = $1; - $main::modlist[$i++] = $mod; - if (!$silent) - { - print "."; - } - } - } - closedir(DIRHANDLE); - - if (!$silent) - { - print "\nOk, $i modules.\n"; - } -} - -sub promptnumeric($$) +sub get_property($$;$) { - my $continue = 0; - my ($prompt, $configitem) = @_; - while (!$continue) - { - print "Please enter the maximum $prompt?\n"; - print "[\e[1;32m$main::config{$configitem}\e[0m] -> "; - chomp(my $var = ); - if ($var eq "") - { - $var = $main::config{$configitem}; - } - if ($var =~ /^\d+$/) { - # We don't care what the number is, set it and be on our way. - $main::config{$configitem} = $var; - $continue = 1; - print "\n"; - } else { - print "You must enter a number in this field. Please try again.\n\n"; + my ($file, $property, $default) = @_; + open(MODULE, $file) or return $default; + while () { + if ($_ =~ /^\/\* \$(\S+): (.+) \*\/$/) { + next unless $1 eq $property; + close(MODULE); + return translate_functions($2, $file); } } + close(MODULE); + return defined $default ? $default : ''; } -sub module_installed($) -{ - my $module = shift; - eval("use $module;"); - return !$@; -} - -sub promptstring_s($$) -{ - my ($prompt,$default) = @_; - my $var; - print "$prompt\n"; - print "[\e[1;32m$default\e[0m] -> "; - chomp($var = ); - $var = $default if $var eq ""; - print "\n"; - return $var; -} - -sub dumphash() -{ +sub dump_hash() { print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n"; print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n"; print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n"; @@ -259,57 +278,163 @@ sub dumphash() print "\e[0mOpenSSL support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n"; } -sub showhelp -{ - chomp(my $PWD = `pwd`); - my (@socketengines, $SELIST); - foreach () { - s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/; - push(@socketengines, $1); - } - $SELIST = join(", ", @socketengines); - print <) { + print_format "Parsing <|GREEN $_|> ...\n"; + open(TEMPLATE, $_) or print_error "unable to read $_: $!"; + my (@lines, $mode, @platforms, %targets); + + # First pass: parse template variables and directives. + while (my $line =