X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=make%2Fconfigure.pm;h=d04a0b645d83fc87777df090025492344173e13b;hb=11f4d02e7020cb5775d2b89af0e652e53cd90ed7;hp=ba67545ac36eb2fe41ec87d0338668fa6de6f072;hpb=68afa315fccf5d741103137cb65d613a4e9bfef1;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/make/configure.pm b/make/configure.pm index ba67545ac..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 run_test test_file test_header promptnumeric dumphash getmodules getrevision get_property 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') { @@ -94,22 +250,6 @@ 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 get_property($$;$) { my ($file, $property, $default) = @_; @@ -125,153 +265,176 @@ sub get_property($$;$) return defined $default ? $default : ''; } -sub getrevision { - return $revision if defined $revision; - chomp(my $tags = `git describe --tags 2>/dev/null`); - $revision = $tags || 'release'; - return $revision; +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"; + print "\e[0mData path:\e[1;32m\t\t\t$main::config{DATA_DIR}\e[0m\n"; + print "\e[0mLog path:\e[1;32m\t\t\t$main::config{LOG_DIR}\e[0m\n"; + print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n"; + print "\e[0mCompiler:\e[1;32m\t\t\t$main::cxx{NAME} $main::cxx{VERSION}\e[0m\n"; + print "\e[0mSocket engine:\e[1;32m\t\t\t$main::config{SOCKETENGINE}\e[0m\n"; + print "\e[0mGnuTLS support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n"; + print "\e[0mOpenSSL support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n"; } -sub getmodules -{ - my ($silent) = @_; +sub parse_templates($$) { - my $i = 0; + # These are actually hash references + my ($config, $compiler) = @_; - if (!$silent) - { - print "Detecting modules "; - } + # Collect settings to be used when generating files + my %settings = __get_template_settings($config, $compiler); + + # Iterate through files in make/template. + foreach () { + print_format "Parsing <|GREEN $_|> ...\n"; + open(TEMPLATE, $_) or print_error "unable to read $_: $!"; + my (@lines, $mode, @platforms, %targets); - 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 "."; + # First pass: parse template variables and directives. + while (my $line =