4 # InspIRCd -- Internet Relay Chat Daemon
6 # Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
7 # Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
8 # Copyright (C) 2003, 2006-2008 Craig Edwards <craigedwards@brainbox.cc>
9 # Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
10 # Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
11 # Copyright (C) 2007 John Brooks <john.brooks@dereferenced.net>
12 # Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
13 # Copyright (C) 2003-2006 Craig McLure <craig@chatspike.net>
15 # This file is part of InspIRCd. InspIRCd is free software: you can
16 # redistribute it and/or modify it under the terms of the GNU General Public
17 # License as published by the Free Software Foundation, version 2.
19 # This program is distributed in the hope that it will be useful, but WITHOUT
20 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
21 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
24 # You should have received a copy of the GNU General Public License
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
34 use warnings FATAL => qw(all);
37 use File::Spec::Functions qw(rel2abs);
44 our ($opt_use_gnutls, $opt_use_openssl, $opt_nointeractive, $opt_socketengine, $opt_freebsd_port,
45 $opt_system, $opt_uid, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir,
46 $opt_data_dir, $opt_log_dir);
50 sub enable_extras (@);
52 sub disable_extras (@);
55 my @opt_disableextras;
58 'enable-gnutls' => \$opt_use_gnutls,
59 'system' => \$opt_system,
61 'enable-openssl' => \$opt_use_openssl,
62 'disable-interactive' => \$opt_nointeractive,
63 'socketengine=s' => \$opt_socketengine,
64 'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
65 'prefix=s' => \$opt_base_dir,
66 'config-dir=s' => \$opt_config_dir,
67 'module-dir=s' => \$opt_module_dir,
68 'binary-dir=s' => \$opt_binary_dir,
69 'data-dir=s' => \$opt_data_dir,
70 'log-dir=s' => \$opt_log_dir,
71 'help' => sub { showhelp(); },
72 'update' => sub { update(); },
73 'clean' => sub { clean(); },
74 'list-extras' => sub { list_extras; exit 0; }, # This, --enable-extras, and --disable-extras are for non-interactive managing.
75 'enable-extras=s@' => \@opt_enableextras, # ^
76 'disable-extras=s@' => \@opt_disableextras, # ^
79 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
80 @opt_enableextras = split /,/, join(',', @opt_enableextras);
81 @opt_disableextras = split /,/, join(',', @opt_disableextras);
82 enable_extras(@opt_enableextras);
83 disable_extras(@opt_disableextras);
85 print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
90 (defined $opt_base_dir) ||
91 (defined $opt_config_dir) ||
92 (defined $opt_module_dir) ||
93 (defined $opt_base_dir) ||
94 (defined $opt_binary_dir) ||
95 (defined $opt_data_dir) ||
96 (defined $opt_log_dir) ||
97 (defined $opt_nointeractive) ||
98 (defined $opt_socketengine) ||
99 (defined $opt_use_openssl) ||
100 (defined $opt_system) ||
101 (defined $opt_uid) ||
102 (defined $opt_use_gnutls) ||
103 (defined $opt_freebsd_port)
106 our $topdir = getcwd();
109 our $cache_loaded = getcache();
111 $config{BASE_DIR} = $topdir."/run";
113 if (defined $opt_base_dir) {
114 $config{BASE_DIR} = $opt_base_dir;
115 } elsif (defined $opt_system) {
116 $config{BASE_DIR} = '/var/lib/inspircd';
119 if (defined $opt_system) {
120 $config{UID} = $opt_uid || 'ircd';
121 $config{CONFIG_DIR} = '/etc/inspircd';
122 $config{MODULE_DIR} = '/usr/lib/inspircd';
123 $config{BINARY_DIR} = '/usr/sbin/';
124 $config{BUILD_DIR} = $topdir."/build";
125 $config{DATA_DIR} = '/var/inspircd';
126 $config{LOG_DIR} = '/var/log/inspircd';
128 $config{UID} = $opt_uid || $<;
129 $config{CONFIG_DIR} = rel2abs($config{BASE_DIR}."/conf");
130 $config{MODULE_DIR} = rel2abs($config{BASE_DIR}."/modules");
131 $config{BINARY_DIR} = rel2abs($config{BASE_DIR}."/bin");
132 $config{BUILD_DIR} = rel2abs($topdir."/build");
133 $config{DATA_DIR} = rel2abs($config{BASE_DIR}."/data");
134 $config{LOG_DIR} = rel2abs($config{BASE_DIR}."/logs");
137 if (defined $opt_config_dir) {
138 $config{CONFIG_DIR} = $opt_config_dir;
140 if (defined $opt_module_dir) {
141 $config{MODULE_DIR} = $opt_module_dir;
143 if (defined $opt_binary_dir) {
144 $config{BINARY_DIR} = $opt_binary_dir;
146 if (defined $opt_data_dir) {
147 $config{DATA_DIR} = $opt_data_dir;
149 if (defined $opt_log_dir) {
150 $config{LOG_DIR} = $opt_log_dir;
152 chomp($config{HAS_GNUTLS} = `pkg-config --modversion gnutls 2>/dev/null`); # GNUTLS Version.
154 if (defined $opt_freebsd_port)
156 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`);
157 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`);
158 $config{USE_FREEBSD_BASE_SSL} = "n";
162 if ($^O eq "freebsd")
164 # default: use base ssl
165 chomp($config{HAS_OPENSSL} = `openssl version | cut -d ' ' -f 2`); # OpenSSL version, freebsd specific
166 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`); # Port version, may be different
170 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`); # Openssl version, others
171 $config{HAS_OPENSSL_PORT} = "";
175 chomp(our $gnutls_ver = $config{HAS_GNUTLS});
176 chomp(our $openssl_ver = $config{HAS_OPENSSL});
177 $config{USE_GNUTLS} = "n";
178 if (defined $opt_use_gnutls)
180 $config{USE_GNUTLS} = "y"; # Use gnutls.
182 $config{USE_OPENSSL} = "n"; # Use openssl.
183 if (defined $opt_use_openssl)
185 $config{USE_OPENSSL} = "y";
188 $config{STARTSCRIPT} = $^O eq 'darwin' ? 'org.inspircd.plist' : 'inspircd';
190 $config{CXX} = defined $ENV{CXX} && !system("$ENV{CXX} -v > /dev/null 2>&1") ? $ENV{CXX} : find_compiler();
191 if ($config{CXX} eq "") {
192 print "A C++ compiler could not be detected on your system!\n";
193 print "Set the CXX environment variable to the full path if this is incorrect.\n";
197 our %cxx = get_compiler_info($config{CXX});
198 if ($cxx{UNSUPPORTED}) {
199 print "Your C++ compiler is too old to build InspIRCd!\n";
200 print "Reason: $cxx{REASON}\n";
204 if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) {
205 $config{HAS_OPENSSL} = $1;
207 $config{HAS_OPENSSL} = "";
210 # Get and Set some important vars..
215 unlink(".config.cache");
221 # Does the cache file exist?
223 # No, No it doesn't.. *BASH*
224 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
227 # We've Loaded the cache file and all our variables..
230 print "Updating files...\n";
231 %cxx = get_compiler_info($config{CXX});
240 print "Configure update failed: $@\n";
245 print "Running non-interactive configure...\n" unless $interactive;
246 print "Checking for cache from previous configure... ";
247 print ($cache_loaded ? "found\n" : "not found\n");
249 $config{HAS_CLOCK_GETTIME} = run_test 'clock_gettime()', test_file($config{CXX}, 'clock_gettime.cpp', '-lrt');
250 $config{HAS_EVENTFD} = run_test 'eventfd()', test_file($config{CXX}, 'eventfd.cpp');
252 if ($config{HAS_EPOLL} = run_test 'epoll', test_header($config{CXX}, 'sys/epoll.h')) {
253 $config{SOCKETENGINE} ||= 'epoll';
256 if ($config{HAS_KQUEUE} = run_test 'kqueue', test_file($config{CXX}, 'kqueue.cpp')) {
257 $config{SOCKETENGINE} ||= 'kqueue';
260 if ($config{HAS_PORTS} = run_test 'Solaris IOCP', test_header($config{CXX}, 'port.h')) {
261 $config{SOCKETENGINE} ||= 'ports';
264 if ($config{HAS_POLL} = run_test 'poll', test_header($config{CXX}, 'poll.h')) {
265 $config{SOCKETENGINE} ||= 'poll';
268 # Select is available on all platforms
269 $config{HAS_SELECT} = 1;
270 $config{SOCKETENGINE} ||= "select";
272 if (defined $opt_socketengine) {
273 my $cfgkey = "HAS_" . uc $opt_socketengine;
274 if ($config{$cfgkey} && -f "src/socketengines/socketengine_$opt_socketengine.cpp") {
275 $config{SOCKETENGINE} = $opt_socketengine;
277 print "Unable to use a socket engine which is not supported on this platform ($opt_socketengine)!\n";
278 print "Available socket engines are:";
279 foreach (<src/socketengines/socketengine_*.cpp>) {
280 s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
281 print " $1" if $config{"HAS_" . uc $1};
288 print "Checking for libgnutls... ";
289 if (defined($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS}) || ($config{HAS_GNUTLS} eq "y"))) {
290 if (defined($gnutls_ver) && ($gnutls_ver ne "")) {
292 $config{HAS_GNUTLS} = "y";
295 $config{HAS_GNUTLS} = "n";
299 $config{HAS_GNUTLS} = "n";
302 print "Checking for openssl... ";
303 if (defined($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL}) || ($config{HAS_OPENSSL} eq "y"))) {
304 if (defined($openssl_ver) && ($openssl_ver ne "")) {
306 $config{HAS_OPENSSL} = "y";
309 $config{HAS_OPENSSL} = "n";
313 $config{HAS_OPENSSL} = "n";
319 system 'tput', 'clear';
321 my $revision = getrevision();
322 chomp(my $version = `sh src/version.sh`);
324 # Display Introduction Message..
326 Welcome to the \e[1mInspIRCd\e[0m Configuration program! (\e[1minteractive mode\e[0m)
327 \e[1mPackage maintainers: Type ./configure --help for non-interactive help\e[0m
329 *** If you are unsure of any of these values, leave it blank for ***
330 *** standard settings that will work, and your server will run ***
331 *** using them. Please consult your IRC network admin if in doubt. ***
333 Press \e[1m<RETURN>\e[0m to accept the default for any option, or enter
334 a new value. Please note: You will \e[1mHAVE\e[0m to read the docs
335 dir, otherwise you won't have a config file!
337 Your operating system is: \e[1;32m$^O\e[0m
339 print "Your InspIRCd version is: \e[1;32m";
340 print $revision eq 'release' ? substr($version, 9) : substr($revision, 1);
342 print "The following compiler has been detected: \e[1;32m$cxx{NAME} $cxx{VERSION}\e[0m ($config{CXX})\n\n";
344 # Directory Settings..
345 my $tmpbase = $config{BASE_DIR};
346 dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
347 if ($tmpbase ne $config{BASE_DIR}) {
348 $config{CONFIG_DIR} = rel2abs($config{BASE_DIR}."/conf");
349 $config{MODULE_DIR} = rel2abs($config{BASE_DIR}."/modules");
350 $config{DATA_DIR} = rel2abs($config{BASE_DIR}."/data");
351 $config{LOG_DIR} = rel2abs($config{BASE_DIR}."/logs");
352 $config{BINARY_DIR} = rel2abs($config{BASE_DIR}."/bin");
355 dir_check("are the configuration files", "CONFIG_DIR");
356 dir_check("are the modules to be compiled to", "MODULE_DIR");
357 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
358 dir_check("are variable data files to be located in", "DATA_DIR");
359 dir_check("are the logs to be stored in", "LOG_DIR");
360 dir_check("do you want the build to take place", "BUILD_DIR");
362 my $chose_hiperf = 0;
363 if ($config{HAS_KQUEUE}) {
364 $config{USE_KQUEUE} = "y";
365 yesno('USE_KQUEUE',"You are running a BSD operating system, and kqueue\nwas detected. Would you like to enable kqueue support?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable kqueue?");
367 if ($config{USE_KQUEUE} eq "y") {
368 $config{SOCKETENGINE} = "kqueue";
372 if ($config{HAS_EPOLL}) {
373 $config{USE_EPOLL} = "y";
374 yesno('USE_EPOLL',"You are running a Linux 2.6+ operating system, and epoll\nwas detected. Would you like to enable epoll support?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable epoll?");
376 if ($config{USE_EPOLL} eq "y") {
377 $config{SOCKETENGINE} = "epoll";
381 if ($config{HAS_PORTS}) {
382 $config{USE_PORTS} = "y";
383 yesno('USE_PORTS',"You are running Solaris 10.\nWould you like to enable I/O completion ports support?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable support for I/O completion ports?");
385 if ($config{USE_PORTS} eq "y") {
386 $config{SOCKETENGINE} = "ports";
391 if (!$chose_hiperf && $config{HAS_POLL}) {
392 $config{USE_POLL} = "y";
393 yesno('USE_POLL', "Would you like to use poll?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable poll?");
394 if ($config{USE_POLL} eq "y") {
395 $config{SOCKETENGINE} = "poll";
398 if (!$chose_hiperf && $config{USE_POLL} ne "y")
400 print "No high-performance socket engines are available, or you chose\n";
401 print "not to enable one. Defaulting to select() engine.\n\n";
402 $config{SOCKETENGINE} = "select";
405 $config{USE_FREEBSD_BASE_SSL} = "n";
406 $config{USE_FREEBSD_PORTS_SSL} = "n";
407 if ($config{HAS_OPENSSL_PORT} ne "")
409 $config{USE_FREEBSD_PORTS_SSL} = "y";
410 print "I have detected the OpenSSL FreeBSD port installed on your system,\n";
411 print "version \e[1;32m".$config{HAS_OPENSSL_PORT}."\e[0m. Your base system OpenSSL is version \e[1;32m".$openssl_ver."\e[0m.\n\n";
412 yesno('USE_FREEBSD_PORTS_SSL', "Do you want to use the FreeBSD ports version?");
414 $config{USE_FREEBSD_BASE_SSL} = "y" if ($config{USE_FREEBSD_PORTS_SSL} eq "n");
416 if ($config{USE_FREEBSD_BASE_SSL} eq "n")
418 # update to port version
419 $openssl_ver = $config{HAS_OPENSSL_PORT};
424 $config{USE_FREEBSD_BASE_SSL} = "y" if ($^O eq "freebsd");
427 $config{USE_SSL} = "n";
429 if ($config{HAS_GNUTLS} eq "y" || $config{HAS_OPENSSL} eq "y")
431 print "Detected GnuTLS version: \e[1;32m" . $gnutls_ver . "\e[0m\n";
432 print "Detected OpenSSL version: \e[1;32m" . $openssl_ver . "\e[0m\n\n";
434 yesno('USE_SSL', "One or more SSL libraries detected. Would you like to enable SSL support?");
435 if ($config{USE_SSL} eq "y")
437 if ($config{HAS_GNUTLS} eq "y")
439 yesno('USE_GNUTLS',"Would you like to enable SSL with m_ssl_gnutls? (recommended)");
440 if ($config{USE_GNUTLS} eq "y")
442 print "\nUsing GnuTLS SSL module.\n";
446 if ($config{HAS_OPENSSL} eq "y")
448 yesno('USE_OPENSSL', "Would you like to enable SSL with m_ssl_openssl?");
449 if ($config{USE_OPENSSL} eq "y")
451 print "\nUsing OpenSSL SSL module.\n";
458 print "\nCould not detect OpenSSL or GnuTLS. Make sure pkg-config is installed and\n";
459 print "is in your path.\n\n";
463 # We are on a POSIX system, we can enable POSIX extras without asking
464 symlink "extra/m_regex_posix.cpp", "src/modules/m_regex_posix.cpp";
466 if (($config{USE_GNUTLS} eq "y") && ($config{HAS_GNUTLS} ne "y"))
468 print "Sorry, but i couldn't detect gnutls. Make sure gnutls-config is in your path.\n";
471 if (($config{USE_OPENSSL} eq "y") && ($config{HAS_OPENSSL} ne "y"))
473 print "Sorry, but i couldn't detect openssl. Make sure openssl is in your path.\n";
477 $config{CERTGEN} ||= 'y';
478 yesno('CERTGEN',"Would you like generate SSL certificates now?") if ($interactive && ($config{USE_GNUTLS} eq "y" || $config{USE_OPENSSL} eq "y"));
480 if ($config{USE_GNUTLS} eq "y") {
481 unless (-r "src/modules/m_ssl_gnutls.cpp") {
482 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
483 symlink "extra/m_ssl_gnutls.cpp", "src/modules/m_ssl_gnutls.cpp" or print STDERR "Symlink failed: $!";
485 if ($interactive && $config{CERTGEN} eq 'y')
487 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem" && -r "$config{CONFIG_DIR}/dhparams.pem") {
488 unless (system './tools/genssl gnutls') {
489 print "\nCertificate generation complete, copying to config directory... ";
490 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
491 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
492 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
497 print "SSL Certificates found, skipping.\n\n";
502 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
506 if ($config{USE_OPENSSL} eq "y") {
507 unless (-r "src/modules/m_ssl_openssl.cpp") {
508 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
509 symlink "extra/m_ssl_openssl.cpp", "src/modules/m_ssl_openssl.cpp" or print STDERR "Symlink failed: $!";
511 if ($interactive && $config{CERTGEN} eq 'y')
513 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem" && -r "$config{CONFIG_DIR}/dhparams.pem") {
514 unless (system './tools/genssl openssl') {
515 print "\nCertificate generation complete, copying to config directory... ";
516 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
517 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
518 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
522 print "SSL Certificates found, skipping.\n\n"
527 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
530 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
531 print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
540 print "To build your server with these settings, please run '\e[1;32mmake\e[0m' now.\n";
541 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
542 print "Please note: for \e[1;32mSSL support\e[0m you will need to load required\n";
543 print "modules in your config. This configure script has added those modules to the\n";
544 print "build process. For more info please refer to:\n";
545 print "\e[1;32mhttp://wiki.inspircd.org/Installation_From_Tarball\e[0m\n";
547 print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n";
550 # Retrieves the .config.cache file, and loads values into the main config hash.
551 open(CACHE, ".config.cache") or return 0;
554 # Ignore Blank lines, and comments..
557 my ($key, $value) = split("=", $_, 2);
558 $value =~ /^\"(.*)\"$/;
559 # Do something with data here!
567 # Dump the contents of %config
568 print "Writing \e[1;32mcache file\e[0m for future ./configures ...\n";
569 open(FILEHANDLE, ">.config.cache");
570 foreach my $key (keys %config) {
571 print FILEHANDLE "$key=\"$config{$key}\"\n";
577 my ($desc, $hash_key) = @_;
580 print "In what directory $desc?\n";
581 print "[\e[1;32m$config{$hash_key}\e[0m] -> ";
582 chomp(my $var = <STDIN>);
584 $var = $config{$hash_key};
586 if ($var =~ /^\~\/(.+)$/) {
587 # Convert it to a full path..
588 $var = rel2abs($ENV{HOME} . "/" . $1);
590 $var = rel2abs($var);
592 print "$var does not exist. Create it?\n[\e[1;32my\e[0m] ";
593 chomp(my $tmp = <STDIN>);
594 if (($tmp eq "") || ($tmp =~ /^y/i)) {
595 # Attempt to Create the Dir..
598 File::Path::mkpath($var, 0, 0777);
601 unless (defined($chk) && -d $var) {
602 print "Unable to create directory. ($var)\n\n";
607 # They said they don't want to create, and we can't install there.
613 # Target exists, but is not a directory.
614 print "File $var exists, but is not a directory.\n\n";
618 # Either Dir Exists, or was created fine.
619 $config{$hash_key} = $var;
626 chomp(my $incos = `uname -n -s -r`);
627 chomp(my $version = `sh src/version.sh`);
628 my $revision = getrevision();
629 my $branch = "InspIRCd-0.0";
630 if ($version =~ /^(InspIRCd-[0-9]+\.[0-9]+)\.[0-9]+/)
634 print "Writing \e[1;32mconfig.h\e[0m\n";
635 open(FILEHANDLE, ">include/config.h.tmp");
636 print FILEHANDLE <<EOF;
637 /* Auto generated by configure, do not modify! */
640 #define BRANCH "$branch"
641 #define VERSION "$version"
642 #define REVISION "$revision"
643 #define SYSTEM "$incos"
645 #define CONFIG_PATH "$config{CONFIG_DIR}"
646 #define DATA_PATH "$config{DATA_DIR}"
647 #define LOG_PATH "$config{LOG_DIR}"
648 #define MOD_PATH "$config{MODULE_DIR}"
652 if ($config{HAS_EVENTFD}) {
653 print FILEHANDLE "#define HAS_EVENTFD\n";
655 if ($config{HAS_CLOCK_GETTIME}) {
656 print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
659 print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n";
662 unlink 'include/config.h';
663 rename 'include/config.h.tmp', 'include/config.h';
665 # Do this once here, and cache it in the .*.inc files,
666 # rather than attempting to read src/version.sh from
667 # compiled code -- we might not have the source to hand.
669 my @dotfiles = qw(main.mk inspircd);
670 push @dotfiles, 'org.inspircd.plist' if $^O eq 'darwin';
672 foreach my $file (@dotfiles) {
673 open(FILEHANDLE, "make/template/$file") or die "Can't open make/template/$file: $!";
674 $_ = join '', <FILEHANDLE>;
677 $config{BUILD_DIR} ||= rel2abs($topdir."/build");
678 $config{COMPILER} = lc $cxx{NAME};
679 $config{SYSTEM} = lc $^O;
682 CXX COMPILER SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID
683 STARTSCRIPT SOCKETENGINE
685 s/\@$var\@/$config{$var}/g;
688 s/\@VERSION\@/$version/ if defined $version;
690 if ($file eq 'main.mk') {
691 print "Writing \e[1;32mGNUmakefile\e[0m ...\n";
694 s/\@IFDEF (\S+)/ifdef $1/g;
695 s/\@IFNDEF (\S+)/ifndef $1/g;
696 s/\@IFEQ (\S+) (\S+)/ifeq ($1,$2)/g;
697 s/\@IFNEQ (\S+) (\S+)/ifneq ($1,$2)/g;
698 s/\@ELSIFEQ (\S+) (\S+)/else ifeq ($1,$2)/g;
701 s/ *\@BSD_ONLY .*\n//g;
703 s/\@DO_EXPORT (.*)/export $1/g;
704 open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!";
708 print "Writing \e[1;32mBSDmakefile\e[0m ...\n";
710 s/\@IFDEF (\S+)/.if defined($1)/g;
711 s/\@IFNDEF (\S+)/.if !defined($1)/g;
712 s/\@IFEQ (\S+) (\S+)/.if $1 == $2/g;
713 s/\@IFNEQ (\S+) (\S+)/.if $1 != $2/g;
714 s/\@ELSIFEQ (\S+) (\S+)/.elif $1 == $2/g;
718 s/ *\@GNU_ONLY .*\n//g;
720 $mk_tmp =~ s#\@DO_EXPORT (.*)#"MAKEENV += ".join ' ', map "$_='\${$_}'", split /\s/, $1#eg;
721 open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!";
725 print "Writing \e[1;32m$file\e[0m ...\n";
726 open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n");
732 chmod 0755, 'inspircd';
738 for my $mod (@modlist) {
739 getcompilerflags("src/modules/m_$mod.cpp");
740 getlinkerflags("src/modules/m_$mod.cpp");
744 # Routine to list out the extra/ modules that have been enabled.
745 # Note: when getting any filenames out and comparing, it's important to lc it if the
746 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
747 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
748 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
752 my $srcdir = File::Spec->catdir("src", "modules");
753 my $abs_srcdir = File::Spec->rel2abs($srcdir);
756 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
757 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
760 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
761 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
764 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
766 EXTRA: for my $extra (@extras) {
767 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
768 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
769 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
770 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
771 if (-l $abs_source) {
772 # Symlink, is it in the right place?
773 my $targ = readlink($abs_source);
774 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
775 if ($abs_targ eq $abs_extra) {
776 $extras{$extra} = "\e[32;1menabled\e[0m";
778 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
780 } elsif (-e $abs_source) {
781 my ($devext, $inoext) = stat($abs_extra);
782 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
784 if ($devsrc == $devext && $inosrc == $inoext) {
785 $extras{$extra} = "\e[32;1menabled\e[0m";
787 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
790 open my $extfd, "<", $abs_extra;
791 open my $srcfd, "<", $abs_source;
793 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
794 $extras{$extra} = "\e[32;1menabled\e[0m";
796 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
800 $extras{$extra} = "\e[33;1mdisabled\e[0m";
803 # Now let's add dependency info
804 for my $extra (keys(%extras)) {
805 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
806 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
807 my @deps = split / +/, getdependencies($abs_extra);
808 for my $dep (@deps) {
809 if (exists($extras{$dep})) {
810 my $ref = \$extras{$dep}; # Take reference.
811 if ($$ref !~ m/needed by/) {
812 # First dependency found.
813 if ($$ref =~ m/enabled/) {
814 $$ref .= " (needed by \e[32;1m$extra\e[0m";
816 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
817 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
820 if ($$ref =~ m/enabled/) {
821 $$ref .= ", \e[32;1m$extra\e[0m";
823 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
829 for my $extra (sort {$a cmp $b} keys(%extras)) {
830 my $text = $extras{$extra};
831 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
832 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
834 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
837 return keys(%extras) if wantarray; # Can be used by manage_extras.
840 sub enable_extras (@) {
842 for my $extra (@extras) {
843 my $extrapath = "src/modules/extra/$extra";
844 if (!-e $extrapath) {
845 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
848 my $source = "src/modules/$extra";
850 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
853 # Get dependencies, and add them to be processed.
854 my @deps = split / +/, getdependencies($extrapath);
855 for my $dep (@deps) {
856 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
857 if (!-e "src/modules/$dep" && !-e "include/$dep") {
858 if (-e "src/modules/extra/$dep") {
859 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
862 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";
866 print "Enabling $extra ... \n";
867 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
871 sub disable_extras (@)
873 opendir my $dd, "src/modules/extra/";
874 my @files = readdir($dd);
877 EXTRA: for my $extra (@extras) {
878 my $extrapath = "src/modules/extra/$extra";
879 my $source = "src/modules/$extra";
880 if (!-e $extrapath) {
881 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
884 if ((! -l $source) || readlink($source) ne "extra/$extra") {
885 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";
888 # Check if anything needs this.
889 for my $file (@files) {
890 my @deps = split / +/, getdependencies("src/modules/extra/$file");
891 # File depends on this extra...
892 if (scalar(grep { $_ eq $extra } @deps) > 0) {
893 # And is both enabled and not about to be disabled.
894 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
895 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
901 print "Disabling $extra ... \n";
902 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";