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