]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Improve feature detection in configure.
authorPeter Powell <petpow@saberuk.com>
Sat, 4 May 2013 15:40:27 +0000 (16:40 +0100)
committerPeter Powell <petpow@saberuk.com>
Thu, 16 May 2013 13:34:07 +0000 (14:34 +0100)
configure
make/check_epoll.cpp [deleted file]
make/check_eventfd.cpp [deleted file]
make/configure.pm
make/test/clock_gettime.cpp [new file with mode: 0644]
make/test/eventfd.cpp [new file with mode: 0644]
make/test/kqueue.cpp [new file with mode: 0644]

index 1dc6b3ef199a811b127d195d051e799e88975036..d86229afbb7752ba20d1ccac81da2c7c9b0ccb15 100755 (executable)
--- a/configure
+++ b/configure
@@ -229,7 +229,6 @@ if (!defined $opt_disable_debug) {
        $config{OPTIMISATI}      = "-O2";
 }
 
-$config{HAS_STRLCPY}   = "false";                                      # strlcpy Check.
 $config{HAS_STDINT}     = "false";                                     # stdint.h check
 $config{USE_KQUEUE}     = "y";                                         # kqueue enabled
 if (defined $opt_nokqueue) {
@@ -331,16 +330,6 @@ sub update
        exit;
 }
 
-
-sub test_compile {
-       my $feature = shift;
-       my $fail = 0;
-       $fail ||= system "$config{CC} -o test_$feature make/check_$feature.cpp >/dev/null 2>&1";
-       $fail ||= system "./test_$feature";
-       unlink "test_$feature";
-       return !$fail;
-}
-
 print "Running non-interactive configure...\n" unless $interactive;
 print "Checking for cache from previous configure... ";
 print ($cache_loaded ? "found\n" : "not found\n");
@@ -352,76 +341,45 @@ chomp($config{GCCVER}             = `$exec`);                             # Major GCC Version
 $exec = $config{CC} . " -dumpversion | cut -c 3";
 chomp($config{GCCMINOR}                = `$exec`);
 
-printf "Checking if stdint.h exists... ";
-$config{HAS_STDINT} = "true";
-our $fail = 0;
-open(STDINT, "</usr/include/stdint.h") or $config{HAS_STDINT} = "false";
-if ($config{HAS_STDINT} eq "true") {
-       close(STDINT);
+
+print "Checking whether <stdint.h> exists... ";
+if (test_header($config{CC}, "stdint.h")) {
+       $config{HAS_STDINT} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_STDINT} = "false";
+       print "no\n";
 }
-print "yes\n" if $config{HAS_STDINT} eq "true";
-print "no\n" if $config{HAS_STDINT} eq "false";
-
-printf "Checking if strlcpy exists... ";
-# Perform the strlcpy() test..
-$config{HAS_STRLCPY} = "false";
-$fail = 0;
-open(STRLCPY, "</usr/include/string.h") or $fail = 1;
-if (!$fail) {
-       while (defined(my $line = <STRLCPY>)) {
-               chomp($line);
-               # try and find the delcaration of:
-               # size_t strlcpy(...)
-               if ($line =~ /size_t(\0x9|\s)+strlcpy/) {
-                       $config{HAS_STRLCPY} = "true";
-               }
-       }
-       close(STRLCPY);
+
+printf "Checking whether clock_gettime() exists... ";
+if (test_file($config{CC}, "clock_gettime.cpp", "-lrt")) {
+       $config{HAS_CLOCK_GETTIME} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_CLOCK_GETTIME} = "false";
+       print "no\n";
 }
-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 (defined(my $line = <KQUEUE>)) {
-               chomp($line);
-               # try and find the delcaration of:
-               # int kqueue(void);
-               if ($line =~ /int(\0x9|\s)+kqueue/) {
-                       $has_kqueue = 1;
-               }
-       }
-       close(KQUEUE);
+
+printf "Checking whether eventfd() exists... ";
+if (test_file($config{CC}, "eventfd.cpp")) {
+       $config{HAS_EVENTFD} = "true";
+       print "yes\n";
+} else {
+       $config{HAS_EVENTFD} = "false";
+       print "no\n";
 }
-print "yes\n" if $has_kqueue == 1;
-print "no\n" if $has_kqueue == 0;
 
-printf "Checking for epoll support... ";
-$has_epoll = test_compile('epoll');
+print "Checking whether epoll is available... ";
+$has_epoll = test_header($config{CC}, "sys/epoll.h");
 print $has_epoll ? "yes\n" : "no\n";
 
-printf "Checking for eventfd support... ";
-$config{HAS_EVENTFD} = test_compile('eventfd') ? 'true' : 'false';
-print $config{HAS_EVENTFD} eq 'true' ? "yes\n" : "no\n";
-
-printf "Checking if Solaris I/O completion ports are available... ";
-$has_ports = 0;
-our $system = `uname -s`;
-chomp ($system);
-$has_ports = 1 if ($system eq "SunOS");
-
-if ($has_ports) {
-       my $kernel = `uname -r`;
-       chomp($kernel);
-       if (($kernel !~ /^5\.1./)) {
-               $has_ports = 0;
-       }
-}
-print "yes\n" if $has_ports == 1;
-print "no\n" if $has_ports == 0;
+print "Checking whether Kqueue is available... ";
+$has_kqueue = test_file($config{CC}, "kqueue.cpp");
+print $has_kqueue ? "yes\n" : "no\n";
+
+print 'Checking whether Solaris IOCP is available... ';
+$has_ports = test_header($config{CC}, 'port.h');
+print $has_ports ? "yes\n" : "no\n";
 
 $config{HAS_EPOLL} = $has_epoll;
 $config{HAS_KQUEUE} = $has_kqueue;
@@ -902,16 +860,13 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
                if ($config{GCCVER} >= 3) {
                        print FILEHANDLE "#define GCC3\n";
                }
-               if ($config{HAS_STRLCPY} eq "true") {
-                       print FILEHANDLE "#define HAS_STRLCPY\n";
-               }
                if ($config{HAS_STDINT} eq "true") {
                        print FILEHANDLE "#define HAS_STDINT\n";
                }
                if ($config{HAS_EVENTFD} eq 'true') {
                        print FILEHANDLE "#define HAS_EVENTFD\n";
                }
-               if ($config{OSNAME} !~ /DARWIN/i) {
+               if ($config{HAS_CLOCK_GETTIME} eq 'true') {
                        print FILEHANDLE "#define HAS_CLOCK_GETTIME\n";
                }
                my $use_hiperf = 0;
diff --git a/make/check_epoll.cpp b/make/check_epoll.cpp
deleted file mode 100644 (file)
index 918d390..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include <sys/epoll.h>
-
-int main() {
-       int fd = epoll_create(1);
-       return (fd < 0);
-}
diff --git a/make/check_eventfd.cpp b/make/check_eventfd.cpp
deleted file mode 100644 (file)
index 980d044..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *
- * This file is part of InspIRCd.  InspIRCd is free software: you can
- * redistribute it and/or modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation, version 2.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include <sys/eventfd.h>
-
-int main() {
-       eventfd_t efd_data;
-       int fd;
-
-       fd = eventfd(0, EFD_NONBLOCK);
-       eventfd_read(fd, &efd_data);
-
-       return (fd < 0);
-}
index 606483e98d8619656751302d0a661839c7a0b898..67e91c825aeb44cf2ad6ec4c6e8647dd206051b2 100644 (file)
@@ -31,10 +31,29 @@ use warnings FATAL => qw(all);
 use Exporter 'import';
 use POSIX;
 use make::utilities;
-our @EXPORT = qw(promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
+our @EXPORT = qw(test_file test_header promptnumeric dumphash is_dir getmodules getrevision getcompilerflags getlinkerflags getdependencies nopedantic resolve_directory yesno showhelp promptstring_s module_installed);
 
 my $no_git = 0;
 
+sub test_file($$;$) {
+       my ($cc, $file, $args) = @_;
+       my $status = 0;
+       $args ||= '';
+       $status ||= system "$cc -o __test_$file make/test/$file $args >/dev/null 2>&1";
+       $status ||= system "./__test_$file >/dev/null 2>&1";
+       unlink  "./__test_$file";
+       return !$status;
+}
+
+sub test_header($$;$) {
+       my ($cc, $header, $args) = @_;
+       $args ||= '';
+       open(CC, "| $cc -E - $args >/dev/null 2>&1") or return 0;
+       print CC "#include <$header>";
+       close(CC);
+       return !$?;
+}
+
 sub yesno {
        my ($flag,$prompt) = @_;
        print "$prompt [\e[1;32m$main::config{$flag}\e[0m] -> ";
diff --git a/make/test/clock_gettime.cpp b/make/test/clock_gettime.cpp
new file mode 100644 (file)
index 0000000..91d8cd4
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <time.h>
+
+int main() {
+       timespec time_spec;
+       clock_gettime(CLOCK_REALTIME, &time_spec);
+       return 0;
+}
diff --git a/make/test/eventfd.cpp b/make/test/eventfd.cpp
new file mode 100644 (file)
index 0000000..980d044
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <sys/eventfd.h>
+
+int main() {
+       eventfd_t efd_data;
+       int fd;
+
+       fd = eventfd(0, EFD_NONBLOCK);
+       eventfd_read(fd, &efd_data);
+
+       return (fd < 0);
+}
diff --git a/make/test/kqueue.cpp b/make/test/kqueue.cpp
new file mode 100644 (file)
index 0000000..a203174
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <sys/event.h>
+
+int main() {
+       int fd = kqueue();
+       return (fd < 0);
+}