diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-06 14:50:49 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-06 14:50:49 +0000 |
commit | 251d1d8bde5196b00b43957ea175a15c3f986b48 (patch) | |
tree | f4973152c106c4663188be6d2a4d9cbf7ba767b3 /ext/socket/extconf.rb | |
parent | 840f61ba5444c0cc59066b63584fd47993bfe036 (diff) |
* ext/socket/extconf.rb: check if getaddrinfo() works fine only when
wide-getaddrinfo option is not given. fixed: [ruby-dev:25422]
* lib/mkmf.rb ($extmk): check if under ext directory.
* lib/mkmf.rb (Logging.postpone): allow recursive operation.
* lib/mkmf.rb (try_constant): make sure if really a constant, reduce
the number of times of compile.
* lib/mkmf.rb (have_macro, have_var, byte_order): new functions.
* lib/mkmf.rb (find_library): allow directory list with separators.
* lib/mkmf.rb (arg_config): manage provided configuration options.
* lib/mkmf.rb (dir_config): accept arrays of directory names as
default values.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7900 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/extconf.rb')
-rw-r--r-- | ext/socket/extconf.rb | 204 |
1 files changed, 54 insertions, 150 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb index 4f7b49407f..66d7462cbf 100644 --- a/ext/socket/extconf.rb +++ b/ext/socket/extconf.rb @@ -24,10 +24,18 @@ else have_library("socket", "socket") end +unless $mswin or $bccwin or $mingw + headers = %w<sys/types.h netdb.h string.h sys/socket.h netinet/in.h> +end +if /solaris/ =~ RUBY_PLATFORM and !try_compile("") + # bug of gcc 3.0 on Solaris 8 ? + headers << "sys/feature_tests.h" +end + $ipv6 = false default_ipv6 = /cygwin/ !~ RUBY_PLATFORM if enable_config("ipv6", default_ipv6) - if try_link(<<EOF) + if checking_for("ipv6") {try_link(<<EOF)} #include <sys/types.h> #include <sys/socket.h> main() @@ -105,90 +113,26 @@ EOS end end - if try_link(<<EOF) -#ifdef _WIN32 -# include <windows.h> -# include <winsock.h> -#else -# include <sys/types.h> -# include <netdb.h> -# include <string.h> -# include <sys/socket.h> -# include <netinet/in.h> -#endif -int -main() -{ - struct sockaddr_in sin; - - sin.sin_len; - return 0; -} -EOF - $CFLAGS="-DHAVE_SIN_LEN "+$CFLAGS +if have_struct_member("struct sockaddr_in", "sin_len", headers) + $defs[-1] = "-DHAVE_SIN_LEN" end - if try_link(<<EOF) -#ifdef _WIN32 -# include <windows.h> -# include <winsock.h> -#else -# include <sys/types.h> -# include <netdb.h> -# include <string.h> -# include <sys/socket.h> -#endif -int -main() -{ - struct sockaddr_storage ss; - - ss.ss_family; - return 0; -} -EOF - $CFLAGS="-DHAVE_SOCKADDR_STORAGE "+$CFLAGS -else # doug's fix, NOW add -Dss_family... only if required! -$CPPFLAGS += " -Dss_family=__ss_family -Dss_len=__ss_len" - if try_link(<<EOF) -#ifdef _WIN32 -# include <windows.h> -# include <winsock.h> -#else -# include <sys/types.h> -# include <netdb.h> -# include <string.h> -# include <sys/socket.h> -#endif -int -main() -{ - struct sockaddr_storage ss; - - ss.ss_family; - return 0; -} -EOF - $CFLAGS="-DHAVE_SOCKADDR_STORAGE "+$CFLAGS -end +# doug's fix, NOW add -Dss_family... only if required! +[nil, " -Dss_family=__ss_family -Dss_len=__ss_len"].each do |flags| + if flags + cppflags = $CPPFLAGS + $CPPFLAGS += flags + end + if have_struct_member("struct sockaddr_storage", "ss_family", headers) + $defs[-1] = "-DHAVE_SOCKADDR_STORAGE" + break + elsif flags + $CPPFLAGS = cppflags + end end - if try_link(<<EOF) -#include <sys/types.h> -#include <netdb.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/in.h> -int -main() -{ - struct sockaddr sa; - - sa.sa_len; - return 0; -} -EOF - $CFLAGS="-DHAVE_SA_LEN "+$CFLAGS +if have_struct_member("struct sockaddr", "sa_len", headers) + $defs[-1] = "-DHAVE_SA_LEN " end have_header("netinet/tcp.h") if not /cygwin/ =~ RUBY_PLATFORM # for cygwin 1.1.5 @@ -199,13 +143,17 @@ if have_func("sendmsg") | have_func("recvmsg") have_struct_member('struct msghdr', 'msg_accrights', ['sys/types.h', 'sys/socket.h']) end -$getaddr_info_ok = false -if !enable_config("wide-getaddrinfo", false) and try_run(<<EOF) -#include <sys/types.h> -#include <netdb.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/in.h> +getaddr_info_ok = enable_config("wide-getaddrinfo") do + checking_for("wide getaddrinfo") {try_run(<<EOF)} +#{cpp_include(headers)} +#include <stdlib.h> + +#ifndef EXIT_SUCCESS +#define EXIT_SUCCESS 0 +#endif +#ifndef EXIT_FAILURE +#define EXIT_FAILURE 1 +#endif #ifndef AF_LOCAL #define AF_LOCAL AF_UNIX @@ -281,79 +229,46 @@ main() if (aitop) freeaddrinfo(aitop); - exit(0); + exit(EXIT_SUCCESS); bad: if (aitop) freeaddrinfo(aitop); - exit(1); + exit(EXIT_FAILURE); } EOF - $getaddr_info_ok = true end -if $ipv6 and not $getaddr_info_ok - print <<EOS +if $ipv6 and not getaddr_info_ok + abort <<EOS Fatal: --enable-ipv6 is specified, and your OS seems to support IPv6 feature. But your getaddrinfo() and getnameinfo() are appeared to be broken. Sorry, you cannot compile IPv6 socket classes with broken these functions. You can try --enable-wide-getaddrinfo. EOS - exit end - + case with_config("lookup-order-hack", "UNSPEC") when "INET" - $CFLAGS="-DLOOKUP_ORDER_HACK_INET "+$CFLAGS + $defs << "-DLOOKUP_ORDER_HACK_INET" when "INET6" - $CFLAGS="-DLOOKUP_ORDER_HACK_INET6 "+$CFLAGS + $defs << "-DLOOKUP_ORDER_HACK_INET6" when "UNSPEC" # nothing special else - print <<EOS + abort <<EOS Fatal: invalid value for --with-lookup-order-hack (expected INET, INET6 or UNSPEC) EOS - exit end $objs = ["socket.#{$OBJEXT}"] - -if $getaddr_info_ok and have_func("getaddrinfo", "netdb.h") and have_func("getnameinfo", "netdb.h") - have_getaddrinfo = true -else - if try_link(<<EOF) -#ifndef _WIN32 -# include <sys/types.h> -# include <netdb.h> -# include <string.h> -# include <sys/socket.h> -# include <netinet/in.h> -#else -# include <windows.h> -# ifdef _WIN32_WCE -# include <winsock.h> -# else -# include <winsock.h> -# endif -#endif -int -main() -{ - struct in6_addr addr; - unsigned char c; - c = addr.s6_addr8; - return 0; -} -EOF - $CFLAGS="-DHAVE_ADDR8 "+$CFLAGS - end -end -if have_getaddrinfo - $CFLAGS="-DHAVE_GETADDRINFO "+$CFLAGS -else - $CFLAGS="-I. "+$CFLAGS +unless getaddr_info_ok and have_func("getnameinfo", "netdb.h") and have_func("getaddrinfo", "netdb.h") + if have_struct_member("struct in6_addr", "s6_addr8", headers) + $defs[-1] = "-DHAVE_ADDR8" + end + $CPPFLAGS="-I. "+$CPPFLAGS $objs += ["getaddrinfo.#{$OBJEXT}"] $objs += ["getnameinfo.#{$OBJEXT}"] have_func("inet_ntop") or have_func("inet_ntoa") @@ -364,20 +279,8 @@ else have_header("resolv.h") end -if !try_link(<<EOF) -#include <sys/types.h> -#include <netdb.h> -#include <string.h> -#include <sys/socket.h> -#include <netinet/in.h> -int -main() -{ - socklen_t len; - return 0; -} -EOF - $CFLAGS="-Dsocklen_t=int "+$CFLAGS +unless have_type("socklen_t", headers) + $defs << "-Dsocklen_t=int" end have_header("sys/un.h") @@ -386,14 +289,15 @@ have_header("sys/uio.h") if have_func(test_func) have_func("hsterror") have_func("getipnodebyname") or have_func("gethostbyname2") + have_func("socketpair") unless have_func("gethostname") have_func("uname") end if enable_config("socks", ENV["SOCKS_SERVER"]) if have_library("socks5", "SOCKSinit") - $CFLAGS+=" -DSOCKS5 -DSOCKS" + $defs << "-DSOCKS5" << "-DSOCKS" elsif have_library("socks", "Rconnect") - $CFLAGS+=" -DSOCKS" + $defs << "-DSOCKS" end end create_makefile("socket") |