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