]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
Properly check that existing key resides in conf/ and not current dir
[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         `cp src/modules/extra/m_ssl_gnutls.cpp src/modules/m_ssl_gnutls.cpp`;
568         $failed = 0;
569         open(TMP, "<$config{CONFIG_DIR}/key.pem") or $failed = 1;
570         close(TMP);
571         open(TMP, "<$config{CONFIG_DIR}/cert.pem") or $failed = 1;
572         close(TMP);
573         if ($failed) {
574                 print "SSL Certificates Not found, Generating.. \n\n
575 *************************************************************
576 * Generating the Private Key may take some time, go grab a  *
577 * Coffee. Even better, to generate some more entropy if it  *
578 * is taking a while, open another console and type du / a   *
579 * few times and get that HD going :) Then answer the        *
580 * Questions which follow. If you are unsure, just hit enter *
581 *************************************************************\n\n";
582                 system("certtool --generate-privkey --outfile key.pem");
583                 system("certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem");
584                 print "\nCertificate generation complete, copying to config directory... ";
585                 `mv key.pem $config{CONFIG_DIR}/key.pem`;
586                 `mv cert.pem $config{CONFIG_DIR}/cert.pem`;
587                 print "Done.\n\n";
588         } else {
589                 print "SSL Certificates found, skipping."
590         }       
591 }
592
593 makecache();
594 writefiles();
595
596 print "\n\n";
597 print "To build your server with these settings, please type '\033[1;32m$config{MAKEPROG}\033[0m' now.\n";
598 print "*** \033[1;32mRemember to edit your configuration files!!!\033[0m ***\n\n\n";
599 if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) {
600         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";
601 }
602 if ($config{OSNAME} =~ /CYGWIN/) {
603         print <<FOO;
604 \033[1;32mWARNING!\033[0m CYGWIN does not properly support shared modules,
605 so modules will be compiled statically into the core of the ircd. The modules
606 will act like they are being loaded from disk and being unloaded from RAM,
607 however they are in fact being enabled and disabled similar to features in
608 other ircds.
609 FOO
610 }
611
612 if ($config{GCCVER} < "3") {
613         print <<FOO2;
614 \033[1;32mWARNING!\033[0m You are attempting to compile InspIRCd on GCC 2.x!
615 GCC 2.x series compilers only had partial (read as broken) C++ support, and
616 your compile will most likely fail horribly! If you have any problems, do NOT
617 report them to the bugtracker or forums without first upgrading your compiler
618 to a newer 3.x or 4.x (or whatever is available currently) version.
619 FOO2
620 }
621
622 ################################################################################
623 #                              HELPER FUNCTIONS                                #
624 ################################################################################
625 sub getcache {
626   # Retrieves the .config.cache file, and loads values into the main config hash.
627   open(CACHE, ".config.cache") or return undef;
628   while (<CACHE>) {
629     chomp;
630
631     # Ignore Blank lines, and comments..
632     next if /^\s*$/;
633     next if /^\s*#/;
634
635     my ($key, $value) = split("=", $_);
636     $value =~ /^\"(.*)\"$/;
637     # Do something with data here!
638     $config{$key} = $1;
639   }
640   close(CONFIG);
641   return "true";
642 }
643
644 sub makecache {
645   # Dump the contents of %config
646   print "Writing \033[1;32mcache file\033[0m for future ./configures ...\n";
647   open(FILEHANDLE, ">.config.cache");
648   foreach $key (keys %config)
649   {
650     print FILEHANDLE "$key=\"$config{$key}\"\n";
651   }
652   close(FILEHANDLE);
653 }
654
655 sub dir_check {
656   my ($desc, $hash_key) = @_;
657   my $complete = 0;
658   while (!$complete) {
659     print "In what directory $desc?\n";
660     print "[\033[1;32m$config{$hash_key}\033[0m] -> ";
661     chomp($var = <STDIN>);
662     if ($var eq "") { $var = $config{$hash_key}; }
663     if ($var =~ /^\~\/(.+)$/) {
664         # Convert it to a full path..
665         $var = resolve_directory($ENV{HOME} . "/" . $1);
666     }
667     if (substr($var,0,1) ne "/")
668     {
669         # Assume relative Path was given.. fill in the rest.
670         $var = $this . "/$var";
671     }
672     $var = resolve_directory($var); 
673     if (! -e $var) {
674       print "$var does not exist. Create it?\n[\033[1;32my\033[0m] ";
675       chomp($tmp = <STDIN>);
676       if (($tmp eq "") || ($tmp =~ /^y/i)) {
677         # Attempt to Create the Dir..
678         $chk = system("mkdir -p \"$var\" >> /dev/null 2>&1") / 256;
679         if ($chk != 0) {
680           print "Unable to create directory. ($var)\n\n";
681           # Restart Loop..
682           next;
683         }
684       } else {
685         # They said they don't want to create, and we can't install there.
686         print "\n\n";
687         next;
688       }
689     } else {
690       if (!is_dir($var)) {
691         # Target exists, but is not a directory.
692         print "File $var exists, but is not a directory.\n\n";
693         next;
694       }
695     }
696     # Either Dir Exists, or was created fine.
697     $config{$hash_key} = $var;
698     $complete = 1;
699     print "\n";
700   }
701 }
702
703 sub getosflags {
704   if ($config{OSNAME} =~ /BSD$/) {
705     $config{LDLIBS} = "-Ldl -lstdc++";
706     $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Wall -Woverloaded-virtual $config{OPTIMISATI}";
707     $config{MAKEPROG} = "gmake";
708     if ($config{OSNAME} eq "OpenBSD") {
709         chomp($foo = `eg++ -dumpversion | cut -c 1`);
710         # theyre running the package version of gcc (eg++)... detect it and set up its version numbers.
711         # if theyre not running this, configure lets the build continue but they probably wont manage to
712         # compile as this standard version is 2.95.3!
713         if ($foo ne "") {
714                 $config{CC} = "eg++";
715                 chomp($config{GCCVER}       = `eg++ -dumpversion | cut -c 1`); # we must redo these if we change
716                 chomp($config{GCC34}        = `eg++ -dumpversion | cut -c 3`); # the compiler path
717         }
718     }
719   } else {
720     $config{LDLIBS} = "-ldl -lstdc++";
721     $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Wall -Woverloaded-virtual $config{OPTIMISATI}";
722     $config{MAKEPROG} = "make";
723     if ($config{OSNAME} =~ /CYGWIN/) {
724        $config{FLAGS}  = "-frtti $OPTIMISATI -Wall -Woverloaded-virtual $config{OPTIMISATI}";
725        $config{LDLIBS} = "";
726        $config{MAKEPROG} = "/usr/bin/make";
727        $config{MAKEORDER} = "mods ircd config bininst";
728        $config{STATICLIBS} = "modules/mods.a";
729        $config{STATIC_LINK} = "yes";
730     }
731   }
732   if ($config{OSNAME} =~ /SunOS/) {
733     # solaris/sunos needs these
734     # socket = bsd sockets api
735     # nsl = dns stuff
736     # rt = POSIX realtime extensions
737     # resolv = inet_aton only (why isnt this in nsl?!)
738     $config{LDLIBS} = $config{LDLIBS} . " -lsocket -lnsl -lrt -lresolv";
739   }
740 }
741
742 sub is_dir {
743   my ($path) = @_;
744   if (chdir($path)) {
745     chdir($this);
746     return 1;
747   } else {
748     # Just in case..
749     chdir($this);
750     return 0;
751   }
752 }
753
754 sub getmodules {
755   my $i = 0;
756   opendir(DIRHANDLE, "src/modules");
757   foreach $name (sort readdir(DIRHANDLE)) {
758     if ($name =~ /^m_(.+)\.cpp$/)
759     {
760       $mod = $1;
761       if ($mod !~ /_static$/) {
762               $modlist[$i++] = $mod;
763       }
764     }
765   }
766   closedir(DIRHANDLE);
767 }
768
769 sub writefiles {
770
771   print "Writing \033[1;32minspircd_config.h\033[0m\n";
772   # First File.. inspircd_config.h
773   chomp(my $incos = `uname -n -s -r`);
774   chomp(my $version = `sh ./src/version.sh`);
775   open(FILEHANDLE, ">include/inspircd_config.h");
776   my $NL = $config{NICK_LENGT}+1;
777   my $CL = $config{CHAN_LENGT}+1;
778   print FILEHANDLE <<EOF;
779 /* Auto generated by configure, do not modify! */
780 #ifndef __CONFIGURATION_AUTO__
781 #define __CONFIGURATION_AUTO__
782
783 #define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf"
784 #define MOD_PATH "$config{MODULE_DIR}"
785 #define VERSION "$version"
786 #define MAXCLIENTS $config{MAX_CLIENT}
787 #define MAX_DESCRIPTORS $config{MAX_DESCRIPTORS}
788 #define NICKMAX $NL
789 #define CHANMAX $CL
790 #define MAXCHANS $config{MAX_CHANNE}
791 #define OPERMAXCHANS $config{MAX_OPERCH}
792 #define MAXMODES $config{MAXI_MODES}
793 #define IDENTMAX $config{MAX_IDENT}
794 #define MAXQUIT $config{MAX_QUIT}
795 #define MAXTOPIC $config{MAX_TOPIC}
796 #define MAXKICK $config{MAX_KICK}
797 #define MAXGECOS $config{MAX_GECOS}
798 #define MAXAWAY $config{MAX_AWAY}
799 #define OPTIMISATION $config{OPTIMITEMP}
800 #define SYSTEM "$incos"
801 #define MAXBUF 514
802 EOF
803
804   if ($config{OSNAME} =~ /SunOS/) {
805     print FILEHANDLE "#define IS_SOLARIS\n";
806   }
807   if ($config{OSNAME} =~ /CYGWIN/) {
808     print FILEHANDLE "#define IS_CYGWIN\n";
809     print FILEHANDLE "#ifndef FD_SETSIZE\n#define FD_SETSIZE    1024\n#endif\n";
810   }
811   if ($config{STATIC_LINK} eq "yes") {
812     print FILEHANDLE "#define STATIC_LINK\n";
813   }
814   if ($config{GCCVER} > 3) {
815     print FILEHANDLE "#define GCC3\n";
816     print FILEHANDLE "#define GCC34\n";
817   }
818   else
819   {
820     if ($config{GCCVER} == 3) {
821       print FILEHANDLE "#define GCC3\n";
822       if ($config{GCC34} > 3) {
823         print FILEHANDLE "#define GCC34\n";
824       }
825     }
826   }
827   if ($config{HAS_STRLCPY} eq "true") {
828     print FILEHANDLE "#define HAS_STRLCPY\n";
829   }
830   if ($config{THREADED_DNS} =~ /y/i) {
831     print FILEHANDLE "#define THREADED_DNS\n";
832   }
833   my $use_hiperf = 0;
834   if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
835     print FILEHANDLE "#define USE_KQUEUE\n";
836     $use_hiperf = 1;
837   }
838   if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
839     print FILEHANDLE "#define USE_EPOLL\n";
840     $use_hiperf = 1;
841   }
842   # user didn't choose either epoll or select for their OS.
843   # default them to USE_SELECT (ewwy puke puke)
844   if (!$use_hiperf) {
845     print FILEHANDLE "#define USE_SELECT\n";
846   }
847   print FILEHANDLE "\n#endif\n";
848   close(FILEHANDLE);
849
850   # Create a Modules List..
851   my $modules = "";
852   foreach $i (@modlist)
853   {
854     if ($config{OSNAME} =~ /CYGWIN/) {
855         $modules .= "m_".$i.".o ";
856     }
857     else {
858         $modules .= "m_".$i.".so ";
859     }
860   }
861   chomp($modules);   # Remove Redundant whitespace..
862
863
864   # Write all .in files.
865   my $tmp = "";
866   my $file = "";
867   my $exe = "inspircd";
868
869   if ($config{OSNAME} =~ /CYGWIN/) {
870     $exe = "inspircd.exe";
871   }
872
873   opendir(DIRHANDLE, $this);
874   if ($config{THREADED_DNS} =~ /y/i) {
875     $config{LDLIBS} = $config{LDLIBS} . " -pthread";
876   }
877   foreach $name (sort readdir(DIRHANDLE)) {
878     if ($name =~ /^\.(.+)\.inc$/)
879     {
880       $file = $1;
881       # All .name.inc files need parsing!
882       $tmp = "";
883       open(FILEHANDLE, ".$file.inc");
884       while (<FILEHANDLE>) {
885         $tmp .= $_;
886       }
887       close(FILEHANDLE);
888
889       $tmp =~ s/\@CC\@/$config{CC}/;
890       $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
891       $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
892       $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
893       $tmp =~ s/\@BASE_DIR\@/$config{BASE_DIR}/;
894       $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
895       $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
896       $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
897       $tmp =~ s/\@LIBRARY_DIR\@/$config{LIBRARY_DIR}/;
898       $tmp =~ s/\@MODULES\@/$modules/;
899       $tmp =~ s/\@EXECUTABLE\@/$exe/;
900       $tmp =~ s/\@MAKEORDER\@/$config{MAKEORDER}/;
901       $tmp =~ s/\@STATICLIBS\@/$config{STATICLIBS}/;
902
903       print "Writing \033[1;32m$file\033[0m\n";
904       open(FILEHANDLE, ">$file");
905       print FILEHANDLE $tmp;
906     }
907   }
908   closedir(DIRHANDLE);
909
910   # Make inspircd executable!
911   chmod 0744, 'inspircd';
912
913   if ($config{OSNAME} =~ /CYGWIN/) {
914         print "Writing static-build \033[1;32msrc/Makefile\033[0m\n";
915         write_static_makefile();
916         write_static_modules_makefile();
917   }
918   else {
919         print "Writing dynamic-build \033[1;32msrc/Makefile\033[0m\n";
920         write_dynamic_makefile();
921         write_dynamic_modules_makefile();
922   }
923 }
924
925 sub getcompilerflags {
926   my ($file) = @_;
927   open(FLAGS, $file);
928   while (<FLAGS>) {
929     if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
930       close(FLAGS);
931       return $1;
932     }
933   }
934   close(FLAGS);
935   return undef;
936 }
937
938 sub getlinkerflags {
939   my ($file) = @_;
940   open(FLAGS, $file);
941   while (<FLAGS>) {
942     if ($_ =~ /^\/\* \$LinkerFlags: (.+) \*\/$/) {
943       close(FLAGS);
944       return $1;
945     }
946   }
947   close(FLAGS);
948   return undef;
949 }
950
951 sub show_splash {
952   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";
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.... \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:\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:\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: \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::\n";
959   print "\033[0m\033[0m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::\n\n";
960 }
961
962 sub resolve_directory {
963         use File::Spec;
964         return File::Spec->rel2abs($_[0]);
965 }
966
967 sub yesno {
968         my ($flag,$prompt) = @_;
969         print "$prompt [\033[1;32m$config{$flag}\033[0m] -> ";
970         chomp($tmp = <STDIN>);
971         if ($tmp eq "") { $tmp = $config{$flag} }
972
973         if (($tmp eq "") || ($tmp =~ /^y/i)) {
974                 $config{$flag} = "y";
975         } else {
976                 $config{$flag} = "n";
977         }
978         return;
979 }
980
981 sub write_static_modules_makefile {
982   # Modules Makefile..
983   print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
984   open(FILEHANDLE, ">src/modules/Makefile");
985
986 ###
987 # Module Makefile Header
988 ###
989   print FILEHANDLE <<EOF;
990 # (C) ChatSpike development team
991 # Makefile by <Craig\@ChatSpike.net>
992 # Many Thanks to Andrew Church <achurch\@achurch.org>
993 #    for assisting with making this work right.
994 #
995 # Automatically Generated by ./configure to add a modules
996 # please run ./configure --update
997
998 all: \$(MODULES)
999
1000 EOF
1001 ###
1002 # End Module Makefile Header
1003 ###
1004
1005 # Create a Modules List..
1006 my $modules = "";
1007 my $cmflags = "";
1008 my $liflags = "";
1009
1010 open(MODLIST,">include/modlist.h");
1011
1012 ###
1013 # Include File Header
1014 ###
1015 print MODLIST <<HEADER;
1016 // Generated automatically by configure. DO NOT EDIT!
1017
1018 #ifndef __SYMBOLS__H_CONFIGURED__
1019 #define __SYMBOLS__H_CONFIGURED__
1020
1021 HEADER
1022 ###
1023 # End Include File Header
1024 ###
1025
1026 # Place Module List into Include
1027 foreach $i (@modlist) {
1028         if ($i !~ /_static$/) {
1029                 print MODLIST "extern \"C\" void * $i\_init (void);\n";
1030         }
1031 }
1032 print MODLIST "\nstruct {const char *name; initfunc *value; } modsyms[] = {\n";
1033
1034 ###
1035 # Build Module Crap
1036 ###
1037 foreach $i (@modlist)
1038 {
1039         if ($i !~ /_static$/) {
1040                 $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1041                 $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1042
1043                 print FILEHANDLE <<EOCHEESE;
1044                 ###
1045                 # Write Entry to the MakeFile
1046                 ###
1047 m_$i.o: m_$i\_static.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h
1048         \$(CC) -pipe -I../../include \$(FLAGS) $flags -export-dynamic -c m_$i\_static.cpp
1049         mv m_$i\_static.o ../m_$i.o
1050
1051 EOCHEESE
1052                 ###
1053                 # End Write Entry to the MakeFile
1054                 ###
1055                 print "Configuring module [\033[1;32mm_$i.so\033[0m] for static linking... ";
1056                 open(MODULE,"<src/modules/m_".$i.".cpp") or die("Could not open m_".$i.".cpp");
1057                 open(MUNGED,">src/modules/m_".$i."_static.cpp") or die("Could not create m_".$i."_static.cpp");
1058                 while (chomp($a = <MODULE>)) { 
1059                         $a =~ s/init_module/$i\_init/g;
1060                         $a =~ s/Srv/$i\Srv/g;
1061                         print MUNGED "$a\n";
1062                 }
1063                 close(MODULE);
1064                 close(MUNGED);
1065                 print MODLIST <<EOENT;
1066 {"m_$i.so",\&$i\_init},
1067 EOENT
1068                 print "done\n";
1069         }
1070 }
1071 print MODLIST "{0}};\n\n#endif\n";
1072 close(MODLIST);
1073 }
1074
1075 sub write_dynamic_modules_makefile {
1076   # Modules Makefile..
1077   print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
1078   open(FILEHANDLE, ">src/modules/Makefile");
1079
1080 ###
1081 # Module Makefile Header
1082 ###
1083   print FILEHANDLE <<EOF;
1084 # (C) ChatSpike development team
1085 # Makefile by <Craig\@ChatSpike.net>
1086 # Many Thanks to Andrew Church <achurch\@achurch.org>
1087 #    for assisting with making this work right.
1088 #
1089 # Automatically Generated by ./configure to add a modules
1090 # please run ./configure --update
1091
1092 all: \$(MODULES)
1093
1094 EOF
1095 ###
1096 # End Module Makefile Header
1097 ###
1098
1099 # Create a Modules List..
1100 my $modules = "";
1101 my $cmflags = "";
1102 my $liflags = "";
1103
1104 foreach $i (@modlist) {
1105         ###
1106         # Write Entry to the MakeFile
1107         ###
1108         print FILEHANDLE <<EOCHEESE;
1109 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
1110         \$(CC) -pipe -I../../include \$(FLAGS) $cmflags -export-dynamic -c m_$i.cpp
1111         \$(CC) \$(FLAGS) -shared $liflags -o m_$i.so m_$i.o
1112         \@-rm -f \$(MODPATH)/m_$i.so
1113         install -v -m 0700 m_$i.so \$(MODPATH)
1114
1115 EOCHEESE
1116         ###
1117         # End Write Entry to the MakeFile
1118         ###
1119 }
1120 }
1121
1122
1123 sub write_static_makefile {
1124         open(FH,">src/Makefile") or die("Could not write src/Makefile!");
1125         my $i = 0;
1126         my @cmdlist = ();
1127         opendir(DIRHANDLE, "src");
1128         foreach $name (sort readdir(DIRHANDLE)) {
1129                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1130                         $cmdlist[$i++] = $1;
1131                 }
1132         }
1133         closedir(DIRHANDLE);
1134         my $cmdobjs = "";
1135         my $srcobjs = "";
1136         foreach my $cmd (@cmdlist) {
1137                 $cmdobjs = $cmdobjs . "cmd_$cmd.o ";
1138                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1139         }
1140         print FH <<EOM;
1141 # Insp Makefile :p
1142 #
1143 # (C) ChatSpike development team
1144 # Makefile by <Craig\@ChatSpike.net>
1145 # Makefile version 2 (dynamically linked core) by <brain\@inspircd.org>
1146 #
1147
1148 CC = im a cheezeball
1149
1150 CXXFLAGS = -I../include \${FLAGS}
1151
1152 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
1153
1154 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
1155         \$(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)
1156
1157 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
1158         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1159
1160 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
1161         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1162
1163 userprocess.o: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1164         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1165
1166 socketengine.o: socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1167         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp
1168
1169 hashcomp.o: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1170         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1171
1172 helperfuncs.o: helperfuncs.cpp ../include/base.h ../include/helperfuncs.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1173         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1174
1175 channels.o: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1176         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1177
1178 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
1179         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1180
1181 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
1182         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1183
1184 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
1185         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1186
1187 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
1188         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1189
1190 base.o: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1191         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1192
1193 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
1194         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd_io.cpp
1195
1196 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
1197         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp
1198
1199 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
1200         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp $cmdobjs
1201
1202 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
1203         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dnsqueue.cpp
1204
1205 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
1206         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1207
1208 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
1209         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1210
1211 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
1212         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1213
1214 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
1215         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1216
1217 socket.o: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1218         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1219
1220 aes.o: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1221         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp
1222
1223 EOM
1224         foreach my $cmd (@cmdlist) {
1225                 print FH <<ITEM;
1226 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
1227         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1228 ITEM
1229         }
1230 close(FH);
1231 }
1232
1233 sub write_dynamic_makefile {
1234
1235         my $i = 0;
1236         my @cmdlist = ();
1237         opendir(DIRHANDLE, "src");
1238         foreach $name (sort readdir(DIRHANDLE)) {
1239                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1240                         $cmdlist[$i++] = $1;
1241                 }
1242         }
1243         closedir(DIRHANDLE);
1244
1245         my $cmdobjs = "";
1246         my $srcobjs = "";
1247         foreach my $cmd (@cmdlist) {
1248                 $cmdobjs = $cmdobjs . "cmd_$cmd.o ";
1249                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1250         }
1251
1252         open(FH,">src/Makefile") or die("Could not write src/Makefile");
1253         print FH <<EOM;
1254 # Insp Makefile :p
1255 #
1256 # (C) ChatSpike development team
1257 # Makefile by <Craig\@ChatSpike.net>
1258 # Makefile version 2 (dynamically linked core) by <brain\@inspircd.org>
1259 #
1260
1261 CC = im a cheezeball
1262
1263 CXXFLAGS = -I../include \${FLAGS}
1264
1265 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
1266
1267 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
1268         \$(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
1269
1270 libIRCDsocketengine.so: socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1271         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp
1272         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocketengine.so socketengine.o
1273
1274 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
1275         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1276         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommand_parse.so command_parse.o
1277
1278 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
1279         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1280         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcull_list.so cull_list.o
1281
1282 libIRCDuserprocess.so: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1283         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1284         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDuserprocess.so userprocess.o
1285
1286 libIRCDhash.so: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1287         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1288         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhash.so hashcomp.o
1289
1290 libIRCDhelper.so: helperfuncs.cpp ../include/base.h ../include/helperfuncs.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1291         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1292         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhelper.so helperfuncs.o
1293
1294 libIRCDchannels.so: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1295         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1296         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDchannels.so channels.o
1297
1298 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
1299         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1300         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmode.so mode.o
1301
1302 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
1303         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1304         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDxline.so xline.o
1305
1306 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
1307         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1308         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDstring.so inspstring.o
1309
1310 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
1311         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1312         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDasyncdns.so dns.o
1313
1314 libIRCDbase.so: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1315         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1316         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDbase.so base.o
1317
1318 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
1319         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd_io.cpp
1320         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDio.so inspircd_io.o
1321
1322 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
1323         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c message.cpp
1324         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmessage.so message.o
1325
1326 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
1327         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp
1328         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommands.so commands.o $cmdobjs
1329
1330 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
1331         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dnsqueue.cpp
1332         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDdnsqueue.so dnsqueue.o
1333
1334 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
1335         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1336         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDdynamic.so dynamic.o
1337
1338 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
1339         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1340         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDusers.so users.o
1341
1342 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
1343         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1344         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmodules.so modules.o
1345
1346 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
1347         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1348         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDwildcard.so wildcard.o
1349
1350 libIRCDsocket.so: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1351         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1352         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocket.so socket.o
1353
1354 libIRCDaes.so: aes.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1355         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c aes.cpp
1356         \$(CC) -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDaes.so aes.o
1357
1358 EOM
1359         foreach my $cmd (@cmdlist) {
1360                 print FH <<ITEM;
1361 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
1362         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1363
1364 ITEM
1365         }
1366         close(FH);
1367 }