3 # InspIRCd -- Internet Relay Chat Daemon
5 # Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6 # Copyright (C) 2019 Anatole Denis <natolumin@rezel.net>
7 # Copyright (C) 2017 emerson <github@emersonveenstra.net>
8 # Copyright (C) 2013-2020 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>
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.
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
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/>.
37 use warnings FATAL => qw(all);
39 use File::Basename qw(basename);
41 use File::Spec::Functions qw(rel2abs);
42 use FindBin qw($RealDir);
43 use Getopt::Long qw(GetOptions);
44 use POSIX qw(getgid getuid);
56 $opt_disable_auto_extras,
57 $opt_disable_interactive,
58 $opt_distribution_label,
72 sub enable_extras (@);
74 sub disable_extras (@);
77 my @opt_disableextras;
79 exit 1 unless GetOptions(
80 'clean' => \&cmd_clean,
82 'update' => \&cmd_update,
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,
93 'log-dir=s' => \$opt_log_dir,
94 'manual-dir=s' => \$opt_manual_dir,
95 'module-dir=s' => \$opt_module_dir,
96 'prefix=s' => \$opt_prefix,
97 'script-dir=s' => \$opt_script_dir,
98 'socketengine=s' => \$opt_socketengine,
99 'system' => \$opt_system,
100 'uid=s' => \$opt_uid,
102 # TODO: when the modulemanager rewrite is done these should be removed.
103 'disable-extras=s@' => \@opt_disableextras,
104 'enable-extras=s@' => \@opt_enableextras,
105 'list-extras' => sub { list_extras; exit 0; },
108 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
109 @opt_enableextras = split /[, ]+/, join(',', @opt_enableextras);
110 @opt_disableextras = split /[, ]+/, join(',', @opt_disableextras);
111 enable_extras(@opt_enableextras);
112 disable_extras(@opt_disableextras);
114 print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
118 our $interactive = !(
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 ||
130 defined $opt_log_dir ||
131 defined $opt_manual_dir ||
132 defined $opt_module_dir ||
133 defined $opt_prefix ||
134 defined $opt_script_dir ||
135 defined $opt_socketengine ||
136 defined $opt_system ||
140 my %version = get_version $opt_distribution_label;
141 print_format "<|BOLD Configuring InspIRCd $version{FULL} on $^O.|>\n";
145 %config = read_config_file(CONFIGURE_CACHE_FILE);
146 run_test CONFIGURE_CACHE_FILE, %config;
147 if (!defined $config{VERSION}) {
148 $config{VERSION} = CONFIGURE_CACHE_VERSION;
149 } elsif ($config{VERSION} != CONFIGURE_CACHE_VERSION) {
150 print_warning "ignoring contents of ${\CONFIGURE_CACHE_FILE} as it was generated by an incompatible version of $0!";
151 %config = ('VERSION', CONFIGURE_CACHE_VERSION);
155 $config{CXX} = find_compiler($config{CXX} // $ENV{CXX});
156 unless ($config{CXX}) {
157 say 'A suitable C++ compiler could not be detected on your system!';
158 unless ($interactive) {
159 say 'Set the CXX environment variable to the path to a C++ compiler binary if this is incorrect.';
162 until ($config{CXX}) {
163 my $compiler_path = prompt_string 1, 'Please enter the path to a C++ compiler binary:', 'c++';
164 $config{CXX} = find_compiler $compiler_path;
167 my %compiler = get_compiler_info($config{CXX});
169 $config{HAS_ARC4RANDOM_BUF} = run_test 'arc4random_buf()', test_file($config{CXX}, 'arc4random_buf.cpp');
170 $config{HAS_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX}, 'clock_gettime.cpp', $^O eq 'darwin' ? undef : '-lrt');
171 $config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
174 push @socketengines, 'epoll' if run_test 'epoll', test_header $config{CXX}, 'sys/epoll.h';
175 push @socketengines, 'kqueue' if run_test 'kqueue', test_file $config{CXX}, 'kqueue.cpp';
176 push @socketengines, 'poll' if run_test 'poll', test_header $config{CXX}, 'poll.h';
177 push @socketengines, 'select';
179 if (defined $opt_socketengine) {
180 unless (grep { $_ eq $opt_socketengine } @socketengines) {
181 my $reason = -f "src/socketengines/socketengine_$opt_socketengine.cpp" ? 'is not available on this platform' : 'does not exist';
182 print_error "The socket engine you requested ($opt_socketengine) $reason!",
183 'Available socket engines are:',
184 map { " * $_" } @socketengines;
187 $config{SOCKETENGINE} = $opt_socketengine // $socketengines[0];
189 if (defined $opt_system) {
190 $config{BASE_DIR} = $opt_prefix // '/var/lib/inspircd';
191 $config{BINARY_DIR} = $opt_binary_dir // '/usr/sbin';
192 $config{CONFIG_DIR} = $opt_config_dir // '/etc/inspircd';
193 $config{DATA_DIR} = $opt_data_dir // '/var/inspircd';
194 $config{EXAMPLE_DIR} = $opt_example_dir // '/usr/share/doc/inspircd';
195 $config{LOG_DIR} = $opt_log_dir // '/var/log/inspircd';
196 $config{MANUAL_DIR} = $opt_manual_dir // '/usr/share/man/man1';
197 $config{MODULE_DIR} = $opt_module_dir // '/usr/lib/inspircd';
198 $config{SCRIPT_DIR} = $opt_script_dir // '/usr/share/inspircd'
200 $config{BASE_DIR} = $opt_prefix // $config{BASE_DIR} // rel2abs 'run';
201 $config{BINARY_DIR} = $opt_binary_dir // $config{BINARY_DIR} // rel2abs $config{BASE_DIR} . '/bin';
202 $config{CONFIG_DIR} = $opt_config_dir // $config{CONFIG_DIR} // rel2abs $config{BASE_DIR} . '/conf';
203 $config{DATA_DIR} = $opt_data_dir // $config{DATA_DIR} // rel2abs $config{BASE_DIR} . '/data';
204 $config{EXAMPLE_DIR} = $opt_example_dir // $config{EXAMPLE_DIR} // $config{CONFIG_DIR} . '/examples';
205 $config{LOG_DIR} = $opt_log_dir // $config{LOG_DIR} // rel2abs $config{BASE_DIR} . '/logs';
206 $config{MANUAL_DIR} = $opt_manual_dir // $config{MANUAL_DIR} // rel2abs $config{BASE_DIR} . '/manuals';
207 $config{MODULE_DIR} = $opt_module_dir // $config{MODULE_DIR} // rel2abs $config{BASE_DIR} . '/modules';
208 $config{SCRIPT_DIR} = $opt_script_dir // $config{SCRIPT_DIR} // $config{BASE_DIR};
211 # Parse --gid=123 or --gid=foo and extract the group id.
213 if (defined $opt_gid) {
214 @group = $opt_gid =~ /^\d+$/ ? getgrgid($opt_gid) : getgrnam($opt_gid);
215 print_error "there is no '$opt_gid' group on this system!" unless @group;
217 @group = $opt_system ? getgrnam('irc') : getgrgid($config{GID} // getgid());
218 print_error "you need to specify a group to run as using '--gid [id|name]'!" unless @group;
220 print_warning <<"EOW";
221 You are building as the privileged $group[0] group and have not specified
222 an unprivileged group to run InspIRCd as.
224 This is almost never what you should do. You should probably either create a new
225 unprivileged user/group to build and run as or pass the '--gid [id|name]' flag
226 to specify an unprivileged group to run as.
228 if (!prompt_bool $interactive, "Are you sure you want to build as the $group[0] group?", 0) {
229 say STDERR "If you are sure you want to build as the $group[0] group pass the --gid $group[2] flag." unless $interactive;
234 $config{GROUP} = $group[0];
235 $config{GID} = $group[2];
237 # Parse --uid=123 or --uid=foo and extract the user id.
239 if (defined $opt_uid) {
240 @user = $opt_uid =~ /^\d+$/ ? getpwuid($opt_uid) : getpwnam($opt_uid);
241 print_error "there is no '$opt_uid' user on this system!" unless @user;
243 @user = $opt_system ? getpwnam('irc') : getpwuid($config{UID} // getuid());
244 print_error "you need to specify a user to run as using '--uid [id|name]'!" unless @user;
246 print_warning <<"EOW";
247 You are building as the privileged $user[0] user and have not specified
248 an unprivileged user to run InspIRCd as.
250 This is almost never what you should do. You should probably either create a new
251 unprivileged user/group to build and run as or pass the '--uid [id|name]' flag
252 to specify an unprivileged user to run as.
254 if (!prompt_bool $interactive, "Are you sure you want to build as the $user[0] user?", 0) {
255 say STDERR "If you are sure you want to build as the $user[0] user pass the --uid $user[2] flag." unless $interactive;
260 $config{USER} = $user[0];
261 $config{UID} = $user[2];
263 # Warn the user about clock drifting when running on OpenVZ.
264 if (-e '/proc/user_beancounters' || -e '/proc/vz/vzaquota') {
265 print_warning <<'EOW';
266 You are building InspIRCd inside of an OpenVZ container. If you
267 plan to use InspIRCd in this container then you should make sure that NTP is
268 configured on the Hardware Node. Failure to do so may result in clock drifting!
272 # Warn the user about OpenBSD shipping incredibly broken compilers/linkers.
273 if ($^O eq 'openbsd') {
274 print_warning <<'EOW';
275 You are building InspIRCd on OpenBSD. The C++ compilers and linkers
276 that OpenBSD ship are incredibly broken. You may have strange linker errors
277 and crashes. Please consider using a different OS like FreeBSD/NetBSD instead.
281 # Check that the user actually wants this version.
282 if (defined $version{REAL_LABEL}) {
283 print_warning <<'EOW';
284 You are building a development version. This contains code which has
285 not been tested as heavily and may contain various faults which could seriously
286 affect the running of your server. It is recommended that you use a stable
289 You can obtain the latest stable version from https://www.inspircd.org or by
290 running `<|GREEN git checkout $(git describe --abbrev=0 --tags insp3)|>` if you are
293 if (!prompt_bool $interactive, 'I understand this warning and want to continue anyway.', $opt_development // 0) {
294 say STDERR 'If you understand this warning and still want to continue pass the --development flag.' unless $interactive;
299 # Configure directory settings.
300 my $question = <<"EOQ";
301 Currently, InspIRCd is configured with the following paths:
303 <|BOLD Base:|> $config{BASE_DIR}
304 <|BOLD Binary:|> $config{BINARY_DIR}
305 <|BOLD Config:|> $config{CONFIG_DIR}
306 <|BOLD Data:|> $config{DATA_DIR}
307 <|BOLD Log:|> $config{LOG_DIR}
308 <|BOLD Manual:|> $config{MANUAL_DIR}
309 <|BOLD Module:|> $config{MODULE_DIR}
310 <|BOLD Script:|> $config{SCRIPT_DIR}
312 Do you want to change these settings?
314 if (prompt_bool $interactive, $question, 0) {
315 my $original_base_dir = $config{BASE_DIR};
316 $config{BASE_DIR} = prompt_dir $interactive, 'In what directory do you wish to install the InspIRCd base?', $config{BASE_DIR};
317 foreach my $key (qw(BINARY_DIR CONFIG_DIR DATA_DIR LOG_DIR MANUAL_DIR MODULE_DIR SCRIPT_DIR)) {
318 $config{$key} =~ s/^\Q$original_base_dir\E/$config{BASE_DIR}/;
320 $config{BINARY_DIR} = prompt_dir $interactive, 'In what directory should the InspIRCd binary be placed?', $config{BINARY_DIR};
321 $config{CONFIG_DIR} = prompt_dir $interactive, 'In what directory are configuration files to be stored?', $config{CONFIG_DIR};
322 $config{DATA_DIR} = prompt_dir $interactive, 'In what directory are variable data files to be stored?', $config{DATA_DIR};
323 $config{LOG_DIR} = prompt_dir $interactive, 'In what directory are log files to be stored?', $config{LOG_DIR};
324 $config{MANUAL_DIR} = prompt_dir $interactive, 'In what directory are manual pages to be placed?', $config{MANUAL_DIR};
325 $config{MODULE_DIR} = prompt_dir $interactive, 'In what directory are modules to be placed?', $config{MODULE_DIR};
326 $config{SCRIPT_DIR} = prompt_dir $interactive, 'In what directory are scripts to be placed?', $config{SCRIPT_DIR};
327 $config{EXAMPLE_DIR} = $config{CONFIG_DIR} . '/examples';
330 # Configure module settings.
332 Currently, InspIRCd is configured to automatically enable all available extra modules.
334 Would you like to enable extra modules manually?
336 if (prompt_bool $interactive, $question, 0) {
337 foreach my $extra (<src/modules/extra/m_*.cpp>) {
338 my $module_name = basename $extra, '.cpp';
339 if (prompt_bool $interactive, "Would you like to enable $module_name?", 0) {
340 enable_extras "$module_name.cpp";
343 } elsif (!defined $opt_disable_auto_extras) {
344 # TODO: finish modulemanager rewrite and replace this code with:
345 # system './modulemanager', 'enable', '--auto';
347 # Missing: m_ldap, m_regex_stdlib, m_ssl_mbedtls
348 'm_geo_maxmind.cpp' => 'pkg-config --exists libmaxminddb',
349 'm_mysql.cpp' => 'mysql_config --version',
350 'm_pgsql.cpp' => 'pg_config --version',
351 'm_regex_pcre.cpp' => 'pcre-config --version',
352 'm_regex_posix.cpp' => undef,
353 'm_regex_re2.cpp' => 'pkg-config --exists re2',
354 'm_regex_tre.cpp' => 'pkg-config --exists tre',
355 'm_sqlite3.cpp' => 'pkg-config --exists sqlite3',
356 'm_ssl_gnutls.cpp' => 'pkg-config --exists gnutls',
357 'm_ssl_openssl.cpp' => 'pkg-config --exists openssl',
358 'm_sslrehashsignal.cpp' => undef,
360 while (my ($module, $command) = each %modules) {
361 unless (defined $command && system "$command 1>/dev/null 2>/dev/null") {
362 enable_extras $module;
367 # Generate SSL certificates.
369 Would you like to generate a self-signed SSL certificate now? This certificate
370 can be used for testing but <|BOLD should not|> be used on a production network.
372 Note: you can get a <|BOLD free|> CA-signed certificate from Let's Encrypt. See
373 https://letsencrypt.org/getting-started/ for more details.
376 if (<src/modules/m_ssl_*.cpp>) {
377 if (prompt_bool $interactive, $question, $interactive) {
378 system './tools/genssl', 'auto';
381 print_warning <<"EOM";
382 You are building without enabling any SSL modules. This is not
383 recommended as SSL greatly enhances the security and privacy of your IRC server
384 and in a future version will be <|BOLD required|> for linking servers.
386 Please read the following documentation pages on how to enable SSL support:
388 GnuTLS (recommended): https://docs.inspircd.org/3/modules/ssl_gnutls
389 mbedTLS: https://docs.inspircd.org/3/modules/ssl_mbedtls
390 OpenSSL: https://docs.inspircd.org/3/modules/ssl_openssl
394 # Cache the distribution label so that its not lost when --update is run.
395 $config{DISTRIBUTION} = $opt_distribution_label if $opt_distribution_label;
397 write_configure_cache %config;
398 parse_templates \%config, \%compiler, \%version;
400 print_format <<"EOM";
402 Configuration is complete! You have chosen to build with the following settings:
405 <|GREEN Binary:|> $config{CXX}
406 <|GREEN Name:|> $compiler{NAME}
407 <|GREEN Version:|> $compiler{VERSION}
409 <|GREEN Extra Modules:|>
412 for my $file (<src/modules/m_*>) {
413 my $module = basename $file, '.cpp';
414 say " * $module" if -l $file;
417 print_format <<"EOM";
420 <|GREEN Base:|> $config{BASE_DIR}
421 <|GREEN Binary:|> $config{BINARY_DIR}
422 <|GREEN Config:|> $config{CONFIG_DIR}
423 <|GREEN Data:|> $config{DATA_DIR}
424 <|GREEN Example:|> $config{EXAMPLE_DIR}
425 <|GREEN Log:|> $config{LOG_DIR}
426 <|GREEN Manual:|> $config{MANUAL_DIR}
427 <|GREEN Module:|> $config{MODULE_DIR}
428 <|GREEN Script:|> $config{SCRIPT_DIR}
430 <|GREEN Execution Group:|> $config{GROUP} ($config{GID})
431 <|GREEN Execution User:|> $config{USER} ($config{UID})
432 <|GREEN Socket Engine:|> $config{SOCKETENGINE}
434 To build with these settings run '<|GREEN make -j${\get_cpu_count + 1} install|>' now.
438 # Routine to list out the extra/ modules that have been enabled.
439 # Note: when getting any filenames out and comparing, it's important to lc it if the
440 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
441 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
442 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
446 my $srcdir = File::Spec->catdir("src", "modules");
447 my $abs_srcdir = File::Spec->rel2abs($srcdir);
450 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
451 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
454 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
455 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
458 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
460 EXTRA: for my $extra (@extras) {
461 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
462 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
463 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
464 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
465 if (-l $abs_source) {
466 # Symlink, is it in the right place?
467 my $targ = readlink($abs_source);
468 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
469 if ($abs_targ eq $abs_extra) {
470 $extras{$extra} = "\e[32;1menabled\e[0m";
472 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
474 } elsif (-e $abs_source) {
475 my ($devext, $inoext) = stat($abs_extra);
476 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
478 if ($devsrc == $devext && $inosrc == $inoext) {
479 $extras{$extra} = "\e[32;1menabled\e[0m";
481 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
484 open my $extfd, "<", $abs_extra;
485 open my $srcfd, "<", $abs_source;
487 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
488 $extras{$extra} = "\e[32;1menabled\e[0m";
490 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
494 $extras{$extra} = "\e[33;1mdisabled\e[0m";
497 # Now let's add dependency info
498 for my $extra (keys(%extras)) {
499 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
500 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
501 my @deps = split /\s+/, get_directive($abs_extra, 'ModDep', '');
502 for my $dep (@deps) {
503 if (exists($extras{$dep})) {
504 my $ref = \$extras{$dep}; # Take reference.
505 if ($$ref !~ m/needed by/) {
506 # First dependency found.
507 if ($$ref =~ m/enabled/) {
508 $$ref .= " (needed by \e[32;1m$extra\e[0m";
510 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
511 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
514 if ($$ref =~ m/enabled/) {
515 $$ref .= ", \e[32;1m$extra\e[0m";
517 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
523 for my $extra (sort {$a cmp $b} keys(%extras)) {
524 my $text = $extras{$extra};
525 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
526 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
528 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
531 return keys(%extras) if wantarray; # Can be used by manage_extras.
534 sub enable_extras (@) {
536 for my $extra (@extras) {
537 $extra = "m_$extra" unless $extra =~ /^m_/;
538 $extra = "$extra.cpp" unless $extra =~ /\.cpp$/;
539 my $extrapath = "src/modules/extra/$extra";
540 if (!-e $extrapath) {
541 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
544 my $source = "src/modules/$extra";
546 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
549 # Get dependencies, and add them to be processed.
550 my @deps = split /\s+/, get_directive($extrapath, 'ModDep', '');
551 for my $dep (@deps) {
552 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
553 if (!-e "src/modules/$dep" && !-e "include/$dep") {
554 if (-e "src/modules/extra/$dep") {
555 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
558 print STDERR "\e[33;1mWARNING:\e[0m module \e[32;1m$extra\e[0m might be missing dependency \e[32;1m$dep\e[0m - YOU are responsible for satisfying it!\n";
562 print "Enabling $extra ... \n";
563 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
567 sub disable_extras (@)
569 opendir my $dd, "src/modules/extra/";
570 my @files = readdir($dd);
573 EXTRA: for my $extra (@extras) {
574 $extra = "m_$extra" unless $extra =~ /^m_/;
575 $extra = "$extra.cpp" unless $extra =~ /\.cpp$/;
576 my $extrapath = "src/modules/extra/$extra";
577 my $source = "src/modules/$extra";
578 if (!-e $extrapath) {
579 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
582 if ((! -l $source) || readlink($source) ne "extra/$extra") {
583 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Source is not a link or doesn't refer to the right file. Remove manually if this is in error.\n";
586 # Check if anything needs this.
587 for my $file (@files) {
588 my @deps = split /\s+/, get_directive("src/modules/extra/$file", 'ModDep', '');
589 # File depends on this extra...
590 if (scalar(grep { $_ eq $extra } @deps) > 0) {
591 # And is both enabled and not about to be disabled.
592 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
593 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
599 print "Disabling $extra ... \n";
600 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";