summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-06 14:51:44 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-02-06 14:51:44 +0000
commit7a07ffe479d8a791ebfc5e57268f15993b622741 (patch)
treef5609e1f9eb3abc53e6810a68ce87fdd57937f79 /ext
parent983de47edc0aeaa08846f9c29f1d58323cff6a9a (diff)
* ext/extmk.rb (extract_makefile): extract previously collected
informations from existing Makefile. * ext/socket/extconf.rb: check if getaddrinfo() works fine only when wide-getaddrinfo option is not given. fixed: [ruby-dev:25422] * ext/tk/extconf.rb: separate tkutil configuration. * 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/trunk@7901 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/extmk.rb124
-rw-r--r--ext/socket/extconf.rb221
-rw-r--r--ext/tk/extconf.rb40
3 files changed, 126 insertions, 259 deletions
diff --git a/ext/extmk.rb b/ext/extmk.rb
index 67fedc67d7..4e692209ee 100644
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -17,6 +17,7 @@ alias $0 $progname
$extlist = []
$extupdate = false
+$compiled = {}
$:.replace ["."]
require 'rbconfig'
@@ -44,6 +45,36 @@ def relative_from(path, base)
end
end
+def extract_makefile(makefile, force = false)
+ m = File.read(makefile)
+ if !(target = m[/^TARGET[ \t]*=[ \t]*(\S*)/, 1])
+ return force
+ end
+ installrb = {}
+ m.scan(/^install-rb-default:[ \t]*(\S+)\n\1:[ \t]*(\S+)/) {installrb[$2] = $1}
+ oldrb = installrb.keys.sort
+ newrb = install_rb(nil, "").collect {|d, *f| f}.flatten.sort
+ unless (oldrb -= newrb).empty?
+ FileUtils.rm_f(oldrb.collect {|old| Config.expand(installrb[old])}, :verbose => true)
+ return false
+ end
+ if target_prefix = m[/^target_prefix[ \t]*=[ \t]*\/(.*)/, 1]
+ target = "#{target_prefix}/#{target}"
+ end
+ $target = target
+ /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = nil
+ $preload = Shellwords.shellwords(m[/^preload[ \t]*=[ \t]*(.*)/, 1] || "")
+ $DLDFLAGS += " " + (m[/^DLDFLAGS[ \t]*=[ \t]*(.*)/, 1] || "")
+ if s = m[/^LIBS[ \t]*=[ \t]*(.*)/, 1]
+ s.sub!(/^#{Regexp.quote($LIBRUBYARG)} */, "")
+ s.sub!(/ *#{Regexp.quote($LIBS)}$/, "")
+ $libs = s
+ end
+ $LOCAL_LIBS = m[/^LOCAL_LIBS[ \t]*=[ \t]*(.*)/, 1] || ""
+ $LIBPATH = Shellwords.shellwords(m[/^libpath[ \t]*=[ \t]*(.*)/, 1] || "") - %w[$(libdir) $(topdir)]
+ true
+end
+
def extmake(target)
print "#{$message} #{target}\n"
$stdout.flush
@@ -57,8 +88,6 @@ def extmake(target)
return true if $nodynamic and not $static
end
- init_mkmf
-
FileUtils.mkpath target unless File.directory?(target)
begin
dir = Dir.pwd
@@ -73,18 +102,20 @@ def extmake(target)
$mdir = target
$srcdir = File.join($top_srcdir, "ext", $mdir)
$preload = nil
+ $compiled[target] = false
makefile = "./Makefile"
+ ok = File.exist?(makefile)
unless $ignore
- if !(t = modified?(makefile, MTIMES)) ||
- %W<#{$srcdir}/makefile.rb #{$srcdir}/extconf.rb
- #{$srcdir}/depend>.any? {|f| modified?(f, [t])}
- then
- $defs = []
- Logging::logfile 'mkmf.log'
- Config::CONFIG["srcdir"] = $srcdir
- Config::CONFIG["topdir"] = $topdir
- rm_f makefile
- begin
+ Config::CONFIG["srcdir"] = $srcdir
+ Config::CONFIG["topdir"] = $topdir
+ begin
+ if (!(ok &&= extract_makefile(makefile)) ||
+ !(t = modified?(makefile, MTIMES)) ||
+ %W"#{$srcdir}/makefile.rb #{$srcdir}/extconf.rb #{$srcdir}/depend".any? {|f| modified?(f, [t])})
+ then
+ init_mkmf
+ Logging::logfile 'mkmf.log'
+ rm_f makefile
if File.exist?($0 = "#{$srcdir}/makefile.rb")
load $0
elsif File.exist?($0 = "#{$srcdir}/extconf.rb")
@@ -93,40 +124,23 @@ def extmake(target)
create_makefile(target)
end
$extupdate = true
- File.exist?(makefile)
- rescue SystemExit
- # ignore
- ensure
- rm_f "conftest*"
- $0 = $PROGRAM_NAME
- Config::CONFIG["srcdir"] = $top_srcdir
- end
- else
- if $static
- m = File.read(makefile)
- if !($target = m[/^TARGET[ \t]*=[ \t]*(\S*)/, 1])
- $static = nil
- elsif target_prefix = m[/^target_prefix[ \t]*=[ \t]*\/(.*)/, 1]
- $target = "#{target_prefix}/#{$target}"
- end
- /^STATIC_LIB[ \t]*=[ \t]*\S+/ =~ m or $static = nil
- $preload = Shellwords.shellwords(m[/^preload[ \t]*=[ \t]*(.*)/, 1] || "")
- $DLDFLAGS += " " + (m[/^DLDFLAGS[ \t]*=[ \t]*(.*)/, 1] || "")
- if s = m[/^LIBS[ \t]*=[ \t]*(.*)/, 1]
- s.sub!(/^#{Regexp.quote($LIBRUBYARG)} */, "")
- s.sub!(/ *#{Regexp.quote($LIBS)}$/, "")
- $libs = s
- end
- $LOCAL_LIBS = m[/^LOCAL_LIBS[ \t]*=[ \t]*(.*)/, 1] || ""
- $LIBPATH = Shellwords.shellwords(m[/^libpath[ \t]*=[ \t]*(.*)/, 1] || "") -
- %w[$(libdir) $(topdir)]
+ ok = File.exist?(makefile)
end
- true
+ rescue SystemExit
+ # ignore
+ ensure
+ rm_f "conftest*"
+ config = $0
+ $0 = $PROGRAM_NAME
+ Config::CONFIG["srcdir"] = $top_srcdir
+ Config::CONFIG["topdir"] = topdir
+ end
+ end
+ ok = yield(ok) if block_given?
+ unless ok
+ open(makefile, "w") do |f|
+ f.print dummy_makefile($srcdir)
end
- else
- File.exist?(makefile)
- end or open(makefile, "w") do |f|
- f.print dummy_makefile($srcdir)
return true
end
args = sysquote($mflags)
@@ -137,6 +151,7 @@ def extmake(target)
unless system($make, *args)
$ignore or $continue or return false
end
+ $compiled[target] = true
if $clean and $clean != true
File.unlink(makefile) rescue nil
end
@@ -164,11 +179,15 @@ def extmake(target)
true
end
+def compiled?(target)
+ $compiled[target]
+end
+
def parse_args()
$mflags = []
opts = nil
- ARGV.options do |opts|
+ $optparser ||= OptionParser.new do |opts|
opts.on('-n') {$dryrun = true}
opts.on('--[no-]extension [EXTS]', Array) do |v|
$extension = (v == false ? [] : v)
@@ -200,13 +219,14 @@ def parse_args()
opts.on('--message [MESSAGE]', String) do |v|
$message = v
end
- begin
- opts.parse!
- rescue OptionParser::InvalidOption => e
- retry if /^--/ =~ e.args[0]
- raise
- end
- end or abort opts.to_s
+ end
+ begin
+ $optparser.parse!(ARGV)
+ rescue OptionParser::InvalidOption => e
+ retry if /^--/ =~ e.args[0]
+ $optparser.warn(e)
+ abort opts.to_s
+ end
$destdir ||= ''
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index acbff10a16..7842899520 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()
@@ -45,14 +53,10 @@ $ipv6lib = nil
$ipv6libdir = nil
$ipv6trylibc = nil
if $ipv6
- if macro_defined?("IPV6_INRIA_VERSION", <<EOF)
-#include <netinet/in.h>
-EOF
+ if have_macro("IPV6_INRIA_VERSION", "netinet/in.h")
$ipv6type = "inria"
$CPPFLAGS="-DINET6 "+$CPPFLAGS
- elsif macro_defined?("__KAME__", <<EOF)
-#include <netinet/in.h>
-EOF
+ elsif have_macro("__KAME__", "netinet/in.h")
$ipv6type = "kame"
$ipv6lib="inet6"
$ipv6libdir="/usr/local/v6/lib"
@@ -63,24 +67,18 @@ EOF
$ipv6lib="inet6"
$ipv6libdir="/usr/inet6/lib"
$CPPFLAGS="-DINET6 -I/usr/inet6/include "+$CPPFLAGS
- elsif macro_defined?("_TOSHIBA_INET6", <<EOF)
-#include <sys/param.h>
-EOF
+ elsif have_macro("_TOSHIBA_INET6", "sys/param.h")
$ipv6type = "toshiba"
$ipv6lib="inet6"
$ipv6libdir="/usr/local/v6/lib"
$CPPFLAGS="-DINET6 "+$CPPFLAGS
- elsif macro_defined?("__V6D__", <<EOF)
-#include </usr/local/v6/include/sys/v6config.h>
-EOF
+ elsif have_macro("__V6D__", "/usr/local/v6/include/sys/v6config.h")
$ipv6type = "v6d"
$ipv6lib="v6"
$ipv6libdir="/usr/local/v6/lib"
$CFLAGS="-I/usr/local/v6/include "+$CFLAGS
$CPPFLAGS="-DINET6 "+$CPPFLAGS
- elsif macro_defined?("_ZETA_MINAMI_INET6", <<EOF)
-#include <sys/param.h>
-EOF
+ elsif have_macro("_ZETA_MINAMI_INET6", "sys/param.h")
$ipv6type = "zeta"
$ipv6lib="inet6"
$ipv6libdir="/usr/local/v6/lib"
@@ -95,101 +93,28 @@ EOF
if File.directory? $ipv6libdir and File.exist? "#{$ipv6libdir}/lib#{$ipv6lib}.a"
$LOCAL_LIBS = " -L#$ipv6libdir -l#$ipv6lib"
elsif !$ipv6trylibc
- print <<EOS
-
+ abort <<EOS
Fatal: no #$ipv6lib library found. cannot continue.
You need to fetch lib#{$ipv6lib}.a from appropriate
ipv6 kit and compile beforehand.
EOS
- exit
end
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
- $CPPFLAGS="-DHAVE_SOCKADDR_STORAGE "+$CPPFLAGS
-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!
+doug = proc {have_struct_member("struct sockaddr_storage", "ss_family", headers)}
+if doug[] or
+ with_cppflags($CPPFLAGS + " -Dss_family=__ss_family -Dss_len=__ss_len", &doug)
+ $defs[-1] = "-DHAVE_SOCKADDR_STORAGE"
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
@@ -200,13 +125,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
@@ -282,79 +211,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"
- $CPPFLAGS="-DLOOKUP_ORDER_HACK_INET "+$CPPFLAGS
+ $defs << "-DLOOKUP_ORDER_HACK_INET"
when "INET6"
- $CPPFLAGS="-DLOOKUP_ORDER_HACK_INET6 "+$CPPFLAGS
+ $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
- $CPPFLAGS="-DHAVE_GETADDRINFO "+$CPPFLAGS
-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")
@@ -365,20 +261,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")
@@ -387,14 +271,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")
diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb
index a677ea3a7c..30dd11ab86 100644
--- a/ext/tk/extconf.rb
+++ b/ext/tk/extconf.rb
@@ -265,52 +265,14 @@ if mac_need_framework ||
$LDFLAGS += ' -framework Tk -framework Tcl'
end
-
if stubs or pthread_check
# create Makefile
- # backup
- if $INSTALLFILES
- installfiles_bup = $INSTALLFILES.dup
- else
- installfiles_bup = nil
- $INSTALLFILES = []
- end
-
# for SUPPORT_STATUS
+ $INSTALLFILES ||= []
$INSTALLFILES << ["lib/tkextlib/SUPPORT_STATUS", "$(RUBYLIBDIR)", "lib"]
# create
create_makefile("tcltklib")
-
- # reset
- $INSTALLFILES = installfiles_bup
-
- # add rules for tkutil
- File::open('Makefile', 'a'){|mfile|
- File::open('make-tkutil', 'r'){|dfile|
- mfile.print "\n###\n"
- while line = dfile.gets()
- mfile.print line
- end
- }
- }
-
- # create tkutil/Makefile
- Dir.chdir 'tkutil'
- if $extout || $extmk
- $srcdir = '../' << $srcdir << '/tkutil'
- $topdir = '../' << $topdir
- $hdrdir = '../' << $hdrdir
- $objs = nil
- $defs = []
- Config::CONFIG["srcdir"] = $srcdir
- else
- puts "entering directory `tkutil'"
- end
- rm_f './Makefile'
- init_mkmf
- load 'subconf.rb'
- Dir.chdir '..'
end
end