]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - make/configure.pm
m_sajoin Abort and report if the target user is already on the channel
[user/henk/code/inspircd.git] / make / configure.pm
1 #
2 # InspIRCd -- Internet Relay Chat Daemon
3 #
4 #   Copyright (C) 2012 Peter Powell <petpow@saberuk.com>
5 #   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
6 #   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
7 #   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
8 #   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
9 #
10 # This file is part of InspIRCd.  InspIRCd is free software: you can
11 # redistribute it and/or modify it under the terms of the GNU General Public
12 # License as published by the Free Software Foundation, version 2.
13 #
14 # This program is distributed in the hope that it will be useful, but WITHOUT
15 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17 # details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23
24 BEGIN {
25         require 5.8.0;
26 }
27
28 package make::configure;
29
30 use strict;
31 use warnings FATAL => qw(all);
32
33 use Cwd;
34 use Exporter 'import';
35
36 use make::utilities;
37
38 our @EXPORT = qw(cmd_clean cmd_help cmd_update
39                  read_configure_cache write_configure_cache
40                  get_compiler_info find_compiler
41                  run_test test_file test_header
42                  get_property get_revision
43                  dump_hash);
44
45 my $revision;
46
47 sub __get_socketengines() {
48         my @socketengines;
49         foreach (<src/socketengines/socketengine_*.cpp>) {
50                 s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
51                 push @socketengines, $1;
52         }
53         return @socketengines;
54 }
55
56 sub cmd_clean {
57         unlink '.config.cache';
58 }
59
60 sub cmd_help {
61         my $PWD = getcwd();
62         my $SELIST = join ', ', __get_socketengines();
63         print <<EOH;
64 Usage: $0 [options]
65
66 When no options are specified, configure runs in interactive mode and you must
67 specify any required values manually. If one or more options are specified,
68 non-interactive configuration is started and any omitted values are defaulted.
69
70 PATH OPTIONS
71
72   --system                      Automatically set up the installation paths
73                                 for system-wide installation.
74   --prefix=[dir]                The root install directory. If this is set then
75                                 all subdirectories will be adjusted accordingly.
76                                 [$PWD/run]
77   --binary-dir=[dir]            The location where the main server binary is
78                                 stored.
79                                 [$PWD/run/bin]
80   --config-dir=[dir]            The location where the configuration files and
81                                 SSL certificates are stored.
82                                 [$PWD/run/conf]
83   --data-dir=[dir]              The location where the data files, such as the
84                                 pid file, are stored.
85                                 [$PWD/run/data]
86   --log-dir=[dir]               The location where the log files are stored.
87                                 [$PWD/run/logs]
88   --module-dir=[dir]            The location where the loadable modules are
89                                 stored.
90                                 [$PWD/run/modules]
91   --build-dir=[dir]             The location to store files in while building.
92
93
94 EXTRA MODULE OPTIONS
95
96   --enable-extras=[extras]      Enables a comma separated list of extra modules.
97   --disable-extras=[extras]     Disables a comma separated list of extra modules.
98   --list-extras                 Shows the availability status of all extra
99                                 modules.
100
101 MISC OPTIONS
102
103   --clean                       Remove the configuration cache file and start
104                                 the interactive configuration wizard.
105   --disable-interactive         Disables the interactive configuration wizard.
106   --help                        Show this message and exit.
107   --uid=[name]                  Sets the user to run InspIRCd as.
108   --socketengine=[name]         Sets the socket engine to be used. Possible
109                                 values are $SELIST.
110   --update                      Updates the build environment.
111
112
113 FLAGS
114
115   CXX=[name]                    Sets the C++ compiler to use when building the
116                                 server. If not specified then the build system
117                                 will search for c++, g++, clang++ or icpc.
118
119 If you have any problems with configuring InspIRCd then visit our IRC channel
120 at irc.ChatSpike.net #InspIRCd.
121
122 EOH
123         exit 0;
124 }
125
126 sub cmd_update {
127         unless (-f '.config.cache') {
128                 print "You have not run $0 before. Please do this before trying to update the build files.\n";
129                 exit 1;
130         }
131         print "Updating...\n";
132         %main::config = read_configure_cache();
133         %main::cxx = get_compiler_info($main::config{CXX});
134         main::writefiles();
135         print "Update complete!\n";
136         exit 0;
137 }
138
139 sub read_configure_cache {
140         my %cfg = ();
141         open(CACHE, '.config.cache') or return %cfg;
142         while (my $line = <CACHE>) {
143                 next if $line =~ /^\s*($|\#)/;
144                 my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/);
145                 $cfg{$key} = $value;
146         }
147         close(CACHE);
148         return %cfg;
149 }
150
151 sub write_configure_cache(%) {
152         my %cfg = @_;
153         open(CACHE, ">.config.cache") or return 0;
154         while (my ($key, $value) = each %cfg) {
155                 $value = "" unless defined $value;
156                 print CACHE "$key=\"$value\"\n";
157         }
158         close(CACHE);
159         return 1;
160 }
161
162 sub get_compiler_info($) {
163         my $binary = shift;
164         my $version = `$binary -v 2>&1`;
165         if ($version =~ /(?:clang|llvm)\sversion\s(\d+\.\d+)/i) {
166                 return (
167                         NAME => 'Clang',
168                         VERSION => $1,
169                         UNSUPPORTED => $1 lt '3.0',
170                         REASON => 'Clang 2.9 and older do not have adequate C++ support.'
171                 );
172         } elsif ($version =~ /gcc\sversion\s(\d+\.\d+)/i) {
173                 return (
174                         NAME => 'GCC',
175                         VERSION => $1,
176                         UNSUPPORTED => $1 lt '4.1',
177                         REASON => 'GCC 4.0 and older do not have adequate C++ support.'
178                 );
179         } elsif ($version =~ /(?:icc|icpc)\sversion\s(\d+\.\d+).\d+\s\(gcc\sversion\s(\d+\.\d+).\d+/i) {
180                 return (
181                         NAME => 'ICC',
182                         VERSION => $1,
183                         UNSUPPORTED => $2 lt '4.1',
184                         REASON => "ICC $1 (GCC $2 compatibility mode) does not have adequate C++ support."
185                 );
186         }
187         return (
188                 NAME => $binary,
189                 VERSION => '0.0'
190         );
191 }
192
193 sub find_compiler {
194         foreach my $compiler ('c++', 'g++', 'clang++', 'icpc') {
195                 return $compiler unless system "$compiler -v > /dev/null 2>&1";
196                 if ($^O eq 'Darwin') {
197                         return $compiler unless system "xcrun $compiler -v > /dev/null 2>&1";
198                 }
199         }
200         return "";
201 }
202
203 sub run_test($$) {
204         my ($what, $result) = @_;
205         print "Checking whether $what is available... ";
206         print $result ? "yes\n" : "no\n";
207         return $result;
208 }
209
210 sub test_file($$;$) {
211         my ($cc, $file, $args) = @_;
212         my $status = 0;
213         $args ||= '';
214         $status ||= system "$cc -o __test_$file make/test/$file $args >/dev/null 2>&1";
215         $status ||= system "./__test_$file >/dev/null 2>&1";
216         unlink  "./__test_$file";
217         return !$status;
218 }
219
220 sub test_header($$;$) {
221         my ($cc, $header, $args) = @_;
222         $args ||= '';
223         open(CC, "| $cc -E - $args >/dev/null 2>&1") or return 0;
224         print CC "#include <$header>";
225         close(CC);
226         return !$?;
227 }
228
229 sub get_property($$;$)
230 {
231         my ($file, $property, $default) = @_;
232         open(MODULE, $file) or return $default;
233         while (<MODULE>) {
234                 if ($_ =~ /^\/\* \$(\S+): (.+) \*\/$/) {
235                         next unless $1 eq $property;
236                         close(MODULE);
237                         return translate_functions($2, $file);
238                 }
239         }
240         close(MODULE);
241         return defined $default ? $default : '';
242 }
243
244 sub get_revision {
245         return $revision if defined $revision;
246         chomp(my $tags = `git describe --tags 2>/dev/null`);
247         $revision = $tags || 'release';
248         return $revision;
249 }
250
251 sub dump_hash()
252 {
253         print "\n\e[1;32mPre-build configuration is complete!\e[0m\n\n";
254         print "\e[0mBase install path:\e[1;32m\t\t$main::config{BASE_DIR}\e[0m\n";
255         print "\e[0mConfig path:\e[1;32m\t\t\t$main::config{CONFIG_DIR}\e[0m\n";
256         print "\e[0mData path:\e[1;32m\t\t\t$main::config{DATA_DIR}\e[0m\n";
257         print "\e[0mLog path:\e[1;32m\t\t\t$main::config{LOG_DIR}\e[0m\n";
258         print "\e[0mModule path:\e[1;32m\t\t\t$main::config{MODULE_DIR}\e[0m\n";
259         print "\e[0mCompiler:\e[1;32m\t\t\t$main::cxx{NAME} $main::cxx{VERSION}\e[0m\n";
260         print "\e[0mSocket engine:\e[1;32m\t\t\t$main::config{SOCKETENGINE}\e[0m\n";
261         print "\e[0mGnuTLS support:\e[1;32m\t\t\t$main::config{USE_GNUTLS}\e[0m\n";
262         print "\e[0mOpenSSL support:\e[1;32m\t\t$main::config{USE_OPENSSL}\e[0m\n";
263 }
264
265 1;