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