summaryrefslogtreecommitdiff
path: root/ext/socket/extconf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/socket/extconf.rb')
-rw-r--r--ext/socket/extconf.rb55
1 files changed, 43 insertions, 12 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index c86cc8f8c0..d44ce31b0a 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -316,6 +316,7 @@ end
netpacket/packet.h
net/ethernet.h
sys/un.h
+ afunix.h
ifaddrs.h
sys/ioctl.h
sys/sockio.h
@@ -326,6 +327,8 @@ end
net/if_dl.h
arpa/nameser.h
resolv.h
+ pthread.h
+ sched.h
].each {|h|
if have_header(h, headers)
headers << h
@@ -346,10 +349,22 @@ have_type("struct sockaddr_storage", headers)
have_type("struct addrinfo", headers)
-if have_type("socklen_t", headers)
- if try_static_assert("sizeof(socklen_t) >= sizeof(long)", headers)
- $defs << "-DRSTRING_SOCKLEN=(socklen_t)RSTRING_LEN"
+def check_socklen(headers)
+ def (fmt = "none").%(x)
+ x || self
+ end
+ s = checking_for("RSTRING_SOCKLEN", fmt) do
+ if try_static_assert("sizeof(socklen_t) >= sizeof(long)", headers)
+ "RSTRING_LEN"
+ else
+ "RSTRING_LENINT"
+ end
end
+ $defs << "-DRSTRING_SOCKLEN=(socklen_t)"+s
+end
+
+if have_type("socklen_t", headers)
+ check_socklen(headers)
end
have_type("struct in_pktinfo", headers) {|src|
@@ -484,6 +499,9 @@ EOF
have_func("getpeerucred(0, (ucred_t **)NULL)", headers) # SunOS
have_func_decl = proc do |name, headers|
+ # check if there is a declaration of <name> by trying to declare
+ # both "int <name>(void)" and "void <name>(void)"
+ # (at least one attempt should fail if there is a declaration)
if !checking_for("declaration of #{name}()") {!%w[int void].all? {|ret| try_compile(<<EOF)}}
#{cpp_include(headers)}
#{ret} #{name}(void);
@@ -492,10 +510,10 @@ EOF
end
end
if have_func('if_indextoname(0, "")', headers)
- have_func_decl["if_indextoname"]
+ have_func_decl["if_indextoname", headers]
end
if have_func('if_nametoindex("")', headers)
- have_func_decl["if_nametoindex"]
+ have_func_decl["if_nametoindex", headers]
end
have_func("hsterror", headers)
@@ -548,7 +566,7 @@ EOS
end
if !have_macro("IPPROTO_IPV6", headers) && have_const("IPPROTO_IPV6", headers)
- IO.read(File.join(File.dirname(__FILE__), "mkconstants.rb")).sub(/\A.*^__END__$/m, '').split(/\r?\n/).grep(/\AIPPROTO_\w*/){$&}.each {|name|
+ File.read(File.join(File.dirname(__FILE__), "mkconstants.rb")).sub(/\A.*^__END__$/m, '').split(/\r?\n/).grep(/\AIPPROTO_\w*/){$&}.each {|name|
have_const(name, headers) unless $defs.include?("-DHAVE_CONST_#{name.upcase}")
}
end
@@ -652,12 +670,20 @@ EOS
end
hdr = "netinet6/in6.h"
- if /darwin/ =~ RUBY_PLATFORM and !try_compile(<<"SRC", nil, :werror=>true)
+ /darwin/ =~ RUBY_PLATFORM and
+ checking_for("if apple's #{hdr} needs s6_addr patch") {!try_compile(<<"SRC", nil, :werror=>true)} and
#include <netinet/in.h>
int t(struct in6_addr *addr) {return IN6_IS_ADDR_UNSPECIFIED(addr);}
SRC
- print "fixing apple's netinet6/in6.h ..."; $stdout.flush
- in6 = File.read("/usr/include/#{hdr}")
+ checking_for("fixing apple's #{hdr}", "%s") do
+ file = xpopen(%w"clang -include netinet/in.h -E -xc -", in: IO::NULL) do |f|
+ re = %r[^# *\d+ *"(.*/netinet/in\.h)"]
+ Logging.message " grep(#{re})\n"
+ f.read[re, 1]
+ end
+ Logging.message "Substitute from #{file}\n"
+
+ in6 = File.read(file)
if in6.gsub!(/\*\(const\s+__uint32_t\s+\*\)\(const\s+void\s+\*\)\(&(\(\w+\))->s6_addr\[(\d+)\]\)/) do
i, r = $2.to_i.divmod(4)
if r.zero?
@@ -667,13 +693,18 @@ SRC
end
end
FileUtils.mkdir_p(File.dirname(hdr))
- open(hdr, "w") {|f| f.write(in6)}
+ File.write(hdr, in6)
$distcleanfiles << hdr
$distcleandirs << File.dirname(hdr)
- puts "done"
+ "done"
else
- puts "not needed"
+ "not needed"
end
end
+
+ have_func("pthread_create")
+ have_func("pthread_detach")
+
+ $VPATH << '$(topdir)' << '$(top_srcdir)'
create_makefile("socket")
end