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