]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - configure
Changed a CXX to a CC
[user/henk/code/inspircd.git] / configure
index 5a8f0e7bccdca717d16aa33283fe51e317a0d6a9..0f95476b5f4b407ec48379cfa01b6f8716d0a195 100755 (executable)
--- a/configure
+++ b/configure
 #
 ########################################
 
-
-$this = resolve_directory($ENV{PWD});                                          # PWD, Regardless.
+chomp($topdir = `pwd`);
+$this = resolve_directory($topdir);                                            # PWD, Regardless.
 @modlist = ();                                                                 # Declare for Module List..
 %config = ();                                                                  # Initiate Configuration Hash..
-$config{ME}                 = resolve_directory($ENV{PWD});                    # Present Working Directory
-$config{CONFIG_DIR}         = resolve_directory($ENV{PWD}."/conf");            # Configuration Directory
-$config{MODULE_DIR}         = resolve_directory($ENV{PWD}."/modules");         # Modules Directory
-$config{BINARY_DIR}         = resolve_directory($ENV{PWD}."/bin");             # Binary Directory
-$config{LIBRARY_DIR}        = resolve_directory($ENV{PWD}."/lib");             # Library Directory
+$config{ME}                 = resolve_directory($topdir);                      # Present Working Directory
+$config{CONFIG_DIR}         = resolve_directory($config{ME}."/conf");          # Configuration Directory
+$config{MODULE_DIR}         = resolve_directory($config{ME}."/modules");       # Modules Directory
+$config{BINARY_DIR}         = resolve_directory($config{ME}."/bin");           # Binary Directory
+$config{LIBRARY_DIR}        = resolve_directory($config{ME}."/lib");           # Library Directory
 $config{OPTIMITEMP}         = "0";                                             # Default Optimisation Value
 $config{OPTIMISATI}         = "-g";                                            # Optimisation Flag
 $config{NICK_LENGT}         = "32";                                            # Default Nick Length
@@ -27,14 +27,19 @@ $config{CHAN_LENGT}         = "64";                                         # Default Chan
 $config{MAX_CHANNE}         = "20";                                            # Default Max. Channels per user..
 $config{MAXI_MODES}         = "20";                                            # Default Max. Number of Modes set at once.
 $config{HAS_STRLCPY}        = "false";                                         # strlcpy Check.
-$config{USE_KQUEUE}         = "false";                                         # kqueue enabled
+$config{USE_KQUEUE}         = "y";                                             # kqueue enabled
+$config{USE_EPOLL}          = "y";                                             # epoll enabled
 chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`);                          # FD Limit
 chomp($config{GCCVER}       = `gcc -dumpversion | cut -c 1`);                  # Major GCC Version
 chomp($config{GCC34}        = `gcc -dumpversion | cut -c 3`);                  # Minor GCC Version
-chomp($config{OSNAME}       = `uname -s`);                                     # Operating System Name
+chomp($config{OSNAME}       = `/bin/uname`);                                   # Operating System Name
+$config{CC}                = "g++";                                            # C++ compiler
 
-if (!$config{OSNAME}) {
-  $config{OSNAME} = "Unknown";                                  # For use when uname fails.
+if ((!$config{OSNAME}) || ($config{OSNAME} eq "")) {
+  chomp($config{OSNAME} = `/usr/bin/uname`);
+  if ((!$config{OSNAME}) || ($config{OSNAME} eq "")){
+       $config{OSNAME} = "Unknown";
+  }
 }
 
 if (!$config{MAX_CLIENT_T}) { 
@@ -64,8 +69,9 @@ if ($arg eq "-update") {
   }
 }
 
-
+print "Checking for cache from previous configure...\n";
 getcache();
+print "Checking operating system version...\n";
 getosflags();
 
 if (!$config{MAX_CLIENT}) { 
@@ -75,21 +81,66 @@ if (!$config{MAX_CLIENT}) {
   $config{MAX_CLIENT} = $config{MAX_CLIENT_T};
 }
 
+printf "Checking if strlcpy exists... ";
 # Perform the strlcpy() test..
-open(STRLCPY, ">.test.cpp");
-print STRLCPY "#include <string.h>
-#include <stdio.h>
-int main() { char a[10]; char b[10]; strlcpy(a,b,10); printf(\"%d\\n\",9); }\n";
-close(STRLCPY);
-
-# Build the Binary..
-system("g++ -o .test .test.cpp 2>&1");
-
-# Was the build succesful?
-if (-e ".test") {
-  $config{HAS_STRLCPY} = "true";
-  system("rm -f .test .test.cpp");
+$config{HAS_STRLCPY} = "false";
+my $fail = 0;
+open(STRLCPY, "</usr/include/string.h") or $fail = 1;
+if (!$fail)
+{
+       while (chomp($line = <STRLCPY>))
+       {
+               # try and find the delcaration of:
+               # size_t strlcpy(...)
+               if (($line =~ /size_t(\0x9|\s)+strlcpy(\0x9|\s)+\(/) || ($line =~ /size_t(\0x9|\s)+strlcpy\(/))
+               {
+                       $config{HAS_STRLCPY} = "true";
+               }
+       }
+       close(STRLCPY);
+}
+print "yes\n" if $config{HAS_STRLCPY} eq "true";
+print "no\n" if $config{HAS_STRLCPY} eq "false";
+
+printf "Checking if kqueue exists... ";
+$has_kqueue = 0;
+$fail = 0;
+open(KQUEUE, "</usr/include/sys/event.h") or $fail = 1;
+if (!$fail)
+{
+        while (chomp($line = <KQUEUE>))
+        {
+                # try and find the delcaration of:
+               # int kqueue(void);
+               if (($line =~ /int(\0x9|\s)+kqueue(\0x9|\s)+\(/) || ($line =~ /int(\0x9|\s)+kqueue\(/))
+               {
+                       $has_kqueue = 1;
+               }
+       }
+       close(KQUEUE);
 }
+print "yes\n" if $has_kqueue == 1;
+print "no\n" if $has_kqueue == 0;
+
+printf "Checking if epoll exists... ";
+$has_epoll = 0;
+$fail = 0;
+open(EPOLL, "</usr/include/sys/epoll.h") or $fail = 1;
+if (!$fail)
+{
+       while (chomp($line = <EPOLL>))
+       {
+               # try and find the declaration of:
+               # extern int epoll_create (int __size) __THROW;
+               if (($line =~ /int(\0x9|\s)+epoll_create(\0x9|\s)+\(/) || ($line =~ /int(\0x9|\s)+epoll_create\(/))
+               {
+                       $has_epoll = 1;
+               }
+       }
+       close(EPOLL);
+}
+print "yes\n" if $has_epoll == 1;
+print "no\n" if $has_epoll == 0;
 
 ################################################################################
 #                          BEGIN INTERACTIVE PART                              #
@@ -123,14 +174,17 @@ dir_check("are the modules to be compiled to", "MODULE_DIR");
 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
 dir_check("are the IRCd libraries to be placed", "LIBRARY_DIR");
 
-if ($config{OSNAME} =~ /BSD$/) {
-       if (yesno(0,"You are running a BSD operating system.\nWould you like to enable kqueue support?\nPlease be aware that kqueue support is\nEXPERIMENTAL and not gauranteed to work properly.\nIf you are unsure, answer no.\n\nEnable kqueue?")) {
-               $config{USE_KQUEUE} = "true";
-       }
-       else
-       {
-               $config{USE_KQUEUE} = "false";
-       }
+if ($has_kqueue) {
+       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?");
+}
+if ($has_epoll) {
+       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?");
+}
+$chose_hiperf = (($config{USE_EPOLL} eq "y") || ($config{USE_KQUEUE} eq "y"));
+if (!$chose_hiperf)
+{
+       print "No high-performance socket engines are available, or you chose\n";
+       print "not to enable one. Defaulting to select() engine.\n\n";
 }
 
 # File Descriptor Settings..
@@ -204,15 +258,19 @@ Please read the documentation for more information.
 
 The Higher the number, the more optimised your binary will be. This value will default to 0
 If you either a) Dont enter a number, or b) Enter a value outside the range.\n";
-print "[\033[1;32m0\033[0m] -> ";
+print "[\033[1;32m$config{OPTIMITEMP}\033[0m] -> ";
 chomp($var = <STDIN>);
-if ($var == 1) {
+if ($var eq "") {
+  $var = $config{OPTIMITEMP};
+}
+
+if ($var eq "1") {
   $config{OPTIMITEMP} = 1;
   $config{OPTIMISATI} = "-O";
-} elsif ($var == 2) {
+} elsif ($var eq "2") {
   $config{OPTIMITEMP} = 2;
   $config{OPTIMISATI} = "-O2";
-} elsif ($var == 3) {
+} elsif ($var eq "3") {
   $config{OPTIMITEMP} = 3;
   $config{OPTIMISATI} = "-O3";
 } else {
@@ -229,7 +287,8 @@ print "\033[0mMax nickname length:\033[1;32m\t\t$config{NICK_LENGT}\n";
 print "\033[0mMax channel length:\033[1;32m\t\t$config{CHAN_LENGT}\n";
 print "\033[0mMax mode length:\033[1;32m\t\t$config{MAXI_MODES}\n";
 print "\033[0mGCC Version Found:\033[1;32m\t\t$config{GCCVER}.$config{GCC34}\n";
-print "\033[0mOptimatizaton Flag:\033[1;32m\t\t$config{OPTIMISATI}\033[0m\n\n";
+print "\033[0mOptimatizaton Flag:\033[1;32m\t\t$config{OPTIMISATI}\033[0m\n";
+print "\033[0mCompiler program:\033[1;32m\t\t$config{CC}\033[0m\n\n";
 
 makecache();
 writefiles();
@@ -320,15 +379,28 @@ sub dir_check {
 }
 
 sub getosflags {
-  if ($config{OSNAME} eq "FreeBSD") {
+  if ($config{OSNAME} =~ /BSD$/) {
     $config{LDLIBS} = "-Ldl";
-    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual -g";
+    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual $config{OPTIMISATI}";
     $config{MAKEPROG} = "gmake";
+    if ($config{OSNAME} eq "OpenBSD") {
+       $config{CC} = "eg++";
+       chomp($config{GCCVER}       = `eg++ -dumpversion | cut -c 1`); # we must redo these if we change
+       chomp($config{GCC34}        = `eg++ -dumpversion | cut -c 3`); # the compiler path
+    }
   } else {
     $config{LDLIBS} = "-ldl";
-    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual -g";
+    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual $config{OPTIMISATI}";
     $config{MAKEPROG} = "make";
   }
+  if ($config{OSNAME} =~ /SunOS/) {
+    # solaris/sunos needs these
+    # socket = bsd sockets api
+    # nsl = dns stuff
+    # rt = POSIX realtime extensions
+    # resolv = inet_aton only (why isnt this in nsl?!)
+    $config{LDLIBS} = $config{LDLIBS} . " -lsocket -lnsl -lrt -lresolv";
+  }
 }
 
 sub is_dir {
@@ -361,7 +433,7 @@ sub writefiles {
   # First File.. inspircd_config.h
   chomp(my $incos = `uname -n -s -r`);
   chomp(my $version = `sh ./src/version.sh`);
-  open(FILEHANDLE, "> include/inspircd_config.h");
+  open(FILEHANDLE, ">include/inspircd_config.h");
   print FILEHANDLE <<EOF;
 /* Auto generated by configure, do not modify! */
 #define SYSLOG_FACILITY LOG_DAEMON
@@ -379,6 +451,9 @@ sub writefiles {
 #define MAXBUF 514
 EOF
 
+  if ($config{OSNAME} =~ /SunOS/) {
+    print FILEHANDLE "#define IS_SOLARIS\n";
+  }
   if ($config{GCCVER} > 3) {
     print FILEHANDLE "#define GCC3\n";
     print FILEHANDLE "#define GCC34\n";
@@ -395,8 +470,19 @@ EOF
   if ($config{HAS_STRLCPY} eq "true") {
     print FILEHANDLE "#define HAS_STRLCPY\n";
   }
-  if ($config{USE_KQUEUE} eq "true") {
+  my $use_hiperf = 0;
+  if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
     print FILEHANDLE "#define USE_KQUEUE\n";
+    $use_hiperf = 1;
+  }
+  if (($has_epoll) && ($config{USE_EPOLL} eq "y")) {
+    print FILEHANDLE "#define USE_EPOLL\n";
+    $use_hiperf = 1;
+  }
+  # user didn't choose either epoll or select for their OS.
+  # default them to USE_SELECT (ewwy puke puke)
+  if (!$use_hiperf) {
+    print FILEHANDLE "#define USE_SELECT\n";
   }
   close(FILEHANDLE);
 
@@ -425,6 +511,7 @@ EOF
       }
       close(FILEHANDLE);
 
+      $tmp =~ s/\@CC\@/$config{CC}/;
       $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
       $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
       $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
@@ -507,17 +594,15 @@ sub resolve_directory {
 }
 
 sub yesno {
-       my ($default,$prompt) = @_;
-       if (!$default) {
-               print "$prompt [\033[1;32mn\033[0m] ";
-               chomp($tmp = <STDIN>);
-               return ($tmp =~ /^y/i);
-               
-       }
-       else {
-               print "$prompt [\033[1;32my\033[0m] ";
-               chomp($tmp = <STDIN>);
-               return (($tmp eq "") || ($tmp =~ /^y/i));
-       }
-       return 0;
+       my ($flag,$prompt) = @_;
+       print "$prompt [\033[1;32m$config{$flag}\033[0m] -> ";
+       chomp($tmp = <STDIN>);
+       if ($tmp eq "") { $tmp = $config{$flag} }
+
+       if (($tmp eq "") || ($tmp =~ /^y/i)) {
+               $config{$flag} = "y";
+       } else {
+               $config{$flag} = "n";
+        }
+       return;
 }