]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
This needs some general QA-ing. Add support to new parser (introduced in 1.1) for...
[user/henk/code/inspircd.git] / configure
1 #!/usr/bin/perl
2
3 # InspIRCd Configuration Script
4 #
5 # Copyright 2002-2007 The ChatSpike Development Team
6 # <brain@chatspike.net>
7 # <Craig@chatspike.net>
8 #
9 # [14:21] Brain: <matrix impression> i know perl-fu!
10 #
11 # $Id$
12 #
13 ########################################
14
15
16 require 5.6.0;
17 use Socket;
18 use Cwd;
19 use Getopt::Long;
20
21 # Utility functions for our buildsystem
22 use make::utilities;
23 use make::configure;
24
25 GetOptions (
26         'enable-gnutls' => \$opt_use_gnutls,
27         'rebuild' => \$opt_rebuild,
28         'enable-openssl' => \$opt_use_openssl,
29         'disable-interactive' => \$opt_nointeractive,
30         'with-nick-length=i' => \$opt_nick_length,
31         'with-channel-length=i' => \$opt_chan_length,
32         'with-max-clients=i' => \$opt_maxclients,
33         'enable-epoll' => \$opt_epoll,
34         'enable-kqueue' => \$opt_kqueue,
35         'disable-epoll' => \$opt_noepoll,
36         'disable-kqueue' => \$opt_nokqueue,
37         'enable-ipv6' => \$opt_ipv6,
38         'enable-remote-ipv6' => \$opt_ipv6links,
39         'disable-remote-ipv6' => \$opt_noipv6links,
40         'with-cc=s' => \$opt_cc,
41         'with-ident-length=i' => \$opt_ident,
42         'with-quit-length=i' => \$opt_quit,
43         'with-topic-length=i' => \$opt_topic,
44         'with-kick-length=i' => \$opt_kick,
45         'with-gecos-length=i' => \$opt_gecos,
46         'with-away-length=i' => \$opt_away,
47         'with-max-modes=i' => \$opt_modes,
48         'prefix=s' => \$opt_base_dir,
49         'config-dir=s' => \$opt_config_dir,
50         'module-dir=s' => \$opt_module_dir,
51         'binary-dir=s' => \$opt_binary_dir,
52         'library-dir=s' => \$opt_library_dir,
53         'disable-debuginfo' => sub { $opt_disable_debug = 1 },
54         'help'  => sub { showhelp(); },
55         'modupdate' => sub { modupdate(); },
56         'update' => sub { update(); },
57         'svnupdate' => sub { svnupdate(); },
58         'clean' => sub { clean(); },
59 );
60
61 my $non_interactive = (
62         (defined $opt_library_dir) ||
63         (defined $opt_base_dir) ||
64         (defined $opt_config_dir) ||
65         (defined $opt_module_dir) ||
66         (defined $opt_base_dir) ||
67         (defined $opt_binary_dir) ||
68         (defined $opt_nointeractive) ||
69         (defined $opt_away) ||
70         (defined $opt_gecos) ||
71         (defined $opt_kick) ||
72         (defined $opt_maxclients) ||
73         (defined $opt_modes) ||
74         (defined $opt_topic) ||
75         (defined $opt_quit) ||
76         (defined $opt_ident) ||
77         (defined $opt_cc) ||
78         (defined $opt_ipv6) ||
79         (defined $opt_ipv6links) ||
80         (defined $opt_noipv6links) ||
81         (defined $opt_kqueue) ||
82         (defined $opt_epoll) ||
83         (defined $opt_maxchans) ||
84         (defined $opt_opermaxchans) ||
85         (defined $opt_chan_length) ||
86         (defined $opt_nick_length) ||
87         (defined $opt_use_openssl) ||
88         (defined $opt_nokqueue) ||
89         (defined $opt_noepoll) ||
90         (defined $opt_use_gnutls)
91 );
92 my $interactive = !$non_interactive;
93
94
95 chomp($topdir = getcwd());
96 $this = resolve_directory($topdir);                                             # PWD, Regardless.
97 @modlist = ();                                                          # Declare for Module List..
98 %config = ();                                                           # Initiate Configuration Hash..
99 $config{ME}              = resolve_directory($topdir);                  # Present Working Directory
100
101 $config{BASE_DIR}          = $config{ME};
102
103 if (defined $opt_base_dir)
104 {
105         $config{BASE_DIR} = $opt_base_dir;
106 }
107
108 $config{CONFIG_DIR}      = resolve_directory($config{BASE_DIR}."/conf");                # Configuration Directory
109 $config{MODULE_DIR}      = resolve_directory($config{BASE_DIR}."/modules");             # Modules Directory
110 $config{BINARY_DIR}      = resolve_directory($config{BASE_DIR}."/bin");         # Binary Directory
111 $config{LIBRARY_DIR}    = resolve_directory($config{BASE_DIR}."/lib");          # Library Directory
112
113 if (defined $opt_config_dir)
114 {
115         $config{CONFIG_DIR} = $opt_config_dir;
116 }
117 if (defined $opt_module_dir)
118 {
119         $config{MODULE_DIR} = $opt_module_dir;
120 }
121 if (defined $opt_binary_dir)
122 {
123         $config{BINARY_DIR} = $opt_binary_dir;
124 }
125 if (defined $opt_library_dir)
126 {
127         $config{LIBRARY_DIR} = $opt_library_dir;
128 }
129 chomp($config{HAS_GNUTLS}   = `libgnutls-config --version 2>/dev/null | cut -c 1,2,3`); # GNUTLS Version.
130 chomp($config{HAS_OPENSSL}  = `pkg-config --modversion openssl 2>/dev/null`);                   # Openssl version
131 chomp($gnutls_ver = $config{HAS_GNUTLS});
132 chomp($openssl_ver = $config{HAS_OPENSSL});
133 $config{USE_GNUTLS}         = "n";
134 if (defined $opt_use_gnutls)
135 {
136         $config{USE_GNUTLS} = "y";                                              # Use gnutls.
137 }
138 $config{USE_OPENSSL}    = "n";                                          # Use openssl.
139 if (defined $opt_use_openssl)
140 {
141         $config{USE_OPENSSL} = "y";
142 }
143
144 # no, let's not change these.
145 $config{OPTIMITEMP}      = "0";                                 # Default Optimisation Value
146 if (!defined $opt_disable_debug)
147 {
148         $config{OPTIMISATI}      = "-g1";                               # Optimisation Flag
149 }
150 else
151 {
152         $config{OPTIMISATI}      = "-O2";                                       # DEBUGGING OFF!
153 }
154
155 $config{NICK_LENGT}      = "31";                                        # Default Nick Length
156 if (defined $opt_nick_length)
157 {
158         $config{NICK_LENGT} = $opt_nick_length;
159 }
160 $config{CHAN_LENGT}      = "64";                                        # Default Channel Name Length
161 if (defined $opt_chan_length)
162 {
163         $config{CHAN_LENGT} = $opt_chan_length;
164 }
165 $config{MAXI_MODES}      = "20";                                        # Default Max. Number of Modes set at once.
166 if (defined $opt_modes)
167 {
168         $config{MAXI_MODES} = $opt_modes;
169 }
170 $config{HAS_STRLCPY}    = "false";                                      # strlcpy Check.
171 $config{HAS_STDINT}      = "false";                                             # stdint.h check
172 $config{USE_KQUEUE}      = "y";                                         # kqueue enabled
173 if (defined $opt_kqueue)
174 {
175         $config{USE_KQUEUE} = "y";
176 }
177 if (defined $opt_nokqueue)
178 {
179         $config{USE_KQUEUE} = "n";
180 }
181 $config{USE_EPOLL}        = "y";                                                # epoll enabled
182 if (defined $opt_epoll)
183 {
184         $config{USE_EPOLL} = "y";
185 }
186 if (defined $opt_noepoll)
187 {
188         $config{USE_EPOLL} = "n";
189 }
190 $config{IPV6}          = "n";                                           # IPv6 support (experimental)
191 if (defined $opt_ipv6)
192 {
193         $config{IPV6} = "y";
194 }
195 $config{SUPPORT_IP6LINKS}   = "y";                                              # IPv4 supporting IPv6 links (experimental)
196 if (defined $opt_ipv6links)
197 {
198         $config{SUPPORT_IP6LINKS} = "y";
199 }
200 if (defined $opt_noipv6links)
201 {
202         $config{SUPPORT_IP6LINKS} = "n";
203 }
204 $config{STATIC_LINK}        = "no";                                             # are doing static modules?
205 chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`);                   # FD Limit
206 chomp($config{MAX_DESCRIPTORS} = `sh -c \"ulimit -n\"`);                        # Hard FD Limit
207 chomp($config{GCCVER}       = `g++ -dumpversion | cut -c 1`);                   # Major GCC Version
208 $config{_SOMAXCONN} = SOMAXCONN;                                                # Max connections in accept queue
209 $config{OSNAME}             = $^O;                                      # Operating System Name
210 $config{IS_DARWIN}          = "NO";                                             # Is OSX?
211 if ($config{OSNAME} =~ /darwin/i)
212 {
213         $config{IS_DARWIN} = "YES";
214 }
215 $config{CC}                 = "g++";                                            # C++ compiler
216 if (defined $opt_cc)
217 {
218         $config{CC} = $opt_cc;
219 }
220 $exec = $config{CC} . " -dumpversion | cut -c 1";
221 chomp($config{GCCVER}       = `$exec`);                                         # Major GCC Version
222 $config{MAKEORDER}          = "ircd mods";                                      # build order
223 $config{STATICLIBS}      = "";                                          # library archive path
224 $config{MAX_IDENT}        = "12";                                               # max ident size
225 $config{MAX_QUIT}          = "255";                                             # max quit message size
226 $config{MAX_TOPIC}        = "307";                                              # max topic size
227 $config{MAX_KICK}          = "255";                                             # max kick message size
228 $config{MAX_GECOS}        = "128";                                              # max GECOS size
229 $config{MAX_AWAY}          = "200";                                             # max AWAY size
230 if (defined $opt_ident)
231 {
232         $config{MAX_IDENT} = $opt_ident;
233 }
234 if (defined $opt_quit)
235 {
236         $config{MAX_QUIT} = $opt_quit;
237 }
238 if (defined $opt_topic)
239 {
240         $config{MAX_TOPIC} = $opt_topic;
241 }
242 if (defined $opt_kick)
243 {
244         $config{MAX_KICK} = $opt_kick;
245 }
246 if (defined $opt_gecos)
247 {
248         $config{MAX_GECOS} = $opt_gecos;
249 }
250 if (defined $opt_away)
251 {
252         $config{MAX_AWAY} = $opt_away;
253 }
254
255 $config{HAS_OPENSSL} =~ /^([-[:digit:].]+)([a-z])?(\-[a-z][0-9])?$/;
256 $config{HAS_OPENSSL} = $1;
257
258 if ($config{GCCVER} eq "") {
259         print $config{CC} . " was not found! You require g++ (the GNU C++ compiler, part of GCC) to build InspIRCd!\n";
260         exit;
261 }
262
263 # Minihack! Convert Cygwin to 'Cyg-Static' so i can
264 # Keep my dynamic module experiments here for later
265 # consideration!
266
267 if ($config{OSNAME} =~ /CYGWIN/i)
268 {
269         $config{OSNAME} = "CYG-STATIC";
270 }
271
272 if (!$config{MAX_CLIENT_T}) { 
273         $config{MAX_CLIENT_T} = 1024;                            # Set a reasonable 'Default'
274         $fd_scan_fail = "true";                                # Used Later
275 }
276
277 # Get and Set some important vars..
278 getmodules();
279
280 sub clean
281 {
282         system("rm -rf .config.cache");
283 }
284
285 sub update
286 {
287         eval {
288                 chomp($topdir = getcwd());
289                 $this = resolve_directory($topdir);                                          # PWD, Regardless.
290                 getmodules();
291                 # Does the cache file exist?
292                 if (!getcache()) {
293                         # No, No it doesn't.. *BASH*
294                         print "You have not run ./configure before. Please do this before trying to run the update script.\n";
295                         exit 0;
296                 } else {
297                         # We've Loaded the cache file and all our variables..
298                         print "Updating Files..\n";
299                         getosflags();
300                         if ($opt_disable_debug == 1)
301                         {
302                                 print "Disabling debug information (-g).\n";
303                                 $config{OPTIMISATI} = "";
304                                 getosflags();
305                         }
306                         $has_epoll = $config{HAS_EPOLL};
307                         $has_kqueue = $config{HAS_KQUEUE};
308                         writefiles(1);
309                         makecache();
310                         print "Complete.\n";
311                         exit;
312                 }
313         };
314         if ($@)
315         {
316                 print "Configure update failed: $@\n";
317         }
318         exit;
319 }
320
321 sub modupdate
322 {
323         eval {
324                 chomp($topdir = getcwd());
325                 $this = resolve_directory($topdir);                                          # PWD, Regardless.
326                 getmodules();
327                 # Does the cache file exist?
328                 if (!getcache()) {
329                         # No, No it doesn't.. *BASH*
330                         print "You have not run ./configure before. Please do this before trying to run the update script.\n";
331                         exit 0;
332                 } else {
333                         # We've Loaded the cache file and all our variables..
334                         print "Updating Files..\n";
335                         getosflags();
336                         $has_epoll = $config{HAS_EPOLL};
337                         $has_kqueue = $config{HAS_KQUEUE};
338                         writefiles(0);
339                         makecache();
340                         print "Complete.\n";
341                         exit;
342                 }
343         };
344         if ($@)
345         {
346                 print "Module update failed: $@\n";
347         }
348         exit;
349 }
350
351
352
353 sub svnupdate
354 {
355         my $fail = 0;
356         open(FH,"<.svn/entries") or $fail = 1;
357         if ($fail) {
358                 print "This is not an SVN copy of InspIRCd.\n";
359                 exit;
360         }
361         else
362         {
363                 close(FH);
364         }
365         system("svn update");
366         system("perl configure -update");
367         if (defined $opt_rebuild) {
368                 system("make install");
369         }
370         exit;
371 }
372
373 print "Running non-interactive configure...\n" unless $interactive;
374 print "Checking for cache from previous configure... ";
375 print ((getcache() eq "true") ? "found\n" : "not found\n");
376 print "Checking operating system version... ";
377 print getosflags() . "\n";
378
379 if (defined $opt_maxclients)
380 {
381         $config{MAX_CLIENT} = $opt_maxclients;
382 }
383
384 if (!$config{MAX_CLIENT}) { 
385         # If the cache hasn't set the max clients, copy the variable of MAX_CLIENT_T, this
386         # allows us to keep _T for testing purposes. (ie. "Are you sure you want to go
387         # higher than the found value" :))
388         $config{MAX_CLIENT} = $config{MAX_CLIENT_T};
389 }
390
391 printf "Checking if stdint.h exists... ";
392 $config{HAS_STDINT} = "true";
393 my $fail = 0;
394 open(STDINT, "</usr/include/stdint.h") or $config{HAS_STDINT} = "false";
395 if ($config{HAS_STDINT} eq "true") {
396         close(STDINT);
397 }
398 print "yes\n" if $config{HAS_STDINT} eq "true";
399 print "no\n" if $config{HAS_STDINT} eq "false";
400
401
402 printf "Checking if strlcpy exists... ";
403 # Perform the strlcpy() test..
404 $config{HAS_STRLCPY} = "false";
405 my $fail = 0;
406 open(STRLCPY, "</usr/include/string.h") or $fail = 1;
407 if (!$fail) {
408         while (chomp($line = <STRLCPY>)) {
409                 # try and find the delcaration of:
410                 # size_t strlcpy(...)
411                 if ($line =~ /size_t(\0x9|\s)+strlcpy/) {
412                         $config{HAS_STRLCPY} = "true";
413                 }
414         }
415         close(STRLCPY);
416 }
417 print "yes\n" if $config{HAS_STRLCPY} eq "true";
418 print "no\n" if $config{HAS_STRLCPY} eq "false";
419
420
421 printf "Checking if kqueue exists... ";
422 $has_kqueue = 0;
423 $fail = 0;
424 open(KQUEUE, "</usr/include/sys/event.h") or $fail = 1;
425 if (!$fail) {
426         while (chomp($line = <KQUEUE>)) {
427                 # try and find the delcaration of:
428                 # int kqueue(void);
429                 if ($line =~ /int(\0x9|\s)+kqueue/) {
430                         $has_kqueue = 1;
431                 }
432         }
433         close(KQUEUE);
434 }
435 print "yes\n" if $has_kqueue == 1;
436 print "no\n" if $has_kqueue == 0;
437
438 printf "Checking if epoll exists... ";
439 $has_epoll = 0;
440 $fail = 0;
441 open(EPOLL, "</usr/include/sys/epoll.h") or $fail = 1;
442 if (!$fail) {
443         $has_epoll = 1;
444         close(EPOLL);
445 }
446 if ($has_epoll) {
447         my $kernel = `uname -r`;
448         chomp($kernel);
449         if (($kernel =~ /^2\.0\./) || ($kernel =~ /^2\.2\./) || ($kernel =~ /^2\.4\./)) {
450                 $has_epoll = 0;
451         }
452 }
453 print "yes\n" if $has_epoll == 1;
454 print "no\n" if $has_epoll == 0;
455
456 if (($config{OSNAME} =~ /CYGWIN/) || ($config{OSNAME} eq "CYG-STATIC")) {
457         $config{HAS_STRLCPY} = "true";
458 }
459
460 $config{HAS_EPOLL} = $has_epoll;
461 $config{HAS_KQUEUE} = $has_kqueue; 
462
463 printf "Checking for libgnutls... ";
464 if (($config{HAS_GNUTLS}) && (($config{HAS_GNUTLS} >= 1.2) || ($config{HAS_GNUTLS} eq "y"))) {
465         print "yes\n";
466         $config{HAS_GNUTLS} = "y";
467 } else {
468         print "no\n";
469         $config{HAS_GNUTLS} = "n";
470 }
471
472 printf "Checking for openssl... ";
473 if (($config{HAS_OPENSSL}) && (($config{HAS_OPENSSL} >= 0.8) || ($config{HAS_OPENSSL} eq "y"))) {
474         print "yes\n";
475         $config{HAS_OPENSSL} = "y";
476 } else {
477         print "no\n";
478         $config{HAS_OPENSSL} = "n";
479 }
480
481 ################################################################################
482 #                         BEGIN INTERACTIVE PART                              #
483 ################################################################################
484
485 # Clear the Screen..
486 if ($interactive)
487 {
488         system("clear");
489         $wholeos = $^O;
490
491         my $rev = getrevision();
492         # Display Introduction Message..
493         print "
494 Welcome to the \033[1mInspIRCd\033[0m Configuration program! (\033[1minteractive mode\033[0m)
495 \033[1mPackage maintainers: Type ./configure --help for non-interactive help\033[0m
496
497 *** If you are unsure of any of these values, leave it blank for    ***
498 *** standard settings that will work, and your server will run      ***
499 *** using them. Please consult your IRC network admin if in doubt.  ***
500
501 Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter
502 a new value. Please note: You will \033[1mHAVE\033[0m to read the docs
503 dir, otherwise you won't have a config file!
504
505 Your operating system is: \033[1;32m$config{OSNAME}\033[0m ($wholeos)
506 Maximum file descriptors: \033[1;32m$config{MAX_CLIENT_T}\033[0m
507 Your InspIRCd revision ID is \033[1;32mr$rev\033[0m";
508         if ($rev eq "r0") {
509                 print " (Non-SVN build)";
510         }
511         print ".\n\n";
512
513         $config{CHANGE_COMPILER} = "n";
514         print "I have detected the following compiler: \033[1;32m$config{CC}\033[0m (version \033[1;32m$config{GCCVER}.x\033[0m)\n";
515
516         while (($config{GCCVER} < 3) || ($config{GCCVER} eq "")) {
517                 print "\033[1;32mIMPORTANT!\033[0m A GCC 2.x compiler has been detected, and
518 should NOT be used. You should probably specify a newer compiler.\n\n";
519                 yesno(CHANGE_COMPILER,"Do you want to change the compiler?");
520                 if ($config{CHANGE_COMPILER} =~ /y/i) {
521                         print "What command do you want to use to invoke your compiler?\n";
522                         print "[\033[1;32m$config{CC}\033[0m] -> ";
523                         chomp($config{CC} = <STDIN>);
524                         if ($config{CC} eq "") {
525                                 $config{CC} = "g++";
526                         }
527                         chomp($foo = `$config{CC} -dumpversion | cut -c 1`);
528                         if ($foo ne "") {
529                                 chomp($config{GCCVER}       = `$config{CC} -dumpversion | cut -c 1`); # we must redo these if we change compilers
530                                 print "Queried compiler: \033[1;32m$config{CC}\033[0m (version \033[1;32m$config{GCCVER}.x\033[0m)\n";
531                                 if ($config{GCCVER} < 3) {
532                                         print "\033[1;32mGCC 2.x WILL NOT WORK!\033[0m. Let's try that again, shall we?\n";
533                                 }
534                         }
535                         else {
536                                 print "\033[1;32mWARNING!\033[0m Could not execute the compiler you specified. You may want to try again.\n";
537                         }
538                 }
539         }
540
541         print "\n";
542
543         # Directory Settings..
544         my $tmpbase = $config{BASE_DIR};
545         dir_check("do you wish to install the InspIRCd base", "BASE_DIR");
546         if ($tmpbase ne $config{BASE_DIR}) {
547                 $config{CONFIG_DIR}      = resolve_directory($config{BASE_DIR}."/conf");           # Configuration Dir
548                 $config{MODULE_DIR}      = resolve_directory($config{BASE_DIR}."/modules");     # Modules Directory
549                 $config{BINARY_DIR}      = resolve_directory($config{BASE_DIR}."/bin");     # Binary Directory
550                 $config{LIBRARY_DIR}    = resolve_directory($config{BASE_DIR}."/lib");      # Library Directory
551         }
552
553         dir_check("are the configuration files", "CONFIG_DIR");
554         dir_check("are the modules to be compiled to", "MODULE_DIR");
555         dir_check("is the IRCd binary to be placed", "BINARY_DIR");
556         dir_check("are the IRCd libraries to be placed", "LIBRARY_DIR");
557
558         if ($has_kqueue) {
559                 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?");
560                 print "\n";
561         }
562         if ($has_epoll) {
563                 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?");
564                 print "\n";
565         }
566         $chose_hiperf = (($config{USE_EPOLL} eq "y") || ($config{USE_KQUEUE} eq "y"));
567         if (!$chose_hiperf) {
568                 print "No high-performance socket engines are available, or you chose\n";
569                 print "not to enable one. Defaulting to select() engine.\n\n";
570         }
571
572         yesno(IPV6,"Would you like to build InspIRCd with IPv6 support?");
573         print "\n";
574
575         if ($config{IPV6} eq "y") {
576                 print "You have chosen to build an \033[1;32mIPV6-enabled\033[0m server.\nTo accept IPV4 users, you can still use IPV4 addresses\nin your port bindings..\n\n";
577                 $config{SUPPORT_IP6LINKS} = "y";
578         } else {
579                 yesno(SUPPORT_IP6LINKS,"You have chosen to build an \033[1;32mIPV4-only\033[0m server.\nWould you like to enable support for linking to IPV6-enabled\nInspIRCd servers?\nIf you are using a recent operating\nsystem and are unsure, answer yes.\nIf you answer 'no' here, your InspIRCd server will be unable\nto parse IPV6 addresses (e.g. for CIDR bans)");
580                 print "\n";
581         }
582
583         if (($config{HAS_GNUTLS} eq "y") && ($config{HAS_OPENSSL} eq "y")) {
584                 print "I have detected both \033[1;32mGnuTLS\033[0m and \033[1;32mOpenSSL\033[0m on your system.\n";
585                 print "I will default to GnuTLS. If you wish to use OpenSSL\n";
586                 print "instead, you should enable the OpenSSL module yourself\n";
587                 print "by copying it from src/modules/extra to src/modules.\n\n";
588                 print "Detected GnuTLS version: \033[1;32m" . $gnutls_ver . "\033[0m\n";
589                 print "Detected OpenSSL version: \033[1;32m" . $openssl_ver . "\033[0m\n\n";
590         }
591
592         if ($config{HAS_GNUTLS} eq "y") {
593                 yesno(USE_GNUTLS, "Would you like to enable SSL Support?");
594                 if ($config{USE_GNUTLS} eq "y") {
595                         print "\nUsing GnuTLS SSL module.\n";
596                 }
597         } elsif ($config{HAS_OPENSSL} eq "y") {
598                         yesno(USE_OPENSSL, "Would you like to enable SSL Support?");
599         if ($config{USE_OPENSSL} eq "y") {
600                         print "\nUsing OpenSSL SSL module.\nYou will get better performance if you move to GnuTLS in the future.\n";
601                 }
602         }
603         else {
604                 print "\nCould not detect OpenSSL or GnuTLS. Make sure pkg-config is installed if\nyou intend to use OpenSSL, or that GnuTLS is in your path if you intend\nto use GnuTLS.\n\n";
605         }
606
607         print "\nThe following questions will ask you for various figures relating\n";
608         print "To your IRCd install. Please note that these should usually be left\n";
609         print "as defaults unless you have a real reason to change them. If they\n";
610         print "changed, then the values must be identical on all servers on your\n";
611         print "network, or malfunctions and/or crashes may occur, with the exception\n";
612         print "of the 'maximum number of clients' setting which may be different on\n";
613         print "different servers on the network.\n\n";
614
615         # File Descriptor Settings..
616         promptnumeric("number of clients at any one time", "MAX_CLIENT_T");
617         $config{MAX_CLIENT} = $config{MAX_CLIENT_T};
618         $config{MAX_DESCRIPTORS} = $config{MAX_CLIENT_T};
619
620         promptnumeric("length of nicknames", "NICK_LENGT");
621         promptnumeric("length of channel names", "CHAN_LENGT");
622         promptnumeric("number of mode changes in one line", "MAXI_MODES");
623         promptnumeric("length of an ident (username)", "MAX_IDENT");
624         promptnumeric("length of a quit message", "MAX_QUIT");
625         promptnumeric("length of a channel topic", "MAX_TOPIC");
626         promptnumeric("length of a kick message", "MAX_KICK");
627         promptnumeric("length of a GECOS (real name)", "MAX_GECOS");
628         promptnumeric("length of an away message", "MAX_AWAY");
629 }
630
631 dumphash();
632
633 if (($config{USE_GNUTLS} eq "y") && ($config{HAS_GNUTLS} ne "y"))
634 {
635         print "Sorry, but i couldn't detect gnutls. Make sure gnutls-config is in your path.\n";
636         exit(0);
637 }
638 if (($config{USE_OPENSSL} eq "y") && ($config{HAS_OPENSSL} ne "y"))
639 {
640         print "Sorry, but i couldn't detect openssl. Make sure openssl is in your path.\n";
641         exit(0);
642 }
643
644 if ($config{USE_GNUTLS} eq "y") {
645         $failed = 0;
646         open(TMP, "<src/modules/m_ssl_gnutls.cpp") or $failed = 1;
647         close(TMP);
648         if ($failed) {
649                 print "Symlinking src/modules/m_ssl_gnutls.cpp from extra/\n";
650                 chdir("src/modules");
651                 system("ln -s extra/m_ssl_gnutls.cpp");
652                 chdir("../..");
653         }
654         getmodules();
655         if ($interactive)
656         {
657                 $failed = 0;
658                 open(TMP, "<$config{CONFIG_DIR}/key.pem") or $failed = 1;
659                 close(TMP);
660                 open(TMP, "<$config{CONFIG_DIR}/cert.pem") or $failed = 1;
661                 close(TMP);
662                 if ($failed) {
663                         print "SSL Certificates Not found, Generating.. \n\n
664 *************************************************************
665 * Generating the Private Key may take some time, go grab a  *
666 * Coffee. Even better, to generate some more entropy if it  *
667 * is taking a while, open another console and type du / a   *
668 * few times and get that HD going :) Then answer the    *
669 * Questions which follow. If you are unsure, just hit enter *
670 *************************************************************\n\n";
671                         system("certtool --generate-privkey --outfile key.pem");
672                         system("certtool --generate-self-signed --load-privkey key.pem --outfile cert.pem");
673                         print "\nCertificate generation complete, copying to config directory... ";
674                         system("mv key.pem $config{CONFIG_DIR}/key.pem");
675                         system("mv cert.pem $config{CONFIG_DIR}/cert.pem");
676                         print "Done.\n\n";
677                 } else {
678                         print "SSL Certificates found, skipping.\n\n"
679                 }
680         }
681         else
682         {
683                 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
684         }
685 } elsif ($config{USE_OPENSSL} eq "y") {
686         $failed = 0;
687         open(TMP, "<src/modules/m_ssl_openssl.cpp") or $failed = 1;
688         close(TMP);
689         if ($failed) {
690                 print "Symlinking src/modules/m_ssl_openssl.cpp from extra/\n";
691                 chdir("src/modules");
692                 system("ln -s extra/m_ssl_openssl.cpp");
693                 chdir("../..");
694         }
695         getmodules();
696         $failed = 0;
697         if ($interactive)
698         {
699                 open(TMP, "<$config{CONFIG_DIR}/key.pem") or $failed = 1;
700                 close(TMP);
701                 open(TMP, "<$config{CONFIG_DIR}/cert.pem") or $failed = 1;
702                 close(TMP);
703                 if ($failed) {
704                         print "SSL Certificates Not found, Generating.. \n\n
705 *************************************************************
706 * Generating the certificates may take some time, go grab a *
707 * coffee, or something.                              *
708 *************************************************************\n\n";
709                         system("openssl req -x509 -nodes -newkey rsa:1024 -keyout key.pem -out cert.pem");
710                         system("openssl dhparam -out dhparams.pem 1024");
711                         print "\nCertificate generation complete, copying to config directory... ";
712                         system("mv key.pem $config{CONFIG_DIR}/key.pem");
713                         system("mv cert.pem $config{CONFIG_DIR}/cert.pem");
714                         system("mv dhparams.pem $config{CONFIG_DIR}/dhparams.pem");
715                         print "Done.\n\n";
716                 } else {
717                         print "SSL Certificates found, skipping.\n\n"
718                 }
719         }
720         else
721         {
722                 print "Skipping SSL certificate generation\nin non-interactive mode.\n\n";
723         }
724 }
725 if (($config{USE_GNUTLS} eq "n") && ($config{USE_OPENSSL} eq "n")) {
726         print "Skipping SSL Certificate generation, SSL support is not available.\n\n";
727 }
728
729 getosflags();
730 writefiles(1);
731 makecache();
732
733 print "\n\n";
734 print "To build your server with these settings, please type '\033[1;32m$config{MAKEPROG}\033[0m' now.\n";
735 if (($config{USE_GNUTLS} eq "y") || ($config{USE_OPENSSL} eq "y")) {
736         print "Please remember that to enable \033[1;32mSSL support\033[0m you must\n";
737         print "load the required modules in your config. This configure process\n";
738         print "has just prepared these modules to be compiled for you, and has not\n";
739         print "configured them to be compiled into the core of the ircd.\n";
740 }
741 print "*** \033[1;32mRemember to edit your configuration files!!!\033[0m ***\n\n\n";
742 if (($config{OSNAME} eq "OpenBSD") && ($config{CC} ne "eg++")) {
743         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";
744 }
745
746 if ($config{GCCVER} < "3") {
747         print <<FOO2;
748 \033[1;32mWARNING!\033[0m You are attempting to compile InspIRCd on GCC 2.x!
749 GCC 2.x series compilers only had partial (read as broken) C++ support, and
750 your compile will most likely fail horribly! If you have any problems, do NOT
751 report them to the bugtracker or forums without first upgrading your compiler
752 to a newer 3.x or 4.x (or whatever is available currently) version.
753 FOO2
754 }
755
756 ################################################################################
757 #                             HELPER FUNCTIONS                          #
758 ################################################################################
759 sub getcache {
760         # Retrieves the .config.cache file, and loads values into the main config hash.
761         open(CACHE, ".config.cache") or return undef;
762         while (<CACHE>) {
763                 chomp;
764                 # Ignore Blank lines, and comments..
765                 next if /^\s*$/;
766                 next if /^\s*#/;
767                 my ($key, $value) = split("=", $_, 2);
768                 $value =~ /^\"(.*)\"$/;
769                 # Do something with data here!
770                 $config{$key} = $1;
771         }
772         close(CONFIG);
773         return "true";
774 }
775
776 sub makecache {
777         # Dump the contents of %config
778         print "Writing \033[1;32mcache file\033[0m for future ./configures ...\n";
779         open(FILEHANDLE, ">.config.cache");
780         foreach $key (keys %config) {
781                 print FILEHANDLE "$key=\"$config{$key}\"\n";
782         }
783         close(FILEHANDLE);
784 }
785
786 sub dir_check {
787         my ($desc, $hash_key) = @_;
788         my $complete = 0;
789         while (!$complete) {
790                 print "In what directory $desc?\n";
791                 print "[\033[1;32m$config{$hash_key}\033[0m] -> ";
792                 chomp($var = <STDIN>);
793                 if ($var eq "") {
794                         $var = $config{$hash_key};
795                 }
796                 if ($var =~ /^\~\/(.+)$/) {
797                         # Convert it to a full path..
798                         $var = resolve_directory($ENV{HOME} . "/" . $1);
799                 }
800                 elsif ((($config{OSNAME} =~ /MINGW32/i) and ($var !~ /^[A-Z]{1}:\\.*/)) and (substr($var,0,1) ne "/"))
801                 {
802                         # Assume relative Path was given.. fill in the rest.
803                         $var = $this . "/$var";
804                 }
805                 
806                 $var = resolve_directory($var); 
807                 if (! -e $var) {
808                         print "$var does not exist. Create it?\n[\033[1;32my\033[0m] ";
809                         chomp($tmp = <STDIN>);
810                         if (($tmp eq "") || ($tmp =~ /^y/i)) {
811                                 # Attempt to Create the Dir..
812                                 
813                                 system("mkdir -p \"$var\" >> /dev/null 2>&1");
814                                 $chk = system("mkdir -p \"$var\" >> /dev/null 2>&1") / 256;
815                                 if ($chk != 0) {
816                                         print "Unable to create directory. ($var)\n\n";
817                                         # Restart Loop..
818                                         next;
819                                 }
820                         } else {
821                                 # They said they don't want to create, and we can't install there.
822                                 print "\n\n";
823                                 next;
824                         }
825                 } else {
826                         if (!is_dir($var)) {
827                                 # Target exists, but is not a directory.
828                                 print "File $var exists, but is not a directory.\n\n";
829                                 next;
830                         }
831                 }
832                 # Either Dir Exists, or was created fine.
833                 $config{$hash_key} = $var;
834                 $complete = 1;
835                 print "\n";
836         }
837 }
838
839 sub getosflags {
840
841         $config{LDLIBS} = "-lstdc++";
842         $config{FLAGS}  = "-fno-strict-aliasing -fPIC -Wall -Woverloaded-virtual $config{OPTIMISATI}";
843         $config{DEVELOPER} = "-fno-strict-aliasing -fPIC -Wall -Woverloaded-virtual -g";
844         $SHARED = "-Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared";
845         $config{MAKEPROG} = "make";
846
847         if ($config{OSNAME} =~ /darwin/i) {
848                 $config{FLAGS}  = "-DDARWIN -frtti -fPIC -Wall -Woverloaded-virtual $config{OPTIMISATI}";
849                 $SHARED = "-bundle -twolevel_namespace -undefined dynamic_lookup";
850                 $config{LDLIBS} = "-ldl -lstdc++";
851         }
852
853         if ($config{OSNAME} =~ /OpenBSD/i) {
854                 $config{MAKEPROG} = "gmake";
855                 chomp($foo = `eg++ -dumpversion | cut -c 1`);
856                 # theyre running the package version of gcc (eg++)... detect it and set up its version numbers.
857                 # if theyre not running this, configure lets the build continue but they probably wont manage to
858                 # compile as this standard version is 2.95.3!
859                 if ($foo ne "") {
860                         $config{CC} = "eg++";
861                         chomp($config{GCCVER}       = `eg++ -dumpversion | cut -c 1`); # we must redo these if we change the compiler path
862                 }
863                 return "OpenBSD";
864         }
865
866         if ($config{OSNAME} =~ /Linux/i) {
867                 $config{LDLIBS} = "-ldl -lstdc++";
868                 $config{FLAGS}  = "-fno-strict-aliasing -fPIC -Wall -Woverloaded-virtual $config{OPTIMISATI}";
869                 $config{FLAGS}  .= " " . $ENV{CXXFLAGS} if exists($ENV{CXXFLAGS});
870                 $config{MAKEPROG} = "make";
871                 if ($config{OSNAME} =~ /CYGWIN/) {
872                         $config{FLAGS}  = "-fno-strict-aliasing -Wall -Woverloaded-virtual $config{OPTIMISATI}";
873                         $config{LDLIBS} = "";
874                         $config{MAKEPROG} = "/usr/bin/make";
875                         $config{MAKEORDER} = "ircd mods";
876                         return "Cygwin";
877                 } elsif ($config{OSNAME} eq "CYG-STATIC") {
878                         $config{FLAGS} = "-fno-strict-aliasing -Wall -Woverloaded-virtual $config{OPTIMISATI}";
879                         $config{LDLIBS} = "";
880                         $config{MAKEPROG} = "/usr/bin/make";
881                         $config{MAKEORDER} = "mods ircd";
882                         $config{STATICLIBS} = "modules/mods.a";
883                         $config{STATIC_LINK} = "yes";
884                         return "Cygwin-Static";
885                 }
886                 $config{FLAGS}  .= " " . $ENV{CXXFLAGS} if exists($ENV{CXXFLAGS});
887         }
888         
889         if ($config{OSNAME} =~ /SunOS/i)
890         {
891                 # solaris/sunos needs these
892                 # socket = bsd sockets api
893                 # nsl = dns stuff
894                 # rt = POSIX realtime extensions
895                 # resolv = inet_aton only (why isnt this in nsl?!)
896                 $config{MAKEPROG} = "gmake";
897                 $config{LDLIBS} = $config{LDLIBS} . " -lsocket -lnsl -lrt -lresolv";
898                 return "Solaris";
899         }
900         
901         if($config{OSNAME} =~ /MINGW32/i)
902         {
903                 # All code is position-independent on windows
904                 $config{FLAGS} =~ s/-fPIC //;
905                 return "MinGW";
906         }
907
908         return $config{OSNAME};
909 }
910
911 sub writefiles {
912         my($writeheader) = @_;
913         # First File.. inspircd_config.h
914         chomp(my $incos = `uname -n -s -r`);
915         chomp($version = `sh src/version.sh`);
916         chomp(my $revision2 = getrevision());
917         if ($writeheader == 1)
918         {
919                 print "Writing \033[1;32minspircd_config.h\033[0m\n";
920                 open(FILEHANDLE, ">include/inspircd_config.h");
921                 my $NL = $config{NICK_LENGT}+1;
922                 my $CL = $config{CHAN_LENGT}+1;
923                 print FILEHANDLE <<EOF;
924 /* Auto generated by configure, do not modify! */
925 #ifndef __CONFIGURATION_AUTO__
926 #define __CONFIGURATION_AUTO__
927
928 #define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf"
929 #define MOD_PATH "$config{MODULE_DIR}"
930 #define VERSION "$version"
931 #define REVISION "$revision2"
932 #define MAXCLIENTS $config{MAX_CLIENT}
933 #define MAXCLIENTS_S "$config{MAX_CLIENT}"
934 #define SOMAXCONN_S "$config{_SOMAXCONN}"
935 #define MAX_DESCRIPTORS $config{MAX_DESCRIPTORS}
936 #define NICKMAX $NL
937 #define CHANMAX $CL
938 #define MAXMODES $config{MAXI_MODES}
939 #define IDENTMAX $config{MAX_IDENT}
940 #define MAXQUIT $config{MAX_QUIT}
941 #define MAXTOPIC $config{MAX_TOPIC}
942 #define MAXKICK $config{MAX_KICK}
943 #define MAXGECOS $config{MAX_GECOS}
944 #define MAXAWAY $config{MAX_AWAY}
945 #define OPTIMISATION $config{OPTIMITEMP}
946 #define LIBRARYDIR "$config{LIBRARY_DIR}"
947 #define SYSTEM "$incos"
948 #define MAXBUF 514
949 EOF
950                 if ($config{OSNAME} =~ /SunOS/i) {
951                         print FILEHANDLE "#define IS_SOLARIS\n";
952                 }
953                 if ($config{OSNAME} =~ /CYGWIN/i) {
954                         print FILEHANDLE "#define IS_CYGWIN\n";
955                         print FILEHANDLE "#ifndef FD_SETSIZE\n#define FD_SETSIZE        1024\n#endif\n";
956                 }
957                 if ($config{OSNAME} =~ /MINGW32/i) {
958                         print FILEHANDLE "#define IS_MINGW\n";
959                 }
960                 if ($config{OSNAME} =~ /CYG-STATIC/i) {
961                         print FILEHANDLE "#ifndef FD_SETSIZE\n#define FD_SETSIZE    1024\n#endif\n";
962                 }
963                 if ($config{STATIC_LINK} eq "yes") {
964                         print FILEHANDLE "#define STATIC_LINK\n";
965                 }
966                 if ($config{GCCVER} >= 3) {
967                         print FILEHANDLE "#define GCC3\n";
968                 }
969                 if ($config{HAS_STRLCPY} eq "true") {
970                         print FILEHANDLE "#define HAS_STRLCPY\n";
971                 }
972                 if ($config{HAS_STDINT} eq "true") {
973                         print FILEHANDLE "#define HAS_STDINT\n";
974                 }
975                 if ($config{IPV6} =~ /y/i) {
976                         print FILEHANDLE "#define IPV6\n";
977                 }
978                 if ($config{SUPPORT_IP6LINKS} =~ /y/i) {
979                         print FILEHANDLE "#define SUPPORT_IP6LINKS\n";
980                 }
981                 my $use_hiperf = 0;
982                 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
983                         print FILEHANDLE "#define USE_KQUEUE\n";
984                         $se = "socketengine_kqueue";
985                         $use_hiperf = 1;
986                 }
987                 if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
988                         print FILEHANDLE "#define USE_EPOLL\n";
989                         $se = "socketengine_epoll";
990                         $use_hiperf = 1;
991                 }
992                 # user didn't choose either epoll or select for their OS.
993                 # default them to USE_SELECT (ewwy puke puke)
994                 if (!$use_hiperf) {
995                         print FILEHANDLE "#define USE_SELECT\n";
996                         $se = "socketengine_select";
997                 }
998                 print FILEHANDLE "\n#endif\n";
999                 close(FILEHANDLE);
1000         }
1001
1002         if ($writeheader)
1003         {
1004                 open(FILEHANDLE, ">include/inspircd_se_config.h");
1005                 print FILEHANDLE <<EOF;
1006 /* Auto generated by configure, do not modify or commit to svn! */
1007 #ifndef __CONFIGURATION_SOCKETENGINE__
1008 #define __CONFIGURATION_SOCKETENGINE__
1009
1010 #include "$se.h"
1011
1012 #endif
1013 EOF
1014                 close(FILEHANDLE);
1015         }
1016
1017
1018         # Create a Modules List..
1019         my $modules = "";
1020         foreach $i (@modlist)
1021         {
1022                 if ($config{STATIC_LINK} eq "yes") {
1023                         $modules .= "m_".$i.".o ";
1024                 }
1025                 else {
1026                         $modules .= "m_".$i.".so ";
1027                 }
1028         }
1029         chomp($modules);   # Remove Redundant whitespace..
1030
1031         opendir(DIRHANDLE, "src/modules");
1032         foreach $name (sort readdir(DIRHANDLE)) {
1033                 if ($name =~ /^m_(.+?)$/) {
1034                         if (opendir(MDIRHANDLE, "src/modules/$name") != 0) {
1035                                 closedir(MDIRHANDLE);
1036                                 $modules .= "$name.so ";
1037                         }
1038                 }
1039         }
1040         closedir(DIRHANDLE);
1041
1042
1043         # Write all .in files.
1044         my $tmp = "";
1045         my $file = "";
1046         my $exe = "inspircd";
1047
1048         if ($config{OSNAME} =~ /CYGWIN/i) {
1049                 $exe = "inspircd.exe";
1050         }
1051
1052         opendir(DIRHANDLE, $this);
1053
1054         # Do this once here, and cache it in the .*.inc files,
1055         # rather than attempting to read src/version.sh from
1056         # compiled code -- we might not have the source to hand.
1057         # Fix for bug#177 by Brain.
1058
1059         chomp(my $version = `sh ./src/version.sh`);
1060         chomp(my $revision = getrevision());
1061         $version = "$version(r$revision)";
1062
1063         my $LIBEXT = "so";
1064         if ($config{IS_DARWIN} eq "YES")
1065         {
1066                 $LIBEXT = "dylib";
1067         }
1068         # We can actually parse any file starting with . and ending with .inc,
1069         # but right now we only parse .inspircd.inc to form './inspircd'
1070
1071         foreach $name (sort readdir(DIRHANDLE)) {
1072                 if ($name =~ /^\.(.+)\.inc$/) {
1073                         $file = $1;
1074                         # All .name.inc files need parsing!
1075                         $tmp = "";
1076                         open(FILEHANDLE, ".$file.inc");
1077                         while (<FILEHANDLE>) {
1078                                 $tmp .= $_;
1079                         }
1080                         close(FILEHANDLE);
1081
1082                         $tmp =~ s/\@CC\@/$config{CC}/;
1083                         $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
1084                         $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
1085                         $tmp =~ s/\@DEVELOPER\@/$config{DEVELOPER}/;
1086                         $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
1087                         $tmp =~ s/\@BASE_DIR\@/$config{BASE_DIR}/;
1088                         $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
1089                         $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
1090                         $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
1091                         $tmp =~ s/\@LIBRARY_DIR\@/$config{LIBRARY_DIR}/;
1092                         $tmp =~ s/\@LIBRARY_EXT\@/$LIBEXT/;
1093                         $tmp =~ s/\@MODULES\@/$modules/;
1094                         $tmp =~ s/\@EXECUTABLE\@/$exe/;
1095                         $tmp =~ s/\@MAKEORDER\@/$config{MAKEORDER}/;
1096                         $tmp =~ s/\@STATICLIBS\@/$config{STATICLIBS}/;
1097                         $tmp =~ s/\@VERSION\@/$version/;
1098
1099                         print "Writing \033[1;32m$file\033[0m\n";
1100                         open(FILEHANDLE, ">$file");
1101                         print FILEHANDLE $tmp;
1102                 }
1103         }
1104         closedir(DIRHANDLE);
1105
1106         # Make inspircd executable!
1107         chmod 0744, 'inspircd';
1108
1109         if ($config{STATIC_LINK} eq "yes") {
1110                 print "Writing static-build \033[1;32msrc/Makefile\033[0m\n";
1111                 write_static_makefile();
1112                 write_static_modules_makefile();
1113         } elsif ($config{OSNAME} =~ /CYGWIN/i) {
1114                 print "Writing cygwin-build \033[1;32msrc/Makefile\033[0m\n";
1115                 write_static_makefile();
1116                 write_dynamic_modules_makefile();
1117         } else {
1118                 print "Writing dynamic-build \033[1;32msrc/Makefile\033[0m\n";
1119                 write_dynamic_makefile();
1120                 write_dynamic_modules_makefile();
1121         }
1122 }
1123
1124 sub write_static_modules_makefile {
1125         # Modules Makefile..
1126         print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
1127         open(FILEHANDLE, ">src/modules/Makefile");
1128
1129         ###
1130         # Module Makefile Header
1131         ###
1132         print FILEHANDLE <<EOF;
1133 # (C) ChatSpike development team
1134 # Makefile by <Craig\@ChatSpike.net>
1135 # Many Thanks to Andrew Church <achurch\@achurch.org>
1136 #    for assisting with making this work right.
1137 #
1138 # Automatically Generated by ./configure to add a modules
1139 # please run ./configure --update
1140
1141 all: \$(MODULES)
1142
1143 EOF
1144         ###
1145         # End Module Makefile Header
1146         ###
1147
1148         # Create a Modules List..
1149         my $modules = "";
1150         my $cmflags = "";
1151         my $liflags = "";
1152
1153         open(MODLIST,">include/modlist.h");
1154
1155         ###
1156         # Include File Header
1157         ###
1158         print MODLIST <<HEADER;
1159 // Generated automatically by configure. DO NOT EDIT!
1160
1161 #ifndef __SYMBOLS__H_CONFIGURED__
1162 #define __SYMBOLS__H_CONFIGURED__
1163
1164 HEADER
1165         ###
1166         # End Include File Header
1167         ###
1168
1169         # Place Module List into Include
1170         foreach $i (@modlist) {
1171                 if ($i !~ /_static$/) {
1172                         print MODLIST "extern \"C\" void * $i\_init (void);\n";
1173                 }
1174         }
1175         print MODLIST "\nstruct {const char *name; initfunc *value; } modsyms[] = {\n";
1176
1177         ###
1178         # Build Module Crap
1179         ###
1180         foreach $i (@modlist)
1181         {
1182                 if ($i !~ /_static$/) {
1183                         $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1184                         $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1185                         $deps = getdependencies("src/modules/m_".$i.".cpp");
1186
1187                         #print "file: $i: cmflags=$cmflags; liflags=$liflags; deps=$deps\n";
1188
1189                         ###
1190                         # Write Entry to the Makefile
1191                         ###
1192                         print FILEHANDLE <<EOCHEESE;
1193 m_$i.o: .m_$i\_static.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h $deps
1194         \$(CC) -pipe -I../../include \$(FLAGS) $flags -export-dynamic -c .m_$i\_static.cpp
1195         mv .m_$i\_static.o ../m_$i.o
1196
1197 EOCHEESE
1198                         ###
1199                         # End Write Entry to the MakeFile
1200                         ###
1201                         print "Configuring module [\033[1;32mm_$i.so\033[0m] for static linking... ";
1202                         open(MODULE,"<src/modules/m_".$i.".cpp") or die("Could not open m_".$i.".cpp");
1203                         open(MUNGED,">src/modules/.m_".$i."_static.cpp") or die("Could not create .m_".$i."_static.cpp");
1204                         while (chomp($a = <MODULE>)) { 
1205                                 $a =~ s/init_module/$i\_init/g;
1206                                 print MUNGED "$a\n";
1207                         }
1208                         close(MODULE);
1209                         close(MUNGED);
1210                         print MODLIST <<EOENT;
1211 {"m_$i.so",\&$i\_init},
1212 EOENT
1213                         print "done\n";
1214                 }
1215         }
1216
1217         print MODLIST "{0}};\n\n#endif\n";
1218         close(MODLIST);
1219 }
1220
1221 sub write_dynamic_modules_makefile {
1222         # Modules Makefile..
1223         print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
1224         open(FILEHANDLE, ">src/modules/Makefile");
1225         my $extra = "";
1226
1227         if ($config{OSNAME} =~ /CYGWIN/i) {
1228                 $extra = "../inspircd.dll.a";
1229         }
1230
1231 ###
1232 # Module Makefile Header
1233 ###
1234         print FILEHANDLE <<EOF;
1235 # (C) ChatSpike development team
1236 # Makefile by <Craig\@ChatSpike.net>
1237 # Many Thanks to Andrew Church <achurch\@achurch.org>
1238 #    for assisting with making this work right.
1239 #
1240 # Automatically Generated by ./configure to add a modules
1241 # please run ./configure -update or ./configure -modupdate
1242
1243 all: \$(MODULES)
1244
1245 EOF
1246         ###
1247         # End Module Makefile Header
1248         ###
1249
1250         # Create a Modules List..
1251         my $modules = "";
1252         my $cmflags = "";
1253         my $liflags = "";
1254         my $crud = "";
1255
1256         foreach $i (@modlist) {
1257                 ###
1258                 # Write Entry to the MakeFile
1259                 ###
1260                 $cmflags = getcompilerflags("src/modules/m_".$i.".cpp");
1261                 $liflags = getlinkerflags("src/modules/m_".$i.".cpp");
1262                 $deps = getdependencies("src/modules/m_".$i.".cpp");
1263         
1264                 #print "file: $i: cmflags=$cmflags; liflags=$liflags; deps=$deps\n";
1265         
1266                 print FILEHANDLE <<EOCHEESE;
1267 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/configreader.h $deps
1268         \$(CC) -pipe -I../../include \$(FLAGS) $cmflags -export-dynamic -c m_$i.cpp
1269 EOCHEESE
1270
1271 if ($config{OSNAME} =~ /darwin/) {
1272                 print FILEHANDLE <<EOCHEESE;
1273         \$(CC) -pipe -twolevel_namespace -undefined dynamic_lookup \$(FLAGS) -bundle $liflags -o m_$i.so m_$i.o $extra
1274
1275 EOCHEESE
1276 } else {
1277                 print FILEHANDLE <<EOCHEESE;
1278         \$(CC) -pipe \$(FLAGS) -shared $liflags -o m_$i.so m_$i.o $extra
1279
1280 EOCHEESE
1281 }
1282                 $crud = $crud . "       install -m \$(INSTMODE) m_$i.so \$(MODPATH)\n";
1283 ###
1284                 # End Write Entry to the MakeFile
1285                 ###
1286         }
1287
1288         opendir(DIRHANDLE, "src/modules");
1289         foreach $name (sort readdir(DIRHANDLE)) {
1290                 if ($name =~ /^m_(.+?)$/) {
1291                         $crapola = "";
1292                         $crap3 = "";
1293                         # A module made of multiple files, in a dir, e.g. src/modules/m_spanningtree/
1294                         if (opendir(MDIRHANDLE, "src/modules/$name") != 0) {
1295                                 print "Composing Makefile rules for directory \033[1;32m$name\033[0m... ";
1296                                 my $i = 0;
1297                                 print FILEHANDLE "$name.so: ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h"; 
1298                                 foreach $fname (sort readdir(MDIRHANDLE)) {
1299                                         if ($fname =~ /\.cpp$/) {
1300                                                 $cmflags = getcompilerflags("src/modules/$name/$fname");
1301                                                 $liflags = getlinkerflags("src/modules/$name/$fname");
1302                                                 $deps = getdependencies("src/modules/$name/$fname");
1303                                                 $oname = $fname;
1304                                                 $oname =~ s/\.cpp$/.o/g;
1305                                                 print FILEHANDLE " $name/$oname";
1306                                                 $crapola = $crapola .  "$name/$oname: $name/$fname ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/base.h ../../include/inspircd_config.h ../../include/inspircd.h ../../include/configreader.h $deps\n";
1307                                                 $crapola = $crapola .  "        \$(CC) -pipe -I../../include -I. \$(FLAGS) $cmflags -export-dynamic -o $name/$oname -c $name/$fname\n\n";
1308                                                 $crap3 = $crap3 . " $name/$oname";
1309                                                 $i++;
1310                                         }
1311                                 }
1312                                 print "(\033[1;32m$i files found\033[0m)\n";
1313                                 if ($config{IS_DARWIN} eq "YES") {
1314                                         print FILEHANDLE "\n    \$(CC) -pipe -twolevel_namespace -undefined dynamic_lookup \$(FLAGS) -bundle -o $name.so $crap3\n"; 
1315                                 } else {
1316                                         print FILEHANDLE "\n    \$(CC) -pipe \$(FLAGS) -shared $liflags -o $name.so $crap3\n";
1317                                 }
1318                                 print FILEHANDLE "\n$crapola\n";
1319                                 closedir(MDIRHANDLE);
1320                                 $crud = $crud . "       install -m \$(INSTMODE) $name.so \$(MODPATH)\n";
1321                         }
1322                 }
1323         }
1324         closedir(DIRHANDLE);
1325
1326         print FILEHANDLE "modinst:\n    \@echo \"Installing modules...\"\n" . $crud;
1327 }
1328
1329
1330 sub write_static_makefile {
1331         open(FH,">src/Makefile") or die("Could not write src/Makefile!");
1332         my $i = 0;
1333         my @cmdlist = ();
1334         opendir(DIRHANDLE, "src");
1335         foreach $name (sort readdir(DIRHANDLE)) {
1336                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1337                         $cmdlist[$i++] = $1;
1338                 }
1339         }
1340         closedir(DIRHANDLE);
1341         my $cmdobjs = "";
1342         my $srcobjs = "";
1343         foreach my $cmd (@cmdlist) {
1344                 $cmdobjs = $cmdobjs . "cmd_$cmd.o ";
1345                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1346         }
1347         print FH <<EOM;
1348 # Insp Makefile :p
1349 #
1350 # (C) ChatSpike development team
1351 # Makefile by <Craig\@ChatSpike.net>
1352 # Makefile version 2 (statically linked core) by <brain\@inspircd.org>
1353 #
1354
1355 CC = im a cheezeball
1356
1357 CXXFLAGS = -I../include \${FLAGS}
1358 CPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* //' | grep -v svn)
1359 RELCPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* /modes\\//' | grep -v svn)
1360
1361 EOM
1362
1363 $se = "socketengine_select";
1364 if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1365         $se = "socketengine_kqueue";
1366 }       
1367 elsif (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1368         $se = "socketengine_epoll";
1369 }
1370
1371         ###
1372         # This next section is for cygwin dynamic module builds.
1373         # Basically, what we do, is build the inspircd core as a library
1374         # then the main executable uses that. the library is capable of
1375         # loading / unloading the modules dynamically :)
1376         # Massive thanks to the guys on #cygwin @ irc.freenode.net for helping
1377         # make this work :)
1378         ###
1379
1380         if ($config{OSNAME} =~ /CYGWIN/i) {
1381                 print FH <<EOM;
1382 all: timer.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 configreader.o inspsocket.o $cmdobjs commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o snomasks.o inspircd.exe
1383
1384 inspircd.exe: inspircd.dll.a
1385         \$(CC) -o \$@ \$^
1386
1387 inspircd.dll inspircd.dll.a: inspircd.o channels.o mode.o xline.o inspstring.o dns.o base.o configreader.o inspsocket.o $cmdobjs  commands.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 timer.o snomasks.o
1388         \$(CC) -shared -Wl,--out-implib=inspircd.dll.a -o inspircd.dll \$^
1389 EOM
1390         } else {
1391                 print FH <<EOM;
1392 all: timer.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 configreader.o inspsocket.o $cmdobjs commands.o dynamic.o users.o modules.o wildcard.o helperfuncs.o snomasks.o \$(MODULES) inspircd.exe
1393
1394 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
1395         \$(CC) -I../include \$(FLAGS) inspircd.cpp -o inspircd.exe \$(LDLIBS) channels.o mode.o xline.o inspstring.o dns.o base.o inspsocket.o configreader.o $cmdobjs commands.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 timer.o snomasks.o modes/modeclasses.a \$(MODULES)
1396 EOM
1397         }
1398
1399         print FH <<EOM;
1400
1401 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
1402         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1403
1404 snomasks.o: snomasks.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/channels.h
1405         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c snomasks.cpp
1406
1407 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
1408         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1409
1410 userprocess.o: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1411         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1412
1413 socketengine.o: $se.cpp socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/$se.h
1414         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp $se.cpp
1415
1416 hashcomp.o: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1417         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1418
1419 helperfuncs.o: helperfuncs.cpp ../include/base.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1420         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1421
1422 channels.o: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1423         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1424
1425 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 \$(RELCPPFILES) modes/modeclasses.a
1426         \${MAKE} -C "modes" DIRNAME="src/modes" CC="\$(CC)" \$(MAKEARGS)
1427         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1428
1429 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
1430         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1431
1432 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
1433         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1434
1435 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 ../include/timer.h
1436         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1437
1438 base.o: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1439         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1440
1441 configreader.o: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1442         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp
1443
1444 commands.o: commands.cpp ../include/base.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h $srcobjs
1445         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp $cmdobjs
1446
1447 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
1448         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1449
1450 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 ../include/timer.h
1451         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1452
1453 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 ../include/timer.h
1454         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1455
1456 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
1457         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1458
1459 socket.o: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1460         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1461         
1462 inspsocket.o: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1463         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp
1464
1465 timer.o: timer.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1466         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c timer.cpp
1467
1468 EOM
1469         foreach my $cmd (@cmdlist) {
1470                 print FH <<ITEM;
1471 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/commands/cmd_$cmd.h
1472         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1473 ITEM
1474         }
1475         close(FH);
1476 }
1477
1478 sub write_dynamic_makefile {
1479
1480         my $i = 0;
1481         my @cmdlist = ();
1482         opendir(DIRHANDLE, "src");
1483         foreach $name (sort readdir(DIRHANDLE)) {
1484                 if ($name =~ /^cmd_(.+)\.cpp$/) {
1485                         $cmdlist[$i++] = $1;
1486                 }
1487         }
1488         closedir(DIRHANDLE);
1489
1490         my $cmdobjs = "";
1491         my $srcobjs = "";
1492         foreach my $cmd (@cmdlist) {
1493                 $cmdobjs = $cmdobjs . "cmd_$cmd.so ";
1494                 $srcobjs = $srcobjs . "cmd_$cmd.cpp ";
1495         }
1496
1497         $se = "socketengine_select";
1498         if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
1499                 $se = "socketengine_kqueue";
1500         }
1501         elsif (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
1502                 $se = "socketengine_epoll";
1503         }
1504
1505         open(FH,">src/Makefile") or die("Could not write src/Makefile");
1506         print FH <<EOM;
1507 # Insp Makefile :p
1508 #
1509 # (C) ChatSpike development team
1510 # Makefile by <Craig\@ChatSpike.net>
1511 # Makefile version 2 (dynamically linked core) by <brain\@inspircd.org>
1512 #
1513
1514 CC = im a cheezeball
1515
1516 CXXFLAGS = -I../include \${FLAGS}
1517 CPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* //' | grep -v svn)
1518 RELCPPFILES = \$(shell /bin/ls -l modes/ | grep '\\.cpp' | sed 's/^.* /modes\\//' | grep -v svn)
1519
1520 EOM
1521
1522 if ($config{IS_DARWIN} eq "YES") {
1523         print FH <<EOM;
1524 all: libIRCDtimer.dylib libIRCDcull_list.dylib libIRCDuserprocess.dylib libIRCDsocketengine.dylib libIRCDsocket.dylib libIRCDhash.dylib libIRCDchannels.dylib libIRCDmode.dylib libIRCDxline.dylib libIRCDstring.dylib libIRCDasyncdns.dylib libIRCDbase.dylib libIRCDconfigreader.dylib libIRCDinspsocket.dylib libIRCDcommands.dylib libIRCDdynamic.dylib libIRCDusers.dylib libIRCDmodules.dylib libIRCDwildcard.dylib libIRCDhelper.dylib libIRCDcommand_parse.dylib libIRCDsnomasks.dylib inspircd
1525
1526 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 $cmdobjs libIRCDtimer.dylib libIRCDcull_list.dylib libIRCDuserprocess.dylib libIRCDsocketengine.dylib libIRCDsocket.dylib libIRCDhash.dylib libIRCDchannels.dylib libIRCDmode.dylib libIRCDxline.dylib libIRCDstring.dylib libIRCDasyncdns.dylib libIRCDbase.dylib libIRCDconfigreader.dylib libIRCDinspsocket.dylib libIRCDsnomasks.dylib libIRCDcommands.dylib libIRCDdynamic.dylib libIRCDusers.dylib libIRCDmodules.dylib libIRCDwildcard.dylib libIRCDhelper.dylib libIRCDcommand_parse.dylib
1527         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspircd.cpp
1528         \$(CC) -pipe -dynamic -bind_at_load -L. -o inspircd \$(LDLIBS) inspircd.o libIRCDchannels.dylib libIRCDmode.dylib libIRCDxline.dylib libIRCDstring.dylib libIRCDasyncdns.dylib libIRCDbase.dylib libIRCDconfigreader.dylib libIRCDinspsocket.dylib libIRCDcommands.dylib libIRCDdynamic.dylib libIRCDusers.dylib libIRCDmodules.dylib libIRCDwildcard.dylib libIRCDhelper.dylib libIRCDhash.dylib libIRCDsocket.dylib libIRCDsocketengine.dylib libIRCDuserprocess.dylib libIRCDcull_list.dylib libIRCDcommand_parse.dylib libIRCDtimer.dylib libIRCDsnomasks.dylib
1529
1530 libIRCDsocketengine.dylib: $se.cpp socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/$se.h
1531         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp
1532         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c $se.cpp
1533         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDsocketengine.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDsocketengine.dylib socketengine.o $se.o
1534
1535 libIRCDsnomasks.dylib: snomasks.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/channels.h
1536         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c snomasks.cpp
1537         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDsnomasks.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDsnomasks.dylib snomasks.o
1538
1539 libIRCDcommand_parse.dylib: command_parse.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1540         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1541         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDcommand_parse.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDcommand_parse.dylib command_parse.o
1542
1543 libIRCDcull_list.dylib: cull_list.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/users.h ../include/channels.h
1544         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1545         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDcull_list.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDcull_list.dylib cull_list.o
1546
1547 libIRCDuserprocess.dylib: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1548         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1549         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDuserprocess.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDuserprocess.dylib userprocess.o
1550
1551 libIRCDhash.dylib: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1552         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1553         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDhash.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDhash.dylib hashcomp.o
1554
1555 libIRCDhelper.dylib: helperfuncs.cpp ../include/base.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1556         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1557         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDhelper.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDhelper.dylib helperfuncs.o
1558
1559 libIRCDchannels.dylib: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1560         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1561         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDchannels.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDchannels.dylib channels.o
1562
1563 libIRCDmode.dylib: mode.cpp ../include/base.h ../include/mode.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h \$(RELCPPFILES)
1564         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1565         \${MAKE} -C "modes" DIRNAME="src/modes" CC="\$(CC)" \$(MAKEARGS) CPPFILES="\$(CPPFILES)"
1566         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDmode.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDmode.dylib mode.o modes/modeclasses.a
1567
1568 libIRCDxline.dylib: xline.cpp ../include/base.h ../include/xline.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1569         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1570         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDxline.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDxline.dylib xline.o
1571
1572 libIRCDstring.dylib: inspstring.cpp ../include/base.h ../include/inspstring.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1573         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1574         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDstring.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDstring.dylib inspstring.o
1575
1576 libIRCDasyncdns.dylib: dns.cpp ../include/base.h ../include/dns.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1577         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1578         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDasyncdns.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDasyncdns.dylib dns.o
1579
1580 libIRCDbase.dylib: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1581         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1582         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDbase.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDbase.dylib base.o
1583
1584 libIRCDconfigreader.dylib: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1585         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp
1586         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDconfigreader.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDconfigreader.dylib configreader.o
1587
1588 libIRCDcommands.dylib: commands.cpp ../include/base.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1589         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp
1590         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDcommands.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDcommands.dylib commands.o
1591
1592 libIRCDdynamic.dylib: dynamic.cpp ../include/base.h ../include/dynamic.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1593         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1594         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDdynamic.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDdynamic.dylib dynamic.o
1595
1596 libIRCDusers.dylib: users.cpp ../include/base.h ../include/users.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1597         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1598         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDusers.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDusers.dylib users.o
1599
1600 libIRCDmodules.dylib: modules.cpp ../include/base.h ../include/modules.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1601         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1602         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDmodules.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDmodules.dylib modules.o
1603
1604 libIRCDwildcard.dylib: wildcard.cpp ../include/base.h ../include/wildcard.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1605         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1606         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDwildcard.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDwildcard.dylib wildcard.o
1607
1608 libIRCDsocket.dylib: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1609         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1610         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDsocket.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDsocket.dylib socket.o
1611
1612 libIRCDinspsocket.dylib: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1613         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp
1614         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDinspsocket.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDinspsocket.dylib inspsocket.o
1615
1616 libIRCDtimer.dylib: timer.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1617         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c timer.cpp
1618         \$(CC) -pipe -install_name $config{LIBRARY_DIR}/libIRCDtimer.dylib -dynamiclib -twolevel_namespace -undefined dynamic_lookup -o libIRCDtimer.dylib timer.o
1619
1620 EOM
1621
1622 } else {
1623
1624         print FH <<EOM;
1625 all: libIRCDtimer.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so $cmdobjs libIRCDcommands.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so libIRCDsnomasks.so inspircd
1626
1627 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 libIRCDtimer.so libIRCDcull_list.so libIRCDuserprocess.so libIRCDsocketengine.so libIRCDsocket.so libIRCDhash.so libIRCDchannels.so libIRCDmode.so libIRCDxline.so libIRCDstring.so libIRCDasyncdns.so libIRCDbase.so libIRCDconfigreader.so libIRCDinspsocket.so $cmdobjs libIRCDsnomasks.so libIRCDcommands.so libIRCDdynamic.so libIRCDusers.so libIRCDmodules.so libIRCDwildcard.so libIRCDhelper.so libIRCDcommand_parse.so
1628         \$(CC) -pipe -I../include $extra -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 libIRCDconfigreader.so libIRCDinspsocket.so libIRCDcommands.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 libIRCDtimer.so libIRCDsnomasks.so
1629
1630 libIRCDsocketengine.so: $se.cpp socketengine.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h ../include/$se.h
1631         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socketengine.cpp $se.cpp
1632         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocketengine.so socketengine.o $se.o
1633
1634 libIRCDsnomasks.so: snomasks.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/channels.h
1635         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c snomasks.cpp
1636         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsnomasks.so snomasks.o
1637
1638 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
1639         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c command_parse.cpp
1640         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommand_parse.so command_parse.o
1641
1642 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
1643         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cull_list.cpp
1644         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcull_list.so cull_list.o
1645
1646 libIRCDuserprocess.so: userprocess.cpp ../include/base.h ../include/hashcomp.h ../include/globals.h ../include/inspircd_config.h
1647         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c userprocess.cpp
1648         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDuserprocess.so userprocess.o
1649
1650 libIRCDhash.so: hashcomp.cpp ../include/base.h ../include/hashcomp.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1651         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c hashcomp.cpp
1652         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhash.so hashcomp.o
1653
1654 libIRCDhelper.so: helperfuncs.cpp ../include/base.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1655         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c helperfuncs.cpp
1656         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDhelper.so helperfuncs.o
1657
1658 libIRCDchannels.so: channels.cpp ../include/base.h ../include/channels.h ../include/inspircd.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1659         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c channels.cpp
1660         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDchannels.so channels.o
1661
1662 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 \$(RELCPPFILES)
1663         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c mode.cpp
1664         \${MAKE} -C "modes" DIRNAME="src/modes" CC="\$(CC)" \$(MAKEARGS) CPPFILES="\$(CPPFILES)"
1665         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmode.so mode.o modes/modeclasses.a
1666
1667 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 ../include/timer.h
1668         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c xline.cpp
1669         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDxline.so xline.o
1670
1671 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
1672         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspstring.cpp
1673         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDstring.so inspstring.o
1674
1675 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 ../include/timer.h
1676         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dns.cpp
1677         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDasyncdns.so dns.o
1678
1679 libIRCDbase.so: base.cpp ../include/base.h ../include/globals.h ../include/inspircd_config.h
1680         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c base.cpp
1681         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDbase.so base.o
1682
1683 libIRCDconfigreader.so: configreader.cpp ../include/base.h ../include/configreader.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h
1684         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c configreader.cpp
1685         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDconfigreader.so configreader.o
1686
1687 libIRCDcommands.so: commands.cpp ../include/base.h ../include/inspircd.h ../include/channels.h ../include/users.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1688         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c commands.cpp
1689         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDcommands.so commands.o
1690
1691 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
1692         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c dynamic.cpp
1693         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDdynamic.so dynamic.o
1694
1695 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 ../include/timer.h
1696         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c users.cpp
1697         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDusers.so users.o
1698
1699 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 ../include/timer.h
1700         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c modules.cpp
1701         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDmodules.so modules.o
1702
1703 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
1704         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c wildcard.cpp
1705         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDwildcard.so wildcard.o
1706
1707 libIRCDsocket.so: socket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h
1708         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c socket.cpp
1709         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDsocket.so socket.o
1710
1711 libIRCDinspsocket.so: inspsocket.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1712         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c inspsocket.cpp
1713         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDinspsocket.so inspsocket.o
1714
1715 libIRCDtimer.so: timer.cpp ../include/base.h ../include/inspircd.h ../include/globals.h ../include/inspircd_config.h ../include/timer.h
1716         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c timer.cpp
1717         \$(CC) -pipe -Wl,--rpath -Wl,$config{LIBRARY_DIR} -shared -o libIRCDtimer.so timer.o
1718
1719 EOM
1720 }
1721         foreach my $cmd (@cmdlist) {
1722                 print FH <<ITEM;
1723 cmd_$cmd.so: 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/commands/cmd_$cmd.h
1724         \$(CC) -pipe -I../include \$(FLAGS) -export-dynamic -c cmd_$cmd.cpp
1725         \$(CC) -pipe $SHARED -o cmd_$cmd.so cmd_$cmd.o
1726
1727 ITEM
1728         }
1729         close(FH);
1730 }
1731