2 ###################################################
3 # InspIRCd Configuration Script
5 # Copyright 2002-2009 The InspIRCd Development Team
6 # http://wiki.inspircd.org/Credits
8 # Licensed under GPL, please see the COPYING file
13 ###################################################
20 use warnings FATAL => qw(all);
24 $Data::Dumper::Sortkeys = 1;
25 $Data::Dumper::Useqq = 1;
33 # Utility functions for our buildsystem
37 use make::opensslcert;
39 ###############################################################################################
43 ###############################################################################################
45 # If you wish to ignore a dependency throughout the entire core, add it here.
48 "inspircd_win32wrapper.h", # windows has its own configure program
51 # If you wish for all files in the entire core to have a given dependency, insert it here.
52 # You should keep this to an absolute minimum to avoid rebuilds that are not neccessary.
54 our @immutabledeps = (
55 "inspircd_config.h", # auto re-generated by configure
59 ###############################################################################################
61 # NON-EDITABLE VARIABLES
63 ###############################################################################################
65 # List of commands that make up 'make install' and 'make deinstall'
67 our $install_list = "";
68 our $uninstall_list = "";
70 # This is a list of all files in the core. Each cpp file is mapped to a shared object file,
71 # whos file extension is omitted (these can vary from system to system). Auto detected by
72 # scanning the src/*.cpp files for files containing /* $Core */ identifiers.
76 # If you wish for a file to have special dependencies in the makefile, add an entry here.
77 # Auto populated by /* $ExtraDeps: */ instruction
79 our %specialdeps = ();
81 # If you wish for a file to have extra make lines (in between the compile and link steps)
82 # then insert them here.
83 # Auto populated by /* $ExtraBuild: */ instruction
85 our %extrabuildlines = ();
87 # If you wish for a file to be linked against extra objects or arctives, insert them here.
88 # Auto populated by /* $ExtraObjects: */ instruction
90 our %extraobjects = ();
92 # If you wish to compile extra cpp sources into an object, define them here.
93 # NOTE: Certain cpp files such as the socket engines have a value auto calculated
94 # for this table so that their derived class is built.
95 # Auto populated by /* $ExtraSources: */ instruction
97 our %extrasources = ();
99 our ($opt_use_gnutls, $opt_rebuild, $opt_use_openssl, $opt_nointeractive, $opt_ports,
100 $opt_epoll, $opt_kqueue, $opt_noports, $opt_noepoll, $opt_nokqueue,
101 $opt_ipv6, $opt_ipv6links, $opt_noipv6links, $opt_maxbuf, $opt_disable_debug,
104 our ($opt_cc, $opt_base_dir, $opt_config_dir, $opt_module_dir, $opt_binary_dir,
109 sub enable_extras (@);
111 sub disable_extras (@);
113 my @opt_enableextras;
114 my @opt_disableextras;
117 'enable-gnutls' => \$opt_use_gnutls,
118 'rebuild' => \$opt_rebuild,
119 'enable-openssl' => \$opt_use_openssl,
120 'disable-interactive' => \$opt_nointeractive,
121 'enable-ports' => \$opt_ports,
122 'enable-epoll' => \$opt_epoll,
123 'enable-kqueue' => \$opt_kqueue,
124 'disable-ports' => \$opt_noports,
125 'disable-epoll' => \$opt_noepoll,
126 'disable-kqueue' => \$opt_nokqueue,
127 'enable-ipv6' => \$opt_ipv6,
128 'enable-remote-ipv6' => \$opt_ipv6links,
129 'disable-remote-ipv6' => \$opt_noipv6links,
130 'with-cc=s' => \$opt_cc,
131 'with-maxbuf=i' => \$opt_maxbuf,
132 'enable-freebsd-ports-openssl' => \$opt_freebsd_port,
133 'prefix=s' => \$opt_base_dir,
134 'config-dir=s' => \$opt_config_dir,
135 'module-dir=s' => \$opt_module_dir,
136 'binary-dir=s' => \$opt_binary_dir,
137 'library-dir=s' => \$opt_library_dir,
138 'disable-debuginfo' => sub { $opt_disable_debug = 1 },
139 'help' => sub { showhelp(); },
140 'modupdate' => sub { modupdate(); },
141 'update' => sub { update(); },
142 'svnupdate' => sub { svnupdate(); },
143 'clean' => sub { clean(); },
144 'list-extras' => sub { list_extras; exit 0; }, # This, --enable-extras, and --disable-extras are for non-interactive managing.
145 'enable-extras=s@' => \@opt_enableextras, # ^
146 'disable-extras=s@' => \@opt_disableextras, # ^
147 'generate-openssl-cert' => sub { make_openssl_cert(); exit(0); },
148 'generate-gnutls-cert' => sub { make_gnutls_cert(); exit(0); }
151 if (scalar(@opt_enableextras) + scalar(@opt_disableextras) > 0) {
152 @opt_enableextras = split /,/, join(',', @opt_enableextras);
153 @opt_disableextras = split /,/, join(',', @opt_disableextras);
154 enable_extras(@opt_enableextras);
155 disable_extras(@opt_disableextras);
157 print "Remember: YOU are responsible for making sure any libraries needed have been installed!\n";
158 print "Run $0 -modupdate after you've done this to update the makefiles.\n";
162 our $non_interactive = (
163 (defined $opt_library_dir) ||
164 (defined $opt_base_dir) ||
165 (defined $opt_config_dir) ||
166 (defined $opt_module_dir) ||
167 (defined $opt_base_dir) ||
168 (defined $opt_binary_dir) ||
169 (defined $opt_nointeractive) ||
171 (defined $opt_ipv6) ||
172 (defined $opt_ipv6links) ||
173 (defined $opt_noipv6links) ||
174 (defined $opt_kqueue) ||
175 (defined $opt_epoll) ||
176 (defined $opt_ports) ||
177 (defined $opt_use_openssl) ||
178 (defined $opt_nokqueue) ||
179 (defined $opt_noepoll) ||
180 (defined $opt_noports) ||
181 (defined $opt_maxbuf) ||
182 (defined $opt_use_gnutls) ||
183 (defined $opt_freebsd_port)
185 our $interactive = !$non_interactive;
187 chomp(our $topdir = getcwd());
188 our $this = resolve_directory($topdir); # PWD, Regardless.
189 our @modlist = (); # Declare for Module List..
190 our %config = (); # Initiate Configuration Hash..
191 $config{ME} = resolve_directory($topdir); # Present Working Directory
193 $config{BASE_DIR} = $config{ME};
195 if (defined $opt_base_dir)
197 $config{BASE_DIR} = $opt_base_dir;
200 $config{CONFIG_DIR} = resolve_directory($config{BASE_DIR}."/conf"); # Configuration Directory
201 $config{MODULE_DIR} = resolve_directory($config{BASE_DIR}."/modules"); # Modules Directory
202 $config{BINARY_DIR} = resolve_directory($config{BASE_DIR}."/bin"); # Binary Directory
203 $config{LIBRARY_DIR} = resolve_directory($config{BASE_DIR}."/lib"); # Library Directory
205 if (defined $opt_config_dir)
207 $config{CONFIG_DIR} = $opt_config_dir;
209 if (defined $opt_module_dir)
211 $config{MODULE_DIR} = $opt_module_dir;
213 if (defined $opt_binary_dir)
215 $config{BINARY_DIR} = $opt_binary_dir;
217 if (defined $opt_library_dir)
219 $config{LIBRARY_DIR} = $opt_library_dir;
221 chomp($config{HAS_GNUTLS} = `pkg-config --modversion gnutls 2>/dev/null | cut -c 1,2,3`); # GNUTLS Version.
223 if (defined $opt_freebsd_port)
225 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`);
226 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`);
227 $config{USE_FREEBSD_BASE_SSL} = "n";
231 if ($^O eq "freebsd")
233 # default: use base ssl
234 chomp($config{HAS_OPENSSL} = `openssl version | cut -d ' ' -f 2`); # OpenSSL version, freebsd specific
235 chomp($config{HAS_OPENSSL_PORT} = `pkg-config --modversion openssl 2>/dev/null`); # Port version, may be different
239 chomp($config{HAS_OPENSSL} = `pkg-config --modversion openssl 2>/dev/null`); # Openssl version, others
240 $config{HAS_OPENSSL_PORT} = "";
244 chomp(our $gnutls_ver = $config{HAS_GNUTLS});
245 chomp(our $openssl_ver = $config{HAS_OPENSSL});
246 $config{USE_GNUTLS} = "n";
247 if (defined $opt_use_gnutls)
249 $config{USE_GNUTLS} = "y"; # Use gnutls.
251 $config{USE_OPENSSL} = "n"; # Use openssl.
252 if (defined $opt_use_openssl)
254 $config{USE_OPENSSL} = "y";
257 # no, let's not change these.
258 $config{OPTIMITEMP} = "0"; # Default Optimisation Value
259 if (!defined $opt_disable_debug)
261 $config{OPTIMISATI} = "-g1"; # Optimisation Flag
265 $config{OPTIMISATI} = "-O2"; # DEBUGGING OFF!
268 $config{HAS_STRLCPY} = "false"; # strlcpy Check.
269 $config{HAS_STDINT} = "false"; # stdint.h check
270 $config{USE_KQUEUE} = "y"; # kqueue enabled
271 if (defined $opt_kqueue)
273 $config{USE_KQUEUE} = "y";
275 if (defined $opt_nokqueue)
277 $config{USE_KQUEUE} = "n";
279 $config{USE_POLL} = "y"; # poll enabled
280 $config{USE_EPOLL} = "y"; # epoll enabled
281 if (defined $opt_epoll)
283 $config{USE_EPOLL} = "y";
285 if (defined $opt_noepoll)
287 $config{USE_EPOLL} = "n";
289 $config{USE_PORTS} = "y"; # epoll enabled
290 if (defined $opt_ports)
292 $config{USE_PORTS} = "y";
294 if (defined $opt_noports)
296 $config{USE_PORTS} = "n";
298 $config{IPV6} = "n"; # IPv6 support (experimental)
299 if (defined $opt_ipv6)
303 $config{SUPPORT_IP6LINKS} = "y"; # IPv4 supporting IPv6 links (experimental)
304 if (defined $opt_ipv6links)
306 $config{SUPPORT_IP6LINKS} = "y";
308 if (defined $opt_noipv6links)
310 $config{SUPPORT_IP6LINKS} = "n";
312 chomp($config{GCCVER} = `g++ -dumpversion | cut -c 1`); # Major GCC Version
313 chomp($config{GCCMINOR} = `g++ -dumpversion | cut -c 3`);
314 $config{_SOMAXCONN} = SOMAXCONN; # Max connections in accept queue
315 $config{OSNAME} = $^O; # Operating System Name
316 $config{IS_DARWIN} = "NO"; # Is OSX?
317 $config{STARTSCRIPT} = "inspircd"; # start script?
318 $config{DESTINATION} = "BASE"; # Is target path.
319 $config{EXTRA_DIR} = ""; # Is empty.
320 if ($config{OSNAME} =~ /darwin/i)
322 $config{IS_DARWIN} = "YES";
323 $config{STARTSCRIPT} = "org.inspircd.plist"; # start script for OSX.
324 $config{DESTINATION} = "LAUNCHDPATH"; # Is OSX target.
325 $config{EXTRA_DIR} = " launchd_dir"; # Is OSX specific path.
327 $config{CC} = "g++"; # C++ compiler
330 $config{CC} = $opt_cc;
332 our $exec = $config{CC} . " -dumpversion | cut -c 1";
333 chomp($config{GCCVER} = `$exec`); # Major GCC Version
334 $exec = $config{CC} . " -dumpversion | cut -c 3";
335 chomp($config{GCCMINOR} = `$exec`);
336 $config{MAXBUF} = "512"; # Max buffer size
338 if ($config{HAS_OPENSSL} =~ /^([-[:digit:].]+)([a-z])?(\-[a-z][0-9])?$/) {
339 $config{HAS_OPENSSL} = $1;
341 $config{HAS_OPENSSL} = "";
344 if (($config{GCCVER} eq "") || ($config{GCCMINOR} eq "")) {
345 print $config{CC} . " was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";
349 # Get and Set some important vars..
354 unlink(".config.cache");
357 our ($has_epoll, $has_ports, $has_kqueue) = (0, 0, 0);
362 chomp($topdir = getcwd());
363 $this = resolve_directory($topdir); # PWD, Regardless.
365 # Does the cache file exist?
367 # No, No it doesn't.. *BASH*
368 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
371 # We've Loaded the cache file and all our variables..
372 print "Updating files...\n";
374 if (defined($opt_disable_debug) && $opt_disable_debug == 1)
376 print "Disabling debug information (-g).\n";
377 $config{OPTIMISATI} = "";
380 $has_epoll = $config{HAS_EPOLL};
381 $has_ports = $config{HAS_PORTS};
382 $has_kqueue = $config{HAS_KQUEUE};
391 print "Configure update failed: $@\n";
399 chomp($topdir = getcwd());
400 $this = resolve_directory($topdir); # PWD, Regardless.
402 # Does the cache file exist?
404 # No, No it doesn't.. *BASH*
405 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
408 # We've Loaded the cache file and all our variables..
409 print "Updating files...\n";
411 $has_epoll = $config{HAS_EPOLL};
412 $has_ports = $config{HAS_PORTS};
413 $has_kqueue = $config{HAS_KQUEUE};
422 print "Module update failed: $@\n";
432 open(FH,"<.svn/entries") or $fail = 1;
434 print "This is not an SVN copy of InspIRCd.\n";
441 open my $fd, "-|", "svn update";
442 my $configurechanged = 0; # Needs ./configure -update
443 my $coredirchanged = 0; # Needs ./configure -update
444 my $moduledirchanged = 0; # Needs ./configure -modupdate
445 my $rootincchanged = 0;
447 while (defined(my $line = <$fd>))
451 $line =~ m/^([ADUCG])\s+(.*)$/ or next;
452 ($action, $file) = ($1, $2);
455 push @conflicted, $file;
456 if ($file eq "configure")
458 $configurechanged = 1;
460 elsif ($file =~ m#^src/modules#)
462 $moduledirchanged = 1;
464 elsif ($file =~ m#^src/#)
468 elsif ($file =~ m/^\..*\.inc$/)
473 elsif ($action eq "U" || $action eq "G")
475 if ($file eq "configure")
477 $configurechanged = 1;
479 elsif ($file =~ m/^\..*\.inc$/)
484 elsif ($action eq "A" || $action eq "D")
486 if ($file =~ m#^src/modules#)
488 $moduledirchanged = 1;
490 elsif ($file =~ m#^src/#)
496 unless (close $fd) # close() waits for exit and returns false if the command failed
500 print STDERR "Problem updating from SVN, please check above for errors\n";
504 print STDERR "Failed to run SVN: $!\n";
508 if (scalar(@conflicted) > 0)
510 print STDERR "\e[0;33;1mERROR:\e[0m You have local modifications which conflicted with the updates from SVN\n";
511 printf STDERR "Configure is not able to complete the update. Please resolve these conflicts, then run ./configure -%supdate\n", (($coredirchanged || $configurechanged) ? "" : "mod");
512 print "Conflicted files: " . join ", ", @conflicted . "\n";
515 if ($configurechanged || $coredirchanged)
517 system("perl configure -update");
519 elsif ($moduledirchanged || $rootincchanged)
521 system("perl configure -modupdate");
525 print "No need to update Makefiles.\n";
527 if (defined $opt_rebuild) {
528 system("make install");
536 $fail ||= system "$config{CC} -o test_$feature make/check_$feature.cpp >/dev/null 2>&1";
537 $fail ||= system "./test_$feature";
538 unlink "test_$feature";
542 print "Running non-interactive configure...\n" unless $interactive;
543 print "Checking for cache from previous configure... ";
544 print ((!getcache()) ? "not found\n" : "found\n");
545 print "Checking operating system version... ";
546 print getosflags() . "\n";
548 printf "Checking if stdint.h exists... ";
549 $config{HAS_STDINT} = "true";
551 open(STDINT, "</usr/include/stdint.h") or $config{HAS_STDINT} = "false";
552 if ($config{HAS_STDINT} eq "true") {
555 print "yes\n" if $config{HAS_STDINT} eq "true";
556 print "no\n" if $config{HAS_STDINT} eq "false";
558 printf "Checking if strlcpy exists... ";
559 # Perform the strlcpy() test..
560 $config{HAS_STRLCPY} = "false";
562 open(STRLCPY, "</usr/include/string.h") or $fail = 1;
564 while (defined(my $line = <STRLCPY>)) {
566 # try and find the delcaration of:
567 # size_t strlcpy(...)
568 if ($line =~ /size_t(\0x9|\s)+strlcpy/) {
569 $config{HAS_STRLCPY} = "true";
574 print "yes\n" if $config{HAS_STRLCPY} eq "true";
575 print "no\n" if $config{HAS_STRLCPY} eq "false";
577 printf "Checking if kqueue exists... ";
580 open(KQUEUE, "</usr/include/sys/event.h") or $fail = 1;
582 while (defined(my $line = <KQUEUE>)) {
584 # try and find the delcaration of:
586 if ($line =~ /int(\0x9|\s)+kqueue/) {
592 print "yes\n" if $has_kqueue == 1;
593 print "no\n" if $has_kqueue == 0;
595 printf "Checking for epoll support... ";
596 $has_epoll = test_compile('epoll');
597 print $has_epoll ? "yes\n" : "no\n";
599 printf "Checking for eventfd support... ";
600 $config{HAS_EVENTFD} = test_compile('eventfd') ? 'true' : 'false';
601 print $config{HAS_EVENTFD} eq 'true' ? "yes\n" : "no\n";
603 printf "Checking if Solaris I/O completion ports are available... ";
605 our $system = `uname -s`;
607 $has_ports = 1 if ($system eq "SunOS");
610 my $kernel = `uname -r`;
612 if (($kernel !~ /^5\.1./)) {
616 print "yes\n" if $has_ports == 1;
617 print "no\n" if $has_ports == 0;
619 $config{HAS_EPOLL} = $has_epoll;
620 $config{HAS_KQUEUE} = $has_kqueue;
622 printf "Checking for libgnutls... ";
623 if (defined($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS}) || ($config{HAS_GNUTLS} eq "y"))) {
624 if (defined($gnutls_ver) && ($gnutls_ver ne "")) {
626 $config{HAS_GNUTLS} = "y";
629 $config{HAS_GNUTLS} = "n";
633 $config{HAS_GNUTLS} = "n";
636 printf "Checking for openssl... ";
637 if (defined($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL}) || ($config{HAS_OPENSSL} eq "y"))) {
638 if (defined($openssl_ver) && ($openssl_ver ne "")) {
640 $config{HAS_OPENSSL} = "y";
643 $config{HAS_OPENSSL} = "n";
647 $config{HAS_OPENSSL} = "n";
650 printf "Checking if you are running an ancient, unsupported OS... ";
651 if ($config{OSNAME} =~ /FreeBSD/i)
653 my $version = `uname -r`;
654 if ($version =~ /^4\./)
656 my $foundit = `ls -l /usr/local/lib/libgnugetopt* | wc -l`;
659 # ICKY ICKY ICK, FREEBSD 4.x! GET AN UPGRADE!
660 $config{CRAQ} = "-L/usr/local/lib -lgnugetopt -DHAVE_DECL_GETOPT=1";
661 print "yes (upgrade ffs, freebsd 4 is *way* out of date)\n";
665 print "\n\nERROR: You require libgnugetopt (from ports or packages) to build InspIRCd on FreeBSD 4.11.\n";
671 print "no ($version)\n";
677 print "no ($config{OSNAME})\n";
680 print "Checking for upgrades to extra and third party modules... ";
681 system "./modulemanager upgrade";
683 ################################################################################
684 # BEGIN INTERACTIVE PART #
685 ################################################################################
690 print "\e[2J\e[0G\e[0d"; # J = Erase in Display, 2 = Entire Screen, (G, d) = Move cursor to (..,..)
693 my $rev = getrevision();
694 # Display Introduction Message..
696 Welcome to the \e[1mInspIRCd\e[0m Configuration program! (\e[1minteractive mode\e[0m)
697 \e[1mPackage maintainers: Type ./configure --help for non-interactive help\e[0m
699 *** If you are unsure of any of these values, leave it blank for ***
700 *** standard settings that will work, and your server will run ***
701 *** using them. Please consult your IRC network admin if in doubt. ***
703 Press \e[1m<RETURN>\e[0m to accept the default for any option, or enter
704 a new value. Please note: You will \e[1mHAVE\e[0m to read the docs
705 dir, otherwise you won't have a config file!
707 Your operating system is: \e[1;32m$config{OSNAME}\e[0m ($wholeos)
708 Your InspIRCd revision ID is \e[1;32mr$rev\e[0m
711 print " (Non-SVN build)";
715 $config{CHANGE_COMPILER} = "n";
716 print "I have detected the following compiler: \e[1;32m$config{CC}\e[0m (version \e[1;32m$config{GCCVER}.$config{GCCMINOR}\e[0m)\n";
718 while (($config{GCCVER} < 3) || ($config{GCCVER} eq "")) {
719 print "\e[1;32mIMPORTANT!\e[0m A GCC 2.x compiler has been detected, and
720 should NOT be used. You should probably specify a newer compiler.\n\n";
721 yesno('CHANGE_COMPILER',"Do you want to change the compiler?");
722 if ($config{CHANGE_COMPILER} =~ /y/i) {
723 print "What command do you want to use to invoke your compiler?\n";
724 print "[\e[1;32m$config{CC}\e[0m] -> ";
725 chomp($config{CC} = <STDIN>);
726 if ($config{CC} eq "") {
729 chomp(my $foo = `$config{CC} -dumpversion | cut -c 1`);
731 chomp($config{GCCVER} = `$config{CC} -dumpversion | cut -c 1`); # we must redo these if we change compilers
732 chomp($config{GCCMINOR} = `$config{CC} -dumpversion | cut -c 3`);
733 print "Queried compiler: \e[1;32m$config{CC}\e[0m (version \e[1;32m$config{GCCVER}.$config{GCCMINOR}\e[0m)\n";
734 if ($config{GCCVER} < 3) {
735 print "\e[1;32mGCC 2.x WILL NOT WORK!\e[0m. Let's try that again, shall we?\n";
739 print "\e[1;32mWARNING!\e[0m Could not execute the compiler you specified. You may want to try again.\n";
746 # Directory Settings..
747 my $tmpbase = $config{BASE_DIR};
748 dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
749 if ($tmpbase ne $config{BASE_DIR}) {
750 $config{CONFIG_DIR} = resolve_directory($config{BASE_DIR}."/conf"); # Configuration Dir
751 $config{MODULE_DIR} = resolve_directory($config{BASE_DIR}."/modules"); # Modules Directory
752 $config{BINARY_DIR} = resolve_directory($config{BASE_DIR}."/bin"); # Binary Directory
753 $config{LIBRARY_DIR} = resolve_directory($config{BASE_DIR}."/lib"); # Library Directory
756 dir_check("are the configuration files", "CONFIG_DIR");
757 dir_check("are the modules to be compiled to", "MODULE_DIR");
758 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
759 dir_check("are the IRCd libraries to be placed", "LIBRARY_DIR");
761 my $chose_hiperf = 0;
763 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?");
765 if ($config{USE_KQUEUE} eq "y") {
770 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?");
772 if ($config{USE_EPOLL} eq "y") {
777 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?");
779 if ($config{USE_PORTS} eq "y") {
784 if (!$chose_hiperf) {
785 yesno('USE_POLL', "Would you like to use poll?\n This is likely to increase performance.\nIf you are unsure, answer yes.\n\nEnable poll?\n");
786 if ($config{USE_POLL} ne "y")
788 print "No high-performance socket engines are available, or you chose\n";
789 print "not to enable one. Defaulting to select() engine.\n\n";
793 yesno('IPV6',"Would you like to build InspIRCd with IPv6 support?");
796 if ($config{IPV6} eq "y") {
797 print "You have chosen to build an \e[1;32mIPV6-enabled\e[0m server.\nTo accept IPV4 users, you can still use IPV4 addresses\nin your port bindings..\n\n";
798 $config{SUPPORT_IP6LINKS} = "y";
800 yesno('SUPPORT_IP6LINKS',"You have chosen to build an \e[1;32mIPV4-only\e[0m server.\nWould you like to enable support for linking to IPV6-enabled\nInspIRCd servers? If you are using a recent operating system and are\nunsure, answer yes. If you answer 'no' here, your InspIRCd server will\nbe unable to parse IPV6 addresses (e.g. for CIDR bans)\n\nEnable linking to servers which have IPV6 enabled?");
804 $config{USE_FREEBSD_BASE_SSL} = "n";
805 $config{USE_FREEBSD_PORTS_SSL} = "n";
806 if ($config{HAS_OPENSSL_PORT} ne "")
808 $config{USE_FREEBSD_PORTS_SSL} = "y";
809 print "I have detected the OpenSSL FreeBSD port installed on your system,\n";
810 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";
811 yesno('USE_FREEBSD_PORTS_SSL', "Do you want to use the FreeBSD ports version?");
813 $config{USE_FREEBSD_BASE_SSL} = "y" if ($config{USE_FREEBSD_PORTS_SSL} eq "n");
815 if ($config{USE_FREEBSD_BASE_SSL} eq "n")
817 # update to port version
818 $openssl_ver = $config{HAS_OPENSSL_PORT};
823 $config{USE_FREEBSD_BASE_SSL} = "y" if ($^O eq "freebsd");
826 $config{USE_SSL} = "n";
828 if ($config{HAS_GNUTLS} eq "y" || $config{HAS_OPENSSL} eq "y")
830 print "Detected GnuTLS version: \e[1;32m" . $gnutls_ver . "\e[0m\n";
831 print "Detected OpenSSL version: \e[1;32m" . $openssl_ver . "\e[0m\n\n";
833 yesno('USE_SSL', "One or more SSL libraries detected. Would you like to enable SSL support?");
834 if ($config{USE_SSL} eq "y")
836 if ($config{HAS_GNUTLS} eq "y")
838 yesno('USE_GNUTLS',"Would you like to enable SSL with m_ssl_gnutls? (recommended)");
839 if ($config{USE_GNUTLS} eq "y")
841 print "\nUsing GnuTLS SSL module.\n";
845 if ($config{HAS_OPENSSL} eq "y")
847 yesno('USE_OPENSSL', "Would you like to enable SSL with m_ssl_openssl?");
848 if ($config{USE_OPENSSL} eq "y")
850 print "\nUsing OpenSSL SSL module.\nYou will get better performance if you move to GnuTLS in the future.\n";
857 print "\nCould not detect OpenSSL or GnuTLS. Make sure pkg-config is installed if\n";
858 print "you intend to use OpenSSL, or that GnuTLS is in your path if you intend\nto use GnuTLS.\n\n";
864 if (($config{USE_GNUTLS} eq "y") && ($config{HAS_GNUTLS} ne "y"))
866 print "Sorry, but i couldn't detect gnutls. Make sure gnutls-config is in your path.\n";
869 if (($config{USE_OPENSSL} eq "y") && ($config{HAS_OPENSSL} ne "y"))
871 print "Sorry, but i couldn't detect openssl. Make sure openssl is in your path.\n";
876 $config{CERTGEN} ||= 'y';
877 yesno('CERTGEN',"Would you like generate SSL certificates now?") if ($interactive && ($config{USE_GNUTLS} eq "y" || $config{USE_OPENSSL} eq "y"));
879 if ($config{USE_GNUTLS} eq "y") {
880 unless (-r "src/modules/m_ssl_gnutls.cpp") {
881 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
882 symlink "extra/m_ssl_gnutls.cpp", "src/modules/m_ssl_gnutls.cpp" or print STDERR "Symlink failed: $!";
884 if ($interactive && $config{CERTGEN} eq 'y')
886 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem") {
887 print "SSL Certificates Not found, Generating.. \n\n
888 *************************************************************
889 * Generating the Private Key may take some time, go grab a *
890 * Coffee. Even better, to generate some more entropy if it *
891 * is taking a while, open another console and type du / a *
892 * few times and get that HD going :) Then answer the *
893 * Questions which follow. If you are unsure, just hit enter *
894 *************************************************************\n\n";
895 $failed = make_gnutls_cert();
897 print "\n\e[1;32mCertificate generation failed!\e[0m\n\n";
899 print "\nCertificate generation complete, copying to config directory... ";
900 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
901 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
906 print "SSL Certificates found, skipping.\n\n";
911 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
915 if ($config{USE_OPENSSL} eq "y") {
916 unless (-r "src/modules/m_ssl_openssl.cpp") {
917 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
918 symlink "extra/m_ssl_openssl.cpp", "src/modules/m_ssl_openssl.cpp" or print STDERR "Symlink failed: $!";
921 if ($interactive && $config{CERTGEN} eq 'y')
923 unless (-r "$config{CONFIG_DIR}/key.pem" && -r "$config{CONFIG_DIR}/cert.pem") {
924 print "SSL Certificates Not found, Generating.. \n\n
925 *************************************************************
926 * Generating the certificates may take some time, go grab a *
927 * coffee, or something. *
928 *************************************************************\n\n";
930 print "\nCertificate generation complete, copying to config directory... ";
931 File::Copy::move("key.pem", "$config{CONFIG_DIR}/key.pem") or print STDERR "Could not copy key.pem!\n";
932 File::Copy::move("cert.pem", "$config{CONFIG_DIR}/cert.pem") or print STDERR "Could not copy cert.pem!\n";
933 File::Copy::move("dhparams.pem", "$config{CONFIG_DIR}/dhparams.pem") or print STDERR "Could not copy dhparams.pem!\n";
936 print "SSL Certificates found, skipping.\n\n"
941 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
944 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
945 print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
953 print "To build your server with these settings, please type '\e[1;32m$config{MAKEPROG}\e[0m' now.\n";
954 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
955 print "Please note: for \e[1;32mSSL support\e[0m you will need to load required\n";
956 print "modules in your config. This configure script has added those modules to the\n";
957 print "build process. For more info please refer to:\n";
958 print "\e[1;32mhttp://wiki.inspircd.org/Installation_From_Tarball\e[0m\n";
960 print "*** \e[1;32mRemember to edit your configuration files!!!\e[0m ***\n\n\n";
961 if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) {
962 print "\e[1;32mWARNING!\e[0m You are running OpenBSD but you are using the base gcc package\nrather than eg++. This compile will most likely fail, but i'm letting you\ngo ahead with it anyway, just in case i'm wrong :-)\n";
965 if ($config{GCCVER} < "3") {
967 \e[1;32mWARNING!\e[0m You are attempting to compile InspIRCd on GCC 2.x!
968 GCC 2.x series compilers only had partial (read as broken) C++ support, and
969 your compile will most likely fail horribly! If you have any problems, do NOT
970 report them to the bugtracker or forums without first upgrading your compiler
971 to a newer 3.x or 4.x (or whatever is available currently) version.
975 ################################################################################
977 ################################################################################
979 # Retrieves the .config.cache file, and loads values into the main config hash.
980 open(CACHE, ".config.cache") or return 0;
983 # Ignore Blank lines, and comments..
986 my ($key, $value) = split("=", $_, 2);
987 $value =~ /^\"(.*)\"$/;
988 # Do something with data here!
996 # Dump the contents of %config
997 print "Writing \e[1;32mcache file\e[0m for future ./configures ...\n";
998 open(FILEHANDLE, ">.config.cache");
999 foreach my $key (keys %config) {
1000 print FILEHANDLE "$key=\"$config{$key}\"\n";
1006 my ($desc, $hash_key) = @_;
1008 while (!$complete) {
1009 print "In what directory $desc?\n";
1010 print "[\e[1;32m$config{$hash_key}\e[0m] -> ";
1011 chomp(my $var = <STDIN>);
1013 $var = $config{$hash_key};
1015 if ($var =~ /^\~\/(.+)$/) {
1016 # Convert it to a full path..
1017 $var = resolve_directory($ENV{HOME} . "/" . $1);
1019 elsif ((($config{OSNAME} =~ /MINGW32/i) and ($var !~ /^[A-Z]{1}:\\.*/)) and (substr($var,0,1) ne "/"))
1021 # Assume relative Path was given.. fill in the rest.
1022 $var = $this . "/$var";
1025 $var = resolve_directory($var);
1027 print "$var does not exist. Create it?\n[\e[1;32my\e[0m] ";
1028 chomp(my $tmp = <STDIN>);
1029 if (($tmp eq "") || ($tmp =~ /^y/i)) {
1030 # Attempt to Create the Dir..
1033 File::Path::mkpath($var, 0, 0777);
1036 unless (defined($chk) && -d $var) {
1037 print "Unable to create directory. ($var)\n\n";
1042 # They said they don't want to create, and we can't install there.
1047 if (!is_dir($var)) {
1048 # Target exists, but is not a directory.
1049 print "File $var exists, but is not a directory.\n\n";
1053 # Either Dir Exists, or was created fine.
1054 $config{$hash_key} = $var;
1064 # Beware: Linux sets it's own cflags below for some retarded reason
1065 $config{LDLIBS} = "-pthread -lstdc++";
1066 $config{FLAGS} = "-pipe -fPIC -Woverloaded-virtual -Wshadow -Wformat=2 -Wmissing-format-attribute -Wall $config{OPTIMISATI}";
1067 $config{DEVELOPER} = "-pipe -fPIC -Woverloaded-virtual -Wshadow -Wall -Wformat=2 -Wmissing-format-attribute -g";
1068 $SHARED = "-shared -export-dynamic";
1069 $config{MAKEPROG} = "make";
1071 if ($config{OSNAME} =~ /darwin/i) {
1072 $config{FLAGS} = "-pipe -DDARWIN -frtti -fPIC -Wall $config{OPTIMISATI}";
1073 $SHARED = "-bundle -twolevel_namespace -undefined dynamic_lookup";
1074 $config{LDLIBS} = "-ldl -pthread -lstdc++";
1077 if ($config{OSNAME} =~ /OpenBSD/i) {
1078 $config{MAKEPROG} = "gmake";
1079 # apparantly (Dagonet says) that this causes problems, so let's try without it.
1080 # $config{LDLIBS} = $config{LDLIBS} . " -lunwind";
1081 chomp(my $foo = `eg++ -dumpversion | cut -c 1`);
1082 # theyre running the package version of gcc (eg++)... detect it and set up its version numbers.
1083 # if theyre not running this, configure lets the build continue but they probably wont manage to
1084 # compile as this standard version is 2.95.3!
1086 $config{CC} = "eg++";
1087 chomp($config{GCCVER} = `eg++ -dumpversion | cut -c 1`); # we must redo these if we change the compiler path
1088 chomp($config{GCCMINOR} = `eg++ -dumpversion | cut -c 3`);
1093 if ($config{OSNAME} =~ /Linux/i) {
1094 $config{LDLIBS} = "-ldl -lstdc++ -pthread";
1095 # $config{FLAGS} = "-fPIC -Woverloaded-virtual -Wshadow -Wall $config{OPTIMISATI}";
1096 $config{FLAGS} .= " " . $ENV{CXXFLAGS} if exists($ENV{CXXFLAGS});
1097 $config{LDLIBS} .= " " . $ENV{LDLIBS} if exists($ENV{LDLIBS});
1098 $config{LDLIBS} .= " " . $ENV{LDFLAGS} if exists($ENV{LDFLAGS});
1099 $config{MAKEPROG} = "make";
1102 if ($config{OSNAME} =~ /FreeBSD/i) {
1103 $config{FLAGS} .= " " . $ENV{CXXFLAGS} if exists($ENV{CXXFLAGS});
1104 $config{LDLIBS} .= " " . $ENV{LDLIBS} if exists($ENV{LDLIBS});
1105 $config{LDLIBS} .= " " . $ENV{LDFLAGS} if exists($ENV{LDFLAGS});
1108 if ($config{OSNAME} =~ /SunOS/i or $config{OSNAME} =~ /solaris/i)
1110 # solaris/sunos needs these
1111 # socket = bsd sockets api
1113 # rt = POSIX realtime extensions
1114 # resolv = inet_aton only (why isnt this in nsl?!)
1115 $config{MAKEPROG} = "gmake";
1116 $config{LDLIBS} .= " -lsocket -lnsl -lrt -lresolv -pthread";
1120 if($config{OSNAME} =~ /MINGW32/i)
1122 # All code is position-independent on windows
1123 $config{FLAGS} =~ s/-fPIC //;
1127 return $config{OSNAME};
1130 my ($mliflags, $mfrules, $mobjs, $mfcount) = ("", "", "", 0);
1133 my($writeheader) = @_;
1135 # First File.. inspircd_config.h
1136 chomp(my $incos = `uname -n -s -r`);
1137 chomp(my $version = `sh src/version.sh`);
1138 chomp(my $revision2 = getrevision());
1139 if ($writeheader == 1)
1141 print "Writing \e[1;32minspircd_config.h\e[0m\n";
1142 open(FILEHANDLE, ">include/inspircd_config.h");
1143 print FILEHANDLE <<EOF;
1144 /* Auto generated by configure, do not modify! */
1145 #ifndef __CONFIGURATION_AUTO__
1146 #define __CONFIGURATION_AUTO__
1148 /* this is for windows support. */
1149 #define CoreExport /**/
1150 #define DllExport /**/
1152 #define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf"
1153 #define MOD_PATH "$config{MODULE_DIR}"
1154 #define VERSION "$version"
1155 #define REVISION "$revision2"
1156 #define SOMAXCONN_S "$config{_SOMAXCONN}"
1157 #define OPTIMISATION $config{OPTIMITEMP}
1158 #define LIBRARYDIR "$config{LIBRARY_DIR}"
1159 #define SYSTEM "$incos"
1160 #define ENTRYPOINT int main(int argc, char** argv)
1163 print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
1165 if ($config{OSNAME} =~ /SunOS/i) {
1166 print FILEHANDLE "#define IS_SOLARIS\n";
1168 if ($config{OSNAME} =~ /MINGW32/i) {
1169 print FILEHANDLE "#define IS_MINGW\n";
1171 if ($config{GCCVER} >= 3) {
1172 print FILEHANDLE "#define GCC3\n";
1175 (($config{GCCVER} == 4) && ($config{GCCMINOR} >= 3))
1177 ($config{GCCVER} > 4)
1179 print FILEHANDLE "#define HASHMAP_DEPRECATED\n";
1181 if ($config{HAS_STRLCPY} eq "true") {
1182 print FILEHANDLE "#define HAS_STRLCPY\n";
1184 if ($config{HAS_STDINT} eq "true") {
1185 print FILEHANDLE "#define HAS_STDINT\n";
1187 if ($config{IPV6} =~ /y/i) {
1188 print FILEHANDLE "#define IPV6\n";
1190 if ($config{SUPPORT_IP6LINKS} =~ /y/i) {
1191 print FILEHANDLE "#define SUPPORT_IP6LINKS\n";
1193 if ($config{HAS_EVENTFD} eq 'true') {
1194 print FILEHANDLE "#define HAS_EVENTFD\n";
1197 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1198 print FILEHANDLE "#define USE_KQUEUE\n";
1199 $se = "socketengine_kqueue";
1202 if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1203 print FILEHANDLE "#define USE_EPOLL\n";
1204 $se = "socketengine_epoll";
1207 if (($has_ports) && ($config{USE_PORTS} eq "y")) {
1208 print FILEHANDLE "#define USE_PORTS\n";
1209 $se = "socketengine_ports";
1212 # user didn't choose either epoll or select for their OS.
1213 # default them to USE_SELECT (ewwy puke puke)
1215 print "no hi-perf, " . $config{USE_POLL};
1216 if ($config{USE_POLL} eq "y")
1218 print FILEHANDLE "#define USE_POLL\n";
1219 $se = "socketengine_poll";
1223 print FILEHANDLE "#define USE_SELECT\n";
1224 $se = "socketengine_select";
1227 print FILEHANDLE "\n#include \"threadengines/threadengine_pthread.h\"\n\n#endif\n";
1233 open(FILEHANDLE, ">include/inspircd_se_config.h");
1234 print FILEHANDLE <<EOF;
1235 /* Auto generated by configure, do not modify or commit to svn! */
1236 #ifndef __CONFIGURATION_SOCKETENGINE__
1237 #define __CONFIGURATION_SOCKETENGINE__
1239 #include "socketengines/$se.h"
1247 # Create a Modules List..
1249 foreach my $i (@modlist)
1251 $modules .= "m_".$i.".so ";
1253 chomp($modules); # Remove Redundant whitespace..
1255 opendir(DIRHANDLE, "src/modules");
1256 foreach my $name2 (sort readdir(DIRHANDLE)) {
1257 if ($name2 =~ /^m_(.+?)$/) {
1258 if (defined(opendir(MDIRHANDLE, "src/modules/$name2"))) {
1259 closedir(MDIRHANDLE);
1260 $modules .= "$name2.so ";
1261 $uninstall_list = $uninstall_list . " -rm \$(MODPATH)/$name2.so\n";
1265 closedir(DIRHANDLE);
1268 # Write all .in files.
1271 my $exe = "inspircd";
1273 # Do this once here, and cache it in the .*.inc files,
1274 # rather than attempting to read src/version.sh from
1275 # compiled code -- we might not have the source to hand.
1276 # Fix for bug#177 by Brain.
1278 chomp($version = `sh ./src/version.sh`);
1279 chomp(my $revision = getrevision());
1280 $version = "$version(r$revision)";
1282 # We can actually parse any file starting with . and ending with .inc,
1283 # but right now we only parse .inspircd.inc to form './inspircd'
1285 print "Writing \e[1;32mMakefiles\e[0m\n";
1286 write_dynamic_modules_makefile();
1287 write_dynamic_makefile();
1289 opendir(DIRHANDLE, $this);
1291 foreach my $name (sort readdir(DIRHANDLE)) {
1292 if ($name =~ /^\.(.+)\.inc$/) {
1295 # Bug #353, omit this on non-darwin
1296 next if (($config{OSNAME} !~ /darwin/) && ($file eq "org.inspircd.plist"));
1298 # All .name.inc files need parsing!
1299 open(FILEHANDLE, ".$file.inc") or die ("Can't open .$file.inc");
1300 $_ = join '', <FILEHANDLE>;
1303 print "Writing \e[1;32m$file\e[0m ...\n";
1305 CC FLAGS DEVELOPER LDLIBS BASE_DIR CONFIG_DIR MODULE_DIR BINARY_DIR LIBRARY_DIR
1306 STARTSCRIPT DESTINATION EXTRA_DIR
1308 s/\@$var\@/$config{$var}/g;
1310 s/\@MODULES\@/$modules/ if defined $modules;
1311 s/\@EXECUTABLE\@/$exe/ if defined $exe;
1312 s/\@VERSION\@/$version/ if defined $version;
1313 s/\@INSTALL_LIST\@/$install_list/ if defined $install_list;
1314 s/\@UNINSTALL_LIST\@/$uninstall_list/ if defined $uninstall_list;
1316 if ($file eq 'Makefile') {
1318 s/\@IFDEF (\S+)/ifdef $1/g;
1319 s/\@IFNDEF (\S+)/ifndef $1/g;
1322 s/\@BSD_ONLY .*\n//g;
1324 open MKF, '>GNUmakefile' or die "Can't write to GNUmakefile: $!";
1328 s/\@IFDEF (\S+)/.if defined($1)/g;
1329 s/\@IFNDEF (\S+)/.if !defined($1)/g;
1333 s/\@GNU_ONLY .*\n//g;
1334 open MKF, '>BSDmakefile' or die "Can't write to BSDmakefile: $!";
1338 open(FILEHANDLE, ">$file") or die("Can't write to $file: $!\n");
1339 print FILEHANDLE $_;
1344 closedir(DIRHANDLE);
1346 # Make inspircd executable!
1347 chmod 0744, 'inspircd';
1350 sub write_dynamic_modules_makefile {
1351 # Modules Makefile..
1352 print "Writing \e[1;32msrc/modules/Makefile\e[0m\n";
1353 open(FILEHANDLE, ">src/modules/Makefile");
1356 # Module Makefile Header
1358 print FILEHANDLE <<EOF;
1359 ###################################################
1360 # Copyright 2002-2009 The InspIRCd Development Team
1361 # http://wiki.inspircd.org/Credits
1363 # Thanks to Andrew Church <achurch\@achurch.org>
1364 # for assisting with making this work right.
1366 # Automatically Generated by ./configure to add a
1367 # modules please run ./configure -modupdate
1368 ###################################################
1374 if ($config{OSNAME} =~ /darwin/) {
1375 print FILEHANDLE <<EOCHEESE;
1377 PICLDFLAGS = -twolevel_namespace -undefined dynamic_lookup -bundle
1381 print FILEHANDLE <<EOCHEESE;
1383 PICLDFLAGS = -fPIC -DPIC -shared
1389 # End Module Makefile Header
1392 # Create a Modules List..
1396 foreach my $i (@modlist) {
1398 # Write Entry to the MakeFile
1400 $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1401 $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1402 my $deps = getdependencies("src/modules/m_".$i.".cpp");
1404 #print "file: $i: cmflags=$cmflags; liflags=$liflags; deps=$deps\n";
1407 if (nopedantic("src/modules/m_".$i.".cpp"))
1410 m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps
1411 \$(RUNCC) \$(NICEFLAGS) $cmflags \$(PICLDFLAGS) $liflags $SHARED -o m_$i.so m_$i.cpp
1417 m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps
1418 \$(RUNCC) \$(FLAGS) $cmflags \$(PICLDFLAGS) $liflags $SHARED -o m_$i.so m_$i.cpp
1421 $install_list = $install_list . " install -m \$(INSTMODE) src/modules/m_$i.so \$(MODPATH)\n";
1422 $uninstall_list = $uninstall_list . " -rm \$(MODULES)/m_$i.so\n";
1424 # End Write Entry to the MakeFile
1428 opendir(DIRHANDLE, "src/modules");
1429 foreach my $name (sort readdir(DIRHANDLE)) {
1430 if ($name =~ /^m_(.+?)$/) {
1435 # A module made of multiple files, in a dir, e.g. src/modules/m_spanningtree/
1436 if (defined(opendir(MDIRHANDLE, "src/modules/$name"))) {
1437 read_module_directory("src/modules/$name", $name);
1438 print "Composing Makefile rules for directory \e[1;32m$name\e[0m... (\e[1;32m$mfcount files found\e[0m)\n";
1439 print FILEHANDLE "$name.so: ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $mobjs\n";
1440 print FILEHANDLE " \$(RUNCC) \$(FLAGS) $SHARED $mliflags -o $name.so $mobjs\n";
1441 print FILEHANDLE "\n$mfrules\n";
1442 closedir(MDIRHANDLE);
1443 $install_list = $install_list . " install -m \$(INSTMODE) src/modules/$name.so \$(MODPATH)\n";
1447 closedir(DIRHANDLE);
1450 sub read_module_directory {
1451 my ($dpath, $reldpath) = @_;
1453 if (opendir(MDIRHANDLE, $dpath) == 0) {
1457 foreach my $fname (sort readdir(MDIRHANDLE)) {
1458 if ($fname =~ /\.cpp$/) {
1459 my $cmflags = getcompilerflags("$dpath/$fname");
1460 $mliflags = $mliflags . " " . getlinkerflags("$dpath/$fname");
1461 my $deps = getdependencies("$dpath/$fname");
1463 $oname =~ s/\.cpp$/.o/g;
1464 $mfrules = $mfrules . "$reldpath/$oname: $reldpath/$fname ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps\n";
1465 $mfrules = $mfrules . " \$(RUNCC) -I. \$(FLAGS) $cmflags $SHARED -o $reldpath/$oname -c $reldpath/$fname\n\n";
1466 $mobjs = $mobjs . " $reldpath/$oname";
1469 elsif ((-d "$dpath/$fname") && !($fname eq ".") && !($fname eq "..")) {
1470 read_module_directory($dpath."/".$fname, $reldpath."/".$fname);
1477 # Yes i know we could use gcc -M but it seems to ideneify a lot of 'deep'
1478 # dependencies which are not relevent in C++.
1482 open (CPP, "<$file") or die("Can't open $file for reading!");
1487 foreach my $d (@ignoredeps)
1493 foreach my $dep (@immutabledeps)
1495 $immutable = $immutable . "../include/$dep ";
1497 $immutable =~ s/ $//g;
1499 while (defined(my $line = <CPP>))
1502 if ($line =~ /#include "(.+\.h)"/)
1504 if (!exists($dupe{$1}))
1506 $retlist = $retlist . "../include/$1 ";
1512 return length($immutable) ? $immutable . " " . $retlist : $retlist;
1515 sub write_dynamic_makefile
1519 my %existing_install_list = ();
1520 my %core_files_list = ();
1522 opendir(DIRHANDLE, "src/commands");
1523 foreach my $name (sort readdir(DIRHANDLE))
1525 if ($name =~ /^cmd_(.+)\.cpp$/)
1527 $cmdlist[$i++] = $1;
1528 $install_list = $install_list . " -install -m \$(INSTMODE) src/commands/cmd_" . $1 . ".so \$(LIBPATH)\n";
1529 $uninstall_list = $uninstall_list . " -rm \$(LIBPATH)/cmd_$1.so\n";
1532 closedir(DIRHANDLE);
1536 $config{USE_EPOLL} = 0;
1540 $config{USE_KQUEUE} = 0;
1544 $config{USE_PORTS} = 0;
1547 # formerly generated below this foreach, now it's not! magic.
1550 foreach my $dir (("src","src/commands","src/modes","src/socketengines","src/modules"))
1552 print "Scanning \e[1;32m$dir\e[0m for core files ";
1553 opendir(DIRHANDLE, $dir);
1554 foreach my $name (sort readdir(DIRHANDLE))
1556 if ($name =~ /\.cpp$/)
1558 open (CPP, "<$dir/$name") or die("Can't open $dir/$name to scan it! oh bugger");
1560 while (defined(my $line = <CPP>))
1563 if ($line =~ /\/\* \$Core \*\//i)
1566 $sname =~ s/\.cpp$/.o/;
1568 # append it to list to be built
1569 $all_core = $all_core . $sname . " ";
1570 $filelist{$name} = $sname;
1572 # mark it as a core file, so it won't get shared object cflags
1573 if (!exists($core_files_list{$name}))
1575 $core_files_list{$name} = 1;
1578 elsif ($line =~ /\/\* \$ExtraDeps: (.*?) \*\//i)
1580 $specialdeps{$name} = $1;
1582 elsif ($line =~ /\/\* \$ExtraObjects: (.*?) \*\//i)
1584 $extraobjects{$name} = $1;
1586 elsif ($line =~ /\/\* \$ExtraBuild: (.*?) \*\//i)
1588 $extrabuildlines{$name} = $1;
1590 elsif ($line =~ /\/\* \$ExtraSources: (.*?) \*\//i)
1592 $extrasources{$name} = $1;
1594 elsif ($line =~ /\/\* \$If: (\w+) \*\//i)
1596 if (defined $config{$1})
1598 if (($config{$1} !~ /y/i) and ($config{$1} ne "1"))
1601 while (defined($line = <CPP>))
1604 die ("\$If buildsystem instruction within another \$If in file $dir/$name") if ($line =~ /\/\* \$If: (\w+) \*\//i);
1605 last if ($line =~ /\/\* \$EndIf \*\//i);
1610 elsif ($line =~ /\/\* \$Install: (.*?) \*\//i)
1612 if (!exists($existing_install_list{$1}))
1614 $existing_install_list{$1} = 1;
1615 my $idir = (split(' ',$1))[1];
1616 my $ifile = (split(' ',$1))[0];
1617 $install_list = $install_list . " -install -m \$(INSTMODE) $1\n";
1618 $ifile =~ s/.*\///g;
1619 $uninstall_list = $uninstall_list . " -rm $idir/$ifile\n";
1622 elsif ($line =~ /\/\* \$CopyInstall: (.*?) \*\//i)
1624 if (!exists($existing_install_list{$1}))
1626 $existing_install_list{$1} = 1;
1627 my $idir = (split(' ',$1))[1];
1628 my $ifile = (split(' ',$1))[0];
1629 $install_list = $install_list . " -cp $1\n";
1630 $ifile =~ s/.*\///g;
1631 $uninstall_list = $uninstall_list . " -rm $idir/$ifile\n";
1638 closedir(DIRHANDLE);
1642 # modes need to be compiled in too
1643 $all_core = $all_core . "modes/modeclasses.a";
1645 my $freebsd4libs = (defined $config{CRAQ} ? $config{CRAQ} : "");
1647 my $libraryext = "";
1648 my $binary_rule = "";
1650 if ($config{IS_DARWIN} eq "YES")
1652 $libraryext = "dylib";
1653 $binary_rule = " \$(RUNCC) -dynamic -bind_at_load -L. -o inspircd \$(LDLIBS) inspircd.o "
1658 $binary_rule = " \$(RUNCC) \$(FLAGS) $freebsd4libs -rdynamic -L. -o inspircd \$(LDLIBS) ";
1661 open(FH,">src/Makefile") or die("Could not write src/Makefile");
1665 CPPFILES = $(shell /bin/ls -l modes/ | grep '\.cpp' | sed 's/^.* //' | grep -v svn)
1666 RELCPPFILES = $(shell /bin/ls -l modes/ | grep '\.cpp' | sed 's/^.* /modes\//' | grep -v svn)
1669 @echo "Don't run make here! Run it in the parent directory"
1674 my $buildstring = "";
1677 foreach my $cpp (sort keys %filelist)
1681 $objs =~ s/\.cpp$/.o/;
1682 if (exists($extraobjects{$cpp}))
1684 $objs = $objs . " " . $extraobjects{$cpp};
1685 $all_core = $all_core . " " . $extraobjects{$cpp};
1687 if (exists($extrasources{$cpp}))
1689 $rawcpp = $rawcpp . " " . $extrasources{$cpp};
1692 $deps = calcdeps("src/$cpp");
1693 if (exists($extrasources{$cpp}))
1695 foreach my $seperate (sort split(' ',$extrasources{$cpp}))
1697 my $d = calcdeps("src/$extrasources{$cpp}") . " ";
1700 $deps = $deps . $d . " ";
1704 $buildstring = $buildstring . $objs . ": $cpp $deps ". (defined($specialdeps{$cpp}) ? $specialdeps{$cpp} : "") . "\n";
1706 if (exists($core_files_list{$cpp}))
1708 # core files are statically linked into the binary and do not require $SHARED shared libs switches
1709 $buildstring = $buildstring . " \$(RUNCC) \$(FLAGS) -c $rawcpp\n";
1713 $buildstring = $buildstring . " \$(RUNCC) \$(FLAGS) $SHARED -c $rawcpp\n";
1716 if (exists($extrabuildlines{$cpp}))
1718 $buildstring = $buildstring . " " . $extrabuildlines{$cpp} . "\n";
1722 print FH "inspircd: $all_core\n";
1723 print FH "$binary_rule $all_core\n\n";
1725 print FH $buildstring;
1728 .PHONY: all commands
1731 @${MAKE} -C commands $(MAKEARGS) commands
1733 modes/modeclasses.a: $(RELCPPFILES) ../include/inspircd.h ../include/inspircd_config.h
1734 @${MAKE} -C modes $(MAKEARGS) CPPFILES="$(CPPFILES)" modeclasses.a
1738 # close main makefile
1742 # generate a list of .so
1743 foreach my $cmd (@cmdlist) {
1744 $cmdobjs = $cmdobjs . "cmd_$cmd.so ";
1747 # and now reopen the commands makefile
1748 open(FH,">src/commands/Makefile") or die("Could not write src/commands/Makefile");
1750 CXXFLAGS = \${FLAGS}
1753 \@echo "Don't run make here! Run it in the root directory"
1756 .PHONY: all commands
1762 # now print the command file detail
1763 foreach my $cmd (@cmdlist) {
1765 cmd_$cmd.so: cmd_$cmd.cpp ../../include/base.h ../../include/modules.h ../../include/inspircd.h ../../include/channels.h ../../include/users.h ../../include/inspircd_config.h ../../include/commands/cmd_$cmd.h
1766 \$(RUNCC) \$(FLAGS) $SHARED -o cmd_$cmd.so cmd_$cmd.cpp
1772 # Routine to list out the extra/ modules that have been enabled.
1773 # Note: when getting any filenames out and comparing, it's important to lc it if the
1774 # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
1775 # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
1776 # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
1777 sub list_extras () {
1780 my $srcdir = File::Spec->catdir("src", "modules");
1781 my $abs_srcdir = File::Spec->rel2abs($srcdir);
1784 opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
1785 my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
1788 opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
1789 my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
1792 my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
1794 EXTRA: for my $extra (@extras) {
1795 next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
1796 next if ($extra eq '.svn');
1797 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
1798 my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
1799 next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
1800 if (-l $abs_source) {
1801 # Symlink, is it in the right place?
1802 my $targ = readlink($abs_source);
1803 my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
1804 if ($abs_targ eq $abs_extra) {
1805 $extras{$extra} = "\e[32;1menabled\e[0m";
1807 $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
1809 } elsif (-e $abs_source) {
1810 my ($devext, $inoext) = stat($abs_extra);
1811 my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
1813 if ($devsrc == $devext && $inosrc == $inoext) {
1814 $extras{$extra} = "\e[32;1menabled\e[0m";
1816 $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
1819 open my $extfd, "<", $abs_extra;
1820 open my $srcfd, "<", $abs_source;
1822 if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
1823 $extras{$extra} = "\e[32;1menabled\e[0m";
1825 $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
1829 $extras{$extra} = "\e[33;1mdisabled\e[0m";
1832 # Now let's add dependency info
1833 for my $extra (keys(%extras)) {
1834 next unless $extras{$extra} =~ m/enabled/; # only process enabled extras.
1835 my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
1836 my @deps = split / +/, getdependencies($abs_extra);
1837 for my $dep (@deps) {
1838 if (exists($extras{$dep})) {
1839 my $ref = \$extras{$dep}; # Take reference.
1840 if ($$ref !~ m/needed by/) {
1841 # First dependency found.
1842 if ($$ref =~ m/enabled/) {
1843 $$ref .= " (needed by \e[32;1m$extra\e[0m";
1845 $$ref =~ s/\e\[.*?m//g; # Strip out previous coloring. Will be set in bold+red+blink later.
1846 $$ref .= " (needed by \e[0;32;1;5m$extra\e[0;31;1;5m";
1849 if ($$ref =~ m/enabled/) {
1850 $$ref .= ", \e[32;1m$extra\e[0m";
1852 $$ref .= ", \e[0;32;1;5m$extra\e[0;31;1;5m";
1858 for my $extra (sort {$a cmp $b} keys(%extras)) {
1859 my $text = $extras{$extra};
1860 if ($text =~ m/needed by/ && $text !~ m/enabled/) {
1861 printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
1863 printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
1866 return keys(%extras) if wantarray; # Can be used by manage_extras.
1869 sub enable_extras (@) {
1871 for my $extra (@extras) {
1872 my $extrapath = "src/modules/extra/$extra";
1873 if (!-e $extrapath) {
1874 print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in src/modules/extra\n";
1877 my $source = "src/modules/$extra";
1879 print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in src/modules exists (might already be enabled?)\n";
1882 # Get dependencies, and add them to be processed.
1883 my @deps = split / +/, getdependencies($extrapath);
1884 for my $dep (@deps) {
1885 next if scalar(grep { $_ eq $dep } (@extras)) > 0; # Skip if we're going to be enabling it anyway.
1886 if (!-e "src/modules/$dep") {
1887 if (-e "src/modules/extra/$dep") {
1888 print STDERR "Will also enable extra \e[32;1m$dep\e[0m (needed by \e[32;1m$extra\e[0m)\n";
1891 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";
1895 print "Enabling $extra ... \n";
1896 symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
1900 sub disable_extras (@)
1902 opendir my $dd, "src/modules/extra/";
1903 my @files = readdir($dd);
1906 EXTRA: for my $extra (@extras) {
1907 my $extrapath = "src/modules/extra/$extra";
1908 my $source = "src/modules/$extra";
1909 if (!-e $extrapath) {
1910 print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
1913 if ((! -l $source) || readlink($source) ne "extra/$extra") {
1914 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";
1917 # Check if anything needs this.
1918 for my $file (@files) {
1919 my @deps = split / +/, getdependencies("src/modules/extra/$file");
1920 # File depends on this extra...
1921 if (scalar(grep { $_ eq $extra } @deps) > 0) {
1922 # And is both enabled and not about to be disabled.
1923 if (-e "src/modules/$file" && scalar(grep { $_ eq $file } @extras) < 1) {
1924 print STDERR "Cannot disable \e[32;1m$extra\e[0m : is needed by \e[32;1m$file\e[0m\n";
1930 print "Disabling $extra ... \n";
1931 unlink "src/modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";