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(catfile catdir 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,
73 sub enable_extras (@);
75 sub disable_extras (@);
78 my @opt_disableextras;
80 exit 1 unless GetOptions(
81 'clean' => \&cmd_clean,
83 'update' => \&cmd_update,
85 'binary-dir=s' => \$opt_binary_dir,
86 'config-dir=s' => \$opt_config_dir,
87 'data-dir=s' => \$opt_data_dir,
88 'development' => \$opt_development,
89 'disable-auto-extras' => \$opt_disable_auto_extras,
90 'disable-interactive' => \$opt_disable_interactive,
91 'distribution-label=s' => \$opt_distribution_label,
92 'example-dir=s' => \$opt_example_dir,
94 'log-dir=s' => \$opt_log_dir,
95 'manual-dir=s' => \$opt_manual_dir,
96 'module-dir=s' => \$opt_module_dir,
97 'portable' => \$opt_portable,
98 'prefix=s' => \$opt_prefix,
99 'script-dir=s' => \$opt_script_dir,
100 'socketengine=s' => \$opt_socketengine,
101 'system' => \$opt_system,
102 'uid=s' => \$opt_uid,
104 # TODO: when the modulemanager rewrite is done these should be removed.
105 'disable-extras=s@' => \@opt_disableextras,
106 'enable-extras=s@' => \@opt_enableextras,
107 'list-extras' => sub { list_extras; exit 0; },
110 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
111 @opt_enableextras = split /[, ]+/, join(',', @opt_enableextras);
112 @opt_disableextras = split /[, ]+/, join(',', @opt_disableextras);
113 enable_extras(@opt_enableextras);
114 disable_extras(@opt_disableextras);
116 print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
120 our $interactive = !(
123 defined $opt_binary_dir ||
124 defined $opt_config_dir ||
125 defined $opt_data_dir ||
126 defined $opt_development ||
127 defined $opt_disable_auto_extras ||
128 defined $opt_disable_interactive ||
129 defined $opt_distribution_label ||
130 defined $opt_example_dir ||
132 defined $opt_log_dir ||
133 defined $opt_manual_dir ||
134 defined $opt_module_dir ||
135 defined $opt_portable ||
136 defined $opt_prefix ||
137 defined $opt_script_dir ||
138 defined $opt_socketengine ||
139 defined $opt_system ||
143 my %version = get_version $opt_distribution_label;
144 print_format "<|BOLD Configuring InspIRCd $version{FULL} on $^O.|>\n";
148 %config = read_config_file(CONFIGURE_CACHE_FILE);
149 run_test CONFIGURE_CACHE_FILE, %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);
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.';
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;
170 my %compiler = get_compiler_info($config{CXX});
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');
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';
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;
190 $config{SOCKETENGINE} = $opt_socketengine // $socketengines[0];
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{SCRIPT_DIR} = $opt_script_dir // $config{BASE_DIR};
204 } elsif (defined $opt_system) {
205 $config{BASE_DIR} = $opt_prefix // '/var/lib/inspircd';
206 $config{BINARY_DIR} = $opt_binary_dir // '/usr/sbin';
207 $config{CONFIG_DIR} = $opt_config_dir // '/etc/inspircd';
208 $config{DATA_DIR} = $opt_data_dir // '/var/inspircd';
209 $config{EXAMPLE_DIR} = $opt_example_dir // '/usr/share/doc/inspircd';
210 $config{LOG_DIR} = $opt_log_dir // '/var/log/inspircd';
211 $config{MANUAL_DIR} = $opt_manual_dir // '/usr/share/man/man1';
212 $config{MODULE_DIR} = $opt_module_dir // '/usr/lib/inspircd';
213 $config{SCRIPT_DIR} = $opt_script_dir // '/usr/share/inspircd'
215 $config{BASE_DIR} = rel2abs $opt_prefix // $config{BASE_DIR} // catdir $RealDir, 'run';
216 $config{BINARY_DIR} = $opt_binary_dir // $config{BINARY_DIR} // catdir $config{BASE_DIR}, 'bin';
217 $config{CONFIG_DIR} = $opt_config_dir // $config{CONFIG_DIR} // catdir $config{BASE_DIR}, 'conf';
218 $config{DATA_DIR} = $opt_data_dir // $config{DATA_DIR} // catdir $config{BASE_DIR}, 'data';
219 $config{EXAMPLE_DIR} = $opt_example_dir // $config{EXAMPLE_DIR} // catdir $config{CONFIG_DIR}, 'examples';
220 $config{LOG_DIR} = $opt_log_dir // $config{LOG_DIR} // catdir $config{BASE_DIR}, 'logs';
221 $config{MANUAL_DIR} = $opt_manual_dir // $config{MANUAL_DIR} // catdir $config{BASE_DIR}, 'manuals';
222 $config{MODULE_DIR} = $opt_module_dir // $config{MODULE_DIR} // catdir $config{BASE_DIR}, 'modules';
223 $config{SCRIPT_DIR} = $opt_script_dir // $config{SCRIPT_DIR} // $config{BASE_DIR};
226 # Parse --gid=123 or --gid=foo and extract the group id.
228 if (defined $opt_gid) {
229 @group = $opt_gid =~ /^\d+$/ ? getgrgid($opt_gid) : getgrnam($opt_gid);
230 print_error "there is no '$opt_gid' group on this system!" unless @group;
232 @group = $opt_system ? getgrnam('irc') : getgrgid($config{GID} // getgid());
233 print_error "you need to specify a group to run as using '--gid [id|name]'!" unless @group;
235 print_warning <<"EOW";
236 You are building as the privileged $group[0] group and have not specified
237 an unprivileged group to run InspIRCd as.
239 This is almost never what you should do. You should probably either create a new
240 unprivileged user/group to build and run as or pass the '--gid [id|name]' flag
241 to specify an unprivileged group to run as.
243 if (!prompt_bool $interactive, "Are you sure you want to build as the $group[0] group?", 0) {
244 # PACKAGERS: You do not need to delete this check. Use `--gid $(id -g)` or `--gid 0` instead.
245 say STDERR "If you are sure you want to build as the $group[0] group pass the --gid $group[2] flag." unless $interactive;
250 $config{GROUP} = $group[0];
251 $config{GID} = $group[2];
253 # Parse --uid=123 or --uid=foo and extract the user id.
255 if (defined $opt_uid) {
256 @user = $opt_uid =~ /^\d+$/ ? getpwuid($opt_uid) : getpwnam($opt_uid);
257 print_error "there is no '$opt_uid' user on this system!" unless @user;
259 @user = $opt_system ? getpwnam('irc') : getpwuid($config{UID} // getuid());
260 print_error "you need to specify a user to run as using '--uid [id|name]'!" unless @user;
262 print_warning <<"EOW";
263 You are building as the privileged $user[0] user and have not specified
264 an unprivileged user to run InspIRCd as.
266 This is almost never what you should do. You should probably either create a new
267 unprivileged user/group to build and run as or pass the '--uid [id|name]' flag
268 to specify an unprivileged user to run as.
270 if (!prompt_bool $interactive, "Are you sure you want to build as the $user[0] user?", 0) {
271 # PACKAGERS: You do not need to delete this check. Use `--uid $(id -u)` or `--uid 0` instead.
272 say STDERR "If you are sure you want to build as the $user[0] user pass the --uid $user[2] flag." unless $interactive;
277 $config{USER} = $user[0];
278 $config{UID} = $user[2];
280 # Warn the user about clock drifting when running on OpenVZ.
281 if (-e '/proc/user_beancounters' || -e '/proc/vz/vzaquota') {
282 print_warning <<'EOW';
283 You are building InspIRCd inside of an OpenVZ container. If you
284 plan to use InspIRCd in this container then you should make sure that NTP is
285 configured on the Hardware Node. Failure to do so may result in clock drifting!
289 # Warn the user about OpenBSD shipping incredibly broken compilers/linkers.
290 if ($^O eq 'openbsd') {
291 print_warning <<'EOW';
292 You are building InspIRCd on OpenBSD. The C++ compilers and linkers
293 that OpenBSD ship are incredibly broken. You may have strange linker errors
294 and crashes. Please consider using a different OS like FreeBSD/NetBSD instead.
298 # Check that the user actually wants this version.
299 if (defined $version{REAL_LABEL}) {
300 print_warning <<'EOW';
301 You are building a development version. This contains code which has
302 not been tested as heavily and may contain various faults which could seriously
303 affect the running of your server. It is recommended that you use a stable
306 You can obtain the latest stable version from https://www.inspircd.org or by
307 running `<|GREEN git checkout $(git describe --abbrev=0 --tags insp3)|>` if you are
310 if (!prompt_bool $interactive, 'I understand this warning and want to continue anyway.', $opt_development // 0) {
311 say STDERR 'If you understand this warning and still want to continue pass the --development flag.' unless $interactive;
316 # Configure directory settings.
317 my $question = <<"EOQ";
318 Currently, InspIRCd is configured with the following paths:
320 <|BOLD Base:|> $config{BASE_DIR}
321 <|BOLD Binary:|> $config{BINARY_DIR}
322 <|BOLD Config:|> $config{CONFIG_DIR}
323 <|BOLD Data:|> $config{DATA_DIR}
324 <|BOLD Log:|> $config{LOG_DIR}
325 <|BOLD Manual:|> $config{MANUAL_DIR}
326 <|BOLD Module:|> $config{MODULE_DIR}
327 <|BOLD Script:|> $config{SCRIPT_DIR}
329 Do you want to change these settings?
331 if (prompt_bool $interactive, $question, 0) {
332 my $original_base_dir = $config{BASE_DIR};
333 $config{BASE_DIR} = prompt_dir $interactive, 'In what directory do you wish to install the InspIRCd base?', $config{BASE_DIR};
334 foreach my $key (qw(BINARY_DIR CONFIG_DIR DATA_DIR LOG_DIR MANUAL_DIR MODULE_DIR SCRIPT_DIR)) {
335 $config{$key} =~ s/^\Q$original_base_dir\E/$config{BASE_DIR}/;
337 $config{BINARY_DIR} = prompt_dir $interactive, 'In what directory should the InspIRCd binary be placed?', $config{BINARY_DIR};
338 $config{CONFIG_DIR} = prompt_dir $interactive, 'In what directory are configuration files to be stored?', $config{CONFIG_DIR};
339 $config{DATA_DIR} = prompt_dir $interactive, 'In what directory are variable data files to be stored?', $config{DATA_DIR};
340 $config{LOG_DIR} = prompt_dir $interactive, 'In what directory are log files to be stored?', $config{LOG_DIR};
341 $config{MANUAL_DIR} = prompt_dir $interactive, 'In what directory are manual pages to be placed?', $config{MANUAL_DIR};
342 $config{MODULE_DIR} = prompt_dir $interactive, 'In what directory are modules to be placed?', $config{MODULE_DIR};
343 $config{SCRIPT_DIR} = prompt_dir $interactive, 'In what directory are scripts to be placed?', $config{SCRIPT_DIR};
344 $config{EXAMPLE_DIR} = $config{CONFIG_DIR} . '/examples';
347 # Configure module settings.
349 Currently, InspIRCd is configured to automatically enable all available extra modules.
351 Would you like to enable extra modules manually?
353 if (prompt_bool $interactive, $question, 0) {
354 foreach my $extra (<src/modules/extra/m_*.cpp>) {
355 my $module_name = basename $extra, '.cpp';
356 if (prompt_bool $interactive, "Would you like to enable $module_name?", 0) {
357 enable_extras "$module_name.cpp";
360 } elsif (!defined $opt_disable_auto_extras) {
361 # TODO: finish modulemanager rewrite and replace this code with:
362 # system './modulemanager', 'enable', '--auto';
364 # Missing: m_ldap, m_regex_stdlib, m_ssl_mbedtls
365 'm_geo_maxmind.cpp' => 'pkg-config --exists libmaxminddb',
366 'm_mysql.cpp' => 'mysql_config --version',
367 'm_pgsql.cpp' => 'pg_config --version',
368 'm_regex_pcre.cpp' => 'pcre-config --version',
369 'm_regex_posix.cpp' => undef,
370 'm_regex_re2.cpp' => 'pkg-config --exists re2',
371 'm_regex_tre.cpp' => 'pkg-config --exists tre',
372 'm_sqlite3.cpp' => 'pkg-config --exists sqlite3',
373 'm_ssl_gnutls.cpp' => 'pkg-config --exists gnutls',
374 'm_ssl_openssl.cpp' => 'pkg-config --exists openssl',
375 'm_sslrehashsignal.cpp' => undef,
377 while (my ($module, $command) = each %modules) {
378 unless (defined $command && system "$command 1>/dev/null 2>/dev/null") {
379 enable_extras $module;
384 # Generate SSL certificates.
386 Would you like to generate a self-signed SSL certificate now? This certificate
387 can be used for testing but <|BOLD should not|> be used on a production network.
389 Note: you can get a <|BOLD free|> CA-signed certificate from Let's Encrypt. See
390 https://letsencrypt.org/getting-started/ for more details.
393 if (<src/modules/m_ssl_*.cpp>) {
394 if (prompt_bool $interactive, $question, $interactive) {
395 system './tools/genssl', 'auto';
398 print_warning <<"EOM";
399 You are building without enabling any SSL modules. This is not
400 recommended as SSL greatly enhances the security and privacy of your IRC server
401 and in a future version will be <|BOLD required|> for linking servers.
403 Please read the following documentation pages on how to enable SSL support:
405 GnuTLS (recommended): https://docs.inspircd.org/3/modules/ssl_gnutls
406 mbedTLS: https://docs.inspircd.org/3/modules/ssl_mbedtls
407 OpenSSL: https://docs.inspircd.org/3/modules/ssl_openssl
411 # Cache the distribution label so that its not lost when --update is run.
412 $config{DISTRIBUTION} = $opt_distribution_label if $opt_distribution_label;
414 write_configure_cache %config;
415 parse_templates \%config, \%compiler, \%version;
417 print_format <<"EOM";
419 Configuration is complete! You have chosen to build with the following settings:
422 <|GREEN Binary:|> $config{CXX}
423 <|GREEN Name:|> $compiler{NAME}
424 <|GREEN Version:|> $compiler{VERSION}
426 <|GREEN Extra Modules:|>
429 for my $file (<src/modules/m_*>) {
430 my $module = basename $file, '.cpp';
431 say " * $module" if -l $file;
434 print_format <<"EOM";
437 <|GREEN Base:|> $config{BASE_DIR}
438 <|GREEN Binary:|> $config{BINARY_DIR}
439 <|GREEN Config:|> $config{CONFIG_DIR}
440 <|GREEN Data:|> $config{DATA_DIR}
441 <|GREEN Example:|> $config{EXAMPLE_DIR}
442 <|GREEN Log:|> $config{LOG_DIR}
443 <|GREEN Manual:|> $config{MANUAL_DIR}
444 <|GREEN Module:|> $config{MODULE_DIR}
445 <|GREEN Script:|> $config{SCRIPT_DIR}
447 <|GREEN Execution Group:|> $config{GROUP} ($config{GID})
448 <|GREEN Execution User:|> $config{USER} ($config{UID})
449 <|GREEN Socket Engine:|> $config{SOCKETENGINE}
451 To build with these settings run '<|GREEN make -j${\(get_cpu_count() + 1)} install|>' now.
455 # Routine to list out the extra/ modules that have been enabled.
456 # Note: when getting any filenames out and comparing, it's important to lc it if the
457 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
458 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
459 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
463 my $srcdir = File::Spec->catdir("src", "modules");
464 my $abs_srcdir = File::Spec->rel2abs($srcdir);
467 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
468 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
471 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
472 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
475 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
477 EXTRA: for my $extra (@extras) {
478 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
479 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
480 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
481 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
482 if (-l $abs_source) {
483 # Symlink, is it in the right place?
484 my $targ = readlink($abs_source);
485 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
486 if ($abs_targ eq $abs_extra) {
487 $extras{$extra} = "\e[32;1menabled\e[0m";
489 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
491 } elsif (-e $abs_source) {
492 my ($devext, $inoext) = stat($abs_extra);
493 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
495 if ($devsrc == $devext && $inosrc == $inoext) {
496 $extras{$extra} = "\e[32;1menabled\e[0m";
498 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
501 open my $extfd, "<", $abs_extra;
502 open my $srcfd, "<", $abs_source;
504 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
505 $extras{$extra} = "\e[32;1menabled\e[0m";
507 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
511 $extras{$extra} = "\e[33;1mdisabled\e[0m";
514 # Now let's add dependency info
515 for my $extra (keys(%extras)) {
516 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
517 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
518 my @deps = split /\s+/, get_directive($abs_extra, 'ModDep', '');
519 for my $dep (@deps) {
520 if (exists($extras{$dep})) {
521 my $ref = \$extras{$dep}; # Take reference.
522 if ($$ref !~ m/needed by/) {
523 # First dependency found.
524 if ($$ref =~ m/enabled/) {
525 $$ref .= " (needed by \e[32;1m$extra\e[0m";
527 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
528 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
531 if ($$ref =~ m/enabled/) {
532 $$ref .= ", \e[32;1m$extra\e[0m";
534 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
540 for my $extra (sort {$a cmp $b} keys(%extras)) {
541 my $text = $extras{$extra};
542 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
543 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
545 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
548 return keys(%extras) if wantarray; # Can be used by manage_extras.
551 sub enable_extras (@) {
553 for my $extra (@extras) {
554 $extra = "m_$extra" unless $extra =~ /^m_/;
555 $extra = "$extra.cpp" unless $extra =~ /\.cpp$/;
556 my $extrapath = "src/modules/extra/$extra";
557 if (!-e $extrapath) {
558 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
561 my $source = "src/modules/$extra";
563 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
566 # Get dependencies, and add them to be processed.
567 my @deps = split /\s+/, get_directive($extrapath, 'ModDep', '');
568 for my $dep (@deps) {
569 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
570 if (!-e "src/modules/$dep" && !-e "include/$dep") {
571 if (-e "src/modules/extra/$dep") {
572 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
575 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";
579 print "Enabling $extra ... \n";
580 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
584 sub disable_extras (@)
586 opendir my $dd, "src/modules/extra/";
587 my @files = readdir($dd);
590 EXTRA: for my $extra (@extras) {
591 $extra = "m_$extra" unless $extra =~ /^m_/;
592 $extra = "$extra.cpp" unless $extra =~ /\.cpp$/;
593 my $extrapath = "src/modules/extra/$extra";
594 my $source = "src/modules/$extra";
595 if (!-e $extrapath) {
596 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
599 if ((! -l $source) || readlink($source) ne "extra/$extra") {
600 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";
603 # Check if anything needs this.
604 for my $file (@files) {
605 my @deps = split /\s+/, get_directive("src/modules/extra/$file", 'ModDep', '');
606 # File depends on this extra...
607 if (scalar(grep { $_ eq $extra } @deps) > 0) {
608 # And is both enabled and not about to be disabled.
609 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
610 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
616 print "Disabling $extra ... \n";
617 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";