More fixups for dual-life to support out-of-core build
authorPaul \"LeoNerd\" Evans <leonerd@leonerd.org.uk>
Tue, 1 Nov 2011 16:16:33 +0000 (16:16 +0000)
committerFlorian Ragwitz <rafl@debian.org>
Thu, 1 Dec 2011 14:23:14 +0000 (15:23 +0100)
 * Use ExtUtils::CChecker when not in core to replace the Configure-time testing that core does
 * Don't actually need to dVAR in getaddrinfo/getnameinfo
 * Expand croak_xs_usage inline rather than rely on xsubpp to write one

cpan/Socket/Makefile.PL
cpan/Socket/Socket.xs

index e5daf93..0667b31 100644 (file)
@@ -1,12 +1,90 @@
 use ExtUtils::MakeMaker;
 use ExtUtils::Constant 0.23 'WriteConstants';
 use Config;
+
+my @DEFINES;
+unless( $ENV{PERL_CORE} ) {
+    # Building standalone, not as core.
+    require ExtUtils::CChecker;
+    my $cc = ExtUtils::CChecker->new;
+
+    my %defines = (
+       # -Dfoo               func()        $Config{key}
+       HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ],
+       HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ],
+       HAS_INET_ATON   => [ "inet_aton",   "d_inetaton" ],
+       HAS_INETNTOP    => [ "inet_ntop",   "d_inetntop" ],
+       HAS_INETPTON    => [ "inet_pton",   "d_inetpton" ],
+    );
+
+    foreach my $define ( sort keys %defines ) {
+       my ( $func, $key ) = @{$defines{$define}};
+       next if exists $Config{$key};
+
+       $cc->try_compile_run(
+           define => $define,
+           source => <<"EOF" )
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+int main(int argc, char *argv[]) {
+    void *p = &$func;
+    return 0;
+}
+EOF
+           and print "$func() found\n"
+           or  print "$func() not found\n";
+    }
+
+    unless( exists $Config{d_sockaddr_sa_len} ) {
+       $cc->try_compile_run(
+           define => "HAS_SOCKADDR_SA_LEN",
+           source => <<'EOF' )
+#include <sys/types.h>
+#include <sys/socket.h>
+int main(int argc, char *argv[]) {
+    struct sockaddr sa;
+    sa.sa_len = 0;
+    return 0;
+}
+EOF
+           and print "sockaddr has sa_len\n"
+           or  print "sockaddr does not have sa_len\n";
+    }
+
+    unless( exists $Config{d_sin6_scope_id} ) {
+       $cc->try_compile_run(
+           define => "HAS_SIN6_SCOPE_ID",
+           source => <<'EOF' )
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+int main(int argc, char *argv[]) {
+    struct sockaddr_in6 sin6;
+    sin6.sin6_scope_id = 0;
+    return 0;
+}
+EOF
+           and print "sockaddr_in6 has sin6_scope_id\n"
+           or  print "sockaddr_in6 does not have sin6_scope_id\n";
+    }
+
+    @DEFINES = @{ $cc->extra_compiler_flags };
+}
+
 WriteMakefile(
     NAME        => 'Socket',
     VERSION_FROM => 'Socket.pm',
    ($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()),
     XSPROTOARG   => '-noprototypes',           # XXX remove later?
     realclean => {FILES=> 'const-c.inc const-xs.inc'},
+    DEFINE       => join( " ", @DEFINES ),
+    CONFIGURE_REQUIRES => {
+       'ExtUtils::CChecker' => 0,
+       'ExtUtils::Constant' => '0.23',
+    },
 );
 my @names = (qw(AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF
                AF_DATAKIT AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK
index f571ac7..b06cfa6 100644 (file)
@@ -241,7 +241,6 @@ static SV *err_to_SV(pTHX_ int err)
 
 static void xs_getaddrinfo(pTHX_ CV *cv)
 {
-       dVAR;
        dXSARGS;
 
        SV   *host;
@@ -258,7 +257,7 @@ static void xs_getaddrinfo(pTHX_ CV *cv)
        int n_res;
 
        if(items > 3)
-               croak_xs_usage(cv, "host, service, hints");
+               croak("Usage: Socket::getaddrinfo(host, service, hints)");
 
        SP -= items;
 
@@ -348,7 +347,6 @@ static void xs_getaddrinfo(pTHX_ CV *cv)
 #ifdef HAS_GETNAMEINFO
 static void xs_getnameinfo(pTHX_ CV *cv)
 {
-       dVAR;
        dXSARGS;
 
        SV  *addr;
@@ -361,7 +359,7 @@ static void xs_getnameinfo(pTHX_ CV *cv)
        int err;
 
        if(items < 1 || items > 2)
-               croak_xs_usage(cv, "addr, flags=0");
+               croak("Usage: Socket::getnameinfo(addr, flags=0)");
 
        SP -= items;