summaryrefslogtreecommitdiff
path: root/make
diff options
context:
space:
mode:
Diffstat (limited to 'make')
-rwxr-xr-xmake/calcdep.pl57
-rw-r--r--make/configure.pm605
-rw-r--r--make/gnutlscert.pm149
-rw-r--r--make/opensslcert.pm59
-rw-r--r--make/template/config.h38
-rw-r--r--make/template/gdbargs4
-rw-r--r--make/template/inspircd7
-rw-r--r--make/template/inspircd-genssl.146
-rw-r--r--make/template/inspircd.1104
-rw-r--r--make/template/inspircd.service35
-rw-r--r--make/template/main.mk111
-rw-r--r--make/template/org.inspircd.plist1
-rw-r--r--make/test/clock_gettime.cpp25
-rw-r--r--make/test/eventfd.cpp (renamed from make/check_eventfd.cpp)0
-rw-r--r--make/test/kqueue.cpp (renamed from make/check_epoll.cpp)5
-rwxr-xr-xmake/unit-cc.pl12
-rw-r--r--make/utilities.pm136
17 files changed, 818 insertions, 576 deletions
diff --git a/make/calcdep.pl b/make/calcdep.pl
index 4a759a24a..376d19573 100755
--- a/make/calcdep.pl
+++ b/make/calcdep.pl
@@ -27,7 +27,7 @@ sub find_output;
sub gendep($);
sub dep_cpp($$$);
sub dep_so($);
-sub dep_dir($);
+sub dep_dir($$);
sub run();
my %f2dep;
@@ -44,7 +44,7 @@ sub run() {
mkdir $_ for qw/bin modules obj/;
# BSD make has a horribly annoying bug resulting in an extra chdir of the make process
# Create symlinks to work around it
- symlink "../$_", "obj/$_" for qw/bin modules obj/;
+ symlink "../$_", "obj/$_" for qw/bin coremods modules obj/;
$build = getcwd();
open MAKE, '>real.mk' or die "Could not write real.mk: $!";
@@ -71,20 +71,28 @@ bad-target:
\@echo "in order to set the correct environment variables"
\@exit 1
-all: inspircd commands modules
+all: inspircd coremods modules
END
- my(@core_deps, @cmdlist, @modlist);
+ my(@core_deps, @cmodlist, @modlist);
for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, "threadengines/threadengine_pthread.cpp") {
my $out = find_output $file;
dep_cpp $file, $out, 'gen-o';
- next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
+ next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
push @core_deps, $out;
}
- for my $file (<commands/*.cpp>) {
- my $out = dep_so $file;
- push @cmdlist, $out;
+ opendir my $coremoddir, 'coremods';
+ for my $file (sort readdir $coremoddir) {
+ next if $file =~ /^\./;
+ if ($file =~ /^core_/ && -d "coremods/$file" && dep_dir "coremods/$file", "modules/$file") {
+ mkdir "$build/obj/$file";
+ push @cmodlist, "modules/$file.so";
+ }
+ if ($file =~ /^core_.*\.cpp$/) {
+ my $out = dep_so "coremods/$file";
+ push @cmodlist, $out;
+ }
}
opendir my $moddir, 'modules';
@@ -96,7 +104,7 @@ END
rename "modules/$file", "modules/$file~";
symlink "extra/$file", "modules/$file";
}
- if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file") {
+ if ($file =~ /^m_/ && -d "modules/$file" && dep_dir "modules/$file", "modules/$file") {
mkdir "$build/obj/$file";
push @modlist, "modules/$file.so";
}
@@ -107,7 +115,7 @@ END
}
my $core_mk = join ' ', @core_deps;
- my $cmds = join ' ', @cmdlist;
+ my $cmods = join ' ', @cmodlist;
my $mods = join ' ', @modlist;
print MAKE <<END;
@@ -116,11 +124,11 @@ bin/inspircd: $core_mk
inspircd: bin/inspircd
-commands: $cmds
+coremods: $cmods
modules: $mods
-.PHONY: all bad-target inspircd commands modules
+.PHONY: all bad-target inspircd coremods modules
END
}
@@ -141,14 +149,14 @@ all: inspircd
END
my(@deps, @srcs);
- for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <commands/*.cpp>,
+ for my $file (<*.cpp>, <modes/*.cpp>, <socketengines/*.cpp>, <coremods/*.cpp>, <coremods/core_*/*.cpp>,
<modules/*.cpp>, <modules/m_*/*.cpp>, "threadengines/threadengine_pthread.cpp") {
my $out = find_output $file, 1;
if ($out =~ m#obj/([^/]+)/[^/]+.o$#) {
mkdir "$ENV{BUILDPATH}/obj/$1";
}
dep_cpp $file, $out, 'gen-o';
- next if $file =~ m#^socketengines/# && $file ne "socketengines/$ENV{SOCKETENGINE}.cpp";
+ next if $file =~ m#^socketengines/# && $file ne "socketengines/socketengine_$ENV{SOCKETENGINE}.cpp";
push @deps, $out;
push @srcs, $file;
}
@@ -173,11 +181,11 @@ END
sub find_output {
my($file, $static) = @_;
my($path,$base) = $file =~ m#^((?:.*/)?)([^/]+)\.cpp# or die "Bad file $file";
- if ($path eq 'modules/' || $path eq 'commands/') {
+ if ($path eq 'modules/' || $path eq 'coremods/') {
return $static ? "obj/$base.o" : "modules/$base.so";
} elsif ($path eq '' || $path eq 'modes/' || $path =~ /^[a-z]+engines\/$/) {
return "obj/$base.o";
- } elsif ($path =~ m#modules/(m_.*)/#) {
+ } elsif ($path =~ m#modules/(m_.*)/# || $path =~ m#coremods/(core_.*)/#) {
return "obj/$1/$base.o";
} else {
die "Can't determine output for $file";
@@ -199,7 +207,7 @@ sub gendep($) {
while (<$in>) {
if (/^\s*#\s*include\s*"([^"]+)"/) {
my $inc = $1;
- next if $inc eq 'inspircd_version.h' && $f eq '../include/inspircd.h';
+ next if $inc eq 'config.h' && $f eq '../include/inspircd.h';
my $found = 0;
for my $loc ("$basedir/$inc", "../include/$inc") {
next unless -e $loc;
@@ -231,20 +239,13 @@ sub dep_cpp($$$) {
sub dep_so($) {
my($file) = @_;
my $out = find_output $file;
- my $split = find_output $file, 1;
- if ($ENV{SPLIT_CC}) {
- dep_cpp $file, $split, 'gen-o';
- print MAKE "$out: $split\n";
- print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-so\$(VERBOSE) \$\@ \$(SOURCEPATH)/src/$file \$>\n";
- } else {
- dep_cpp $file, $out, 'gen-so';
- }
+ dep_cpp $file, $out, 'gen-so';
return $out;
}
-sub dep_dir($) {
- my($dir) = @_;
+sub dep_dir($$) {
+ my($dir, $outdir) = @_;
my @ofiles;
opendir DIR, $dir;
for my $file (sort readdir DIR) {
@@ -256,7 +257,7 @@ sub dep_dir($) {
closedir DIR;
if (@ofiles) {
my $ofiles = join ' ', @ofiles;
- print MAKE "$dir.so: $ofiles\n";
+ print MAKE "$outdir.so: $ofiles\n";
print MAKE "\t@\$(SOURCEPATH)/make/unit-cc.pl link-dir\$(VERBOSE) \$\@ \$^ \$>\n";
return 1;
} else {
diff --git a/make/configure.pm b/make/configure.pm
index f877846fc..905233835 100644
--- a/make/configure.pm
+++ b/make/configure.pm
@@ -1,7 +1,7 @@
#
# InspIRCd -- Internet Relay Chat Daemon
#
-# Copyright (C) 2012 Peter Powell <petpow@saberuk.com>
+# Copyright (C) 2012-2014 Peter Powell <petpow@saberuk.com>
# Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
# Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
# Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
@@ -21,289 +21,422 @@
#
-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::utilities;
-our @EXPORT = qw(promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
-
-my $no_git = 0;
-
-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";
+
+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 (<src/socketengines/socketengine_*.cpp>) {
+ s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
+ push @socketengines, $1;
}
- return;
+ return @socketengines;
}
-sub resolve_directory
-{
- my $ret = $_[0];
- eval
- {
- use File::Spec;
- $ret = File::Spec->rel2abs($_[0]);
- };
- return $ret;
-}
+# TODO: when buildtool is done this can be mostly removed with
+# the remainder being merged into parse_templates.
+sub __get_template_settings($$) {
-sub getrevision {
- if ($no_git)
- {
- return "0";
+ # 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;
}
- my $data = `git describe --tags 2>/dev/null`;
- if ($data eq "")
- {
- $no_git = 1;
- return '0';
+
+ # Version information
+ my %version = get_version();
+ while (my ($key, $value) = each %version) {
+ $settings{'VERSION_' . $key} = $value;
}
- chomp $data; # remove \n
- return $data;
+
+ # Miscellaneous information
+ $settings{SYSTEM_NAME} = lc $^O;
+ chomp($settings{SYSTEM_NAME_VERSION} = `uname -sr 2>/dev/null`);
+
+ return %settings;
}
-sub getcompilerflags {
- my ($file) = @_;
- open(FLAGS, $file) or return "";
- while (<FLAGS>) {
- if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
- my $x = translate_functions($1, $file);
- next if ($x eq "");
- close(FLAGS);
- return $x;
- }
- }
- close(FLAGS);
- return "";
+sub cmd_clean {
+ unlink '.config.cache';
}
-sub getlinkerflags {
- my ($file) = @_;
- open(FLAGS, $file) or return "";
- while (<FLAGS>) {
- if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
- my $x = translate_functions($1, $file);
- next if ($x eq "");
- close(FLAGS);
- return $x;
- }
- }
- close(FLAGS);
- return "";
+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 getdependencies {
- my ($file) = @_;
- open(FLAGS, $file) or return "";
- while (<FLAGS>) {
- if ($_ =~ /^\/\* \$ModDep: (.+) \*\/$/) {
- my $x = translate_functions($1, $file);
- next if ($x eq "");
- close(FLAGS);
- return $x;
- }
+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;
}
- close(FLAGS);
- return "";
+ print "Updating...\n";
+ my %config = read_configure_cache();
+ my %compiler = get_compiler_info($config{CXX});
+ parse_templates(\%config, \%compiler);
+ print "Update complete!\n";
+ exit 0;
}
-sub nopedantic {
- my ($file) = @_;
- open(FLAGS, $file) or return "";
- while (<FLAGS>) {
- if ($_ =~ /^\/\* \$NoPedantic \*\/$/) {
- my $x = translate_functions($_, $file);
- next if ($x eq "");
- close(FLAGS);
- return 1;
- }
+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(FLAGS);
- return 0;
+ close(CACHE);
+ return %cfg;
}
-sub getmodules
-{
- my ($silent) = @_;
-
- my $i = 0;
+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;
+}
- if (!$silent)
- {
- print "Detecting modules ";
+sub get_compiler_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'
+ );
+}
- 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 ".";
- }
+sub find_compiler {
+ foreach my $compiler ('c++', 'g++', 'clang++', 'icpc') {
+ return $compiler unless system "$compiler -v > /dev/null 2>&1";
+ if ($^O eq 'Darwin') {
+ return $compiler unless system "xcrun $compiler -v > /dev/null 2>&1";
}
}
- closedir(DIRHANDLE);
+ return "";
+}
- if (!$silent)
- {
- print "\nOk, $i modules.\n";
- }
+sub run_test($$) {
+ my ($what, $result) = @_;
+ print "Checking whether $what is available... ";
+ print $result ? "yes\n" : "no\n";
+ return $result;
}
-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 test_file($$;$) {
+ my ($cc, $file, $args) = @_;
+ my $status = 0;
+ $args ||= '';
+ $status ||= system "$cc -o __test_$file make/test/$file $args >/dev/null 2>&1";
+ $status ||= system "./__test_$file >/dev/null 2>&1";
+ unlink "./__test_$file";
+ return !$status;
}
-sub module_installed($)
-{
- my $module = shift;
- eval("use $module;");
- return !$@;
+sub test_header($$;$) {
+ my ($cc, $header, $args) = @_;
+ $args ||= '';
+ open(CC, "| $cc -E - $args >/dev/null 2>&1") or return 0;
+ print CC "#include <$header>";
+ close(CC);
+ return !$?;
}
-sub promptstring_s($$)
+sub get_property($$;$)
{
- 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;
+ my ($file, $property, $default) = @_;
+ open(MODULE, $file) or return $default;
+ while (<MODULE>) {
+ if ($_ =~ /^\/\* \$(\S+): (.+) \*\/$/) {
+ next unless $1 eq $property;
+ close(MODULE);
+ return translate_functions($2, $file);
+ }
+ }
+ close(MODULE);
+ return defined $default ? $default : '';
}
-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";
+ 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[0mGCC Version Found:\e[1;32m\t\t$main::config{GCCVER}.$main::config{GCCMINOR}\e[0m\n";
- print "\e[0mCompiler program:\e[1;32m\t\t$main::config{CC}\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\n";
- print "\e[1;32mImportant note: The maximum length values are now configured in the\e[0m\n";
- print "\e[1;32m configuration file, not in ./configure! See the <limits>\e[0m\n";
- print "\e[1;32m tag in the configuration file for more information.\e[0m\n\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 is_dir
-{
- my ($path) = @_;
- if (chdir($path))
- {
- chdir($main::this);
- return 1;
- }
- else
- {
- # Just in case..
- chdir($main::this);
- return 0;
- }
-}
+sub parse_templates($$) {
+
+ # These are actually hash references
+ my ($config, $compiler) = @_;
+
+ # Collect settings to be used when generating files
+ my %settings = __get_template_settings($config, $compiler);
+
+ # Iterate through files in make/template.
+ foreach (<make/template/*>) {
+ print "Parsing $_...\n";
+ open(TEMPLATE, $_);
+ my (@lines, $mode, @platforms, %targets);
+
+ # First pass: parse template variables and directives.
+ while (my $line = <TEMPLATE>) {
+ chomp $line;
+
+ # Does this line match a variable?
+ while ($line =~ /(@(\w+?)@)/) {
+ my ($variable, $name) = ($1, $2);
+ if (defined $settings{$name}) {
+ $line =~ s/$variable/$settings{$name}/;
+ } else {
+ print STDERR "Warning: unknown template variable '$name' in $_!\n";
+ last;
+ }
+ }
-sub showhelp
-{
- chomp(my $PWD = `pwd`);
- print <<EOH;
-Usage: configure [options]
-
-*** NOTE: NON-INTERACTIVE CONFIGURE IS *NOT* SUPPORTED BY THE ***
-*** INSPIRCD DEVELOPMENT TEAM. DO NOT ASK FOR HELP REGARDING ***
-*** NON-INTERACTIVE CONFIGURE ON THE FORUMS OR ON IRC! ***
-
-Options: [defaults in brackets after descriptions]
-
-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, as in
-InspIRCd 1.0.x, 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]
- --enable-epoll Enable epoll() where supported [set]
- --enable-kqueue Enable kqueue() where supported [set]
- --disable-epoll Do not enable epoll(), fall back
- to select() [not set]
- --disable-kqueue Do not enable kqueue(), fall back
- to select() [not set]
- --with-cc=[filename] Use an alternative compiler to
- build InspIRCd [g++]
- --with-maxbuf=[n] Change the per message buffer size [512]
- DO NOT ALTER THIS OPTION WITHOUT GOOD REASON
- AS IT *WILL* BREAK CLIENTS!!!
- --prefix=[directory] Base directory to install into (if defined,
- can automatically define config, module, bin
- and library dirs as subdirectories of prefix)
- [$PWD]
- --config-dir=[directory] Config file directory for config and SSL certs
- [$PWD/run/conf]
- --log-dir=[directory] Log file directory for logs
- [$PWD/run/logs]
- --data-dir=[directory] Data directory for variable data, such as the
- permchannel configuration and the XLine database
- [$PWD/run/data]
- --module-dir=[directory] Modules directory for loadable modules
- [$PWD/run/modules]
- --binary-dir=[directory] Binaries directory for core binary
- [$PWD/run/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
+ # Does this line match a directive?
+ if ($line =~ /^\s*%(\w+)\s+(.+)$/) {
+ if ($1 eq 'define') {
+ if ($settings{$2}) {
+ push @lines, "#define $2";
+ } else {
+ push @lines, "#undef $2";
+ }
+ } elsif ($1 eq 'mode') {
+ $mode = oct $2;
+ } elsif ($1 eq 'platform') {
+ push @platforms, $2;
+ } elsif ($1 eq 'target') {
+ if ($2 =~ /(\w+)\s(.+)/) {
+ $targets{$1} = $2;
+ } else {
+ $targets{DEFAULT} = $2;
+ }
+ } else {
+ print STDERR "Warning: unknown template command '$1' in $_!\n";
+ push @lines, $line;
+ }
+ next;
+ }
+ push @lines, $line;
+ }
+ close(TEMPLATE);
-EOH
- exit(0);
+ # Only proceed if this file should be templated on this platform.
+ if ($#platforms < 0 || grep { $_ eq $^O } @platforms) {
+
+ # Add a default target if the template has not defined one.
+ unless (scalar keys %targets) {
+ $targets{DEFAULT} = basename $_;
+ }
+
+ # Second pass: parse makefile junk and write files.
+ while (my ($name, $target) = each %targets) {
+
+ # TODO: when buildtool is done this mess can be removed completely.
+ my @final_lines;
+ foreach my $line (@lines) {
+
+ # Are we parsing a makefile and does this line match a statement?
+ if ($name =~ /(?:BSD|GNU)_MAKE/ && $line =~ /^\s*\@(\w+)(?:\s+(.+))?$/) {
+ my @tokens = split /\s/, $2 if defined $2;
+ if ($1 eq 'DO_EXPORT' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ foreach my $variable (@tokens) {
+ push @final_lines, "MAKEENV += $variable='\${$variable}'";
+ }
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "export $2";
+ }
+ } elsif ($1 eq 'ELSE') {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".else";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "else";
+ }
+ } elsif ($1 eq 'ENDIF') {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".endif";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "endif";
+ }
+ } elsif ($1 eq 'ELSIFEQ' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".elif $tokens[0] == $tokens[1]";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "else ifeq ($tokens[0], $tokens[1])";
+ }
+ } elsif ($1 eq 'IFDEF' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".if defined($2)";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "ifdef $2";
+ }
+ } elsif ($1 eq 'IFEQ' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".if $tokens[0] == $tokens[1]";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "ifeq ($tokens[0],$tokens[1])";
+ }
+ } elsif ($1 eq 'IFNEQ' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".if $tokens[0] != $tokens[1]";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "ifneq ($tokens[0],$tokens[1])";
+ }
+ } elsif ($1 eq 'IFNDEF' && defined $2) {
+ if ($name eq 'BSD_MAKE') {
+ push @final_lines, ".if !defined($2)";
+ } elsif ($name eq 'GNU_MAKE') {
+ push @final_lines, "ifndef $2";
+ }
+ } elsif ($1 eq 'TARGET' && defined $2) {
+ if ($tokens[0] eq $name) {
+ push @final_lines, substr($2, length($tokens[0]) + 1);
+ }
+ } elsif ($1 !~ /[A-Z]/) {
+ # HACK: silently ignore if lower case as these are probably make commands.
+ push @final_lines, $line;
+ } else {
+ print STDERR "Warning: unknown template command '$1' in $_!\n";
+ push @final_lines, $line;
+ }
+ next;
+ }
+
+ push @final_lines, $line;
+ }
+
+ # Write the template file.
+ print "Writing $target...\n";
+ open(TARGET, ">$target");
+ foreach (@final_lines) {
+ print TARGET $_, "\n";
+ }
+ close(TARGET);
+
+ # Set file permissions.
+ if (defined $mode) {
+ chmod $mode, $target;
+ }
+ }
+ }
+ }
}
1;
-
diff --git a/make/gnutlscert.pm b/make/gnutlscert.pm
deleted file mode 100644
index 1204369a9..000000000
--- a/make/gnutlscert.pm
+++ /dev/null
@@ -1,149 +0,0 @@
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-# Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
-# Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# 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
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-package make::gnutlscert;
-
-require 5.8.0;
-
-use strict;
-use warnings FATAL => qw(all);
-
-use Exporter 'import';
-use make::configure;
-our @EXPORT = qw(make_gnutls_cert);
-
-
-sub make_gnutls_cert()
-{
- open (FH, ">certtool.template");
- my $timestr = time();
- my $commonname = promptstring_s('What is the hostname of your server?', 'irc.example.com');
- my $email = promptstring_s('What email address can you be contacted at?', 'example@example.com');
- my $unit = promptstring_s('What is the name of your unit?', 'Server Admins');
- my $org = promptstring_s('What is the name of your organization?', 'Example IRC Network');
- my $city = promptstring_s('What city are you located in?', 'Example City');
- my $state = promptstring_s('What state are you located in?', 'Example State');
- my $country = promptstring_s('What is the ISO 3166-1 code for the country you are located in?', 'XZ');
- my $days = promptstring_s('How many days do you want your certificate to be valid for?', '365');
- print FH <<__END__;
-# X.509 Certificate options
-#
-# DN options
-
-# The organization of the subject.
-organization = "$org"
-
-# The organizational unit of the subject.
-unit = "$unit"
-
-# The locality of the subject.
-locality = "$city"
-
-# The state of the certificate owner.
-state = "$state"
-
-# The country of the subject. Two letter code.
-country = "$country"
-
-# The common name of the certificate owner.
-cn = "$commonname"
-
-# A user id of the certificate owner.
-#uid = "clauper"
-
-# If the supported DN OIDs are not adequate you can set
-# any OID here.
-# For example set the X.520 Title and the X.520 Pseudonym
-# by using OID and string pairs.
-#dn_oid = "2.5.4.12" "Dr." "2.5.4.65" "jackal"
-
-# This is deprecated and should not be used in new
-# certificates.
-# pkcs9_email = "none\@none.org"
-
-# The serial number of the certificate
-serial = $timestr
-
-# In how many days, counting from today, this certificate will expire.
-expiration_days = $days
-
-# X.509 v3 extensions
-
-# A dnsname in case of a WWW server.
-#dns_name = "www.none.org"
-
-# An IP address in case of a server.
-#ip_address = "192.168.1.1"
-
-# An email in case of a person
-email = "$email"
-
-# An URL that has CRLs (certificate revocation lists)
-# available. Needed in CA certificates.
-#crl_dist_points = "http://www.getcrl.crl/getcrl/"
-
-# Whether this is a CA certificate or not
-#ca
-
-# Whether this certificate will be used for a TLS client
-tls_www_client
-
-# Whether this certificate will be used for a TLS server
-tls_www_server
-
-# Whether this certificate will be used to sign data (needed
-# in TLS DHE ciphersuites).
-signing_key
-
-# Whether this certificate will be used to encrypt data (needed
-# in TLS RSA ciphersuites). Note that it is prefered to use different
-# keys for encryption and signing.
-encryption_key
-
-# Whether this key will be used to sign other certificates.
-cert_signing_key
-
-# Whether this key will be used to sign CRLs.
-crl_signing_key
-
-# Whether this key will be used to sign code.
-code_signing_key
-
-# Whether this key will be used to sign OCSP data.
-ocsp_signing_key
-
-# Whether this key will be used for time stamping.
-time_stamping_key
-__END__
-close(FH);
-my $certtool = "certtool";
-if (`uname -s` eq "Darwin\n") {
- # On OS X the certtool binary name is different to prevent
- # collisions with the system certtool from NSS.
- $certtool = "gnutls-certtool";
-}
-if ( (my $status = system("$certtool --generate-privkey --outfile key.pem")) ne 0) { return 1; }
-if ( (my $status = system("$certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem --template certtool.template")) ne 0) { return 1; }
-unlink("certtool.template");
-return 0;
-}
-
-1;
-
diff --git a/make/opensslcert.pm b/make/opensslcert.pm
deleted file mode 100644
index b8c9d164f..000000000
--- a/make/opensslcert.pm
+++ /dev/null
@@ -1,59 +0,0 @@
-#
-# InspIRCd -- Internet Relay Chat Daemon
-#
-# Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
-# Copyright (C) 2007 Craig Edwards <craigedwards@brainbox.cc>
-#
-# 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
-# License as published by the Free Software Foundation, version 2.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
-# details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-
-
-package make::opensslcert;
-
-require 5.8.0;
-
-use strict;
-use warnings FATAL => qw(all);
-
-use Exporter 'import';
-use make::configure;
-our @EXPORT = qw(make_openssl_cert);
-
-
-sub make_openssl_cert()
-{
- open (FH, ">openssl.template");
- my $commonname = promptstring_s('What is the hostname of your server?', 'irc.example.com');
- my $email = promptstring_s('What email address can you be contacted at?', 'example@example.com');
- my $unit = promptstring_s('What is the name of your unit?', 'Server Admins');
- my $org = promptstring_s('What is the name of your organization?', 'Example IRC Network');
- my $city = promptstring_s('What city are you located in?', 'Example City');
- my $state = promptstring_s('What state are you located in?', 'Example State');
- my $country = promptstring_s('What is the ISO 3166-1 code for the country you are located in?', 'XZ');
- my $time = promptstring_s('How many days do you want your certificate to be valid for?', '365');
- print FH <<__END__;
-$country
-$state
-$city
-$org
-$unit
-$commonname
-$email
-__END__
-close(FH);
-system("cat openssl.template | openssl req -x509 -nodes -newkey rsa:1024 -keyout key.pem -out cert.pem -days $time 2>/dev/null");
-system("openssl dhparam -out dhparams.pem 1024");
-unlink("openssl.template");
-}
-
-1;
diff --git a/make/template/config.h b/make/template/config.h
new file mode 100644
index 000000000..513c550f5
--- /dev/null
+++ b/make/template/config.h
@@ -0,0 +1,38 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2014 Peter Powell <petpow@saberuk.com>
+ *
+ * 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
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#define INSPIRCD_BRANCH "InspIRCd-@VERSION_MAJOR@.@VERSION_MINOR@"
+#define INSPIRCD_VERSION "InspIRCd-@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@"
+#define INSPIRCD_REVISION "@VERSION_LABEL@"
+#define INSPIRCD_SYSTEM "@SYSTEM_NAME_VERSION@"
+
+#define INSPIRCD_CONFIG_PATH "@CONFIG_DIR@"
+#define INSPIRCD_DATA_PATH "@DATA_DIR@"
+#define INSPIRCD_LOG_PATH "@LOG_DIR@"
+#define INSPIRCD_MODULE_PATH "@MODULE_DIR@"
+
+#define INSPIRCD_SOCKETENGINE_NAME "@SOCKETENGINE@"
+
+#ifndef _WIN32
+ %target include/config.h
+ %define HAS_CLOCK_GETTIME
+ %define HAS_EVENTFD
+#endif
diff --git a/make/template/gdbargs b/make/template/gdbargs
new file mode 100644
index 000000000..de76c7270
--- /dev/null
+++ b/make/template/gdbargs
@@ -0,0 +1,4 @@
+%target .gdbargs
+handle SIGPIPE pass nostop noprint
+handle SIGHUP pass nostop noprint
+run
diff --git a/make/template/inspircd b/make/template/inspircd
index 322ee2cd6..7610557b8 100644
--- a/make/template/inspircd
+++ b/make/template/inspircd
@@ -1,3 +1,4 @@
+%mode 0750
#!/usr/bin/env perl
#
@@ -29,11 +30,11 @@ my $binpath = "@BINARY_DIR@";
my $runpath = "@BASE_DIR@";
my $datadir = "@DATA_DIR@";
my $valgrindlogpath = "$basepath/valgrindlogs";
-my $executable = "@EXECUTABLE@";
-my $version = "@VERSION@";
+my $executable = "inspircd";
+my $version = "@VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@+@VERSION_LABEL@";
my $uid = "@UID@";
-if ($< == 0 || $> == 0) {
+if (!("--runasroot" ~~ @ARGV) && ($< == 0 || $> == 0)) {
if ($uid !~ /^\d+$/) {
# Named UID, look it up
$uid = getpwnam $uid;
diff --git a/make/template/inspircd-genssl.1 b/make/template/inspircd-genssl.1
new file mode 100644
index 000000000..4be5f394c
--- /dev/null
+++ b/make/template/inspircd-genssl.1
@@ -0,0 +1,46 @@
+.\"
+.\" InspIRCd -- Internet Relay Chat Daemon
+.\"
+.\" Copyright (C) 2014 Peter Powell <petpow@saberuk.com>
+.\"
+.\" 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
+.\" License as published by the Free Software Foundation, version 2.
+.\"
+.\" This program is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+.\" FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+.\" details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
+.\"
+
+
+.TH "InspIRCd" "1" "June 2014" "InspIRCd @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@+@VERSION_LABEL@" "InspIRCd Manual"
+
+.SH "NAME"
+\t\fBInspIRCd\fR - \fIthe\fR stable, high-performance and modular Internet Relay Chat Daemon
+.BR
+
+.SH "SYNOPSIS"
+\t\fBinspircd-genssl\fR [ auto | gnutls | openssl ]
+
+.SH "OPTIONS"
+.TP
+.B "auto"
+.br
+Looks for both GnuTLS and OpenSSL and uses the first one which is available for certificate generation.
+.TP
+.B "gnutls"
+.br
+Generates certificates using GnuTLS.
+.TP
+.br
+.B "openssl"
+Generates certificates using OpenSSL.
+
+.SH "SUPPORT"
+IRC support for InspIRCd can be found at irc://irc.inspircd.org/inspircd.
+
+Bug reports and feature requests can be filed at https://github.com/inspircd/inspircd/issues.
diff --git a/make/template/inspircd.1 b/make/template/inspircd.1
new file mode 100644
index 000000000..463db5c47
--- /dev/null
+++ b/make/template/inspircd.1
@@ -0,0 +1,104 @@
+.\"
+.\" InspIRCd -- Internet Relay Chat Daemon
+.\"
+.\" Copyright (C) 2014 Peter Powell <petpow@saberuk.com>
+.\"
+.\" 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
+.\" License as published by the Free Software Foundation, version 2.
+.\"
+.\" This program is distributed in the hope that it will be useful, but WITHOUT
+.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+.\" FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+.\" details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
+.\"
+
+
+.TH "InspIRCd" "1" "June 2014" "InspIRCd @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@+@VERSION_LABEL@" "InspIRCd Manual"
+
+.SH "NAME"
+\t\fBInspIRCd\fR - \fIthe\fR stable, high-performance and modular Internet Relay Chat Daemon
+.BR
+
+.SH "SYNOPSIS"
+\t\fBinspircd\fR [--config <file>] [--debug] [--nofork] [--nolog] [--runasroot] [--version]
+
+.SH "OPTIONS"
+.TP
+.B "--config <file>"
+.br
+Sets the path to the main configuration file. Defaults to \fI@CONFIG_DIR@/inspircd.conf\fR.
+.TP
+.B "--debug"
+.br
+Log verbosely to the standard output stream.
+.TP
+.B "--nofork"
+.br
+Don't fork into the background after starting up.
+.TP
+.B "--nolog"
+.br
+Don't write to log files.
+.TP
+.B "--runasroot"
+.br
+Allow the server to start as root (not recommended).
+.TP
+.B "--version"
+.br
+Displays the InspIRCd version and exits.
+
+.SH "EXIT STATUS"
+.TP
+.B "0 (EXIT_STATUS_NOERROR)"
+.br
+The server exited cleanly.
+.TP
+.B "1 (EXIT_STATUS_DIE)"
+.br
+The server exited because the DIE command was executed.
+.TP
+.B "2 (EXIT_STATUS_CONFIG)"
+.br
+The server exited because of a configuration file error.
+.TP
+.B "3 (EXIT_STATUS_LOG)"
+.br
+The server exited because of a log file error.
+.TP
+.B "4 (EXIT_STATUS_FORK)"
+.br
+The server exited because it was unable to fork into the background.
+.TP
+.B "5 (EXIT_STATUS_ARGV)"
+.br
+The server exited because an invalid argument was passed to it on the command line.
+.TP
+.B "6 (EXIT_STATUS_PID)"
+.br
+The server exited because it was unable to write to the PID file.
+.TP
+.B "7 (EXIT_STATUS_SOCKETENGINE)"
+.br
+The server exited because it was unable to initialize the @SOCKETENGINE@ socket engine.
+.TP
+.B "8 (EXIT_STATUS_ROOT)"
+.br
+The server exited because the user tried to start as root without \fI--runasroot\fR.
+.TP
+.B "9 (EXIT_STATUS_MODULE)"
+.br
+The server exited because it was unable to load a module on first run.
+.TP
+.B "10 (EXIT_STATUS_SIGTERM)"
+.br
+The server exited because it received SIGTERM.
+
+.SH "SUPPORT"
+IRC support for InspIRCd can be found at irc://irc.inspircd.org/inspircd.
+
+Bug reports and feature requests can be filed at https://github.com/inspircd/inspircd/issues.
diff --git a/make/template/inspircd.service b/make/template/inspircd.service
new file mode 100644
index 000000000..0d75b5cb6
--- /dev/null
+++ b/make/template/inspircd.service
@@ -0,0 +1,35 @@
+%platform linux
+#
+# InspIRCd -- Internet Relay Chat Daemon
+#
+# Copyright (C) 2014 Peter Powell <petpow@saberuk.com>
+#
+# 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
+# License as published by the Free Software Foundation, version 2.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+[Unit]
+After=network.target
+Description=Inspire Internet Relay Chat Daemon
+Requires=network.target
+
+[Service]
+ExecReload=@BASE_DIR@/inspircd rehash
+ExecStart=@BASE_DIR@/inspircd start
+ExecStop=@BASE_DIR@/inspircd stop
+PIDFile=@DATA_DIR@/inspircd.pid
+Restart=on-failure
+Type=forking
+
+[Install]
+WantedBy=multi-user.target
diff --git a/make/template/main.mk b/make/template/main.mk
index e55e36c0a..5806d568a 100644
--- a/make/template/main.mk
+++ b/make/template/main.mk
@@ -1,3 +1,5 @@
+%target BSD_MAKE BSDmakefile
+%target GNU_MAKE GNUmakefile
#
# InspIRCd -- Internet Relay Chat Daemon
#
@@ -30,13 +32,13 @@
#
-CC = @CC@
-SYSTEM = @SYSTEM@
-BUILDPATH = @BUILD_DIR@
+CXX = @CXX@
+COMPILER = @COMPILER_NAME@
+SYSTEM = @SYSTEM_NAME@
+BUILDPATH ?= $(PWD)/build
SOCKETENGINE = @SOCKETENGINE@
-CXXFLAGS = -pipe -fPIC -DPIC
-LDLIBS = -pthread -lstdc++
-LDFLAGS =
+CORECXXFLAGS = -fPIC -fvisibility-inlines-hidden -pipe -Iinclude -Wall -Wextra -Wfatal-errors -Wno-unused-parameter -Wshadow
+LDLIBS = -lstdc++
CORELDFLAGS = -rdynamic -L. $(LDFLAGS)
PICLDFLAGS = -fPIC -shared -rdynamic $(LDFLAGS)
BASE = "$(DESTDIR)@BASE_DIR@"
@@ -46,16 +48,21 @@ 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
-@IFEQ $(CC) icc
- CXXFLAGS += -Wshadow
-@ELSE
- CXXFLAGS += -pedantic -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute -Wall
+@IFNEQ $(COMPILER) ICC
+ CORECXXFLAGS += -pedantic -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute
+@ENDIF
+
+@IFNEQ $(SYSTEM)-$(COMPILER) darwin-GCC
+ CORECXXFLAGS += -fvisibility=hidden
@ENDIF
+@IFNEQ $(SYSTEM) darwin
+ LDLIBS += -pthread
+@ENDIF
@IFEQ $(SYSTEM) linux
LDLIBS += -ldl -lrt
@@ -70,19 +77,11 @@ INSTMODE_LIB = 0644
LDLIBS += -lsocket -lnsl -lrt -lresolv
INSTALL = ginstall
@ENDIF
-@IFEQ $(SYSTEM) sunos
- LDLIBS += -lsocket -lnsl -lrt -lresolv
- INSTALL = ginstall
-@ENDIF
@IFEQ $(SYSTEM) darwin
- CXXFLAGS += -DDARWIN -frtti
LDLIBS += -ldl
CORELDFLAGS = -dynamic -bind_at_load -L. $(LDFLAGS)
PICLDFLAGS = -fPIC -shared -twolevel_namespace -undefined dynamic_lookup $(LDFLAGS)
@ENDIF
-@IFEQ $(SYSTEM) interix
- CXXFLAGS += -D_ALL_SOURCE -I/usr/local/include
-@ENDIF
@IFNDEF D
D=0
@@ -90,49 +89,51 @@ INSTMODE_LIB = 0644
DBGOK=0
@IFEQ $(D) 0
- CXXFLAGS += -O2
-@IFEQ $(CC) gcc
- CXXFLAGS += -g1
+ CORECXXFLAGS += -O2
+@IFEQ $(COMPILER) GCC
+ CORECXXFLAGS += -g1
@ENDIF
HEADER = std-header
DBGOK=1
@ENDIF
@IFEQ $(D) 1
- CXXFLAGS += -O0 -g3 -Werror
+ CORECXXFLAGS += -O0 -g3 -Werror
HEADER = debug-header
DBGOK=1
@ENDIF
@IFEQ $(D) 2
- CXXFLAGS += -O2 -g3
+ CORECXXFLAGS += -O2 -g3
HEADER = debug-header
DBGOK=1
@ENDIF
FOOTER = finishmessage
-CXXFLAGS += -Iinclude
+@TARGET GNU_MAKE MAKEFLAGS += --no-print-directory
-@GNU_ONLY MAKEFLAGS += --no-print-directory
-
-@GNU_ONLY SOURCEPATH = $(shell /bin/pwd)
-@BSD_ONLY SOURCEPATH != /bin/pwd
+@TARGET GNU_MAKE SOURCEPATH = $(shell /bin/pwd)
+@TARGET BSD_MAKE SOURCEPATH != /bin/pwd
@IFDEF V
- RUNCC = $(CC)
- RUNLD = $(CC)
+ RUNCC = $(CXX)
+ RUNLD = $(CXX)
VERBOSE = -v
@ELSE
- @GNU_ONLY MAKEFLAGS += --silent
- @BSD_ONLY MAKE += -s
- RUNCC = perl $(SOURCEPATH)/make/run-cc.pl $(CC)
- RUNLD = perl $(SOURCEPATH)/make/run-cc.pl $(CC)
+ @TARGET GNU_MAKE MAKEFLAGS += --silent
+ @TARGET BSD_MAKE MAKE += -s
+ RUNCC = perl $(SOURCEPATH)/make/run-cc.pl $(CXX)
+ RUNLD = perl $(SOURCEPATH)/make/run-cc.pl $(CXX)
@ENDIF
@IFDEF PURE_STATIC
- CXXFLAGS += -DPURE_STATIC
+ CORECXXFLAGS += -DPURE_STATIC
@ENDIF
-@DO_EXPORT RUNCC RUNLD CXXFLAGS LDLIBS PICLDFLAGS VERBOSE SOCKETENGINE CORELDFLAGS
-@DO_EXPORT SOURCEPATH BUILDPATH PURE_STATIC SPLIT_CC
+# Add the users CXXFLAGS to the base ones to allow them to override
+# things like -Wfatal-errors if they wish to.
+CORECXXFLAGS += $(CXXFLAGS)
+
+@DO_EXPORT RUNCC RUNLD CORECXXFLAGS LDLIBS PICLDFLAGS VERBOSE SOCKETENGINE CORELDFLAGS
+@DO_EXPORT SOURCEPATH BUILDPATH PURE_STATIC
# Default target
TARGET = all
@@ -140,8 +141,8 @@ TARGET = all
@IFDEF M
HEADER = mod-header
FOOTER = mod-footer
- @BSD_ONLY TARGET = modules/${M:S/.so$//}.so
- @GNU_ONLY TARGET = modules/$(M:.so=).so
+ @TARGET BSD_MAKE TARGET = modules/${M:S/.so$//}.so
+ @TARGET GNU_MAKE TARGET = modules/$(M:.so=).so
@ENDIF
@IFDEF T
@@ -229,8 +230,17 @@ install: target
@IFNDEF PURE_STATIC
[ $(BUILDPATH)/modules/ -ef $(MODPATH) ] || $(INSTALL) -m $(INSTMODE_LIB) $(BUILDPATH)/modules/*.so $(MODPATH)
@ENDIF
- -$(INSTALL) -m $(INSTMODE_BIN) @STARTSCRIPT@ $(BASE) 2>/dev/null
- -$(INSTALL) -m $(INSTMODE_LIB) tools/gdbargs $(BASE)/.gdbargs 2>/dev/null
+ -$(INSTALL) -m $(INSTMODE_BIN) inspircd $(BASE) 2>/dev/null
+ -$(INSTALL) -m $(INSTMODE_LIB) .gdbargs $(BASE)/.gdbargs 2>/dev/null
+@IFEQ $(SYSTEM) darwin
+ -$(INSTALL) -m $(INSTMODE_BIN) org.inspircd.plist $(BASE) 2>/dev/null
+@ENDIF
+@IFEQ $(SYSTEM) linux
+ -$(INSTALL) -m $(INSTMODE_LIB) inspircd.service $(BASE) 2>/dev/null
+@ENDIF
+ -$(INSTALL) -m $(INSTMODE_LIB) inspircd.1 $(BASE) 2>/dev/null
+ -$(INSTALL) -m $(INSTMODE_LIB) inspircd-genssl.1 $(BASE) 2>/dev/null
+ -$(INSTALL) -m $(INSTMODE_BIN) tools/genssl $(BINPATH)/inspircd-genssl 2>/dev/null
-$(INSTALL) -m $(INSTMODE_LIB) docs/conf/*.example $(CONPATH)/examples
-$(INSTALL) -m $(INSTMODE_LIB) docs/conf/aliases/*.example $(CONPATH)/examples/aliases
-$(INSTALL) -m $(INSTMODE_LIB) docs/conf/modules/*.example $(CONPATH)/examples/modules
@@ -248,11 +258,9 @@ install: target
@echo 'Remember to create your config file:' $(CONPATH)/inspircd.conf
@echo 'Examples are available at:' $(CONPATH)/examples/
-@GNU_ONLY RCS_FILES = $(wildcard .git/index src/version.sh)
-@BSD_ONLY RCS_FILES = src/version.sh
-GNUmakefile BSDmakefile: make/template/main.mk configure $(RCS_FILES)
+GNUmakefile BSDmakefile: make/template/main.mk src/version.sh configure .config.cache
./configure -update
-@BSD_ONLY .MAKEFILEDEPS: BSDmakefile
+@TARGET BSD_MAKE .MAKEFILEDEPS: BSDmakefile
clean:
@echo Cleaning...
@@ -269,14 +277,11 @@ deinstall:
-rm -f $(BASE)/.gdbargs
-rm -f $(BASE)/org.inspircd.plist
-squeakyclean: distclean
-
configureclean:
rm -f .config.cache
rm -f BSDmakefile
rm -f GNUmakefile
- rm -f include/inspircd_config.h
- rm -f include/inspircd_version.h
+ rm -f include/config.h
rm -f inspircd
-rm -f org.inspircd.plist
@@ -312,4 +317,4 @@ help:
@echo ' deinstall Removes the files created by "make install"'
@echo
-.PHONY: all target debug debug-header mod-header mod-footer std-header finishmessage install clean deinstall squeakyclean configureclean help
+.PHONY: all target debug debug-header mod-header mod-footer std-header finishmessage install clean deinstall configureclean help
diff --git a/make/template/org.inspircd.plist b/make/template/org.inspircd.plist
index 2656d1df3..4bcb3e7c3 100644
--- a/make/template/org.inspircd.plist
+++ b/make/template/org.inspircd.plist
@@ -1,3 +1,4 @@
+%platform darwin
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
diff --git a/make/test/clock_gettime.cpp b/make/test/clock_gettime.cpp
new file mode 100644
index 000000000..91d8cd412
--- /dev/null
+++ b/make/test/clock_gettime.cpp
@@ -0,0 +1,25 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * 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
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <time.h>
+
+int main() {
+ timespec time_spec;
+ clock_gettime(CLOCK_REALTIME, &time_spec);
+ return 0;
+}
diff --git a/make/check_eventfd.cpp b/make/test/eventfd.cpp
index 980d04485..980d04485 100644
--- a/make/check_eventfd.cpp
+++ b/make/test/eventfd.cpp
diff --git a/make/check_epoll.cpp b/make/test/kqueue.cpp
index 918d3907e..a8b9882cf 100644
--- a/make/check_epoll.cpp
+++ b/make/test/kqueue.cpp
@@ -16,9 +16,10 @@
*/
-#include <sys/epoll.h>
+#include <sys/types.h>
+#include <sys/event.h>
int main() {
- int fd = epoll_create(1);
+ int fd = kqueue();
return (fd < 0);
}
diff --git a/make/unit-cc.pl b/make/unit-cc.pl
index 7474365aa..77f97a3f2 100755
--- a/make/unit-cc.pl
+++ b/make/unit-cc.pl
@@ -52,7 +52,7 @@ exit 1;
sub do_static_find {
my @flags;
for my $file (@ARGV) {
- push @flags, getlinkerflags($file);
+ push @flags, get_property($file, 'LinkerFlags');
}
open F, '>', $out;
print F join ' ', @flags;
@@ -97,12 +97,10 @@ sub do_compile {
my $libs = '';
my $binary = $ENV{RUNCC};
if ($do_compile) {
- $flags = $ENV{CXXFLAGS};
- $flags =~ s/ -pedantic// if nopedantic($file);
- $flags .= ' ' . getcompilerflags($file);
+ $flags = $ENV{CORECXXFLAGS} . ' ' . get_property($file, 'CompileFlags');
- if ($file =~ m#(?:^|/)((?:m|cmd)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
- $flags .= ' -DMODNAME='.$1.'.so';
+ if ($file =~ m#(?:^|/)((?:m|core)_[^/. ]+)(?:\.cpp|/.*\.cpp)$#) {
+ $flags .= ' -DMODNAME=\\"'.$1.'\\"';
}
} else {
$binary = $ENV{RUNLD};
@@ -110,7 +108,7 @@ sub do_compile {
if ($do_link) {
$flags = join ' ', $flags, $ENV{PICLDFLAGS};
- $libs = join ' ', getlinkerflags($file);
+ $libs = get_property($file, 'LinkerFlags');
} else {
$flags .= ' -c';
}
diff --git a/make/utilities.pm b/make/utilities.pm
index 8c8ac0d49..7db557d11 100644
--- a/make/utilities.pm
+++ b/make/utilities.pm
@@ -20,27 +20,113 @@
#
-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);
-
-# Parse the output of a *_config program,
-# such as pcre_config, take out the -L
-# directive and return an rpath for it.
+use File::Path;
+use File::Spec::Functions qw(rel2abs);
+use Getopt::Long;
+use POSIX;
-# \e[1;32msrc/Makefile\e[0m
+our @EXPORT = qw(get_version module_installed prompt_bool prompt_dir prompt_string get_cpu_count make_rpath pkgconfig_get_include_dirs pkgconfig_get_lib_dirs pkgconfig_check_version translate_functions promptstring);
my %already_added = ();
-my $if_skip_lines = 0;
+my %version = ();
+
+sub get_version {
+ return %version if %version;
+
+ # Attempt to retrieve version information from src/version.sh
+ chomp(my $vf = `sh src/version.sh 2>/dev/null`);
+ if ($vf =~ /^InspIRCd-([0-9]+)\.([0-9]+)\.([0-9]+)(?:\+(\w+))?$/) {
+ %version = ( MAJOR => $1, MINOR => $2, PATCH => $3, LABEL => $4 );
+ }
+
+ # Attempt to retrieve missing version information from Git
+ chomp(my $gr = `git describe --tags 2>/dev/null`);
+ if ($gr =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)(?:-\d+-(\w+))?$/) {
+ $version{MAJOR} = $1 unless defined $version{MAJOR};
+ $version{MINOR} = $2 unless defined $version{MINOR};
+ $version{PATCH} = $3 unless defined $version{PATCH};
+ $version{LABEL} = $4 if defined $4;
+ }
+
+ # The user is using a stable release which does not have
+ # a label attached.
+ $version{LABEL} = 'release' unless defined $version{LABEL};
+
+ # If any of these fields are missing then the user has deleted the
+ # version file and is not running from Git. Fill in the fields with
+ # dummy data so we don't get into trouble with undef values later.
+ $version{MAJOR} = '0' unless defined $version{MAJOR};
+ $version{MINOR} = '0' unless defined $version{MINOR};
+ $version{PATCH} = '0' unless defined $version{PATCH};
+
+ return %version;
+}
+
+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 get_cpu_count {
+ my $count = 1;
+ if ($^O =~ /bsd/) {
+ $count = `sysctl -n hw.ncpu`;
+ } elsif ($^O eq 'darwin') {
+ $count = `sysctl -n hw.activecpu`;
+ } elsif ($^O eq 'linux') {
+ $count = `getconf _NPROCESSORS_ONLN`;
+ } elsif ($^O eq 'solaris') {
+ $count = `psrinfo -p`;
+ }
+ chomp($count);
+ return $count;
+}
sub promptstring($$$$$)
{
@@ -109,15 +195,6 @@ sub pkgconfig_get_include_dirs($$$;$)
{
my ($packagename, $headername, $defaults, $module) = @_;
- my $key = "default_includedir_$packagename";
- if (exists $main::config{$key})
- {
- print "Locating include directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
- my $ret = $main::config{$key};
- print "\e[1;32m$ret\e[0m (cached)\n";
- return $ret;
- }
-
extend_pkg_path();
print "Locating include directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
@@ -225,15 +302,6 @@ sub pkgconfig_get_lib_dirs($$$;$)
{
my ($packagename, $libname, $defaults, $module) = @_;
- my $key = "default_libdir_$packagename";
- if (exists $main::config{$key})
- {
- print "Locating library directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
- my $ret = $main::config{$key};
- print "\e[1;32m$ret\e[0m (cached)\n";
- return $ret;
- }
-
extend_pkg_path();
print "Locating library directory for package \e[1;32m$packagename\e[0m for module \e[1;32m$module\e[0m... ";
@@ -308,16 +376,6 @@ sub translate_functions($$)
$module =~ /modules*\/(.+?)$/;
$module = $1;
- # This is only a cursory check, just designed to catch casual accidental use of backticks.
- # There are pleanty of ways around it, but its not supposed to be for security, just checking
- # that people are using the new configuration api as theyre supposed to and not just using
- # backticks instead of eval(), being as eval has accountability. People wanting to get around
- # the accountability will do so anyway.
- if (($line =~ /`/) && ($line !~ /eval\(.+?`.+?\)/))
- {
- die "Developers should no longer use backticks in configuration macros. Please use exec() and eval() macros instead. Offending line: $line (In module: $module)";
- }
-
if ($line =~ /ifuname\(\!"(\w+)"\)/)
{
my $uname = $1;