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