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 print "Checking whether clock_gettime() is available... ";
250 if (test_file($config{CXX}, "clock_gettime.cpp", "-lrt")) {
251 $config{HAS_CLOCK_GETTIME} = "true";
254 $config{HAS_CLOCK_GETTIME} = "false";
258 print "Checking whether eventfd() is available... ";
259 if (test_file($config{CXX}, "eventfd.cpp")) {
260 $config{HAS_EVENTFD} = "true";
263 $config{HAS_EVENTFD} = "false";
267 print "Checking whether epoll is available... ";
268 $config{HAS_EPOLL} = test_header($config{CXX}, "sys/epoll.h");
269 print $config{HAS_EPOLL} ? "yes\n" : "no\n";
270 $config{SOCKETENGINE} ||= "epoll" if $config{HAS_EPOLL};
272 print "Checking whether Kqueue is available... ";
273 $config{HAS_KQUEUE} = test_file($config{CXX}, "kqueue.cpp");
274 print $config{HAS_KQUEUE} ? "yes\n" : "no\n";
275 $config{SOCKETENGINE} ||= "kqueue" if $config{HAS_KQUEUE};
277 print 'Checking whether Solaris IOCP is available... ';
278 $config{HAS_PORTS} = test_header($config{CXX}, 'port.h');
279 print $config{HAS_PORTS} ? "yes\n" : "no\n";
280 $config{SOCKETENGINE} ||= "ports" if $config{HAS_PORTS};
282 print 'Checking whether poll is available... ';
283 $config{HAS_POLL} = test_header($config{CXX}, 'poll.h');
284 print $config{HAS_POLL} ? "yes\n" : "no\n";
285 $config{SOCKETENGINE} ||= "poll" if $config{HAS_POLL};
287 # Select is available on all platforms
288 $config{HAS_SELECT} = 1;
289 $config{SOCKETENGINE} ||= "select";
291 if (defined $opt_socketengine) {
292 my $cfgkey = "HAS_" . uc $opt_socketengine;
293 if ($config{$cfgkey} && -f "src/socketengines/socketengine_$opt_socketengine.cpp") {
294 $config{SOCKETENGINE} = $opt_socketengine;
296 print "Unable to use a socket engine which is not supported on this platform ($opt_socketengine)!\n";
297 print "Available socket engines are:";
298 foreach (<src/socketengines/socketengine_*.cpp>) {
299 s/src\/socketengines\/socketengine_(\w+)\.cpp/$1/;
300 print " $1" if $config{"HAS_" . uc $1};
307 print "Checking for libgnutls... ";
308 if (defined($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS}) || ($config{HAS_GNUTLS} eq "y"))) {
309 if (defined($gnutls_ver) && ($gnutls_ver ne "")) {
311 $config{HAS_GNUTLS} = "y";
314 $config{HAS_GNUTLS} = "n";
318 $config{HAS_GNUTLS} = "n";
321 print "Checking for openssl... ";
322 if (defined($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL}) || ($config{HAS_OPENSSL} eq "y"))) {
323 if (defined($openssl_ver) && ($openssl_ver ne "")) {
325 $config{HAS_OPENSSL} = "y";
328 $config{HAS_OPENSSL} = "n";
332 $config{HAS_OPENSSL} = "n";
338 system 'tput', 'clear';
340 my $revision = getrevision();
341 chomp(my $version = `sh src/version.sh`);
343 # Display Introduction Message..
345 Welcome to the \e[1mInspIRCd\e[0m Configuration program! (\e[1minteractive mode\e[0m)
346 \e[1mPackage maintainers: Type ./configure --help for non-interactive help\e[0m
348 *** If you are unsure of any of these values, leave it blank for ***
349 *** standard settings that will work, and your server will run ***
350 *** using them. Please consult your IRC network admin if in doubt. ***
352 Press \e[1m<RETURN>\e[0m to accept the default for any option, or enter
353 a new value. Please note: You will \e[1mHAVE\e[0m to read the docs
354 dir, otherwise you won't have a config file!
356 Your operating system is: \e[1;32m$^O\e[0m
358 print "Your InspIRCd version is: \e[1;32m";
359 print $revision eq 'release' ? substr($version, 9) : substr($revision, 1);
361 print "The following compiler has been detected: \e[1;32m$cxx{NAME} $cxx{VERSION}\e[0m ($config{CXX})\n\n";
363 # Directory Settings..
364 my $tmpbase = $config{BASE_DIR};
365 dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
366 if ($tmpbase ne $config{BASE_DIR}) {
367 $config{CONFIG_DIR} = rel2abs($config{BASE_DIR}."/conf");
368 $config{MODULE_DIR} = rel2abs($config{BASE_DIR}."/modules");
369 $config{DATA_DIR} = rel2abs($config{BASE_DIR}."/data");
370 $config{LOG_DIR} = rel2abs($config{BASE_DIR}."/logs");
371 $config{BINARY_DIR} = rel2abs($config{BASE_DIR}."/bin");
374 dir_check("are the configuration files", "CONFIG_DIR");
375 dir_check("are the modules to be compiled to", "MODULE_DIR");
376 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
377 dir_check("are variable data files to be located in", "DATA_DIR");
378 dir_check("are the logs to be stored in", "LOG_DIR");
379 dir_check("do you want the build to take place", "BUILD_DIR");
381 my $chose_hiperf = 0;
382 if ($config{HAS_KQUEUE}) {
383 $config{USE_KQUEUE} = "y";
384 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?");
386 if ($config{USE_KQUEUE} eq "y") {
387 $config{SOCKETENGINE} = "kqueue";
391 if ($config{HAS_EPOLL}) {
392 $config{USE_EPOLL} = "y";
393 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?");
395 if ($config{USE_EPOLL} eq "y") {
396 $config{SOCKETENGINE} = "epoll";
400 if ($config{HAS_PORTS}) {
401 $config{USE_PORTS} = "y";
402 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?");
404 if ($config{USE_PORTS} eq "y") {
405 $config{SOCKETENGINE} = "ports";
410 if (!$chose_hiperf && $config{HAS_POLL}) {
411 $config{USE_POLL} = "y";
412 yesno('USE_POLL', "Would you like to use poll?\nThis is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable poll?");
413 if ($config{USE_POLL} eq "y") {
414 $config{SOCKETENGINE} = "poll";
417 if (!$chose_hiperf && $config{USE_POLL} ne "y")
419 print "No high-performance socket engines are available, or you chose\n";
420 print "not to enable one. Defaulting to select() engine.\n\n";
421 $config{SOCKETENGINE} = "select";
424 $config{USE_FREEBSD_BASE_SSL} = "n";
425 $config{USE_FREEBSD_PORTS_SSL} = "n";
426 if ($config{HAS_OPENSSL_PORT} ne "")
428 $config{USE_FREEBSD_PORTS_SSL} = "y";
429 print "I have detected the OpenSSL FreeBSD port installed on your system,\n";
430 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";
431 yesno('USE_FREEBSD_PORTS_SSL', "Do you want to use the FreeBSD ports version?");
433 $config{USE_FREEBSD_BASE_SSL} = "y" if ($config{USE_FREEBSD_PORTS_SSL} eq "n");
435 if ($config{USE_FREEBSD_BASE_SSL} eq "n")
437 # update to port version
438 $openssl_ver = $config{HAS_OPENSSL_PORT};
443 $config{USE_FREEBSD_BASE_SSL} = "y" if ($^O eq "freebsd");
446 $config{USE_SSL} = "n";
448 if ($config{HAS_GNUTLS} eq "y" || $config{HAS_OPENSSL} eq "y")
450 print "Detected GnuTLS version: \e[1;32m" . $gnutls_ver . "\e[0m\n";
451 print "Detected OpenSSL version: \e[1;32m" . $openssl_ver . "\e[0m\n\n";
453 yesno('USE_SSL', "One or more SSL libraries detected. Would you like to enable SSL support?");
454 if ($config{USE_SSL} eq "y")
456 if ($config{HAS_GNUTLS} eq "y")
458 yesno('USE_GNUTLS',"Would you like to enable SSL with m_ssl_gnutls? (recommended)");
459 if ($config{USE_GNUTLS} eq "y")
461 print "\nUsing GnuTLS SSL module.\n";
465 if ($config{HAS_OPENSSL} eq "y")
467 yesno('USE_OPENSSL', "Would you like to enable SSL with m_ssl_openssl?");
468 if ($config{USE_OPENSSL} eq "y")
470 print "\nUsing OpenSSL SSL module.\n";
477 print "\nCould not detect OpenSSL or GnuTLS. Make sure pkg-config is installed and\n";
478 print "is in your path.\n\n";
482 # We are on a POSIX system, we can enable POSIX extras without asking
483 symlink "extra/m_regex_posix.cpp", "src/modules/m_regex_posix.cpp";
485 if (($config{USE_GNUTLS} eq "y") && ($config{HAS_GNUTLS} ne "y"))
487 print "Sorry, but i couldn't detect gnutls. Make sure gnutls-config is in your path.\n";
490 if (($config{USE_OPENSSL} eq "y") && ($config{HAS_OPENSSL} ne "y"))
492 print "Sorry, but i couldn't detect openssl. Make sure openssl is in your path.\n";
496 $config{CERTGEN} ||= 'y';
497 yesno('CERTGEN',"Would you like generate SSL certificates now?") if ($interactive && ($config{USE_GNUTLS} eq "y" || $config{USE_OPENSSL} eq "y"));
499 if ($config{USE_GNUTLS} eq "y") {
500 unless (-r "src/modules/m_ssl_gnutls.cpp") {
501 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
502 symlink "extra/m_ssl_gnutls.cpp", "src/modules/m_ssl_gnutls.cpp" or print STDERR "Symlink failed: $!";
504 if ($interactive && $config{CERTGEN} eq 'y')
506 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem" && -r "$config{CONFIG_DIR}/dhparams.pem") {
507 unless (system './tools/genssl gnutls') {
508 print "\nCertificate generation complete, copying to config directory... ";
509 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
510 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
511 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
516 print "SSL Certificates found, skipping.\n\n";
521 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
525 if ($config{USE_OPENSSL} eq "y") {
526 unless (-r "src/modules/m_ssl_openssl.cpp") {
527 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
528 symlink "extra/m_ssl_openssl.cpp", "src/modules/m_ssl_openssl.cpp" or print STDERR "Symlink failed: $!";
530 if ($interactive && $config{CERTGEN} eq 'y')
532 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem" && -r "$config{CONFIG_DIR}/dhparams.pem") {
533 unless (system './tools/genssl openssl') {
534 print "\nCertificate generation complete, copying to config directory... ";
535 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
536 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
537 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
541 print "SSL Certificates found, skipping.\n\n"
546 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
549 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
550 print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
559 print "To build your server with these settings, please run '\e[1;32mmake\e[0m' now.\n";
560 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
561 print "Please note: for \e[1;32mSSL support\e[0m you will need to load required\n";
562 print "modules in your config. This configure script has added those modules to the\n";
563 print "build process. For more info please refer to:\n";
564 print "\e[1;32mhttp://wiki.inspircd.org/Installation_From_Tarball\e[0m\n";
566 print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n";
569 # Retrieves the .config.cache file, and loads values into the main config hash.
570 open(CACHE, ".config.cache") or return 0;
573 # Ignore Blank lines, and comments..
576 my ($key, $value) = split("=", $_, 2);
577 $value =~ /^\"(.*)\"$/;
578 # Do something with data here!
586 # Dump the contents of %config
587 print "Writing \e[1;32mcache file\e[0m for future ./configures ...\n";
588 open(FILEHANDLE, ">.config.cache");
589 foreach my $key (keys %config) {
590 print FILEHANDLE "$key=\"$config{$key}\"\n";
596 my ($desc, $hash_key) = @_;
599 print "In what directory $desc?\n";
600 print "[\e[1;32m$config{$hash_key}\e[0m] -> ";
601 chomp(my $var = <STDIN>);
603 $var = $config{$hash_key};
605 if ($var =~ /^\~\/(.+)$/) {
606 # Convert it to a full path..
607 $var = rel2abs($ENV{HOME} . "/" . $1);
609 $var = rel2abs($var);
611 print "$var does not exist. Create it?\n[\e[1;32my\e[0m] ";
612 chomp(my $tmp = <STDIN>);
613 if (($tmp eq "") || ($tmp =~ /^y/i)) {
614 # Attempt to Create the Dir..
617 File::Path::mkpath($var, 0, 0777);
620 unless (defined($chk) && -d $var) {
621 print "Unable to create directory. ($var)\n\n";
626 # They said they don't want to create, and we can't install there.
632 # Target exists, but is not a directory.
633 print "File $var exists, but is not a directory.\n\n";
637 # Either Dir Exists, or was created fine.
638 $config{$hash_key} = $var;
645 chomp(my $incos = `uname -n -s -r`);
646 chomp(my $version = `sh src/version.sh`);
647 my $revision = getrevision();
648 my $branch = "InspIRCd-0.0";
649 if ($version =~ /^(InspIRCd-[0-9]+\.[0-9]+)\.[0-9]+/)
653 print "Writing \e[1;32mconfig.h\e[0m\n";
654 open(FILEHANDLE, ">include/config.h.tmp");
655 print FILEHANDLE <<EOF;
656 /* Auto generated by configure, do not modify! */
659 #define BRANCH "$branch"
660 #define VERSION "$version"
661 #define REVISION "$revision"
662 #define SYSTEM "$incos"
664 #define CONFIG_PATH "$config{CONFIG_DIR}"
665 #define DATA_PATH "$config{DATA_DIR}"
666 #define LOG_PATH "$config{LOG_DIR}"
667 #define MOD_PATH "$config{MODULE_DIR}"
671 if ($config{HAS_EVENTFD} eq 'true') {
672 print FILEHANDLE "#define HAS_EVENTFD\n";
674 if ($config{HAS_CLOCK_GETTIME} eq 'true') {
675 print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
678 print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n";
681 unlink 'include/config.h';
682 rename 'include/config.h.tmp', 'include/config.h';
684 # Do this once here, and cache it in the .*.inc files,
685 # rather than attempting to read src/version.sh from
686 # compiled code -- we might not have the source to hand.
688 my @dotfiles = qw(main.mk inspircd);
689 push @dotfiles, 'org.inspircd.plist' if $^O eq 'darwin';
691 foreach my $file (@dotfiles) {
692 open(FILEHANDLE, "make/template/$file") or die "Can't open make/template/$file: $!";
693 $_ = join '', <FILEHANDLE>;
696 $config{BUILD_DIR} ||= rel2abs($topdir."/build");
697 $config{COMPILER} = lc $cxx{NAME};
698 $config{SYSTEM} = lc $^O;
701 CXX COMPILER SYSTEM BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR BUILD_DIR DATA_DIR UID
702 STARTSCRIPT SOCKETENGINE
704 s/\@$var\@/$config{$var}/g;
707 s/\@VERSION\@/$version/ if defined $version;
709 if ($file eq 'main.mk') {
710 print "Writing \e[1;32mGNUmakefile\e[0m ...\n";
713 s/\@IFDEF (\S+)/ifdef $1/g;
714 s/\@IFNDEF (\S+)/ifndef $1/g;
715 s/\@IFEQ (\S+) (\S+)/ifeq ($1,$2)/g;
716 s/\@IFNEQ (\S+) (\S+)/ifneq ($1,$2)/g;
717 s/\@ELSIFEQ (\S+) (\S+)/else ifeq ($1,$2)/g;
720 s/ *\@BSD_ONLY .*\n//g;
722 s/\@DO_EXPORT (.*)/export $1/g;
723 open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!";
727 print "Writing \e[1;32mBSDmakefile\e[0m ...\n";
729 s/\@IFDEF (\S+)/.if defined($1)/g;
730 s/\@IFNDEF (\S+)/.if !defined($1)/g;
731 s/\@IFEQ (\S+) (\S+)/.if $1 == $2/g;
732 s/\@IFNEQ (\S+) (\S+)/.if $1 != $2/g;
733 s/\@ELSIFEQ (\S+) (\S+)/.elif $1 == $2/g;
737 s/ *\@GNU_ONLY .*\n//g;
739 $mk_tmp =~ s#\@DO_EXPORT (.*)#"MAKEENV += ".join ' ', map "$_='\${$_}'", split /\s/, $1#eg;
740 open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!";
744 print "Writing \e[1;32m$file\e[0m ...\n";
745 open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n");
751 chmod 0755, 'inspircd';
757 for my $mod (@modlist) {
758 getcompilerflags("src/modules/m_$mod.cpp");
759 getlinkerflags("src/modules/m_$mod.cpp");
763 # Routine to list out the extra/ modules that have been enabled.
764 # Note: when getting any filenames out and comparing, it's important to lc it if the
765 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
766 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
767 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
771 my $srcdir = File::Spec->catdir("src", "modules");
772 my $abs_srcdir = File::Spec->rel2abs($srcdir);
775 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
776 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
779 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
780 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
783 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
785 EXTRA: for my $extra (@extras) {
786 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
787 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
788 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
789 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
790 if (-l $abs_source) {
791 # Symlink, is it in the right place?
792 my $targ = readlink($abs_source);
793 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
794 if ($abs_targ eq $abs_extra) {
795 $extras{$extra} = "\e[32;1menabled\e[0m";
797 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
799 } elsif (-e $abs_source) {
800 my ($devext, $inoext) = stat($abs_extra);
801 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
803 if ($devsrc == $devext && $inosrc == $inoext) {
804 $extras{$extra} = "\e[32;1menabled\e[0m";
806 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
809 open my $extfd, "<", $abs_extra;
810 open my $srcfd, "<", $abs_source;
812 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
813 $extras{$extra} = "\e[32;1menabled\e[0m";
815 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
819 $extras{$extra} = "\e[33;1mdisabled\e[0m";
822 # Now let's add dependency info
823 for my $extra (keys(%extras)) {
824 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
825 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
826 my @deps = split / +/, getdependencies($abs_extra);
827 for my $dep (@deps) {
828 if (exists($extras{$dep})) {
829 my $ref = \$extras{$dep}; # Take reference.
830 if ($$ref !~ m/needed by/) {
831 # First dependency found.
832 if ($$ref =~ m/enabled/) {
833 $$ref .= " (needed by \e[32;1m$extra\e[0m";
835 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
836 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
839 if ($$ref =~ m/enabled/) {
840 $$ref .= ", \e[32;1m$extra\e[0m";
842 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
848 for my $extra (sort {$a cmp $b} keys(%extras)) {
849 my $text = $extras{$extra};
850 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
851 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
853 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
856 return keys(%extras) if wantarray; # Can be used by manage_extras.
859 sub enable_extras (@) {
861 for my $extra (@extras) {
862 my $extrapath = "src/modules/extra/$extra";
863 if (!-e $extrapath) {
864 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
867 my $source = "src/modules/$extra";
869 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
872 # Get dependencies, and add them to be processed.
873 my @deps = split / +/, getdependencies($extrapath);
874 for my $dep (@deps) {
875 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
876 if (!-e "src/modules/$dep" && !-e "include/$dep") {
877 if (-e "src/modules/extra/$dep") {
878 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
881 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";
885 print "Enabling $extra ... \n";
886 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
890 sub disable_extras (@)
892 opendir my $dd, "src/modules/extra/";
893 my @files = readdir($dd);
896 EXTRA: for my $extra (@extras) {
897 my $extrapath = "src/modules/extra/$extra";
898 my $source = "src/modules/$extra";
899 if (!-e $extrapath) {
900 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
903 if ((! -l $source) || readlink($source) ne "extra/$extra") {
904 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";
907 # Check if anything needs this.
908 for my $file (@files) {
909 my @deps = split / +/, getdependencies("src/modules/extra/$file");
910 # File depends on this extra...
911 if (scalar(grep { $_ eq $extra } @deps) > 0) {
912 # And is both enabled and not about to be disabled.
913 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
914 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
920 print "Disabling $extra ... \n";
921 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";