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