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