]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
Update the module descriptions.
[user/henk/code/inspircd.git] / configure
1 #!/usr/bin/env perl
2 #
3 # InspIRCd -- Internet Relay Chat Daemon
4 #
5 #   Copyright (C) 2020 Nicole Kleinhoff <ilbelkyr@shalture.org>
6 #   Copyright (C) 2020 Daniel Vassdal <shutter@canternet.org>
7 #   Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
8 #   Copyright (C) 2019 Anatole Denis <natolumin@rezel.net>
9 #   Copyright (C) 2013-2021 Sadie Powell <sadie@witchery.services>
10 #   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
11 #   Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
12 #   Copyright (C) 2010 Daniel De Graaf <danieldg@inspircd.org>
13 #   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
14 #   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
15 #   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
16 #   Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
17 #
18 # This file is part of InspIRCd.  InspIRCd is free software: you can
19 # redistribute it and/or modify it under the terms of the GNU General Public
20 # License as published by the Free Software Foundation, version 2.
21 #
22 # This program is distributed in the hope that it will be useful, but WITHOUT
23 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
24 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
25 # details.
26 #
27 # You should have received a copy of the GNU General Public License
28 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
29 #
30
31
32 use v5.10.0;
33 use strict;
34 use warnings FATAL => qw(all);
35
36 use Cwd                   qw(getcwd);
37 use File::Basename        qw(basename);
38 use File::Copy            ();
39 use File::Spec::Functions qw(abs2rel catfile catdir rel2abs);
40 use FindBin               qw($RealDir);
41 use Getopt::Long          qw(GetOptions);
42 use POSIX                 qw(getgid getuid);
43
44 use lib $RealDir;
45 use make::common;
46 use make::configure;
47 use make::console;
48 use make::directive;
49
50 my ($opt_binary_dir,
51     $opt_config_dir,
52     $opt_data_dir,
53     $opt_development,
54     $opt_disable_auto_extras,
55     $opt_disable_interactive,
56     $opt_distribution_label,
57     $opt_example_dir,
58     $opt_gid,
59     $opt_log_dir,
60     $opt_manual_dir,
61     $opt_module_dir,
62     $opt_portable,
63     $opt_prefix,
64     $opt_runtime_dir,
65     $opt_script_dir,
66     $opt_socketengine,
67     $opt_system,
68     $opt_uid);
69
70 sub list_extras ();
71
72 sub enable_extras (@);
73
74 sub disable_extras (@);
75
76 my @opt_enableextras;
77 my @opt_disableextras;
78
79 exit 1 unless GetOptions(
80         'clean'  => \&cmd_clean,
81         'help'   => \&cmd_help,
82         'update' => \&cmd_update,
83
84         'binary-dir=s'         => \$opt_binary_dir,
85         'config-dir=s'         => \$opt_config_dir,
86         'data-dir=s'           => \$opt_data_dir,
87         'development'          => \$opt_development,
88         'disable-auto-extras'  => \$opt_disable_auto_extras,
89         'disable-interactive'  => \$opt_disable_interactive,
90         'distribution-label=s' => \$opt_distribution_label,
91         'example-dir=s'        => \$opt_example_dir,
92         'gid=s'                => \$opt_gid,
93         'log-dir=s'            => \$opt_log_dir,
94         'manual-dir=s'         => \$opt_manual_dir,
95         'module-dir=s'         => \$opt_module_dir,
96         'portable'             => \$opt_portable,
97         'prefix=s'             => \$opt_prefix,
98         'runtime-dir=s'        => \$opt_runtime_dir,
99         'script-dir=s'         => \$opt_script_dir,
100         'socketengine=s'       => \$opt_socketengine,
101         'system'               => \$opt_system,
102         'uid=s'                => \$opt_uid,
103
104         'disable-extras=s@' => \@opt_disableextras,
105         'enable-extras=s@'  => \@opt_enableextras,
106         'list-extras'       => sub { list_extras; exit 0; },
107 );
108
109 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
110         @opt_enableextras = grep { /\S/ } split /[, ]+/, join(',', @opt_enableextras);
111         @opt_disableextras = grep { /\S/ } split /[, ]+/, join(',', @opt_disableextras);
112         enable_extras(@opt_enableextras);
113         disable_extras(@opt_disableextras);
114         list_extras;
115         print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
116         exit 0;
117 }
118
119 our $interactive = !(
120         !-t STDIN ||
121         !-t STDOUT ||
122         defined $opt_binary_dir ||
123         defined $opt_config_dir ||
124         defined $opt_data_dir ||
125         defined $opt_development ||
126         defined $opt_disable_auto_extras ||
127         defined $opt_disable_interactive ||
128         defined $opt_distribution_label ||
129         defined $opt_example_dir ||
130         defined $opt_gid ||
131         defined $opt_log_dir ||
132         defined $opt_manual_dir ||
133         defined $opt_module_dir ||
134         defined $opt_portable ||
135         defined $opt_prefix ||
136         defined $opt_runtime_dir ||
137         defined $opt_script_dir ||
138         defined $opt_socketengine ||
139         defined $opt_system ||
140         defined $opt_uid
141 );
142
143 my %version = get_version $opt_distribution_label;
144 say console_format "<|BOLD Configuring InspIRCd $version{FULL} on $^O.|>";
145
146 my %config;
147 if ($interactive) {
148         %config = read_config_file(CONFIGURE_CACHE_FILE);
149         run_test abs2rel(CONFIGURE_CACHE_FILE, $RealDir), %config;
150         if (!defined $config{VERSION}) {
151                 $config{VERSION} = CONFIGURE_CACHE_VERSION;
152         } elsif ($config{VERSION} != CONFIGURE_CACHE_VERSION) {
153                 print_warning "ignoring contents of ${\CONFIGURE_CACHE_FILE} as it was generated by an incompatible version of $0!";
154                 %config = ('VERSION', CONFIGURE_CACHE_VERSION);
155         }
156 }
157
158 $config{CXX} = find_compiler($config{CXX} // $ENV{CXX});
159 unless ($config{CXX}) {
160         say 'A suitable C++ compiler could not be detected on your system!';
161         unless ($interactive) {
162                 say 'Set the CXX environment variable to the path to a C++ compiler binary if this is incorrect.';
163                 exit 1;
164         }
165         until ($config{CXX}) {
166                 my $compiler_path = prompt_string 1, 'Please enter the path to a C++ compiler binary:', 'c++';
167                 $config{CXX} = find_compiler $compiler_path;
168         }
169 }
170 my %compiler = get_compiler_info($config{CXX});
171
172 $config{HAS_ARC4RANDOM_BUF} = run_test 'arc4random_buf()', test_file($config{CXX}, 'arc4random_buf.cpp');
173 $config{HAS_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX}, 'clock_gettime.cpp', $^O eq 'darwin' ? undef : '-lrt');
174 $config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
175
176 my @socketengines;
177 push @socketengines, 'epoll'  if run_test 'epoll', test_header $config{CXX}, 'sys/epoll.h';
178 push @socketengines, 'kqueue' if run_test 'kqueue', test_file $config{CXX}, 'kqueue.cpp';
179 push @socketengines, 'poll'   if run_test 'poll', test_header $config{CXX}, 'poll.h';
180 push @socketengines, 'select';
181
182 if (defined $opt_socketengine) {
183         unless (grep { $_ eq $opt_socketengine } @socketengines) {
184                 my $reason = -f "src/socketengines/socketengine_$opt_socketengine.cpp" ? 'is not available on this platform' : 'does not exist';
185                 print_error "The socket engine you requested ($opt_socketengine) $reason!",
186                         'Available socket engines are:',
187                         map { "  * $_" } @socketengines;
188         }
189 }
190 $config{SOCKETENGINE} = $opt_socketengine // $socketengines[0];
191
192 if (defined $opt_portable) {
193         print_error '--portable and --system can not be used together!' if defined $opt_system;
194         $config{DESTDIR}     = catfile $RealDir, 'run', '';
195         $config{BASE_DIR}    = $opt_prefix      // '';
196         $config{BINARY_DIR}  = $opt_binary_dir  // 'bin';
197         $config{CONFIG_DIR}  = $opt_config_dir  // 'conf';
198         $config{DATA_DIR}    = $opt_data_dir    // 'data';
199         $config{EXAMPLE_DIR} = $opt_example_dir // catdir $config{CONFIG_DIR}, 'examples';
200         $config{LOG_DIR}     = $opt_log_dir     // 'logs';
201         $config{MANUAL_DIR}  = $opt_manual_dir  // 'manuals';
202         $config{MODULE_DIR}  = $opt_module_dir  // 'modules';
203         $config{RUNTIME_DIR} = $opt_runtime_dir // $config{DATA_DIR};
204         $config{SCRIPT_DIR}  = $opt_script_dir  // $config{BASE_DIR};
205 } elsif (defined $opt_system) {
206         $config{BASE_DIR}    = $opt_prefix      // '/';
207         $config{BINARY_DIR}  = $opt_binary_dir  // catdir $config{BASE_DIR}, 'usr/sbin';
208         $config{CONFIG_DIR}  = $opt_config_dir  // catdir $config{BASE_DIR}, 'etc/inspircd';
209         $config{DATA_DIR}    = $opt_data_dir    // catdir $config{BASE_DIR}, 'var/lib/inspircd';
210         $config{EXAMPLE_DIR} = $opt_example_dir // catdir $config{BASE_DIR}, 'usr/share/doc/inspircd';
211         $config{LOG_DIR}     = $opt_log_dir     // catdir $config{BASE_DIR}, 'var/log/inspircd';
212         $config{MANUAL_DIR}  = $opt_manual_dir  // catdir $config{BASE_DIR}, 'usr/share/man/man1';
213         $config{MODULE_DIR}  = $opt_module_dir  // catdir $config{BASE_DIR}, 'usr/lib/inspircd';
214         $config{RUNTIME_DIR} = $opt_runtime_dir // catdir $config{BASE_DIR}, 'var/run/inspircd';
215         $config{SCRIPT_DIR}  = $opt_script_dir  // catdir $config{BASE_DIR}, 'usr/share/inspircd';
216 } else {
217         $config{BASE_DIR}    = rel2abs $opt_prefix // $config{BASE_DIR}    // catdir $RealDir,            'run';
218         $config{BINARY_DIR}  = $opt_binary_dir     // $config{BINARY_DIR}  // catdir $config{BASE_DIR},   'bin';
219         $config{CONFIG_DIR}  = $opt_config_dir     // $config{CONFIG_DIR}  // catdir $config{BASE_DIR},   'conf';
220         $config{DATA_DIR}    = $opt_data_dir       // $config{DATA_DIR}    // catdir $config{BASE_DIR},   'data';
221         $config{EXAMPLE_DIR} = $opt_example_dir    // $config{EXAMPLE_DIR} // catdir $config{CONFIG_DIR}, 'examples';
222         $config{LOG_DIR}     = $opt_log_dir        // $config{LOG_DIR}     // catdir $config{BASE_DIR},   'logs';
223         $config{MANUAL_DIR}  = $opt_manual_dir     // $config{MANUAL_DIR}  // catdir $config{BASE_DIR},   'manuals';
224         $config{MODULE_DIR}  = $opt_module_dir     // $config{MODULE_DIR}  // catdir $config{BASE_DIR},   'modules';
225         $config{RUNTIME_DIR} = $opt_runtime_dir    // $config{RUNTIME_DIR} // $config{DATA_DIR};
226         $config{SCRIPT_DIR}  = $opt_script_dir     // $config{SCRIPT_DIR}  // $config{BASE_DIR};
227 }
228
229 # Parse --gid=123 or --gid=foo and extract the group id.
230 my @group;
231 if (defined $opt_gid) {
232         @group = $opt_gid =~ /^\d+$/ ? getgrgid($opt_gid) : getgrnam($opt_gid);
233         print_error "there is no '$opt_gid' group on this system!" unless @group;
234 } else {
235         @group = $opt_system ? getgrnam('irc') : getgrgid($config{GID} // getgid());
236         print_error "you need to specify a group to run as using '--gid [id|name]'!" unless @group;
237         unless ($group[2]) {
238                 print_warning <<"EOW";
239 You are building as the privileged $group[0] group and have not specified
240 an unprivileged group to run InspIRCd as.
241
242 This is almost never what you should do. You should probably either create a new
243 unprivileged user/group to build and run as or pass the '--gid [id|name]' flag
244 to specify an unprivileged group to run as.
245 EOW
246                 if (!prompt_bool $interactive, "Are you sure you want to build as the $group[0] group?", 0) {
247                         # PACKAGERS: You do not need to delete this check. Use `--gid $(id -g)` or `--gid 0` instead.
248                         say STDERR "If you are sure you want to build as the $group[0] group pass the --gid $group[2] flag." unless $interactive;
249                         exit 1;
250                 }
251         }
252 }
253 $config{GROUP} = $group[0];
254 $config{GID}   = $group[2];
255
256 # Parse --uid=123 or --uid=foo and extract the user id.
257 my @user;
258 if (defined $opt_uid) {
259         @user = $opt_uid =~ /^\d+$/ ? getpwuid($opt_uid) : getpwnam($opt_uid);
260         print_error "there is no '$opt_uid' user on this system!" unless @user;
261 } else {
262         @user = $opt_system ? getpwnam('irc') : getpwuid($config{UID} // getuid());
263         print_error "you need to specify a user to run as using '--uid [id|name]'!" unless @user;
264         unless ($user[2]) {
265                 print_warning <<"EOW";
266 You are building as the privileged $user[0] user and have not specified
267 an unprivileged user to run InspIRCd as.
268
269 This is almost never what you should do. You should probably either create a new
270 unprivileged user/group to build and run as or pass the '--uid [id|name]' flag
271 to specify an unprivileged user to run as.
272 EOW
273                 if (!prompt_bool $interactive, "Are you sure you want to build as the $user[0] user?", 0) {
274                         # PACKAGERS: You do not need to delete this check. Use `--uid $(id -u)` or `--uid 0` instead.
275                         say STDERR "If you are sure you want to build as the $user[0] user pass the --uid $user[2] flag." unless $interactive;
276                         exit 1;
277                 }
278         }
279 }
280 $config{USER} = $user[0];
281 $config{UID}  = $user[2];
282
283 # Warn the user about clock drifting when running on OpenVZ.
284 if (-e '/proc/user_beancounters' || -e '/proc/vz/vzaquota') {
285         print_warning <<'EOW';
286 You are building InspIRCd inside of an OpenVZ container. If you
287 plan to use InspIRCd in this container then you should make sure that NTP is
288 configured on the Hardware Node. Failure to do so may result in clock drifting!
289 EOW
290 }
291
292 # Warn the user about OpenBSD shipping incredibly broken compilers/linkers.
293 if ($^O eq 'openbsd') {
294         print_warning <<'EOW';
295 You are building InspIRCd on OpenBSD. The C++ compilers and linkers
296 that OpenBSD ship are incredibly broken. You may have strange linker errors
297 and crashes. Please consider using a different OS like FreeBSD/NetBSD instead.
298 EOW
299 }
300
301 # Warn about Perl versions that will not be supported in the future.
302 if ($^V lt 'v5.26.0') {
303         print_warning <<"EOW";
304 You are building InspIRCd with Perl $^V. This is very old and will
305 not be supported by the next major version of InspIRCd. Please consider updating
306 to Perl v5.26 or newer.
307 EOW
308 }
309
310 # Warn about compiler versions that will not be supported in the future.
311 my %future_compilers = (
312         AppleClang => version->parse('10.0'),
313         Clang      => version->parse('5.0'),
314         GCC        => version->parse('7.0'),
315 );
316 if (exists $future_compilers{$compiler{NAME}} && $compiler{VERSION} lt $future_compilers{$compiler{NAME}}) {
317         print_warning <<"EOW";
318 You are building InspIRCd with $compiler{NAME} v$compiler{VERSION}. This is very old and
319 will not be supported by the next major version of InspIRCd. Please consider
320 updating to $compiler{NAME} v$future_compilers{$compiler{NAME}} or newer.
321 EOW
322 }
323
324 # Check that the user actually wants this version.
325 if (defined $version{REAL_LABEL}) {
326         print_warning <<'EOW';
327 You are building a development version. This contains code which has
328 not been tested as heavily and may contain various faults which could seriously
329 affect the running of your server. It is recommended that you use a stable
330 version instead.
331
332 You can obtain the latest stable version from https://www.inspircd.org or by
333 running `<|GREEN git checkout $(git describe --abbrev=0 --tags insp3)|>` if you are
334 installing from Git.
335 EOW
336         if (!prompt_bool $interactive, 'I understand this warning and want to continue anyway.', $opt_development // 0) {
337                 say STDERR 'If you understand this warning and still want to continue pass the --development flag.' unless $interactive;
338                 exit 1;
339         }
340 }
341
342 # Configure directory settings.
343 my $question = <<"EOQ";
344 Currently, InspIRCd is configured with the following paths:
345
346 <|BOLD Binary:|> $config{BINARY_DIR}
347 <|BOLD Config:|> $config{CONFIG_DIR}
348 <|BOLD Data:|>   $config{DATA_DIR}
349 <|BOLD Log:|>    $config{LOG_DIR}
350 <|BOLD Manual:|> $config{MANUAL_DIR}
351 <|BOLD Module:|> $config{MODULE_DIR}
352 <|BOLD Script:|> $config{SCRIPT_DIR}
353
354 Do you want to change these settings?
355 EOQ
356 if (prompt_bool $interactive, $question, 0) {
357         my $original_base_dir = $config{BASE_DIR};
358         $config{BASE_DIR} = prompt_dir $interactive, 'In what directory do you wish to install the InspIRCd base?', $config{BASE_DIR};
359         for my $key (qw(BINARY_DIR CONFIG_DIR DATA_DIR LOG_DIR MANUAL_DIR MODULE_DIR SCRIPT_DIR)) {
360                 $config{$key} =~ s/^\Q$original_base_dir\E/$config{BASE_DIR}/;
361         }
362         $config{BINARY_DIR} = prompt_dir $interactive, 'In what directory should the InspIRCd binary be placed?', $config{BINARY_DIR};
363         $config{CONFIG_DIR} = prompt_dir $interactive, 'In what directory are configuration files to be stored?', $config{CONFIG_DIR};
364         $config{DATA_DIR}   = prompt_dir $interactive, 'In what directory are variable data files to be stored?', $config{DATA_DIR};
365         $config{LOG_DIR}    = prompt_dir $interactive, 'In what directory are log files to be stored?',           $config{LOG_DIR};
366         $config{MANUAL_DIR} = prompt_dir $interactive, 'In what directory are manual pages to be placed?',        $config{MANUAL_DIR};
367         $config{MODULE_DIR} = prompt_dir $interactive, 'In what directory are modules to be placed?',             $config{MODULE_DIR};
368         $config{SCRIPT_DIR} = prompt_dir $interactive, 'In what directory are scripts to be placed?',             $config{SCRIPT_DIR};
369         $config{EXAMPLE_DIR} = $config{CONFIG_DIR} . '/examples';
370         $config{RUNTIME_DIR} = $config{DATA_DIR};
371 }
372
373 # Configure module settings.
374 $question = <<'EOQ';
375 Currently, InspIRCd is configured to automatically enable all available extra modules.
376
377 Would you like to enable extra modules manually?
378 EOQ
379 if (prompt_bool $interactive, $question, 0) {
380         for my $extra (<$RealDir/src/modules/extra/m_*.cpp>) {
381                 my $module_name = module_shrink $extra;
382                 if (prompt_bool $interactive, "Would you like to enable the <|BOLD $module_name|> module?", 0) {
383                         enable_extras $module_name;
384                 }
385         }
386 } elsif (!defined $opt_disable_auto_extras) {
387         my %modules = (
388                 'm_argon2.cpp'          => 'pkg-config --exists libargon2',
389                 'm_geo_maxmind.cpp'     => 'pkg-config --exists libmaxminddb',
390                 'm_mysql.cpp'           => 'mysql_config --version',
391                 'm_pgsql.cpp'           => 'pg_config --version',
392                 'm_ldap.cpp'            => "echo '#include <ldap.h>' | $config{CXX} -E -",
393                 'm_regex_pcre.cpp'      => 'pcre-config --version',
394                 'm_regex_posix.cpp'     => undef,
395                 'm_regex_re2.cpp'       => 'pkg-config --exists re2',
396                 'm_regex_stdlib.cpp'    => "$config{CXX} -o /dev/null -std=c++11 $RealDir/make/test/compiler.cpp",
397                 'm_regex_tre.cpp'       => 'pkg-config --exists tre',
398                 'm_sqlite3.cpp'         => 'pkg-config --exists sqlite3',
399                 'm_ssl_gnutls.cpp'      => 'pkg-config --exists gnutls',
400                 'm_ssl_mbedtls.cpp'     => "echo '#include <mbedtls/version.h>' | $config{CXX} -E -",
401                 'm_ssl_openssl.cpp'     => 'pkg-config --exists openssl',
402                 'm_sslrehashsignal.cpp' => undef,
403         );
404         while (my ($module, $command) = each %modules) {
405                 unless (defined $command && system "$command 1>/dev/null 2>/dev/null") {
406                         enable_extras $module;
407                 }
408         }
409 }
410
411 # Generate SSL certificates.
412 $question = <<EOQ;
413 Would you like to generate a self-signed SSL certificate now? This certificate
414 can be used for testing but <|BOLD should not|> be used on a production network.
415
416 Note: you can get a <|BOLD free|> CA-signed certificate from Let's Encrypt. See
417 https://letsencrypt.org/getting-started/ for more details.
418 EOQ
419
420 if (<$RealDir/src/modules/m_ssl_*.cpp>) {
421         if (prompt_bool $interactive, $question, $interactive) {
422                 create_directory CONFIGURE_DIRECTORY, 0750 or print_error "unable to create ${\CONFIGURE_DIRECTORY}: $!";
423                 system './tools/genssl', 'auto', CONFIGURE_DIRECTORY;
424         } else {
425                 my @pems = <${\CONFIGURE_DIRECTORY}/{cert,csr,dhparams,key}.pem>;
426                 $question = <<EOQ;
427 The following self-signed files were previously generated and will be installed
428 when you run Make. Do you want to delete them?
429
430   * ${\join "\n  * ", @pems}
431 EOQ
432                 if (@pems && prompt_bool $interactive, $question, 0) {
433                         unlink @pems;
434                 }
435         }
436 } elsif (!defined $opt_disable_auto_extras) {
437         print_warning <<"EOM";
438 You are building without enabling any SSL modules. This is not
439 recommended as SSL greatly enhances the security and privacy of your IRC server
440 and in a future version will be <|BOLD required|> for linking servers.
441
442 Please read the following documentation pages on how to enable SSL support:
443
444 GnuTLS (recommended): https://docs.inspircd.org/3/modules/ssl_gnutls
445 mbedTLS:              https://docs.inspircd.org/3/modules/ssl_mbedtls
446 OpenSSL:              https://docs.inspircd.org/3/modules/ssl_openssl
447 EOM
448 }
449
450 # Cache the distribution label so that its not lost when --update is run.
451 $config{DISTRIBUTION} = $opt_distribution_label if $opt_distribution_label;
452
453 write_configure_cache %config;
454 parse_templates \%config, \%compiler, \%version;
455
456 print console_format <<"EOM";
457
458 Configuration is complete! You have chosen to build with the following settings:
459
460 <|GREEN Compiler:|>
461   <|GREEN Binary:|>  $config{CXX}
462   <|GREEN Name:|>    $compiler{NAME}
463   <|GREEN Version:|> $compiler{VERSION}
464
465 <|GREEN Extra Modules:|>
466 EOM
467
468 for my $file (<$RealDir/src/modules/m_*>) {
469         say "  * ${\module_shrink $file}" if -l $file;
470 }
471
472 my @makeargs;
473 push @makeargs, "-C${\abs2rel $RealDir}" unless getcwd eq $RealDir;
474 push @makeargs, "-j${\(get_cpu_count() + 1)}";
475
476 print console_format <<"EOM";
477
478 <|GREEN Paths:|>
479   <|GREEN Binary:|>  $config{BINARY_DIR}
480   <|GREEN Config:|>  $config{CONFIG_DIR}
481   <|GREEN Data:|>    $config{DATA_DIR}
482   <|GREEN Example:|> $config{EXAMPLE_DIR}
483   <|GREEN Log:|>     $config{LOG_DIR}
484   <|GREEN Manual:|>  $config{MANUAL_DIR}
485   <|GREEN Module:|>  $config{MODULE_DIR}
486   <|GREEN Runtime:|> $config{RUNTIME_DIR}
487   <|GREEN Script:|>  $config{SCRIPT_DIR}
488
489 <|GREEN Execution Group:|> $config{GROUP} ($config{GID})
490 <|GREEN Execution User:|>  $config{USER} ($config{UID})
491 <|GREEN Socket Engine:|>   $config{SOCKETENGINE}
492
493 To build with these settings run '<|GREEN make ${\join ' ', @makeargs} install|>' now.
494
495 EOM
496
497 # Routine to list out the extra/ modules that have been enabled.
498 # Note: when getting any filenames out and comparing, it's important to lc it if the
499 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
500 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
501 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
502 sub list_extras () {
503         use File::Spec;
504         # @_ not used
505         my $srcdir = File::Spec->catdir("src", "modules");
506         my $abs_srcdir = File::Spec->rel2abs($srcdir);
507         local $_;
508         my $dd;
509         opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
510         my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
511         closedir $dd;
512         undef $dd;
513         opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
514         my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
515         closedir $dd;
516         undef $dd;
517         my $maxlen = (sort { $b <=> $a } (map { length module_shrink $_ } (@extras)))[0];
518         my %extras = ();
519 EXTRA:  for my $extra (@extras) {
520                 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
521                 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
522                 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
523                 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
524                 if (-l $abs_source) {
525                         # Symlink, is it in the right place?
526                         my $targ = readlink($abs_source);
527                         my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
528                         if ($abs_targ eq $abs_extra) {
529                                 $extras{$extra} = "\e[32;1menabled\e[0m";
530                         } else {
531                                 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
532                         }
533                 } elsif (-e $abs_source) {
534                         my ($devext, $inoext) = stat($abs_extra);
535                         my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
536                         if ($lnksrc > 1) {
537                                 if ($devsrc == $devext && $inosrc == $inoext) {
538                                         $extras{$extra} = "\e[32;1menabled\e[0m";
539                                 } else {
540                                         $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
541                                 }
542                         } else {
543                                 open my $extfd, "<", $abs_extra;
544                                 open my $srcfd, "<", $abs_source;
545                                 local $/ = undef;
546                                 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
547                                         $extras{$extra} = "\e[32;1menabled\e[0m";
548                                 } else {
549                                         $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
550                                 }
551                         }
552                 } else {
553                         $extras{$extra} = "\e[33;1mdisabled\e[0m";
554                 }
555         }
556         # Now let's add dependency info
557         for my $extra (keys(%extras)) {
558                 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
559                 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
560                 my @deps = split /\s+/, get_directive($abs_extra, 'ModDep', '');
561                 for my $dep (@deps) {
562                         if (exists($extras{$dep})) {
563                                 my $ref = \$extras{$dep}; # Take reference.
564                                 if ($$ref !~ m/needed by/) {
565                                         # First dependency found.
566                                         if ($$ref =~ m/enabled/) {
567                                                 $$ref .= " (needed by \e[32;1m$extra\e[0m";
568                                         } else {
569                                                 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
570                                                 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
571                                         }
572                                 } else {
573                                         if ($$ref =~ m/enabled/) {
574                                                 $$ref .= ", \e[32;1m$extra\e[0m";
575                                         } else {
576                                                 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
577                                         }
578                                 }
579                         }
580                 }
581         }
582         for my $extra (sort {$a cmp $b} keys(%extras)) {
583                 my $text = $extras{$extra};
584                 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
585                         printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, module_shrink($extra), $text, ($text =~ m/needed by/ ? ")" : "");
586                 } else {
587                         printf "%-*s = %s%s\n", $maxlen, module_shrink($extra), $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
588                 }
589         }
590         return keys(%extras) if wantarray; # Can be used by manage_extras.
591 }
592
593 sub enable_extras(@) {
594         my $moduledir = catdir $RealDir, 'src', 'modules';
595         my $extradir = catdir $moduledir, 'extra';
596
597         for my $extra (@_) {
598                 my $shortname = module_shrink $extra;
599                 my $extrafile = module_expand $extra;
600
601                 my $extrapath = catfile $extradir, $extrafile;
602                 if (!-f $extrapath) {
603                         print_error "<|GREEN $extra|> is not an extra module!";
604                 }
605
606                 my $modulepath = catfile $moduledir, $extrafile;
607                 if (-l $modulepath) {
608                         if (readlink($modulepath) ne $extrapath) {
609                                 unlink $modulepath; # Remove the dead symlink.
610                         } else {
611                                 next; # Module is already enabled.
612                         }
613                 }
614
615                 if (-e $modulepath) {
616                         print_error "unable to symlink <|GREEN ${\abs2rel $modulepath}|> to <|GREEN ${\abs2rel $extrapath}|>: the target exists and is not a symlink.";
617                 } else {
618                         say console_format "Enabling the <|GREEN $shortname|> module ...";
619                         symlink $extrapath, $modulepath or print_error "unable to symlink <|GREEN ${\abs2rel $modulepath}|> to <|GREEN ${\abs2rel $extrapath}|>: $!";
620                 }
621         }
622 }
623
624 sub disable_extras(@) {
625         my $moduledir = catdir $RealDir, 'src', 'modules';
626         my $extradir = catdir $moduledir, 'extra';
627
628         for my $extra (@_) {
629                 my $shortname = module_shrink $extra;
630                 my $extrafile = module_expand $extra;
631
632                 my $modulepath = catfile $moduledir, $extrafile;
633                 my $extrapath = catfile $extradir, $extrafile;
634                 if (!-e $modulepath && !-e $extrapath) {
635                         print_error "the <|GREEN $shortname|> module does not exist!";
636                 } elsif (!-e $modulepath && -e $extrapath) {
637                         print_error "the <|GREEN $shortname|> module is not currently enabled!";
638                 } elsif ((-e $modulepath && !-e $extrapath) || !-l $modulepath) {
639                         print_error "the <|GREEN $shortname|> module is not an extra module!";
640                 } else {
641                         say console_format "Disabling the <|GREEN $shortname|> module ...";
642                         unlink $modulepath or print_error "unable to unlink <|GREEN $extrapath|>: $!";
643                 }
644         }
645 }