]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - configure
A few simple output lines (similar to gnu autoconf so people know what's happening)
[user/henk/code/inspircd.git] / configure
index b36e30b9cbb7f8c024ef3991e64bf808b86ab5d5..428328e424858ea9c55b730725ab5f3fc765d9ff 100755 (executable)
--- a/configure
+++ b/configure
 ########################################
 
 
-$this = $ENV{PWD};                                              # PWD, Regardless.
-@modlist = ();                                                  # Declare for Module List..
-%config = ();                                                   # Initiate Configuration Hash..
-$config{ME}                 = $ENV{PWD};                        # Present Working Directory
-$config{CONFIG_DIR}         = $ENV{PWD}."/conf";                # Configuration Directory
-$config{MODULE_DIR}         = $ENV{PWD}."/modules";             # Modules Directory
-$config{BINARY_DIR}         = $ENV{PWD}."/bin";                 # Binary Directory
-$config{OPTIMITEMP}         = "0";                              # Default Optimisation Value
-$config{OPTIMISATI}         = "-g";                             # Optimisation Flag
-$config{NICK_LENGT}         = "32";                             # Default Nick Length
-$config{CHAN_LENGT}         = "64";                             # Default Channel Name Length
-$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.
-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
+$this = resolve_directory($ENV{PWD});                                          # 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{OPTIMITEMP}         = "0";                                             # Default Optimisation Value
+$config{OPTIMISATI}         = "-g";                                            # Optimisation Flag
+$config{NICK_LENGT}         = "32";                                            # Default Nick Length
+$config{CHAN_LENGT}         = "64";                                            # Default Channel Name Length
+$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}         = "n";                                             # kqueue 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
 
 if (!$config{OSNAME}) {
   $config{OSNAME} = "Unknown";                                  # For use when uname fails.
@@ -41,7 +43,6 @@ if (!$config{MAX_CLIENT_T}) {
 }
 
 # Get and Set some important vars..
-getosflags();
 getmodules();
 
 my $arg = $ARGV[0];                                            # Do Some Argument Checks..
@@ -56,13 +57,17 @@ if ($arg eq "-update") {
   } else {
     # We've Loaded the cache file and all our variables..
     print "Updating Files..\n";
+    getosflags();
     writefiles();
     print "Complete.\n";
     exit;
   }
 }
 
-getcache();                                                     # Load the config.cache file.
+print "Checking for cache from previous configure...\n";
+getcache();
+print "Checking operating system version...\n";
+getosflags();
 
 if (!$config{MAX_CLIENT}) { 
   # If the cache hasn't set the max clients, copy the variable of MAX_CLIENT_T, this
@@ -71,21 +76,46 @@ 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;
 
 ################################################################################
 #                          BEGIN INTERACTIVE PART                              #
@@ -117,6 +147,11 @@ Your operating system is: \033[1;32m$config{OSNAME}\033[0m ($wholeos), fdmax: $c
 dir_check("are the configuration files", "CONFIG_DIR");
 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 ($has_kqueue) {
+       yesno(USE_KQUEUE,"You are running a BSD operating system, and kqueue\nwas detected. Would you like to enable kqueue support?\nIf you are unsure, answer no.\n\nEnable kqueue?");
+}
 
 # File Descriptor Settings..
 my $continue = 0;
@@ -189,15 +224,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 {
@@ -264,20 +303,20 @@ sub dir_check {
     print "[\033[1;32m$config{$hash_key}\033[0m] -> ";
     chomp($var = <STDIN>);
     if ($var eq "") { $var = $config{$hash_key}; }
+    if ($var =~ /^\~\/(.+)$/) {
+       # Convert it to a full path..
+       $var = resolve_directory($ENV{HOME} . "/" . $1);
+    }
     if (substr($var,0,1) ne "/")
     {
-       # Assume relative Path was given.. fill in the rest.
-       $var = $this . "/$var";
+        # Assume relative Path was given.. fill in the rest.
+        $var = $this . "/$var";
     }
-    if (substr($var, 0, 1) eq "~") {
-       # Convert it to a full path..
-       
-       $var = $this . substr(1,0);
-    } 
+    $var = resolve_directory($var); 
     if (! -e $var) {
       print "$var does not exist. Create it?\n[\033[1;32my\033[0m] ";
       chomp($tmp = <STDIN>);
-      if (($tmp eq "") || ($tmp = "y")) {
+      if (($tmp eq "") || ($tmp =~ /^y/i)) {
         # Attempt to Create the Dir..
         $chk = system("mkdir -p \"$var\" >> /dev/null 2>&1") / 256;
         if ($chk != 0) {
@@ -307,11 +346,11 @@ sub dir_check {
 sub getosflags {
   if ($config{OSNAME} eq "FreeBSD") {
     $config{LDLIBS} = "-Ldl";
-    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Wcomment -Wformat -Wunused -Wshadow -Werror -Wswitch -Wchar-subscripts -Wparentheses -Woverloaded-virtual";
+    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual $config{OPTIMISATI}";
     $config{MAKEPROG} = "gmake";
   } else {
     $config{LDLIBS} = "-ldl";
-    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Wcomment -Wformat -Wunused -Wshadow -Werror -Wswitch -Wchar-subscripts -Wparentheses -Woverloaded-virtual";
+    $config{FLAGS}  = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual $config{OPTIMISATI}";
     $config{MAKEPROG} = "make";
   }
 }
@@ -364,24 +403,27 @@ sub writefiles {
 #define MAXBUF 514
 EOF
 
-  if ($config{GCCVER} == 3) {
+  if ($config{GCCVER} > 3) {
     print FILEHANDLE "#define GCC3\n";
-    if ($config{GCC34} > 3) {
-      print FILEHANDLE "#define GCC34\n";
+    print FILEHANDLE "#define GCC34\n";
+  }
+  else
+  {
+    if ($config{GCCVER} == 3) {
+      print FILEHANDLE "#define GCC3\n";
+      if ($config{GCC34} > 3) {
+        print FILEHANDLE "#define GCC34\n";
+      }
     }
   }
   if ($config{HAS_STRLCPY} eq "true") {
     print FILEHANDLE "#define HAS_STRLCPY\n";
   }
+  if ($config{USE_KQUEUE} eq "y") {
+    print FILEHANDLE "#define USE_KQUEUE\n";
+  }
   close(FILEHANDLE);
 
-  # Now the Makefile..
-  print "Writing \033[1;32mMakefile\033[0m\n";
-  my $makefile = "";
-  open(FILEHANDLE, ".Makefile.inc");
-  while (<FILEHANDLE>) {
-    $makefile .= $_;
-  }
   # Create a Modules List..
   my $modules = "";
   foreach $i (@modlist)
@@ -389,25 +431,50 @@ EOF
     $modules .= "m_".$i.".so ";
   }
   chomp($modules);   # Remove Redundant whitespace..
-  $makefile =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
-  $makefile =~ s/\@FLAGS\@/$config{FLAGS}/;
-  $makefile =~ s/\@LDLIBS\@/$config{LDLIBS}/;
-  $makefile =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
-  $makefile =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
-  $makefile =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
-  $makefile =~ s/\@MODULES\@/$modules/;
-
-  open(FILEHANDLE, ">Makefile");
-  print FILEHANDLE $makefile;
-  close(FILEHANDLE);
+
+
+  # Write all .in files.
+  my $tmp = "";
+  my $file = "";
+  opendir(DIRHANDLE, $this);
+  foreach $name (sort readdir(DIRHANDLE)) {
+    if ($name =~ /^\.(.+)\.inc$/)
+    {
+      $file = $1;
+      # All .name.inc files need parsing!
+      $tmp = "";
+      open(FILEHANDLE, ".$file.inc");
+      while (<FILEHANDLE>) {
+        $tmp .= $_;
+      }
+      close(FILEHANDLE);
+
+      $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
+      $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
+      $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
+      $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
+      $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
+      $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
+      $tmp =~ s/\@LIBRARY_DIR\@/$config{LIBRARY_DIR}/;
+      $tmp =~ s/\@MODULES\@/$modules/;
+
+      print "Writing \033[1;32m$file\033[0m\n";
+      open(FILEHANDLE, ">$file");
+      print FILEHANDLE $tmp;
+    }
+  }
+  closedir(DIRHANDLE);
+
+  # Make inspircd executable!
+  chmod 0744, 'inspircd';
 
   # Modules Makefile..
   print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
   open(FILEHANDLE, ">src/modules/Makefile");
   print FILEHANDLE <<EOF;
 # (C) ChatSpike development team
-# Makefile by <Craig@ChatSpike.net>
-# Many Thanks to Andrew Church <achurch@achurch.org>
+# Makefile by <Craig\@ChatSpike.net>
+# Many Thanks to Andrew Church <achurch\@achurch.org>
 #    for assisting with making this work right.
 #
 # Automatically Generated by ./configure to add a modules
@@ -425,8 +492,10 @@ EOF
     $flags = getcompilerflags("src/modules/m_".$i.".cpp");
     print FILEHANDLE <<EOCHEESE;
 m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/servers.h ../../include/base.h
-       \$(CC) -I../../include \$(FLAGS) -shared $flags -o m_$i.so m_$i.cpp
-       \@cp m_$i.so \$(MODPATH)/
+       \$(CC) -pipe -I../../include \$(FLAGS) $flags -export-dynamic -c m_$i.cpp
+       \$(CC) \$(FLAGS) -shared $flags -o m_$i.so m_$i.o
+       cp m_$i.so \$(MODPATH)/
+       chmod 0700 \$(MODPATH)/m_$i.so
 
 EOCHEESE
   }
@@ -455,3 +524,22 @@ sub show_splash {
   print "'\033[1;33m####\033[0m: \033[1;33m##\033[0m::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m##\033[0m::::::::'\033[1;33m####\033[0m: \033[1;33m##\033[0m:::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m########\033[0m::\n";
   print "\033[0m\033[0m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::\n\n";
 }
+
+sub resolve_directory {
+       use File::Spec;
+       return File::Spec->rel2abs($_[0]);
+}
+
+sub yesno {
+       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;
+}