summaryrefslogtreecommitdiff
path: root/make
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2013-08-18 03:49:25 -0700
committerAttila Molnar <attilamolnar@hush.com>2013-08-18 03:49:25 -0700
commit02267976f636e3c4fffc8732a949b4777a771ca2 (patch)
tree03139f43d6723876a8c9480a91207de62ed90028 /make
parente950f568d0f571e9475aa38177486468714de4d3 (diff)
parent3070548ceeffd3c09ce26d816a1d225dbe9d137e (diff)
Merge pull request #609 from SaberUK/master+configure-sub-shuffle
Clean up and move various subroutines.
Diffstat (limited to 'make')
-rw-r--r--make/configure.pm331
-rw-r--r--make/template/main.mk6
-rw-r--r--make/utilities.pm55
3 files changed, 213 insertions, 179 deletions
diff --git a/make/configure.pm b/make/configure.pm
index ba67545ac..286424080 100644
--- a/make/configure.pm
+++ b/make/configure.pm
@@ -21,42 +21,175 @@
#
-package make::configure;
+BEGIN {
+ require 5.8.0;
+}
-require 5.8.0;
+package make::configure;
use strict;
use warnings FATAL => qw(all);
+use Cwd;
use Exporter 'import';
-use POSIX;
+
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);
+
+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
+ get_property get_revision
+ dump_hash);
my $revision;
+sub __get_socketengines() {
+ my @socketengines;
+ foreach (<src/socketengines/socketengine_*.cpp>) {
+ s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
+ push @socketengines, $1;
+ }
+ return @socketengines;
+}
+
+sub cmd_clean {
+ unlink '.config.cache';
+}
+
+sub cmd_help {
+ my $PWD = getcwd();
+ my $SELIST = join ', ', __get_socketengines();
+ print <<EOH;
+Usage: $0 [options]
+
+When no options are specified, configure runs in interactive mode and you must
+specify any required values manually. If one or more options are specified,
+non-interactive configuration is started and any omitted values are defaulted.
+
+PATH OPTIONS
+
+ --system Automatically set up the installation paths
+ for system-wide installation.
+ --prefix=[dir] The root install directory. If this is set then
+ all subdirectories will be adjusted accordingly.
+ [$PWD/run]
+ --binary-dir=[dir] The location where the main server binary is
+ stored.
+ [$PWD/run/bin]
+ --config-dir=[dir] The location where the configuration files and
+ SSL certificates are stored.
+ [$PWD/run/conf]
+ --data-dir=[dir] The location where the data files, such as the
+ pid file, are stored.
+ [$PWD/run/data]
+ --log-dir=[dir] The location where the log files are stored.
+ [$PWD/run/logs]
+ --module-dir=[dir] The location where the loadable modules are
+ stored.
+ [$PWD/run/modules]
+ --build-dir=[dir] The location to store files in while building.
+
+
+EXTRA MODULE OPTIONS
+
+ --enable-extras=[extras] Enables a comma separated list of extra modules.
+ --disable-extras=[extras] Disables a comma separated list of extra modules.
+ --list-extras Shows the availability status of all extra
+ modules.
+
+MISC OPTIONS
+
+ --clean Remove the configuration cache file and start
+ the interactive configuration wizard.
+ --disable-interactive Disables the interactive configuration wizard.
+ --help Show this message and exit.
+ --uid=[name] Sets the user to run InspIRCd as.
+ --socketengine=[name] Sets the socket engine to be used. Possible
+ values are $SELIST.
+ --update Updates the build environment.
+
+
+FLAGS
+
+ CXX=[name] Sets the C++ compiler to use when building the
+ server. If not specified then the build system
+ will search for c++, g++, clang++ or icpc.
+
+If you have any problems with configuring InspIRCd then visit our IRC channel
+at irc.ChatSpike.net #InspIRCd.
+
+EOH
+ exit 0;
+}
+
+sub cmd_update {
+ unless (-f '.config.cache') {
+ print "You have not run $0 before. Please do this before trying to update the build files.\n";
+ exit 1;
+ }
+ print "Updating...\n";
+ %main::config = read_configure_cache();
+ %main::cxx = get_compiler_info($main::config{CXX});
+ $main::topdir = getcwd();
+ main::writefiles();
+ print "Update complete!\n";
+ exit 0;
+}
+
+sub read_configure_cache {
+ my %cfg = ();
+ open(CACHE, '.config.cache') or return %cfg;
+ while (my $line = <CACHE>) {
+ 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 +227,6 @@ sub test_header($$;$) {
return !$?;
}
-sub yesno {
- my ($flag,$prompt) = @_;
- print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
- chomp(my $tmp = <STDIN>);
- 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,89 +242,14 @@ sub get_property($$;$)
return defined $default ? $default : '';
}
-sub getrevision {
+sub get_revision {
return $revision if defined $revision;
chomp(my $tags = `git describe --tags 2>/dev/null`);
$revision = $tags || 'release';
return $revision;
}
-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($$)
-{
- 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 = <STDIN>);
- 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";
- }
- }
-}
-
-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 = <STDIN>);
- $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";
@@ -221,57 +263,4 @@ 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 (<src/socketengines/socketengine_*.cpp>) {
- s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
- push(@socketengines, $1);
- }
- $SELIST = join(", ", @socketengines);
- print <<EOH;
-Usage: configure [options]
-
-When no options are specified, interactive
-configuration is started and you must specify
-any required values manually. If one or more
-options are specified, non-interactive configuration
-is started, and any omitted values are defaulted.
-
-Arguments with a single \"-\" symbol are also allowed.
-
- --disable-interactive Sets no options itself, but
- will disable any interactive prompting.
- --update Update makefiles and dependencies
- --clean Remove .config.cache file and go interactive
- --enable-gnutls Enable GnuTLS module [no]
- --enable-openssl Enable OpenSSL module [no]
- --socketengine=[name] Sets the socket engine to be used. Possible values are
- $SELIST.
- --prefix=[directory] Base directory to install into (if defined,
- can automatically define config, data, module,
- log and binary dirs as subdirectories of prefix)
- [$PWD]
- --config-dir=[directory] Config file directory for config and SSL certs
- [$PWD/conf]
- --log-dir=[directory] Log file directory for logs
- [$PWD/logs]
- --data-dir=[directory] Data directory for variable data, such as the permchannel
- configuration and the XLine database
- [$PWD/data]
- --module-dir=[directory] Modules directory for loadable modules
- [$PWD/modules]
- --binary-dir=[directory] Binaries directory for core binary
- [$PWD/bin]
- --list-extras Show current status of extra modules
- --enable-extras=[extras] Enable the specified list of extras
- --disable-extras=[extras] Disable the specified list of extras
- --help Show this help text and exit
-
-EOH
- exit(0);
-}
-
1;
-
diff --git a/make/template/main.mk b/make/template/main.mk
index b93c15094..bdb4d9762 100644
--- a/make/template/main.mk
+++ b/make/template/main.mk
@@ -46,9 +46,9 @@ DATPATH = "$(DESTDIR)@DATA_DIR@"
BINPATH = "$(DESTDIR)@BINARY_DIR@"
INSTALL = install
INSTUID = @UID@
-INSTMODE_DIR = 0755
-INSTMODE_BIN = 0755
-INSTMODE_LIB = 0644
+INSTMODE_DIR = 0750
+INSTMODE_BIN = 0750
+INSTMODE_LIB = 0640
@IFNEQ $(COMPILER) icc
CORECXXFLAGS += -pedantic -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute
diff --git a/make/utilities.pm b/make/utilities.pm
index 9bafe372e..87aa46d6e 100644
--- a/make/utilities.pm
+++ b/make/utilities.pm
@@ -20,18 +20,22 @@
#
-package make::utilities;
+BEGIN {
+ require 5.8.0;
+}
-require 5.8.0;
+package make::utilities;
use strict;
use warnings FATAL => qw(all);
use Exporter 'import';
-use POSIX;
-use Getopt::Long;
use Fcntl;
-our @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
+use File::Path;
+use File::Spec::Functions qw(rel2abs);
+use Getopt::Long;
+
+our @EXPORT = qw(module_installed prompt_bool prompt_dir prompt_string make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
# Parse the output of a *_config program,
# such as pcre_config, take out the -L
@@ -42,6 +46,47 @@ our @EXPORT = qw(make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pk
my %already_added = ();
my $if_skip_lines = 0;
+sub module_installed($)
+{
+ my $module = shift;
+ eval("use $module;");
+ return !$@;
+}
+
+sub prompt_bool($$$) {
+ my ($interactive, $question, $default) = @_;
+ my $answer = prompt_string($interactive, $question, $default ? 'y' : 'n');
+ return $answer =~ /y/i;
+}
+
+sub prompt_dir($$$) {
+ my ($interactive, $question, $default) = @_;
+ my ($answer, $create) = (undef, 'y');
+ do {
+ $answer = rel2abs(prompt_string($interactive, $question, $default));
+ $create = prompt_bool($interactive && !-d $answer, "$answer does not exist. Create it?", 'y');
+ my $mkpath = eval {
+ mkpath($answer, 0, 0750);
+ return 1;
+ };
+ unless (defined $mkpath) {
+ print "Error: unable to create $answer!\n\n";
+ $create = 0;
+ }
+ } while (!$create);
+ return $answer;
+}
+
+sub prompt_string($$$) {
+ my ($interactive, $question, $default) = @_;
+ return $default unless $interactive;
+ print $question, "\n";
+ print "[\e[1;32m$default\e[0m] => ";
+ chomp(my $answer = <STDIN>);
+ print "\n";
+ return $answer ? $answer : $default;
+}
+
sub promptstring($$$$$)
{
my ($prompt, $configitem, $default, $package, $commandlineswitch) = @_;