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);
38 $Data::Dumper::Sortkeys = 1;
39 $Data::Dumper::Useqq = 1;
46 # Utility functions for our buildsystem
50 ###############################################################################################
52 # NON-EDITABLE VARIABLES
54 ###############################################################################################
56 our ($opt_use_gnutls, $opt_use_openssl, $opt_nointeractive, $opt_socketengine, $opt_freebsd_port,
57 $opt_system, $opt_uid);
59 our ($opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir, $opt_data_dir, $opt_log_dir);
63 sub enable_extras (@);
65 sub disable_extras (@);
68 my @opt_disableextras;
71 'enable-gnutls' => \$opt_use_gnutls,
72 'system' => \$opt_system,
74 'enable-openssl' => \$opt_use_openssl,
75 'disable-interactive' => \$opt_nointeractive,
76 'socketengine=s' => \$opt_socketengine,
77 'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
78 'prefix=s' => \$opt_base_dir,
79 'config-dir=s' => \$opt_config_dir,
80 'module-dir=s' => \$opt_module_dir,
81 'binary-dir=s' => \$opt_binary_dir,
82 'data-dir=s' => \$opt_data_dir,
83 'log-dir=s' => \$opt_log_dir,
84 'help' => sub { showhelp(); },
85 'update' => sub { update(); },
86 'clean' => sub { clean(); },
87 'list-extras' => sub { list_extras; exit 0; }, # This, --enable-extras, and --disable-extras are for non-interactive managing.
88 'enable-extras=s@' => \@opt_enableextras, # ^
89 'disable-extras=s@' => \@opt_disableextras, # ^
92 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
93 @opt_enableextras = split /,/, join(',', @opt_enableextras);
94 @opt_disableextras = split /,/, join(',', @opt_disableextras);
95 enable_extras(@opt_enableextras);
96 disable_extras(@opt_disableextras);
98 print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
102 our $interactive = !(
103 (defined $opt_base_dir) ||
104 (defined $opt_config_dir) ||
105 (defined $opt_module_dir) ||
106 (defined $opt_base_dir) ||
107 (defined $opt_binary_dir) ||
108 (defined $opt_data_dir) ||
109 (defined $opt_log_dir) ||
110 (defined $opt_nointeractive) ||
111 (defined $opt_socketengine) ||
112 (defined $opt_use_openssl) ||
113 (defined $opt_system) ||
114 (defined $opt_uid) ||
115 (defined $opt_use_gnutls) ||
116 (defined $opt_freebsd_port)
119 chomp(our $topdir = getcwd());
120 our $this = resolve_directory($topdir); # PWD, Regardless.
121 our @modlist = (); # Declare for Module List..
122 our %config = (); # Initiate Configuration Hash..
123 our $cache_loaded = getcache();
124 $config{ME} = resolve_directory($topdir); # Present Working Directory
126 $config{BASE_DIR} = $config{ME}."/run";
128 if (defined $opt_base_dir) {
129 $config{BASE_DIR} = $opt_base_dir;
130 } elsif (defined $opt_system) {
131 $config{BASE_DIR} = '/var/lib/inspircd';
134 if (defined $opt_system) {
135 $config{UID} = $opt_uid || 'ircd';
136 $config{CONFIG_DIR} = '/etc/inspircd';
137 $config{MODULE_DIR} = '/usr/lib/inspircd';
138 $config{BINARY_DIR} = '/usr/sbin/';
139 $config{BUILD_DIR} = resolve_directory($config{ME}."/build"); # Build Directory
140 $config{DATA_DIR} = '/var/inspircd';
141 $config{LOG_DIR} = '/var/log/inspircd';
143 $config{UID} = $opt_uid || $<;
144 $config{CONFIG_DIR} = resolve_directory($config{BASE_DIR}."/conf"); # Configuration Directory
145 $config{MODULE_DIR} = resolve_directory($config{BASE_DIR}."/modules"); # Modules Directory
146 $config{BINARY_DIR} = resolve_directory($config{BASE_DIR}."/bin"); # Binary Directory
147 $config{BUILD_DIR} = resolve_directory($config{ME}."/build"); # Build Directory
148 $config{DATA_DIR} = resolve_directory($config{BASE_DIR}."/data"); # Data directory
149 $config{LOG_DIR} = resolve_directory($config{BASE_DIR}."/logs"); # Log directory
152 if (defined $opt_config_dir) {
153 $config{CONFIG_DIR} = $opt_config_dir;
155 if (defined $opt_module_dir) {
156 $config{MODULE_DIR} = $opt_module_dir;
158 if (defined $opt_binary_dir) {
159 $config{BINARY_DIR} = $opt_binary_dir;
161 if (defined $opt_data_dir) {
162 $config{DATA_DIR} = $opt_data_dir;
164 if (defined $opt_log_dir) {
165 $config{LOG_DIR} = $opt_log_dir;
167 chomp($config{HAS_GNUTLS} = `pkg-config --modversion gnutls 2>/dev/null`); # GNUTLS Version.
169 if (defined $opt_freebsd_port)
171 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`);
172 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`);
173 $config{USE_FREEBSD_BASE_SSL} = "n";
177 if ($^O eq "freebsd")
179 # default: use base ssl
180 chomp($config{HAS_OPENSSL} = `openssl version | cut -d ' ' -f 2`); # OpenSSL version, freebsd specific
181 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`); # Port version, may be different
185 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`); # Openssl version, others
186 $config{HAS_OPENSSL_PORT} = "";
190 chomp(our $gnutls_ver = $config{HAS_GNUTLS});
191 chomp(our $openssl_ver = $config{HAS_OPENSSL});
192 $config{USE_GNUTLS} = "n";
193 if (defined $opt_use_gnutls)
195 $config{USE_GNUTLS} = "y"; # Use gnutls.
197 $config{USE_OPENSSL} = "n"; # Use openssl.
198 if (defined $opt_use_openssl)
200 $config{USE_OPENSSL} = "y";
203 $config{HAS_STDINT} = "false"; # stdint.h check
204 $config{OSNAME} = $^O; # Operating System Name
205 $config{STARTSCRIPT} = "inspircd"; # start script?
206 $config{DESTINATION} = "BASE"; # Is target path.
207 if ($config{OSNAME} =~ /darwin/i)
209 $config{STARTSCRIPT} = "org.inspircd.plist"; # start script for OSX.
212 $config{CXX} = defined $ENV{CXX} && !system("$ENV{CXX} -v > /dev/null 2>&1") ? $ENV{CXX} : find_compiler();
213 if ($config{CXX} eq "") {
214 print "A C++ compiler could not be detected on your system!\n";
215 print "Set the CXX environment variable to the full path if this is incorrect.\n";
219 our %cxx = get_compiler_info($config{CXX});
220 if ($cxx{UNSUPPORTED}) {
221 print "Your C++ compiler is too old to build InspIRCd!\n";
222 print "Reason: $cxx{REASON}\n";
226 if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)(?:[a-z])?(?:\-[a-z][0-9])?/) {
227 $config{HAS_OPENSSL} = $1;
229 $config{HAS_OPENSSL} = "";
232 # Get and Set some important vars..
237 unlink(".config.cache");
243 chomp($topdir = getcwd());
244 $this = resolve_directory($topdir); # PWD, Regardless.
246 # Does the cache file exist?
248 # No, No it doesn't.. *BASH*
249 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
252 # We've Loaded the cache file and all our variables..
253 print "Updating files...\n";
254 %cxx = get_compiler_info($config{CXX});
263 print "Configure update failed: $@\n";
268 print "Running non-interactive configure...\n" unless $interactive;
269 print "Checking for cache from previous configure... ";
270 print ($cache_loaded ? "found\n" : "not found\n");
271 $config{SYSTEM} = lc $^O;
272 print "Checking operating system version... $config{SYSTEM}\n";
274 print "Checking whether <stdint.h> exists... ";
275 if (test_header($config{CXX}, "stdint.h")) {
276 $config{HAS_STDINT} = "true";
279 $config{HAS_STDINT} = "false";
283 printf "Checking whether clock_gettime() exists... ";
284 if (test_file($config{CXX}, "clock_gettime.cpp", "-lrt")) {
285 $config{HAS_CLOCK_GETTIME} = "true";
288 $config{HAS_CLOCK_GETTIME} = "false";
292 printf "Checking whether eventfd() exists... ";
293 if (test_file($config{CXX}, "eventfd.cpp")) {
294 $config{HAS_EVENTFD} = "true";
297 $config{HAS_EVENTFD} = "false";
301 print "Checking whether epoll is available... ";
302 $config{HAS_EPOLL} = test_header($config{CXX}, "sys/epoll.h");
303 print $config{HAS_EPOLL} ? "yes\n" : "no\n";
304 $config{SOCKETENGINE} ||= "epoll" if $config{HAS_EPOLL};
306 print "Checking whether Kqueue is available... ";
307 $config{HAS_KQUEUE} = test_file($config{CXX}, "kqueue.cpp");
308 print $config{HAS_KQUEUE} ? "yes\n" : "no\n";
309 $config{SOCKETENGINE} ||= "kqueue" if $config{HAS_KQUEUE};
311 print 'Checking whether Solaris IOCP is available... ';
312 $config{HAS_PORTS} = test_header($config{CXX}, 'port.h');
313 print $config{HAS_PORTS} ? "yes\n" : "no\n";
314 $config{SOCKETENGINE} ||= "ports" if $config{HAS_PORTS};
316 print 'Checking whether poll is available... ';
317 $config{HAS_POLL} = test_header($config{CXX}, 'poll.h');
318 print $config{HAS_POLL} ? "yes\n" : "no\n";
319 $config{SOCKETENGINE} ||= "poll" if $config{HAS_POLL};
321 # Select is available on all platforms
322 $config{HAS_SELECT} = 1;
323 $config{SOCKETENGINE} ||= "select";
325 if (defined $opt_socketengine) {
326 my $cfgkey = "HAS_" . uc $opt_socketengine;
327 if ($config{$cfgkey} && -f "src/socketengines/socketengine_$opt_socketengine.cpp") {
328 $config{SOCKETENGINE} = $opt_socketengine;
330 print "Unable to use a socket engine which is not supported on this platform ($opt_socketengine)!\n";
331 print "Available socket engines are:";
332 foreach (<src/socketengines/socketengine_*.cpp>) {
333 s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
334 print " $1" if $config{"HAS_" . uc $1};
341 printf "Checking for libgnutls... ";
342 if (defined($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS}) || ($config{HAS_GNUTLS} eq "y"))) {
343 if (defined($gnutls_ver) && ($gnutls_ver ne "")) {
345 $config{HAS_GNUTLS} = "y";
348 $config{HAS_GNUTLS} = "n";
352 $config{HAS_GNUTLS} = "n";
355 printf "Checking for openssl... ";
356 if (defined($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL}) || ($config{HAS_OPENSSL} eq "y"))) {
357 if (defined($openssl_ver) && ($openssl_ver ne "")) {
359 $config{HAS_OPENSSL} = "y";
362 $config{HAS_OPENSSL} = "n";
366 $config{HAS_OPENSSL} = "n";
369 printf "Checking if you are running an ancient, unsupported OS... ";
370 if ($config{OSNAME} =~ /FreeBSD/i)
372 my $version = `uname -r`;
373 if ($version =~ /^4\./)
376 print "FreeBSD 4.x is no longer supported. By ANYONE.\n";
377 print "To build, you will need to add the following to CXXFLAGS:\n";
378 print "\t-L/usr/local/lib -lgnugetopt -DHAVE_DECL_GETOPT=1\n";
382 print "no ($version)\n";
387 print "no ($config{OSNAME})\n";
390 ################################################################################
391 # BEGIN INTERACTIVE PART #
392 ################################################################################
397 print "\e[2J\e[0G\e[0d"; # J = Erase in Display, 2 = Entire Screen, (G, d) = Move cursor to (..,..)
400 my $rev = getrevision();
401 # Display Introduction Message..
403 Welcome to the \e[1mInspIRCd\e[0m Configuration program! (\e[1minteractive mode\e[0m)
404 \e[1mPackage maintainers: Type ./configure --help for non-interactive help\e[0m
406 *** If you are unsure of any of these values, leave it blank for ***
407 *** standard settings that will work, and your server will run ***
408 *** using them. Please consult your IRC network admin if in doubt. ***
410 Press \e[1m<RETURN>\e[0m to accept the default for any option, or enter
411 a new value. Please note: You will \e[1mHAVE\e[0m to read the docs
412 dir, otherwise you won't have a config file!
414 Your operating system is: \e[1;32m$config{OSNAME}\e[0m ($wholeos)
415 Your InspIRCd revision ID is \e[1;32mr$rev\e[0m
418 print " (Non-SVN build)";
422 print "I have detected the following compiler: \e[1;32m$cxx{NAME}\e[0m (version \e[1;32m$cxx{VERSION}\e[0m)\n\n";
424 # Directory Settings..
425 my $tmpbase = $config{BASE_DIR};
426 dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
427 if ($tmpbase ne $config{BASE_DIR}) {
428 $config{CONFIG_DIR} = resolve_directory($config{BASE_DIR}."/conf"); # Configuration Dir
429 $config{MODULE_DIR} = resolve_directory($config{BASE_DIR}."/modules"); # Modules Directory
430 $config{DATA_DIR} = resolve_directory($config{BASE_DIR}."/data"); # Data Directory
431 $config{LOG_DIR} = resolve_directory($config{BASE_DIR}."/logs"); # Log Directory
432 $config{BINARY_DIR} = resolve_directory($config{BASE_DIR}."/bin"); # Binary Directory
435 dir_check("are the configuration files", "CONFIG_DIR");
436 dir_check("are the modules to be compiled to", "MODULE_DIR");
437 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
438 dir_check("are variable data files to be located in", "DATA_DIR");
439 dir_check("are the logs to be stored in", "LOG_DIR");
440 dir_check("do you want the build to take place", "BUILD_DIR");
442 my $chose_hiperf = 0;
443 if ($config{HAS_KQUEUE}) {
444 $config{USE_KQUEUE} = "y";
445 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?");
447 if ($config{USE_KQUEUE} eq "y") {
448 $config{SOCKETENGINE} = "kqueue";
452 if ($config{HAS_EPOLL}) {
453 $config{USE_EPOLL} = "y";
454 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?");
456 if ($config{USE_EPOLL} eq "y") {
457 $config{SOCKETENGINE} = "epoll";
461 if ($config{HAS_PORTS}) {
462 $config{USE_PORTS} = "y";
463 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?");
465 if ($config{USE_PORTS} eq "y") {
466 $config{SOCKETENGINE} = "ports";
471 if (!$chose_hiperf && $config{HAS_POLL}) {
472 $config{USE_POLL} = "y";
473 yesno('USE_POLL', "Would you like to use poll?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable poll?");
474 if ($config{USE_POLL} eq "y") {
475 $config{SOCKETENGINE} = "poll";
478 if (!$chose_hiperf && $config{USE_POLL} ne "y")
480 print "No high-performance socket engines are available, or you chose\n";
481 print "not to enable one. Defaulting to select() engine.\n\n";
482 $config{SOCKETENGINE} = "select";
485 $config{USE_FREEBSD_BASE_SSL} = "n";
486 $config{USE_FREEBSD_PORTS_SSL} = "n";
487 if ($config{HAS_OPENSSL_PORT} ne "")
489 $config{USE_FREEBSD_PORTS_SSL} = "y";
490 print "I have detected the OpenSSL FreeBSD port installed on your system,\n";
491 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";
492 yesno('USE_FREEBSD_PORTS_SSL', "Do you want to use the FreeBSD ports version?");
494 $config{USE_FREEBSD_BASE_SSL} = "y" if ($config{USE_FREEBSD_PORTS_SSL} eq "n");
496 if ($config{USE_FREEBSD_BASE_SSL} eq "n")
498 # update to port version
499 $openssl_ver = $config{HAS_OPENSSL_PORT};
504 $config{USE_FREEBSD_BASE_SSL} = "y" if ($^O eq "freebsd");
507 $config{USE_SSL} = "n";
508 $config{MODUPDATE} = 'n';
510 if ($config{HAS_GNUTLS} eq "y" || $config{HAS_OPENSSL} eq "y")
512 print "Detected GnuTLS version: \e[1;32m" . $gnutls_ver . "\e[0m\n";
513 print "Detected OpenSSL version: \e[1;32m" . $openssl_ver . "\e[0m\n\n";
515 yesno('USE_SSL', "One or more SSL libraries detected. Would you like to enable SSL support?");
516 if ($config{USE_SSL} eq "y")
518 if ($config{HAS_GNUTLS} eq "y")
520 yesno('USE_GNUTLS',"Would you like to enable SSL with m_ssl_gnutls? (recommended)");
521 if ($config{USE_GNUTLS} eq "y")
523 print "\nUsing GnuTLS SSL module.\n";
527 if ($config{HAS_OPENSSL} eq "y")
529 yesno('USE_OPENSSL', "Would you like to enable SSL with m_ssl_openssl?");
530 if ($config{USE_OPENSSL} eq "y")
532 print "\nUsing OpenSSL SSL module.\nYou will get better performance if you move to GnuTLS in the future.\n";
539 print "\nCould not detect OpenSSL or GnuTLS. Make sure pkg-config is installed and\n";
540 print "is in your path.\n\n";
543 yesno('MODUPDATE',"Would you like to check for updates to third-party modules?");
545 if ($config{MODUPDATE} eq "y") {
546 print "Checking for upgrades to extra and third party modules... ";
547 system "./modulemanager upgrade";
551 # We are on a POSIX system, we can enable POSIX extras without asking
552 symlink "extra/m_regex_posix.cpp", "src/modules/m_regex_posix.cpp";
554 if (($config{USE_GNUTLS} eq "y") && ($config{HAS_GNUTLS} ne "y"))
556 print "Sorry, but i couldn't detect gnutls. Make sure gnutls-config is in your path.\n";
559 if (($config{USE_OPENSSL} eq "y") && ($config{HAS_OPENSSL} ne "y"))
561 print "Sorry, but i couldn't detect openssl. Make sure openssl is in your path.\n";
566 $config{CERTGEN} ||= 'y';
567 yesno('CERTGEN',"Would you like generate SSL certificates now?") if ($interactive && ($config{USE_GNUTLS} eq "y" || $config{USE_OPENSSL} eq "y"));
569 if ($config{USE_GNUTLS} eq "y") {
570 unless (-r "src/modules/m_ssl_gnutls.cpp") {
571 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
572 symlink "extra/m_ssl_gnutls.cpp", "src/modules/m_ssl_gnutls.cpp" or print STDERR "Symlink failed: $!";
574 if ($interactive && $config{CERTGEN} eq 'y')
576 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem") {
577 print "SSL Certificates Not found, Generating.. \n\n
578 *************************************************************
579 * Generating the Private Key may take some time, go grab a *
580 * Coffee. Even better, to generate some more entropy if it *
581 * is taking a while, open another console and type du / a *
582 * few times and get that HD going :) Then answer the *
583 * Questions which follow. If you are unsure, just hit enter *
584 *************************************************************\n\n";
585 $failed = system "./tools/genssl gnutls";
587 print "\n\e[1;32mCertificate generation failed!\e[0m\n\n";
589 print "\nCertificate generation complete, copying to config directory... ";
590 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
591 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
596 print "SSL Certificates found, skipping.\n\n";
601 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
605 if ($config{USE_OPENSSL} eq "y") {
606 unless (-r "src/modules/m_ssl_openssl.cpp") {
607 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
608 symlink "extra/m_ssl_openssl.cpp", "src/modules/m_ssl_openssl.cpp" or print STDERR "Symlink failed: $!";
611 if ($interactive && $config{CERTGEN} eq 'y')
613 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem") {
614 print "SSL Certificates Not found, Generating.. \n\n
615 *************************************************************
616 * Generating the certificates may take some time, go grab a *
617 * coffee, or something. *
618 *************************************************************\n\n";
619 system "./tools/genssl openssl";
620 print "\nCertificate generation complete, copying to config directory... ";
621 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
622 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
623 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
626 print "SSL Certificates found, skipping.\n\n"
631 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
634 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
635 print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
644 print "To build your server with these settings, please run '\e[1;32mmake\e[0m' now.\n";
645 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
646 print "Please note: for \e[1;32mSSL support\e[0m you will need to load required\n";
647 print "modules in your config. This configure script has added those modules to the\n";
648 print "build process. For more info please refer to:\n";
649 print "\e[1;32mhttp://wiki.inspircd.org/Installation_From_Tarball\e[0m\n";
651 print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n";
653 ################################################################################
655 ################################################################################
657 # Retrieves the .config.cache file, and loads values into the main config hash.
658 open(CACHE, ".config.cache") or return 0;
661 # Ignore Blank lines, and comments..
664 my ($key, $value) = split("=", $_, 2);
665 $value =~ /^\"(.*)\"$/;
666 # Do something with data here!
674 # Dump the contents of %config
675 print "Writing \e[1;32mcache file\e[0m for future ./configures ...\n";
676 open(FILEHANDLE, ">.config.cache");
677 foreach my $key (keys %config) {
678 print FILEHANDLE "$key=\"$config{$key}\"\n";
684 my ($desc, $hash_key) = @_;
687 print "In what directory $desc?\n";
688 print "[\e[1;32m$config{$hash_key}\e[0m] -> ";
689 chomp(my $var = <STDIN>);
691 $var = $config{$hash_key};
693 if ($var =~ /^\~\/(.+)$/) {
694 # Convert it to a full path..
695 $var = resolve_directory($ENV{HOME} . "/" . $1);
697 elsif ((($config{OSNAME} =~ /MINGW32/i) and ($var !~ /^[A-Z]{1}:\\.*/)) and (substr($var,0,1) ne "/"))
699 # Assume relative Path was given.. fill in the rest.
700 $var = $this . "/$var";
703 $var = resolve_directory($var);
705 print "$var does not exist. Create it?\n[\e[1;32my\e[0m] ";
706 chomp(my $tmp = <STDIN>);
707 if (($tmp eq "") || ($tmp =~ /^y/i)) {
708 # Attempt to Create the Dir..
711 File::Path::mkpath($var, 0, 0777);
714 unless (defined($chk) && -d $var) {
715 print "Unable to create directory. ($var)\n\n";
720 # They said they don't want to create, and we can't install there.
726 # Target exists, but is not a directory.
727 print "File $var exists, but is not a directory.\n\n";
731 # Either Dir Exists, or was created fine.
732 $config{$hash_key} = $var;
740 my ($mliflags, $mfrules, $mobjs, $mfcount) = ("", "", "", 0);
743 my($writeheader) = @_;
744 # First File.. config.h
745 chomp(my $incos = `uname -n -s -r`);
746 chomp(my $version = `sh src/version.sh`);
747 chomp(my $revision2 = getrevision());
748 my $branch = "InspIRCd-0.0";
749 if ($version =~ /^(InspIRCd-[0-9]+\.[0-9]+)\.[0-9]+/)
753 if ($writeheader == 1)
755 print "Writing \e[1;32mconfig.h\e[0m\n";
756 open(FILEHANDLE, ">include/config.h.tmp");
757 print FILEHANDLE <<EOF;
758 /* Auto generated by configure, do not modify! */
761 #define BRANCH "$branch"
762 #define VERSION "$version"
763 #define REVISION "$revision2"
764 #define SYSTEM "$incos"
766 #define CONFIG_PATH "$config{CONFIG_DIR}"
767 #define DATA_PATH "$config{DATA_DIR}"
768 #define LOG_PATH "$config{LOG_DIR}"
769 #define MOD_PATH "$config{MODULE_DIR}"
773 if ($config{HAS_STDINT} eq "true") {
774 print FILEHANDLE "#define HAS_STDINT\n";
776 if ($config{HAS_EVENTFD} eq 'true') {
777 print FILEHANDLE "#define HAS_EVENTFD\n";
779 if ($config{HAS_CLOCK_GETTIME} eq 'true') {
780 print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
783 print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n";
786 my $file = 'include/config.h';
788 open my $fh1, $file or $diff = 1;
789 open my $fh2, $file.'.tmp' or die "Can't read $file.tmp that we just wrote: $!";
793 if (defined($line1) != defined($line2)) {
795 } elsif (!defined $line1) {
798 $diff = ($line1 ne $line2);
803 rename "$file.tmp", $file;
809 # Write all .in files.
812 my $exe = "inspircd";
814 # Do this once here, and cache it in the .*.inc files,
815 # rather than attempting to read src/version.sh from
816 # compiled code -- we might not have the source to hand.
817 # Fix for bug#177 by Brain.
819 chomp($version = `sh ./src/version.sh`);
820 chomp(my $revision = getrevision());
821 $version = "$version(r$revision)";
823 my @dotfiles = qw(main.mk inspircd);
824 push @dotfiles, 'org.inspircd.plist' if $config{OSNAME} eq 'darwin';
826 foreach my $file (@dotfiles) {
827 open(FILEHANDLE, "make/template/$file") or die "Can't open make/template/$file: $!";
828 $_ = join '', <FILEHANDLE>;
831 $config{BUILD_DIR} ||= resolve_directory($config{ME}."/build");
832 $config{COMPILER} = lc $cxx{NAME};
835 CXX COMPILER SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID
836 STARTSCRIPT DESTINATION SOCKETENGINE
838 s/\@$var\@/$config{$var}/g;
840 s/\@EXECUTABLE\@/$exe/ if defined $exe;
841 s/\@VERSION\@/$version/ if defined $version;
843 if ($file eq 'main.mk') {
844 print "Writing \e[1;32mGNUmakefile\e[0m ...\n";
847 s/\@IFDEF (\S+)/ifdef $1/g;
848 s/\@IFNDEF (\S+)/ifndef $1/g;
849 s/\@IFEQ (\S+) (\S+)/ifeq ($1,$2)/g;
850 s/\@IFNEQ (\S+) (\S+)/ifneq ($1,$2)/g;
851 s/\@ELSIFEQ (\S+) (\S+)/else ifeq ($1,$2)/g;
854 s/ *\@BSD_ONLY .*\n//g;
856 s/\@DO_EXPORT (.*)/export $1/g;
857 open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!";
861 print "Writing \e[1;32mBSDmakefile\e[0m ...\n";
863 s/\@IFDEF (\S+)/.if defined($1)/g;
864 s/\@IFNDEF (\S+)/.if !defined($1)/g;
865 s/\@IFEQ (\S+) (\S+)/.if $1 == $2/g;
866 s/\@IFNEQ (\S+) (\S+)/.if $1 != $2/g;
867 s/\@ELSIFEQ (\S+) (\S+)/.elif $1 == $2/g;
871 s/ *\@GNU_ONLY .*\n//g;
873 $mk_tmp =~ s#\@DO_EXPORT (.*)#"MAKEENV += ".join ' ', map "$_='\${$_}'", split /\s/, $1#eg;
874 open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!";
878 print "Writing \e[1;32m$file\e[0m ...\n";
879 open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n");
885 chmod 0755, 'inspircd';
891 for my $mod (@modlist) {
892 getcompilerflags("src/modules/m_$mod.cpp");
893 getlinkerflags("src/modules/m_$mod.cpp");
897 # Routine to list out the extra/ modules that have been enabled.
898 # Note: when getting any filenames out and comparing, it's important to lc it if the
899 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
900 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
901 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
905 my $srcdir = File::Spec->catdir("src", "modules");
906 my $abs_srcdir = File::Spec->rel2abs($srcdir);
909 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
910 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
913 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
914 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
917 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
919 EXTRA: for my $extra (@extras) {
920 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
921 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
922 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
923 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
924 if (-l $abs_source) {
925 # Symlink, is it in the right place?
926 my $targ = readlink($abs_source);
927 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
928 if ($abs_targ eq $abs_extra) {
929 $extras{$extra} = "\e[32;1menabled\e[0m";
931 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
933 } elsif (-e $abs_source) {
934 my ($devext, $inoext) = stat($abs_extra);
935 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
937 if ($devsrc == $devext && $inosrc == $inoext) {
938 $extras{$extra} = "\e[32;1menabled\e[0m";
940 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
943 open my $extfd, "<", $abs_extra;
944 open my $srcfd, "<", $abs_source;
946 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
947 $extras{$extra} = "\e[32;1menabled\e[0m";
949 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
953 $extras{$extra} = "\e[33;1mdisabled\e[0m";
956 # Now let's add dependency info
957 for my $extra (keys(%extras)) {
958 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
959 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
960 my @deps = split / +/, getdependencies($abs_extra);
961 for my $dep (@deps) {
962 if (exists($extras{$dep})) {
963 my $ref = \$extras{$dep}; # Take reference.
964 if ($$ref !~ m/needed by/) {
965 # First dependency found.
966 if ($$ref =~ m/enabled/) {
967 $$ref .= " (needed by \e[32;1m$extra\e[0m";
969 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
970 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
973 if ($$ref =~ m/enabled/) {
974 $$ref .= ", \e[32;1m$extra\e[0m";
976 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
982 for my $extra (sort {$a cmp $b} keys(%extras)) {
983 my $text = $extras{$extra};
984 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
985 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
987 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
990 return keys(%extras) if wantarray; # Can be used by manage_extras.
993 sub enable_extras (@) {
995 for my $extra (@extras) {
996 my $extrapath = "src/modules/extra/$extra";
997 if (!-e $extrapath) {
998 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
1001 my $source = "src/modules/$extra";
1003 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
1006 # Get dependencies, and add them to be processed.
1007 my @deps = split / +/, getdependencies($extrapath);
1008 for my $dep (@deps) {
1009 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
1010 if (!-e "src/modules/$dep" && !-e "include/$dep") {
1011 if (-e "src/modules/extra/$dep") {
1012 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
1015 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";
1019 print "Enabling $extra ... \n";
1020 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
1024 sub disable_extras (@)
1026 opendir my $dd, "src/modules/extra/";
1027 my @files = readdir($dd);
1030 EXTRA: for my $extra (@extras) {
1031 my $extrapath = "src/modules/extra/$extra";
1032 my $source = "src/modules/$extra";
1033 if (!-e $extrapath) {
1034 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
1037 if ((! -l $source) || readlink($source) ne "extra/$extra") {
1038 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";
1041 # Check if anything needs this.
1042 for my $file (@files) {
1043 my @deps = split / +/, getdependencies("src/modules/extra/$file");
1044 # File depends on this extra...
1045 if (scalar(grep { $_ eq $extra } @deps) > 0) {
1046 # And is both enabled and not about to be disabled.
1047 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
1048 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
1054 print "Disabling $extra ... \n";
1055 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";