]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
Comments
[user/henk/code/inspircd.git] / configure
1 #!/usr/bin/perl
2
3 # InspIRCd Configuration Script
4 #
5 # Copyright 2003 The ChatSpike Development Team
6 # <brain@chatspike.net>
7 # <Craig@chatspike.net>
8 #
9 # [14:21] Brain: <matrix impression> i know perl-fu!
10 #
11 # $Id$
12 #
13 ########################################
14
15 chomp($topdir = `pwd`);
16 $this = resolve_directory($topdir);                                             # PWD, Regardless.
17 @modlist = ();                                                                  # Declare for Module List..
18 %config = ();                                                                   # Initiate Configuration Hash..
19 $config{ME}                 = resolve_directory($topdir);                       # Present Working Directory
20 $config{BASE_DIR}           = $config{ME};                                      # Use CWD as 'Base' Directory.
21 $config{CONFIG_DIR}         = resolve_directory($config{ME}."/conf");           # Configuration Directory
22 $config{MODULE_DIR}         = resolve_directory($config{ME}."/modules");        # Modules Directory
23 $config{BINARY_DIR}         = resolve_directory($config{ME}."/bin");            # Binary Directory
24 $config{LIBRARY_DIR}        = resolve_directory($config{ME}."/lib");            # Library Directory
25 chomp($config{HAS_GNUTLS}   = `libgnutls-config --version 2>/dev/null | cut -c 1,2,3`); # GNUTLS Version.
26 chomp($config{HAS_OPENSSL}  = `openssl version 2>/dev/null`);                   # Openssl version
27 $config{USE_GNUTLS}         = "n";                                              # Use gnutls.
28 $config{USE_OPENSSL}        = "n";                                              # Use openssl.
29 $config{OPTIMITEMP}         = "0";                                              # Default Optimisation Value
30 $config{OPTIMISATI}         = "-g";                                             # Optimisation Flag
31 $config{NICK_LENGT}         = "31";                                             # Default Nick Length
32 $config{CHAN_LENGT}         = "64";                                             # Default Channel Name Length
33 $config{MAX_CHANNE}         = "20";                                             # Default Max. Channels per user
34 $config{MAX_OPERCH}         = "60";                                             # Default Max. Channels per oper
35 $config{MAXI_MODES}         = "20";                                             # Default Max. Number of Modes set at once.
36 $config{HAS_STRLCPY}        = "false";                                          # strlcpy Check.
37 $config{HAS_STDINT}         = "false";                                          # stdint.h check
38 $config{HAS_EXECINFO}       = "0";                                              # execinfo.h Check.
39 $config{USE_KQUEUE}         = "y";                                              # kqueue enabled
40 $config{USE_EPOLL}          = "y";                                              # epoll enabled
41 $config{THREADED_DNS}       = "n";                                              # threaded dns
42 $config{IPV6}               = "n";                                              # IPv6 support (experimental)
43 $config{SUPPORT_IP6LINKS}   = "y";                                              # IPv4 supporting IPv6 links (experimental)
44 $config{STATIC_LINK}        = "no";                                             # are doing static modules?
45 chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`);                           # FD Limit
46 chomp($config{MAX_DESCRIPTORS} = `sh -c \"ulimit -n\"`);                        # Hard FD Limit
47 chomp($config{GCCVER}       = `g++ -dumpversion | cut -c 1`);                   # Major GCC Version
48 chomp($config{OSNAME}       = `/bin/uname`);                                    # Operating System Name
49 $config{CC}                 = "g++";                                            # C++ compiler
50 $config{MAKEORDER}          = "ircd mods";                                      # build order
51 $config{STATICLIBS}         = "";                                               # library archive path
52 $config{MAX_IDENT}          = "12";                                             # max ident size
53 $config{MAX_QUIT}           = "255";                                            # max quit message size
54 $config{MAX_TOPIC}          = "307";                                            # max topic size
55 $config{MAX_KICK}           = "255";                                            # max kick message size
56 $config{MAX_GECOS}          = "128";                                            # max GECOS size
57 $config{MAX_AWAY}           = "200";                                            # max AWAY size
58
59 $no_svn = 0;
60
61 $config{HAS_OPENSSL} =~ /OpenSSL (\S+) \d+ \S+ \d{4}/;
62 $config{HAS_OPENSSL} = $1;
63
64 if ($config{GCCVER} eq "") {
65         print "g++ was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";
66         exit;
67 }
68
69 # Minihack! Convert Cygwin to 'Cyg-Static' so i can
70 # Keep my dynamic module experiments here for later
71 # concideration!
72
73 if ($config{OSNAME} =~ /CYGWIN/) {
74         $config{OSNAME} = "CYG-STATIC";
75 }
76
77 if ((!$config{OSNAME}) || ($config{OSNAME} eq "")) {
78         chomp($config{OSNAME} = `/usr/bin/uname`);
79         if ((!$config{OSNAME}) || ($config{OSNAME} eq "")){
80                 $config{OSNAME} = "Unknown";
81         }
82 }
83
84 if (!$config{MAX_CLIENT_T}) { 
85         $config{MAX_CLIENT_T} = 1024;                                 # Set a reasonable 'Default'
86         $fd_scan_fail = "true";                                       # Used Later
87 }
88
89 # Get and Set some important vars..
90 getmodules();
91
92 my $arg = $ARGV[0];                                             # Do Some Argument Checks..
93 if ($arg eq "-clean") {
94         system("rm -rf .config.cache");
95 }               # Remove the config.cache file.
96
97 if ($arg eq "-update") {
98         # Does the cache file exist?
99         if (!getcache()) {
100                 # No, No it doesn't.. *BASH*
101                 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
102                 exit 0;
103         } else {
104                 # We've Loaded the cache file and all our variables..
105                 print "Updating Files..\n";
106                 getosflags();
107                 $has_epoll = $config{HAS_EPOLL};
108                 $has_kqueue = $config{HAS_KQUEUE};
109                 writefiles(1);
110                 print "Complete.\n";
111                 exit;
112         }
113 }
114
115 if ($arg eq "-modupdate") {
116         # Does the cache file exist?
117         if (!getcache()) {
118                 # No, No it doesn't.. *BASH*
119                 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
120                 exit 0;
121         } else {
122                 # We've Loaded the cache file and all our variables..
123                 print "Updating Files..\n";
124                 getosflags();
125                 $has_epoll = $config{HAS_EPOLL};
126                 $has_kqueue = $config{HAS_KQUEUE};
127                 writefiles(0);
128                 print "Complete.\n";
129                 exit;
130         }
131 }
132
133
134
135 if ($arg eq "-svnupdate") {
136         my $fail = 0;
137         open(FH,"<.svn/entries") or $fail = 1;
138         if ($fail) {
139                 print "This is not an SVN copy of InspIRCd.\n";
140                 exit;
141         }
142         system("svn update");
143         system("perl configure -update");
144         if ($ARGV[1] eq "rebuild") {
145                 system("make install");
146         }
147         exit;
148 }
149
150 print "Checking for cache from previous configure...\n";
151 getcache();
152 print "Checking operating system version...\n";
153 getosflags();
154
155 if (!$config{MAX_CLIENT}) { 
156         # If the cache hasn't set the max clients, copy the variable of MAX_CLIENT_T, this
157         # allows us to keep _T for testing purposes. (ie. "Are you sure you want to go
158         # higher than the found value" :))
159         $config{MAX_CLIENT} = $config{MAX_CLIENT_T};
160 }
161
162 printf "Checking if stdint.h exists... ";
163 $config{HAS_STDINT} = "true";
164 my $fail = 0;
165 open(STDINT, "</usr/include/stdint.h") or $config{HAS_STDINT} = "false";
166 if ($config{HAS_STDINT} eq "true") {
167         close(STDINT);
168 }
169 print "yes\n" if $config{HAS_STDINT} eq "true";
170 print "no\n" if $config{HAS_STDINT} eq "false";
171
172
173 printf "Checking if strlcpy exists... ";
174 # Perform the strlcpy() test..
175 $config{HAS_STRLCPY} = "false";
176 my $fail = 0;
177 open(STRLCPY, "</usr/include/string.h") or $fail = 1;
178 if (!$fail) {
179         while (chomp($line = <STRLCPY>)) {
180                 # try and find the delcaration of:
181                 # size_t strlcpy(...)
182                 if ($line =~ /size_t(\0x9|\s)+strlcpy/) {
183                         $config{HAS_STRLCPY} = "true";
184                 }
185         }
186         close(STRLCPY);
187 }
188 print "yes\n" if $config{HAS_STRLCPY} eq "true";
189 print "no\n" if $config{HAS_STRLCPY} eq "false";
190
191 printf "Checking if execinfo.h exists... ";
192 $config{HAS_EXECINFO} = "0";
193 my $fail = 0;
194 open(EXECINFO, "</usr/include/execinfo.h") or $fail = 1;
195 if ($fail) {
196         $fail = 0;
197         open(EXECINFO, "</usr/local/include/execinfo.h") or $fail = 1;
198         if (!$fail) {
199                 printf "/usr/local/include/execinfo.h\n";
200                 $config{HAS_EXECINFO} = "1";
201                 close(EXECINFO);
202         }
203         else {
204                 printf "Not found!\n";
205         }
206 }
207 else {
208         printf "/usr/include/execinfo.h\n";
209         $config{HAS_EXECINFO} = "1";
210         close(EXECINFO);
211 }
212
213 printf "Checking if kqueue exists... ";
214 $has_kqueue = 0;
215 $fail = 0;
216 open(KQUEUE, "</usr/include/sys/event.h") or $fail = 1;
217 if (!$fail) {
218         while (chomp($line = <KQUEUE>)) {
219                 # try and find the delcaration of:
220                 # int kqueue(void);
221                 if ($line =~ /int(\0x9|\s)+kqueue/) {
222                         $has_kqueue = 1;
223                 }
224         }
225         close(KQUEUE);
226 }
227 print "yes\n" if $has_kqueue == 1;
228 print "no\n" if $has_kqueue == 0;
229
230 printf "Checking if epoll exists... ";
231 $has_epoll = 0;
232 $fail = 0;
233 open(EPOLL, "</usr/include/sys/epoll.h") or $fail = 1;
234 if (!$fail) {
235         $has_epoll = 1;
236         close(EPOLL);
237 }
238 if ($has_epoll) {
239         my $kernel = `uname -r`;
240         chomp($kernel);
241         if (($kernel =~ /2\.0/) || ($kernel =~ /2\.2/) || ($kernel =~ /2\.4/)) {
242                 $has_epoll = 0;
243         }
244 }
245 print "yes\n" if $has_epoll == 1;
246 print "no\n" if $has_epoll == 0;
247
248 if (($config{OSNAME} =~ /CYGWIN/) || ($config{OSNAME} eq "CYG-STATIC")) {
249         $config{HAS_STRLCPY} = "true";
250 }
251
252 $config{HAS_EPOLL} = $has_epoll;
253 $config{HAS_KQUEUE} = $has_kqueue; 
254
255 printf "Checking for libgnutls... ";
256 if (($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS} >= 1.2) || ($config{HAS_GNUTLS} eq "y"))) {
257         print "yes\n";
258         $config{HAS_GNUTLS} = "y";
259 } else {
260         print "no\n";
261         $config{HAS_GNUTLS} = "n";
262 }
263
264 printf "Checking for openssl... ";
265 if (($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL} >= 0.8) || ($config{HAS_OPENSSL} eq "y"))) {
266         print "yes\n";
267         $config{HAS_OPENSSL} = "y";
268 } else {
269         print "no\n";
270         $config{HAS_OPENSSL} = "n";
271 }
272
273 ################################################################################
274 #                          BEGIN INTERACTIVE PART                              #
275 ################################################################################
276
277 # Clear the Screen..
278 system("clear");
279 # Display Splash Logo..
280 show_splash();
281 chomp($wholeos = `uname -mnr`);
282
283 my $rev = getrevision();
284 # Display Introduction Message..
285 print "
286 Welcome to the InspIRCd Configuration program!
287
288 *** If you are unsure of any of these values, leave it blank for    ***
289 *** standard settings that will work, and your server will run      ***
290 *** using them. If you are running this server as part of a         ***
291 *** larger network, you must consult with your network admins       ***
292 *** for the proper values to use, or server links will be unstable! ***
293
294 Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter
295 a new value. Please note: You will \033[1mHAVE\033[0m to read the docs
296 dir, otherwise you won't have a config file!
297
298 Your operating system is: \033[1;32m$config{OSNAME}\033[0m ($wholeos), fdmax: $config{MAX_CLIENT_T}
299 Your InspIRCd revision ID is \033[1;32mr$rev\033[0m";
300 if ($rev eq "r0") {
301         print " (Non-SVN build)";
302 }
303 print ".\n\n";
304
305 $config{CHANGE_COMPILER} = "n";
306 print "I have detected the following compiler: \033[1;32m$config{CC}\033[0m (version \033[1;32m$config{GCCVER}.x\033[0m)\n";
307
308 while (($config{GCCVER} < 3) || ($config{GCCVER} eq "")) {
309         print "\033[1;32mIMPORTANT!\033[0m A GCC 2.x compiler has been detected, and
310 should NOT be used. You should probably specify a newer compiler.\n\n";
311         yesno(CHANGE_COMPILER,"Do you want to change the compiler?");
312         if ($config{CHANGE_COMPILER} =~ /y/i) {
313                 print "What command do you want to use to invoke your compiler?\n";
314                 print "[\033[1;32m$config{CC}\033[0m] -> ";
315                 chomp($config{CC} = <STDIN>);
316                 if ($config{CC} eq "") {
317                         $config{CC} = "g++";
318                 }
319                 chomp($foo = `$config{CC} -dumpversion | cut -c 1`);
320                 if ($foo ne "") {
321                         chomp($config{GCCVER}       = `$config{CC} -dumpversion | cut -c 1`); # we must redo these if we change compilers
322                         print "Queried compiler: \033[1;32m$config{CC}\033[0m (version \033[1;32m$config{GCCVER}.x\033[0m)\n";
323                         if ($config{GCCVER} < 3) {
324                                 print "\033[1;32mGCC 2.x WILL NOT WORK!\033[0m. Let's try that again, shall we?\n";
325                         }
326                 }
327                 else {
328                         print "\033[1;32mWARNING!\033[0m Could not execute the compiler you specified. You may want to try again.\n";
329                 }
330         }
331 }
332
333 print "\n";
334
335 # Directory Settings..
336 my $tmpbase = $config{BASE_DIR};
337 dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
338 if ($tmpbase ne $config{BASE_DIR}) {
339         $config{CONFIG_DIR}         = resolve_directory($config{BASE_DIR}."/conf");           # Configuration Directory
340         $config{MODULE_DIR}         = resolve_directory($config{BASE_DIR}."/modules");        # Modules Directory
341         $config{BINARY_DIR}         = resolve_directory($config{BASE_DIR}."/bin");            # Binary Directory
342         $config{LIBRARY_DIR}        = resolve_directory($config{BASE_DIR}."/lib");            # Library Directory
343 }
344
345 dir_check("are the configuration files", "CONFIG_DIR");
346 dir_check("are the modules to be compiled to", "MODULE_DIR");
347 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
348 dir_check("are the IRCd libraries to be placed", "LIBRARY_DIR");
349
350 if ($has_kqueue) {
351         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?");
352         print "\n";
353 }
354 if ($has_epoll) {
355         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?");
356         print "\n";
357 }
358 $chose_hiperf = (($config{USE_EPOLL} eq "y") || ($config{USE_KQUEUE} eq "y"));
359 if (!$chose_hiperf) {
360         print "No high-performance socket engines are available, or you chose\n";
361         print "not to enable one. Defaulting to select() engine.\n\n";
362 }
363
364 yesno(IPV6,"Would you like to build InspIRCd with IPv6 support?");
365 print "\n";
366
367 if ($config{IPV6} eq "y") {
368         print "You have chosen to build an \033[1;32mIPV6-only\033[0m server.\nTo accept IPV4 users, you must use the '::ffff:' notation of addresses.\n\n";
369         $config{SUPPORT_IP6LINKS} = "y";
370 } else {
371         yesno(SUPPORT_IP6LINKS,"You have chosen to build an \033[1;32mIPV4-only\033[0m server.\nWould you like to enable support for linking to IPV6-enabled\nInspIRCd servers which are using '::ffff:' notation?\nIf you are using a recent operating\nsystem and are unsure, answer yes.");
372         print "\n";
373 }
374
375 if (($config{HAS_GNUTLS} eq "y") && ($config{HAS_OPENSSL} eq "y")) {
376         print "I have detected both GnuTLS and OpenSSL on your system.\n";
377         print "I will default to GnuTLS. If you wish to use OpenSSL\n";
378         print "instead, you should enable the OpenSSL module yourself\n";
379         print "by copying it from src/modules/extra to src/modules.\n\n";
380 }
381
382 if ($config{HAS_GNUTLS} eq "y") {
383         yesno(USE_GNUTLS, "Would you like to enable SSL Support?");
384         if ($config{USE_GNUTLS} eq "y") {
385                 print "\nUsing GnuTLS SSL module.\n";
386         }
387 } elsif ($config{HAS_OPENSSL} eq "y") {
388         yesno(USE_OPENSSL, "Would you like to enable SSL Support?");
389         if ($config{USE_OPENSSL} eq "y") {
390                 print "\nUsing OpenSSL SSL module.\nYou will get better performance if you move to GnuTLS in the future.\n";
391         }
392 }
393
394 print "\nThe following questions will ask you for various figures relating\n";
395 print "To your IRCd install. Please note that these should usually be left\n";
396 print "as defaults unless you have a real reason to change them. If they\n";
397 print "changed, then the values must be identical on all servers on your\n";
398 print "network, or malfunctions and/or crashes may occur, with the exception\n";
399 print "of the 'maximum number of clients' setting which may be different on\n";
400 print "different servers on the network.\n\n";
401
402 # File Descriptor Settings..
403 my $continue = 0;
404 while (!$continue) {
405         print "Maximum number of clients at any one time ($config{MAX_CLIENT_T})\n";
406         print "[\033[1;32m$config{MAX_CLIENT}\033[0m] -> ";
407         chomp($var = <STDIN>);
408         if ($var eq "") {
409                 $var = $config{MAX_CLIENT};
410         }
411         if ($var =~ /^\d+$/) {
412                 if (($var > $config{MAX_CLIENT_T}) && ($fd_scan_failed ne true)) {
413                         # Client has entered a larger number than the 'discovered' value
414                         # Confirm.
415                         print "WARNING: Our scans have indicated that you are attempting
416 to use more sockets than there are avaliable. Are you sure
417 you wish to do this? It may cause the IRCd to malfunction [y/n]
418 [\033[1;32mn\033[0m] -> $c";
419                         chomp($tmp = <STDIN>);
420                         if ($tmp ne "y") {
421                                 print "Please enter the correct value.\n\n";
422                                 next;
423                         }
424                 }
425         } else {
426                 print "You must enter a number in this field. Please try again.\n\n";
427                 next;
428         }
429         # If we get here, we should be good to go.
430         $config{MAX_CLIENT} = $var;
431         $continue = 1;
432         print "\n";
433 }
434
435 my $continue = 0;
436 while (!$continue) {
437         print "What is the maximum length of nicknames?\n";
438         print "[\033[1;32m$config{NICK_LENGT}\033[0m] -> ";
439         chomp($var = <STDIN>);
440         if ($var eq "") {
441                 $var = $config{NICK_LENGT};
442         }
443         if ($var =~ /^\d+$/) {
444                 # We don't care what the number is, set it and be on our way.
445                 $config{NICK_LENGT} = $var;
446                 $continue = 1;
447                 print "\n";
448         } else {
449                 print "You must enter a number in this field. Please try again.\n\n";
450         }
451 }
452
453 $continue = 0;
454 while (!$continue) {
455         print "What is the maximum length of channel names?\n";
456         print "[\033[1;32m$config{CHAN_LENGT}\033[0m] -> ";
457         chomp($var = <STDIN>);
458         if ($var eq "") {
459                 $var = $config{CHAN_LENGT};
460         }
461         if ($var =~ /^\d+$/) {
462                 # We don't care what the number is, set it and be on our way.
463                 $config{CHAN_LENGT} = $var;
464                 $continue = 1;
465                 print "\n";
466         } else {
467                 print "You must enter a number in this field. Please try again.\n\n";
468         }
469 }
470
471 $continue = 0;
472 while (!$continue) {
473         print "What is the maximum number of channels a normal user may join at any one time?\n";
474         print "[\033[1;32m$config{MAX_CHANNE}\033[0m] -> ";
475         chomp($var = <STDIN>);
476         if ($var eq "") {
477                 $var = $config{MAX_CHANNE};
478         }
479         if ($var =~ /^\d+$/) {
480                 # We don't care what the number is, set it and be on our way.
481                 $config{MAX_CHANNE} = $var;
482                 $continue = 1;
483                 print "\n";
484         } else {
485                 print "You must enter a number in this field. Please try again.\n\n";
486         }
487 }
488
489 $continue = 0;
490 while (!$continue) {
491         print "What is the maximum number of channels an oper may join at any one time?\n";
492         print "[\033[1;32m$config{MAX_OPERCH}\033[0m] -> ";
493         chomp($var = <STDIN>);
494         if ($var eq "") {
495                 $var = $config{MAX_OPERCH};
496         }
497         if ($var =~ /^\d+$/) {
498                 # We don't care what the number is, set it and be on our way.
499                 $config{MAX_OPERCH} = $var;
500                 $continue = 1;
501                 print "\n";
502         }
503 }
504
505 $continue = 0;
506 while (!$continue) {
507         print "What is the maximum number of mode changes in one line?\n";
508         print "[\033[1;32m$config{MAXI_MODES}\033[0m] -> ";
509         chomp($var = <STDIN>);
510         if ($var eq "") {
511                 $var = $config{MAXI_MODES};
512         }
513         if ($var =~ /^\d+$/) {
514                 # We don't care what the number is, set it and be on our way.
515                 $config{MAXI_MODES} = $var;
516                 $continue = 1;
517                 print "\n";
518         } else {
519                 print "You must enter a number in this field. Please try again.\n\n";
520         }
521 }
522
523 $continue = 0;
524 while (!$continue) {
525         print "What is the maximum length of an ident (username)?\n";
526         print "[\033[1;32m$config{MAX_IDENT}\033[0m] -> ";
527         chomp($var = <STDIN>);
528         if ($var eq "") {
529                 $var = $config{MAX_IDENT};
530         }
531         if ($var =~ /^\d+$/) {
532                 # We don't care what the number is, set it and be on our way.
533                 $config{MAX_IDENT} = $var;
534                 $continue = 1;
535                 print "\n";
536         } else {
537                 print "You must enter a number in this field. Please try again.\n\n";
538         }
539 }
540
541 $continue = 0;
542 while (!$continue) {
543         print "What is the maximum length of a quit message?\n";
544         print "[\033[1;32m$config{MAX_QUIT}\033[0m] -> ";
545         chomp($var = <STDIN>);
546         if ($var eq "") {
547                 $var = $config{MAX_QUIT};
548         }
549         if ($var =~ /^\d+$/) {
550                 # We don't care what the number is, set it and be on our way.
551                 $config{MAX_QUIT} = $var;
552                 $continue = 1;
553                 print "\n";
554         } else {
555                 print "You must enter a number in this field. Please try again.\n\n";
556         }
557 }
558
559 $continue = 0;
560 while (!$continue) {
561         print "What is the maximum length of a channel topic?\n";
562         print "[\033[1;32m$config{MAX_TOPIC}\033[0m] -> ";
563         chomp($var = <STDIN>);
564         if ($var eq "") {
565                 $var = $config{MAX_TOPIC};
566         }
567         if ($var =~ /^\d+$/) {
568                 # We don't care what the number is, set it and be on our way.
569                 $config{MAX_TOPIC} = $var;
570                 $continue = 1;
571                 print "\n";
572         } else {
573                 print "You must enter a number in this field. Please try again.\n\n";
574         }
575 }
576
577 $continue = 0;
578 while (!$continue) {
579         print "What is the maximum length of a kick message?\n";
580         print "[\033[1;32m$config{MAX_KICK}\033[0m] -> ";
581         chomp($var = <STDIN>);
582         if ($var eq "") {
583                 $var = $config{MAX_KICK};
584         }
585         if ($var =~ /^\d+$/) {
586                 # We don't care what the number is, set it and be on our way.
587                 $config{MAX_KICK} = $var;
588                 $continue = 1;
589                 print "\n";
590         } else {
591                 print "You must enter a number in this field. Please try again.\n\n";
592         }
593 }
594
595 $continue = 0;
596 while (!$continue) {
597         print "What is the maximum length of a GECOS (real name) field?\n";
598         print "[\033[1;32m$config{MAX_GECOS}\033[0m] -> ";
599         chomp($var = <STDIN>);
600         if ($var eq "") {
601                 $var = $config{MAX_GECOS};
602         }
603         if ($var =~ /^\d+$/) {
604                 # We don't care what the number is, set it and be on our way.
605                 $config{MAX_GECOS} = $var;
606                 $continue = 1;
607                 print "\n";
608         } else {
609                 print "You must enter a number in this field. Please try again.\n\n";
610         }
611 }
612
613 $continue = 0;
614 while (!$continue) {
615         print "What is the maximum length of an away message?\n";
616         print "[\033[1;32m$config{MAX_AWAY}\033[0m] -> ";
617         chomp($var = <STDIN>);
618         if ($var eq "") {
619                 $var = $config{MAX_AWAY};
620         }
621         if ($var =~ /^\d+$/) {
622                 # We don't care what the number is, set it and be on our way.
623                 $config{MAX_AWAY} = $var;
624                 $continue = 1;
625                 print "\n";
626         } else {
627                 print "You must enter a number in this field. Please try again.\n\n";
628         }
629 }
630
631 # Code Optimisation
632 print "Enter the Level Of Binary optimisation. This is a number between 0 and 3.
633 The InspIRCd Team will NOT support any bug reports above 0. Also note,
634 the IRCd behaviour will be different depending on this value. Please
635 read the documentation for more information.
636
637 The higher the number, the more optimised your binary will be. This
638 value will default to 0 if you either don't enter a number, or enter
639 a value outside the range.
640
641 As always, if you are unsure, just press enter and accept the default.\n\n";
642 print "[\033[1;32m$config{OPTIMITEMP}\033[0m] -> ";
643 chomp($var = <STDIN>);
644 if ($var eq "") {
645         $var = $config{OPTIMITEMP};
646 }
647
648 if ($var eq "1") {
649         $config{OPTIMITEMP} = 1;
650         $config{OPTIMISATI} = "-O";
651 } elsif ($var eq "2") {
652         $config{OPTIMITEMP} = 2;
653         $config{OPTIMISATI} = "-O2";
654 } elsif ($var eq "3") {
655         $config{OPTIMITEMP} = 3;
656         $config{OPTIMISATI} = "-O3";
657 } else {
658         $config{OPTIMITEMP} = 0;
659         $config{OPTIMISATI} = "-g";
660 }
661
662 print "\n\033[1;32mPre-build configuration is complete!\033[0m\n\n";
663 print "\033[0mBase install path:\033[1;32m\t\t$config{BASE_DIR}\033[0m\n";
664 print "\033[0mConfig path:\033[1;32m\t\t\t$config{CONFIG_DIR}\033[0m\n";
665 print "\033[0mModule path:\033[1;32m\t\t\t$config{MODULE_DIR}\033[0m\n";
666 print "\033[0mLibrary path:\033[1;32m\t\t\t$config{LIBRARY_DIR}\033[0m\n";
667 print "\033[0mMax connections:\033[1;32m\t\t$config{MAX_CLIENT}\033[0m\n";
668 print "\033[0mMax User Channels:\033[1;32m\t\t$config{MAX_CHANNE}\033[0m\n";
669 print "\033[0mMax Oper Channels:\033[1;32m\t\t$config{MAX_OPERCH}\033[0m\n";
670 print "\033[0mMax nickname length:\033[1;32m\t\t$config{NICK_LENGT}\033[0m\n";
671 print "\033[0mMax channel length:\033[1;32m\t\t$config{CHAN_LENGT}\033[0m\n";
672 print "\033[0mMax mode length:\033[1;32m\t\t$config{MAXI_MODES}\033[0m\n";
673 print "\033[0mMax ident length:\033[1;32m\t\t$config{MAX_IDENT}\033[0m\n";
674 print "\033[0mMax quit length:\033[1;32m\t\t$config{MAX_QUIT}\033[0m\n";
675 print "\033[0mMax topic length:\033[1;32m\t\t$config{MAX_TOPIC}\033[0m\n";
676 print "\033[0mMax kick length:\033[1;32m\t\t$config{MAX_KICK}\033[0m\n";
677 print "\033[0mMax name length:\033[1;32m\t\t$config{MAX_GECOS}\033[0m\n";
678 print "\033[0mMax away length:\033[1;32m\t\t$config{MAX_AWAY}\033[0m\n";
679 print "\033[0mGCC Version Found:\033[1;32m\t\t$config{GCCVER}.x\033[0m\n";
680 print "\033[0mOptimization Flag:\033[1;32m\t\t$config{OPTIMISATI}\033[0m\n";
681 print "\033[0mCompiler program:\033[1;32m\t\t$config{CC}\033[0m\n";
682 print "\033[0mStatic modules:\033[1;32m\t\t\t$config{STATIC_LINK}\033[0m\n";
683 print "\033[0mMultithread DNS:\033[1;32m\t\t$config{THREADED_DNS}\033[0m\n";
684 print "\033[0mIPv6 Support:\033[1;32m\t\t\t$config{IPV6}\033[0m\n";
685 print "\033[0mIPv6 to IPv4 Links:\033[1;32m\t\t$config{SUPPORT_IP6LINKS}\033[0m\n";
686 print "\033[0mGnuTLS Support:\033[1;32m\t\t\t$config{USE_GNUTLS}\033[0m\n";
687 print "\033[0mOpenSSL Support:\033[1;32m\t\t$config{USE_OPENSSL}\033[0m\n\n";
688
689 if ($config{USE_GNUTLS} eq "y") {
690         $failed = 0;
691         open(TMP, "<src/modules/m_ssl_gnutls.cpp") or $failed = 1;
692         close(TMP);
693         if ($failed) {
694                 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
695                 chdir("src/modules");
696                 system("ln -s extra/m_ssl_gnutls.cpp");
697                 chdir("../..");
698         }
699         getmodules();
700         $failed = 0;
701         open(TMP, "<$config{CONFIG_DIR}/key.pem") or $failed = 1;
702         close(TMP);
703         open(TMP, "<$config{CONFIG_DIR}/cert.pem") or $failed = 1;
704         close(TMP);
705         if ($failed) {
706                 print "SSL Certificates Not found, Generating.. \n\n
707 *************************************************************
708 * Generating the Private Key may take some time, go grab a  *
709 * Coffee. Even better, to generate some more entropy if it  *
710 * is taking a while, open another console and type du / a   *
711 * few times and get that HD going :) Then answer the        *
712 * Questions which follow. If you are unsure, just hit enter *
713 *************************************************************\n\n";
714                 system("certtool --generate-privkey --outfile key.pem");
715                 system("certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem");
716                 print "\nCertificate generation complete, copying to config directory... ";
717                 system("mv key.pem $config{CONFIG_DIR}/key.pem");
718                 system("mv cert.pem $config{CONFIG_DIR}/cert.pem");
719                 print "Done.\n\n";
720         } else {
721                 print "SSL Certificates found, skipping.\n\n"
722         }       
723 } elsif ($config{USE_OPENSSL} eq "y") {
724         $failed = 0;
725         open(TMP, "<src/modules/m_ssl_openssl.cpp") or $failed = 1;
726         close(TMP);
727         if ($failed) {
728                 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
729                 chdir("src/modules");
730                 system("ln -s extra/m_ssl_openssl.cpp");
731                 chdir("../..");
732         }
733         getmodules();
734         $failed = 0;
735         open(TMP, "<$config{CONFIG_DIR}/key.pem") or $failed = 1;
736         close(TMP);
737         open(TMP, "<$config{CONFIG_DIR}/cert.pem") or $failed = 1;
738         close(TMP);
739         if ($failed) {
740                 print "SSL Certificates Not found, Generating.. \n\n
741 *************************************************************
742 * Generating the certificates may take some time, go grab a *
743 * coffee, or something.                                     *
744 *************************************************************\n\n";
745                 system("openssl req -x509 -nodes -newkey rsa:1024 -keyout key.pem -out cert.pem");
746                 system("openssl dhparam -out dhparams.pem 1024");
747                 print "\nCertificate generation complete, copying to config directory... ";
748                 system("mv key.pem $config{CONFIG_DIR}/key.pem");
749                 system("mv cert.pem $config{CONFIG_DIR}/cert.pem");
750                 system("mv dhparams.pem $config{CONFIG_DIR}/dhparams.pem");
751                 print "Done.\n\n";
752         } else {
753                 print "SSL Certificates found, skipping.\n\n"
754         }
755 }
756 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
757         print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
758 }
759
760 getosflags();
761 makecache();
762 writefiles(1);
763
764 print "\n\n";
765 print "To build your server with these settings, please type '\033[1;32m$config{MAKEPROG}\033[0m' now.\n";
766 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
767         print "Please remember that to enable \033[1;32mSSL support\033[0m you must\n";
768         print "load the required modules in your config. This configure process\n";
769         print "has just prepared these modules to be compiled for you, and has not\n";
770         print "configured them to be compiled into the core of the ircd.\n";
771 }
772 print "*** \033[1;32mRemember to edit your configuration files!!!\033[0m ***\n\n\n";
773 if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) {
774         print "\033[1;32mWARNING!\033[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";
775 }
776
777 if ($config{GCCVER} < "3") {
778         print <<FOO2;
779 \033[1;32mWARNING!\033[0m You are attempting to compile InspIRCd on GCC 2.x!
780 GCC 2.x series compilers only had partial (read as broken) C++ support, and
781 your compile will most likely fail horribly! If you have any problems, do NOT
782 report them to the bugtracker or forums without first upgrading your compiler
783 to a newer 3.x or 4.x (or whatever is available currently) version.
784 FOO2
785 }
786
787 ################################################################################
788 #                              HELPER FUNCTIONS                                #
789 ################################################################################
790 sub getcache {
791         # Retrieves the .config.cache file, and loads values into the main config hash.
792         open(CACHE, ".config.cache") or return undef;
793         while (<CACHE>) {
794                 chomp;
795                 # Ignore Blank lines, and comments..
796                 next if /^\s*$/;
797                 next if /^\s*#/;
798                 my ($key, $value) = split("=", $_);
799                 $value =~ /^\"(.*)\"$/;
800                 # Do something with data here!
801                 $config{$key} = $1;
802         }
803         close(CONFIG);
804         return "true";
805 }
806
807 sub makecache {
808         # Dump the contents of %config
809         print "Writing \033[1;32mcache file\033[0m for future ./configures ...\n";
810         open(FILEHANDLE, ">.config.cache");
811         foreach $key (keys %config) {
812                 print FILEHANDLE "$key=\"$config{$key}\"\n";
813         }
814         close(FILEHANDLE);
815 }
816
817 sub dir_check {
818         my ($desc, $hash_key) = @_;
819         my $complete = 0;
820         while (!$complete) {
821                 print "In what directory $desc?\n";
822                 print "[\033[1;32m$config{$hash_key}\033[0m] -> ";
823                 chomp($var = <STDIN>);
824                 if ($var eq "") {
825                         $var = $config{$hash_key};
826                 }
827                 if ($var =~ /^\~\/(.+)$/) {
828                         # Convert it to a full path..
829                         $var = resolve_directory($ENV{HOME} . "/" . $1);
830                 }
831                 if (substr($var,0,1) ne "/")
832                 {
833                         # Assume relative Path was given.. fill in the rest.
834                         $var = $this . "/$var";
835                 }
836                 $var = resolve_directory($var); 
837                 if (! -e $var) {
838                         print "$var does not exist. Create it?\n[\033[1;32my\033[0m] ";
839                         chomp($tmp = <STDIN>);
840                         if (($tmp eq "") || ($tmp =~ /^y/i)) {
841                                 # Attempt to Create the Dir..
842                                 $chk = system("mkdir -p \"$var\" >> /dev/null 2>&1") / 256;
843                                 if ($chk != 0) {
844                                         print "Unable to create directory. ($var)\n\n";
845                                         # Restart Loop..
846                                         next;
847                                 }
848                         } else {
849                                 # They said they don't want to create, and we can't install there.
850                                 print "\n\n";
851                                 next;
852                         }
853                 } else {
854                         if (!is_dir($var)) {
855                                 # Target exists, but is not a directory.
856                                 print "File $var exists, but is not a directory.\n\n";
857                                 next;
858                         }
859                 }
860                 # Either Dir Exists, or was created fine.
861                 $config{$hash_key} = $var;
862                 $complete = 1;
863                 print "\n";
864         }
865 }
866
867 sub getosflags {
868         if ($config{OSNAME} =~ /BSD$/) {
869                 $config{LDLIBS} = "-Ldl -lstdc++";
870                 $config{FLAGS}  = "-fPIC -frtti -Wall -Woverloaded-virtual $config{OPTIMISATI}";
871                 $config{MAKEPROG} = "gmake";
872                 if ($config{OSNAME} eq "OpenBSD") {
873                         chomp($foo = `eg++ -dumpversion | cut -c 1`);
874                         # theyre running the package version of gcc (eg++)... detect it and set up its version numbers.
875                         # if theyre not running this, configure lets the build continue but they probably wont manage to
876                         # compile as this standard version is 2.95.3!
877                         if ($foo ne "") {
878                                 $config{CC} = "eg++";
879                                 chomp($config{GCCVER}       = `eg++ -dumpversion | cut -c 1`); # we must redo these if we change the compiler path
880                         }
881                 }
882         } else {
883                 $config{LDLIBS} = "-ldl -lstdc++";
884                 $config{FLAGS}  = "-fPIC -frtti -Wall -Woverloaded-virtual $config{OPTIMISATI}";
885                 $config{MAKEPROG} = "make";
886                 if ($config{OSNAME} =~ /CYGWIN/) {
887                         $config{FLAGS}  = "-frtti -Wall -Woverloaded-virtual $config{OPTIMISATI}";
888                         $config{LDLIBS} = "";
889                         $config{MAKEPROG} = "/usr/bin/make";
890                         $config{MAKEORDER} = "ircd mods";
891                 } elsif ($config{OSNAME} eq "CYG-STATIC") {
892                         $config{FLAGS} = "-frtti -Wall -Woverloaded-virtual $config{OPTIMISATI}";
893                         $config{LDLIBS} = "";
894                         $config{MAKEPROG} = "/usr/bin/make";
895                         $config{MAKEORDER} = "mods ircd";
896                         $config{STATICLIBS} = "modules/mods.a";
897                         $config{STATIC_LINK} = "yes";
898                 }
899         }
900         if ($config{OSNAME} =~ /SunOS/) {
901                 # solaris/sunos needs these
902                 # socket = bsd sockets api
903                 # nsl = dns stuff
904                 # rt = POSIX realtime extensions
905                 # resolv = inet_aton only (why isnt this in nsl?!)
906                 $config{LDLIBS} = $config{LDLIBS} . " -lsocket -lnsl -lrt -lresolv";
907         }
908 }
909
910 sub is_dir {
911         my ($path) = @_;
912         if (chdir($path)) {
913                 chdir($this);
914                 return 1;
915         } else {
916                 # Just in case..
917                 chdir($this);
918                 return 0;
919         }
920 }
921
922 sub getmodules {
923         my $i = 0;
924         print "Detecting modules ";
925         opendir(DIRHANDLE, "src/modules");
926         foreach $name (sort readdir(DIRHANDLE)) {
927                 if ($name =~ /^m_(.+)\.cpp$/)
928                 {
929                         $mod = $1;
930                         if ($mod !~ /_static$/) {
931                                 $modlist[$i++] = $mod;
932                                 print ".";
933                         }
934                 }
935         }
936         closedir(DIRHANDLE);
937         print "\nOk, $i modules.\n";
938 }
939
940 sub getrevision {
941         if ($no_svn) {
942                 return "0";
943         }
944         my $data = `svn info`;
945         if ($data eq "") {
946                 $no_svn = 1;
947                 $rev = "0";
948                 return $rev;
949         }
950         $data =~ /Revision: (\d+)/;
951         my $rev = $1;
952         if (!defined($rev)) {
953                 $rev = "0";
954         }
955         return $rev;
956 }
957
958 sub writefiles {
959         my($writeheader) = @_;
960         # First File.. inspircd_config.h
961         chomp(my $incos = `uname -n -s -r`);
962         chomp(my $version = `sh ./src/version.sh`);
963         chomp(my $revision = getrevision());
964         $version = "$version(r$revision)";
965         chomp(my $revision2 = getrevision());
966         if ($writeheader == 1)
967         {
968                 print "Writing \033[1;32minspircd_config.h\033[0m\n";
969                 open(FILEHANDLE, ">include/inspircd_config.h");
970                 my $NL = $config{NICK_LENGT}+1;
971                 my $CL = $config{CHAN_LENGT}+1;
972                 print FILEHANDLE <<EOF;
973 /* Auto generated by configure, do not modify! */
974 #ifndef __CONFIGURATION_AUTO__
975 #define __CONFIGURATION_AUTO__
976
977 #define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf"
978 #define MOD_PATH "$config{MODULE_DIR}"
979 #define VERSION "$version"
980 #define REVISION "$revision2"
981 #define MAXCLIENTS $config{MAX_CLIENT}
982 #define MAX_DESCRIPTORS $config{MAX_DESCRIPTORS}
983 #define NICKMAX $NL
984 #define CHANMAX $CL
985 #define MAXCHANS $config{MAX_CHANNE}
986 #define OPERMAXCHANS $config{MAX_OPERCH}
987 #define MAXMODES $config{MAXI_MODES}
988 #define IDENTMAX $config{MAX_IDENT}
989 #define MAXQUIT $config{MAX_QUIT}
990 #define MAXTOPIC $config{MAX_TOPIC}
991 #define MAXKICK $config{MAX_KICK}
992 #define MAXGECOS $config{MAX_GECOS}
993 #define MAXAWAY $config{MAX_AWAY}
994 #define OPTIMISATION $config{OPTIMITEMP}
995 #define SYSTEM "$incos"
996 #define MAXBUF 514
997 EOF
998                 if ($config{OSNAME} =~ /SunOS/) {
999                         print FILEHANDLE "#define IS_SOLARIS\n";
1000                 }
1001                 if ($config{OSNAME} =~ /CYGWIN/) {
1002                         print FILEHANDLE "#define IS_CYGWIN\n";
1003                         print FILEHANDLE "#ifndef FD_SETSIZE\n#define FD_SETSIZE        1024\n#endif\n";
1004                 }
1005                 if ($config{OSNAME} eq "CYG-STATIC") {
1006                         print FILEHANDLE "#ifndef FD_SETSIZE\n#define FD_SETSIZE    1024\n#endif\n";
1007                 }
1008                 if ($config{HAS_EXECINFO} eq "1") {
1009                         print FILEHANDLE "#define HAS_EXECINFO\n";
1010                 }
1011                 if ($config{STATIC_LINK} eq "yes") {
1012                         print FILEHANDLE "#define STATIC_LINK\n";
1013                 }
1014                 if ($config{GCCVER} >= 3) {
1015                         print FILEHANDLE "#define GCC3\n";
1016                 }
1017                 if ($config{HAS_STRLCPY} eq "true") {
1018                         print FILEHANDLE "#define HAS_STRLCPY\n";
1019                 }
1020                 if ($config{HAS_STDINT} eq "true") {
1021                         print FILEHANDLE "#define HAS_STDINT\n";
1022                 }
1023                 if ($config{THREADED_DNS} =~ /y/i) {
1024                         print FILEHANDLE "#define THREADED_DNS\n";
1025                 }
1026                 if ($config{IPV6} =~ /y/i) {
1027                         print FILEHANDLE "#define IPV6\n";
1028                 }
1029                 if ($config{SUPPORT_IP6LINKS} =~ /y/i) {
1030                         print FILEHANDLE "#define SUPPORT_IP6LINKS\n";
1031                 }
1032                 my $use_hiperf = 0;
1033                 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1034                         print FILEHANDLE "#define USE_KQUEUE\n";
1035                         $se = "socketengine_kqueue";
1036                         $use_hiperf = 1;
1037                 }
1038                 if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1039                         print FILEHANDLE "#define USE_EPOLL\n";
1040                         $se = "socketengine_epoll";
1041                         $use_hiperf = 1;
1042                 }
1043                 # user didn't choose either epoll or select for their OS.
1044                 # default them to USE_SELECT (ewwy puke puke)
1045                 if (!$use_hiperf) {
1046                         print FILEHANDLE "#define USE_SELECT\n";
1047                         $se = "socketengine_select";
1048                 }
1049                 print FILEHANDLE "\n#endif\n";
1050                 close(FILEHANDLE);
1051         }
1052
1053         if ($writeheader)
1054         {
1055                 open(FILEHANDLE, ">include/inspircd_se_config.h");
1056                 print FILEHANDLE <<EOF;
1057 /* Auto generated by configure, do not modify or commit to svn! */
1058 #ifndef __CONFIGURATION_SOCKETENGINE__
1059 #define __CONFIGURATION_SOCKETENGINE__
1060
1061 #include "$se.h"
1062
1063 #endif
1064 EOF
1065                 close(FILEHANDLE);
1066         }
1067
1068
1069         # Create a Modules List..
1070         my $modules = "";
1071         foreach $i (@modlist)
1072         {
1073                 if ($config{STATIC_LINK} eq "yes") {
1074                         $modules .= "m_".$i.".o ";
1075                 }
1076                 else {
1077                         $modules .= "m_".$i.".so ";
1078                 }
1079         }
1080         chomp($modules);   # Remove Redundant whitespace..
1081
1082
1083         # Write all .in files.
1084         my $tmp = "";
1085         my $file = "";
1086         my $exe = "inspircd";
1087
1088         if ($config{OSNAME} =~ /CYGWIN/) {
1089                 $exe = "inspircd.exe";
1090         }
1091
1092         opendir(DIRHANDLE, $this);
1093         if ($config{THREADED_DNS} =~ /y/i) {
1094                 $config{LDLIBS} = $config{LDLIBS} . " -pthread";
1095         }
1096         foreach $name (sort readdir(DIRHANDLE)) {
1097                 if ($name =~ /^\.(.+)\.inc$/) {
1098                         $file = $1;
1099                         # All .name.inc files need parsing!
1100                         $tmp = "";
1101                         open(FILEHANDLE, ".$file.inc");
1102                         while (<FILEHANDLE>) {
1103                                 $tmp .= $_;
1104                         }
1105                         close(FILEHANDLE);
1106
1107                         $tmp =~ s/\@CC\@/$config{CC}/;
1108                         $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
1109                         $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
1110                         $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
1111                         $tmp =~ s/\@BASE_DIR\@/$config{BASE_DIR}/;
1112                         $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
1113                         $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
1114                         $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
1115                         $tmp =~ s/\@LIBRARY_DIR\@/$config{LIBRARY_DIR}/;
1116                         $tmp =~ s/\@MODULES\@/$modules/;
1117                         $tmp =~ s/\@EXECUTABLE\@/$exe/;
1118                         $tmp =~ s/\@MAKEORDER\@/$config{MAKEORDER}/;
1119                         $tmp =~ s/\@STATICLIBS\@/$config{STATICLIBS}/;
1120
1121                         print "Writing \033[1;32m$file\033[0m\n";
1122                         open(FILEHANDLE, ">$file");
1123                         print FILEHANDLE $tmp;
1124                 }
1125         }
1126         closedir(DIRHANDLE);
1127
1128         # Make inspircd executable!
1129         chmod 0744, 'inspircd';
1130
1131         if ($config{STATIC_LINK} eq "yes") {
1132                 print "Writing static-build \033[1;32msrc/Makefile\033[0m\n";
1133                 write_static_makefile();
1134                 write_static_modules_makefile();
1135         } elsif ($config{OSNAME} =~ /CYGWIN/) {
1136                 print "Writing cygwin-build \033[1;32msrc/Makefile\033[0m\n";
1137                 write_static_makefile();
1138                 write_dynamic_modules_makefile();
1139         } else {
1140                 print "Writing dynamic-build \033[1;32msrc/Makefile\033[0m\n";
1141                 write_dynamic_makefile();
1142                 write_dynamic_modules_makefile();
1143         }
1144 }
1145
1146 sub getcompilerflags {
1147         my ($file) = @_;
1148         open(FLAGS, $file);
1149         while (<FLAGS>) {
1150         if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
1151                 close(FLAGS);
1152                         return $1;
1153                 }
1154         }
1155         close(FLAGS);
1156         return undef;
1157 }
1158
1159 sub getlinkerflags {
1160         my ($file) = @_;
1161         open(FLAGS, $file);
1162         while (<FLAGS>) {
1163                 if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
1164                         close(FLAGS);
1165                         return $1;
1166                 }
1167         }
1168         close(FLAGS);
1169         return undef;
1170 }
1171
1172 sub show_splash {
1173   print "'\033[1;33m####\033[0m:'\033[1;33m##\033[0m::: \033[1;33m##\033[0m::'\033[1;33m######\033[0m::'\033[1;33m########\033[0m::'\033[1;33m####\033[0m:'\033[1;33m########\033[0m:::'\033[1;33m######\033[0m::'\033[1;33m########\033[0m::\n";
1174   print ". \033[1;33m##\033[0m:: \033[1;33m###\033[0m:: \033[1;33m##\033[0m:'\033[1;33m##\033[0m... \033[1;33m##\033[0m: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:. \033[1;33m##\033[0m:: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:'\033[1;33m##\033[0m... \033[1;33m##\033[0m: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:\n";
1175   print ": \033[1;33m##\033[0m:: \033[1;33m####\033[0m: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::..:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::..:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
1176   print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m \033[1;33m##\033[0m \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m########\033[0m::: \033[1;33m##\033[0m:: \033[1;33m########\033[0m:: \033[1;33m##\033[0m::::::: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
1177   print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m. \033[1;33m####\033[0m::..... \033[1;33m##\033[0m: \033[1;33m##\033[0m.....:::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m.. \033[1;33m##\033[0m::: \033[1;33m##\033[0m::::::: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
1178   print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m:. \033[1;33m###\033[0m:'\033[1;33m##\033[0m::: \033[1;33m##\033[0m: \033[1;33m##\033[0m::::::::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m::. \033[1;33m##\033[0m:: \033[1;33m##\033[0m::: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
1179   print "'\033[1;33m####\033[0m: \033[1;33m##\033[0m::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m##\033[0m::::::::'\033[1;33m####\033[0m: \033[1;33m##\033[0m:::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m########\033[0m::\n";
1180   print "\033[0m\033[0m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::\n\n";
1181 }
1182
1183 sub resolve_directory {
1184         use File::Spec;
1185         return File::Spec->rel2abs($_[0]);
1186 }
1187
1188 sub yesno {
1189         my ($flag,$prompt) = @_;
1190         print "$prompt [\033[1;32m$config{$flag}\033[0m] -> ";
1191         chomp($tmp = <STDIN>);
1192         if ($tmp eq "") { $tmp = $config{$flag} }
1193
1194         if (($tmp eq "") || ($tmp =~ /^y/i)) {
1195                 $config{$flag} = "y";
1196         } else {
1197                 $config{$flag} = "n";
1198         }
1199         return;
1200 }
1201
1202 sub write_static_modules_makefile {
1203         # Modules Makefile..
1204         print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
1205         open(FILEHANDLE, ">src/modules/Makefile");
1206
1207         ###
1208         # Module Makefile Header
1209         ###
1210         print FILEHANDLE <<EOF;
1211 # (C) ChatSpike development team
1212 # Makefile by <Craig\@ChatSpike.net>
1213 # Many Thanks to Andrew Church <achurch\@achurch.org>
1214 #    for assisting with making this work right.
1215 #
1216 # Automatically Generated by ./configure to add a modules
1217 # please run ./configure --update
1218
1219 all: \$(MODULES)
1220
1221 EOF
1222         ###
1223         # End Module Makefile Header
1224         ###
1225
1226         # Create a Modules List..
1227         my $modules = "";
1228         my $cmflags = "";
1229         my $liflags = "";
1230
1231         open(MODLIST,">include/modlist.h");
1232
1233         ###
1234         # Include File Header
1235         ###
1236         print MODLIST <<HEADER;
1237 // Generated automatically by configure. DO NOT EDIT!
1238
1239 #ifndef __SYMBOLS__H_CONFIGURED__
1240 #define __SYMBOLS__H_CONFIGURED__
1241
1242 HEADER
1243         ###
1244         # End Include File Header
1245         ###
1246
1247         # Place Module List into Include
1248         foreach $i (@modlist) {
1249                 if ($i !~ /_static$/) {
1250                         print MODLIST "extern \"C\" void * $i\_init (void);\n";
1251                 }
1252         }
1253         print MODLIST "\nstruct {const char *name; initfunc *value; } modsyms[] = {\n";
1254
1255         ###
1256         # Build Module Crap
1257         ###
1258         foreach $i (@modlist)
1259         {
1260                 if ($i !~ /_static$/) {
1261                         $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1262                         $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1263
1264                         ###
1265                         # Write Entry to the Makefile
1266                         ###
1267                         print FILEHANDLE <<EOCHEESE;
1268 m_$i.o: .m_$i\_static.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h
1269         \$(CC) -pipe -I../../include \$(FLAGS) $flags -export-dynamic -c .m_$i\_static.cpp
1270         mv .m_$i\_static.o ../m_$i.o
1271
1272 EOCHEESE
1273                         ###
1274                         # End Write Entry to the MakeFile
1275                         ###
1276                         print "Configuring module [\033[1;32mm_$i.so\033[0m] for static linking... ";
1277                         open(MODULE,"<src/modules/m_".$i.".cpp") or die("Could not open m_".$i.".cpp");
1278                         open(MUNGED,">src/modules/.m_".$i."_static.cpp") or die("Could not create .m_".$i."_static.cpp");
1279                         while (chomp($a = <MODULE>)) { 
1280                                 $a =~ s/init_module/$i\_init/g;
1281                                 print MUNGED "$a\n";
1282                         }
1283                         close(MODULE);
1284                         close(MUNGED);
1285                         print MODLIST <<EOENT;
1286 {"m_$i.so",\&$i\_init},
1287 EOENT
1288                         print "done\n";
1289                 }
1290         }
1291         print MODLIST "{0}};\n\n#endif\n";
1292         close(MODLIST);
1293 }
1294
1295 sub write_dynamic_modules_makefile {
1296         # Modules Makefile..
1297         print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
1298         open(FILEHANDLE, ">src/modules/Makefile");
1299         my $extra = "";
1300
1301         if ($config{OSNAME} =~ /CYGWIN/) {
1302                 $extra = "../inspircd.dll.a";
1303         }
1304
1305 ###
1306 # Module Makefile Header
1307 ###
1308         print FILEHANDLE <<EOF;
1309 # (C) ChatSpike development team
1310 # Makefile by <Craig\@ChatSpike.net>
1311 # Many Thanks to Andrew Church <achurch\@achurch.org>
1312 #    for assisting with making this work right.
1313 #
1314 # Automatically Generated by ./configure to add a modules
1315 # please run ./configure -update or ./configure -modupdate
1316
1317 all: \$(MODULES)
1318
1319 EOF
1320         ###
1321         # End Module Makefile Header
1322         ###
1323
1324         # Create a Modules List..
1325         my $modules = "";
1326         my $cmflags = "";
1327         my $liflags = "";
1328         my $crud = "";
1329
1330         foreach $i (@modlist) {
1331         ###
1332         # Write Entry to the MakeFile
1333         ###
1334         $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1335         $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1336         print FILEHANDLE <<EOCHEESE;
1337 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
1338         \$(CC) -pipe -I../../include \$(FLAGS) $cmflags -export-dynamic -c m_$i.cpp
1339         \$(CC) \$(FLAGS) -shared $liflags -o m_$i.so m_$i.o $extra
1340
1341 EOCHEESE
1342         $crud = $crud . "       \@install -v -m 0700 m_$i.so \$(MODPATH)\n";
1343         ###
1344         # End Write Entry to the MakeFile
1345         ###
1346         }
1347         print FILEHANDLE "modinst:\n    \@echo \"Installing modules...\"\n" . $crud;
1348 }
1349
1350
1351 sub write_static_makefile {
1352         open(FH,">src/Makefile") or die("Could not write src/Makefile!");
1353         my $i = 0;
1354         my @cmdlist = ();
1355         opendir(DIRHANDLE, "src");
1356         foreach $name (sort readdir(DIRHANDLE)) {
1357                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1358                         $cmdlist[$i++] = $1;
1359                 }
1360         }
1361         closedir(DIRHANDLE);
1362         my $cmdobjs = "";
1363         my $srcobjs = "";
1364         foreach my $cmd (@cmdlist) {
1365                 $cmdobjs = $cmdobjs . "cmd_$cmd.o ";
1366                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1367         }
1368         print FH <<EOM;
1369 # Insp Makefile :p
1370 #
1371 # (C) ChatSpike development team
1372 # Makefile by <Craig\@ChatSpike.net>
1373 # Makefile version 2 (statically linked core) by <brain\@inspircd.org>
1374 #
1375
1376 CC = im a cheezeball
1377
1378 CXXFLAGS = -I../include \${FLAGS}
1379 CPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* //' | grep -v svn)
1380 RELCPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* /modes\\//' | grep -v svn)
1381
1382 EOM
1383
1384 $se = "socketengine_select";
1385 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1386         $se = "socketengine_kqueue";
1387 }       
1388 elsif (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1389         $se = "socketengine_epoll";
1390 }
1391
1392         ###
1393         # This next section is for cygwin dynamic module builds.
1394         # Basically, what we do, is build the inspircd core as a library
1395         # then the main executable uses that. the library is capable of
1396         # loading / unloading the modules dynamically :)
1397         # Massive thanks to the guys on #cygwin @ irc.freenode.net for helping
1398         # make this work :)
1399         ###
1400
1401         if ($config{OSNAME} =~ /CYGWIN/) {
1402                 print FH <<EOM;
1403 all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o snomasks.o inspircd.exe
1404
1405 inspircd.exe: inspircd.dll.a
1406         \$(CC) -o \$@ \$^
1407
1408 inspircd.dll inspircd.dll.a: inspircd.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs  commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o snomasks.o
1409         \$(CC) -shared -Wl,--out-implib=inspircd.dll.a -o inspircd.dll \$^
1410 EOM
1411         } else {
1412                 print FH <<EOM;
1413 all: timer.o aes.o command_parse.o cull_list.o userprocess.o socketengine.o socket.o hashcomp.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o message.o $cmdobjs commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o snomasks.o \$(MODULES) inspircd.exe
1414
1415 inspircd.exe: inspircd.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/channels.h ../include/globals.h ../include/inspircd_config.h ../include/base.h
1416         \$(CC) -I../include \$(FLAGS) inspircd.cpp -o inspircd.exe \$(LDLIBS) channels.o mode.o xline.o inspstring.o dns.o base.o inspsocket.o configreader.o message.o $cmdobjs commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o hashcomp.o socket.o socketengine.o userprocess.o cull_list.o command_parse.o aes.o timer.o snomasks.o modes/modeclasses.a \$(MODULES)
1417 EOM
1418         }
1419
1420         print FH <<EOM;
1421
1422 cull_list.o: cull_list.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/users.h ../include/channels.h
1423         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1424
1425 snomasks.o: snomasks.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/channels.h
1426         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c snomasks.cpp
1427
1428 command_parse.o: command_parse.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1429         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1430
1431 userprocess.o: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1432         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1433
1434 socketengine.o: $se.cpp socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/$se.h
1435         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp $se.cpp
1436
1437 hashcomp.o: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1438         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1439
1440 helperfuncs.o: helperfuncs.cpp ../include/base.h ../include/helperfuncs.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1441         \$(CC) -pipe -I/usr/local/include -L/usr/local/lib -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1442
1443 channels.o: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1444         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1445
1446 mode.o: mode.cpp ../include/base.h ../include/mode.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h \$(RELCPPFILES)
1447         \${MAKE} -C "modes" DIRNAME="src/modes" \$(MAKEARGS) CPPFILES="\$(CPPFILES)"
1448         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1449
1450 xline.o: xline.cpp ../include/base.h ../include/xline.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1451         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1452
1453 inspstring.o: inspstring.cpp ../include/base.h ../include/inspstring.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1454         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1455
1456 dns.o: dns.cpp ../include/base.h ../include/dns.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1457         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1458
1459 base.o: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1460         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1461
1462 configreader.o: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1463         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp
1464
1465 message.o: message.cpp ../include/base.h ../include/message.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1466         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp
1467
1468 commands.o: commands.cpp ../include/base.h ../include/commands.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h $srcobjs
1469         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp $cmdobjs
1470
1471 dynamic.o: dynamic.cpp ../include/base.h ../include/dynamic.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1472         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1473
1474 users.o: users.cpp ../include/base.h ../include/users.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1475         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1476
1477 modules.o: modules.cpp ../include/base.h ../include/modules.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1478         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1479
1480 wildcard.o: wildcard.cpp ../include/base.h ../include/wildcard.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1481         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1482
1483 socket.o: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1484         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1485         
1486 inspsocket.o: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1487         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp
1488
1489 aes.o: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1490         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp
1491
1492 timer.o: timer.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1493         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c timer.cpp
1494
1495 EOM
1496         foreach my $cmd (@cmdlist) {
1497                 print FH <<ITEM;
1498 cmd_$cmd.o: cmd_$cmd.cpp ../include/base.h ../include/modules.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/commands/cmd_$cmd.h
1499         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1500 ITEM
1501         }
1502         close(FH);
1503 }
1504
1505 sub write_dynamic_makefile {
1506
1507         my $i = 0;
1508         my @cmdlist = ();
1509         opendir(DIRHANDLE, "src");
1510         foreach $name (sort readdir(DIRHANDLE)) {
1511                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1512                         $cmdlist[$i++] = $1;
1513                 }
1514         }
1515         closedir(DIRHANDLE);
1516
1517         my $cmdobjs = "";
1518         my $srcobjs = "";
1519         foreach my $cmd (@cmdlist) {
1520                 $cmdobjs = $cmdobjs . "cmd_$cmd.o ";
1521                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1522         }
1523
1524 if (($config{OSNAME} !~ /Linux/i) && ($config{HAS_EXECINFO} eq "1")) {
1525         $extra = "-L/usr/local/lib -lexecinfo";
1526 } else {
1527         $extra = "";
1528 }
1529
1530 $se = "socketengine_select";
1531 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1532         $se = "socketengine_kqueue";
1533 }
1534 elsif (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1535         $se = "socketengine_epoll";
1536 }
1537
1538         open(FH,">src/Makefile") or die("Could not write src/Makefile");
1539         print FH <<EOM;
1540 # Insp Makefile :p
1541 #
1542 # (C) ChatSpike development team
1543 # Makefile by <Craig\@ChatSpike.net>
1544 # Makefile version 2 (dynamically linked core) by <brain\@inspircd.org>
1545 #
1546
1547 CC = im a cheezeball
1548
1549 CXXFLAGS = -I../include \${FLAGS}
1550 CPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* //' | grep -v svn)
1551 RELCPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* /modes\\//' | grep -v svn)
1552
1553 all: libIRCDtimer.so libIRCDaes.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so libIRCDmessage.so $cmdobjs libIRCDcommands.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so libIRCDsnomasks.so inspircd
1554
1555 inspircd: inspircd.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/channels.h ../include/globals.h ../include/inspircd_config.h ../include/socket.h libIRCDtimer.so libIRCDaes.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so libIRCDmessage.so $cmdobjs libIRCDsnomasks.so libIRCDcommands.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so
1556         \$(CC) -I../include $extra -Wl,--rpath -Wl,/usr/local/lib -Wl,--rpath -Wl,$config{LIBRARY_DIR} \$(FLAGS) -rdynamic -L. inspircd.cpp -o inspircd \$(LDLIBS) libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so libIRCDmessage.so libIRCDcommands.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDhash.so libIRCDsocket.so libIRCDsocketengine.so libIRCDuserprocess.so libIRCDcull_list.so libIRCDcommand_parse.so libIRCDaes.so libIRCDtimer.so libIRCDsnomasks.so
1557
1558 libIRCDsocketengine.so: $se.cpp socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/$se.h
1559         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp $se.cpp
1560         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocketengine.so socketengine.o $se.o
1561
1562 libIRCDsnomasks.so: snomasks.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/channels.h
1563          \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c snomasks.cpp
1564           \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsnomasks.so snomasks.o
1565
1566 libIRCDcommand_parse.so: command_parse.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1567         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1568         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommand_parse.so command_parse.o
1569
1570 libIRCDcull_list.so: cull_list.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/users.h ../include/channels.h
1571         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1572         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcull_list.so cull_list.o
1573
1574 libIRCDuserprocess.so: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1575         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1576         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDuserprocess.so userprocess.o
1577
1578 libIRCDhash.so: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1579         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1580         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhash.so hashcomp.o
1581
1582 libIRCDhelper.so: helperfuncs.cpp ../include/base.h ../include/helperfuncs.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1583         \$(CC) -pipe -I/usr/local/include -L/usr/local/lib -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1584         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhelper.so helperfuncs.o
1585
1586 libIRCDchannels.so: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1587         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1588         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDchannels.so channels.o
1589
1590 libIRCDmode.so: mode.cpp ../include/base.h ../include/mode.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h \$(RELCPPFILES)
1591         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1592         \${MAKE} -C "modes" DIRNAME="src/modes" \$(MAKEARGS) CPPFILES="\$(CPPFILES)"
1593         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmode.so mode.o modes/modeclasses.a
1594
1595 libIRCDxline.so: xline.cpp ../include/base.h ../include/xline.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1596         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1597         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDxline.so xline.o
1598
1599 libIRCDstring.so: inspstring.cpp ../include/base.h ../include/inspstring.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1600         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1601         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDstring.so inspstring.o
1602
1603 libIRCDasyncdns.so: dns.cpp ../include/base.h ../include/dns.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1604         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1605         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDasyncdns.so dns.o
1606
1607 libIRCDbase.so: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1608         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1609         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDbase.so base.o
1610
1611 libIRCDconfigreader.so: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1612         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp
1613         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDconfigreader.so configreader.o
1614
1615 libIRCDmessage.so: message.cpp ../include/base.h ../include/message.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1616         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp
1617         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmessage.so message.o
1618
1619 libIRCDcommands.so: commands.cpp ../include/base.h ../include/commands.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h $srcobjs
1620         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp
1621         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommands.so commands.o $cmdobjs
1622
1623 libIRCDdynamic.so: dynamic.cpp ../include/base.h ../include/dynamic.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1624         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1625         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDdynamic.so dynamic.o
1626
1627 libIRCDusers.so: users.cpp ../include/base.h ../include/users.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1628         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1629         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDusers.so users.o
1630
1631 libIRCDmodules.so: modules.cpp ../include/base.h ../include/modules.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1632         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1633         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmodules.so modules.o
1634
1635 libIRCDwildcard.so: wildcard.cpp ../include/base.h ../include/wildcard.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1636         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1637         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDwildcard.so wildcard.o
1638
1639 libIRCDsocket.so: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1640         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1641         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocket.so socket.o
1642
1643 libIRCDinspsocket.so: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1644         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp
1645         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDinspsocket.so inspsocket.o
1646
1647 libIRCDaes.so: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1648         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp
1649         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDaes.so aes.o
1650
1651 libIRCDtimer.so: timer.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1652         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c timer.cpp
1653         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDtimer.so timer.o
1654
1655 EOM
1656         foreach my $cmd (@cmdlist) {
1657                 print FH <<ITEM;
1658 cmd_$cmd.o: cmd_$cmd.cpp ../include/base.h ../include/modules.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/commands/cmd_$cmd.h
1659         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1660
1661 ITEM
1662         }
1663         close(FH);
1664 }