diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-04-28 09:34:10 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-04-28 09:34:10 +0000 |
commit | 38060327e8cca6955e3066878cc7c20e539feeee (patch) | |
tree | 03519598cfdf538932a6010e3b811c77d9e59fe2 | |
parent | 839b0e3f3872b4cb7faec9b43e7f2690cade1693 (diff) |
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ext/extmk.rb.in | 83 | ||||
-rw-r--r-- | lib/mkmf.rb | 68 |
2 files changed, 103 insertions, 48 deletions
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in index 39fd657927..e0b31528f7 100644 --- a/ext/extmk.rb.in +++ b/ext/extmk.rb.in @@ -97,12 +97,41 @@ def xsystem command return r end -def try_link(libs) - xsystem(format(LINK, $CFLAGS, $LDFLAGS, libs)) +def try_link(src, opt="") + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + xsystem(format(LINK, $CFLAGS, $LDFLAGS, opt)) end -def try_cpp - xsystem(format(CPP, $CFLAGS)) +def try_cpp(src, opt=$CFLAGS) + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + xsystem(format(CPP, opt)) +end + +def egrep_cpp(pat, src, opt=$CFLAGS) + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + xsystem(format(CPP+"|egrep #{pat}", opt)) +end + +def try_run(src, opt="") + begin + if try_link(src, opt) + if xsystem("./conftest") + true + else + false + end + else + nil + end + ensure + system "rm -f conftest*" + end end def install_rb(mfile) @@ -138,20 +167,16 @@ def have_library(lib, func="main") end if func && func != "" - cfile = open("conftest.c", "w") - cfile.printf "\ -int main() { return 0; } -int t() { %s(); return 0; } -", func - cfile.close - begin if $libs libs = "-l" + lib + " " + $libs else libs = "-l" + lib end - unless try_link(libs) + unless try_link(<<"SRC", libs) +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC $lib_cache[lib] = 'no' $cache_mod = TRUE return FALSE @@ -183,19 +208,15 @@ def have_func(func) end end - cfile = open("conftest.c", "w") - cfile.printf "\ -char %s(); -int main() { return 0; } -int t() { %s(); return 0; } -", func, func - cfile.close - libs = $libs libs = "" if libs == nil begin - unless try_link(libs) + unless try_link(<<"SRC", libs) +char #{func}(); +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC $func_cache[func] = 'no' $cache_mod = TRUE return FALSE @@ -220,14 +241,10 @@ def have_header(header) end end - cfile = open("conftest.c", "w") - cfile.printf "\ -#include <%s> -", header - cfile.close - begin - unless try_cpp + unless try_cpp(<<"SRC") +#include <#{header}> +SRC $hdr_cache[header] = 'no' $cache_mod = TRUE return FALSE @@ -264,6 +281,16 @@ def with_config(config, default=nil) arg_config(config, default) end +def enable_config(config, default=nil) + if arg_config("--enable-"+config, true) + true + elsif arg_config("--disable-"+config, false) + false + else + default + end +end + def create_header() if $defs.length > 0 hfile = open("extconf.h", "w") diff --git a/lib/mkmf.rb b/lib/mkmf.rb index 2c6cdc1d68..fb37cae9ea 100644 --- a/lib/mkmf.rb +++ b/lib/mkmf.rb @@ -79,12 +79,35 @@ def xsystem command return r end -def try_link(libs) +def try_link(src, opt="") + cfile = open("conftest.c", "w") + cfile.print src + cfile.close xsystem(format(LINK, $CFLAGS, $LDFLAGS, libs)) end -def try_cpp - xsystem(format(CPP, $CFLAGS)) +def try_cpp(src, opt=$CFLAGS) + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + xsystem(format(CPP, opt)) +end + +def egrep_cpp(pat, src, opt=$CFLAGS) + cfile = open("conftest.c", "w") + cfile.print src + cfile.close + xsystem(format(CPP+"|egrep #{pat}", opt)) +end + +def try_run(src, opt="") + begin + if try_link(src, opt) + xsystem("./conftest") + end + ensure + system "rm -f conftest*" + end end def install_rb(mfile) @@ -137,7 +160,10 @@ int t() { %s(); return 0; } else libs = "-l" + lib end - unless try_link(libs) + unless try_link(<<"SRC", libs) +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC $lib_cache[lib] = 'no' $cache_mod = TRUE print "no\n" @@ -175,19 +201,15 @@ def have_func(func) end end - cfile = open("conftest.c", "w") - cfile.printf "\ -char %s(); -int main() { return 0; } -int t() { %s(); return 0; } -", func, func - cfile.close - libs = $libs libs = "" if libs == nil begin - unless try_link(libs) + unless try_link(<<"SRC", libs) +char #{func}(); +int main() { return 0; } +int t() { #{func}(); return 0; } +SRC $func_found[func] = 'no' $found = TRUE print "no\n" @@ -218,14 +240,10 @@ def have_header(header) end end - cfile = open("conftest.c", "w") - cfile.printf "\ -#include <%s> -", header - cfile.close - begin - unless try_cpp + unless try_cpp(<<"SRC") +#include <#{header}> +SRC $hdr_found[header] = 'no' $found = TRUE print "no\n" @@ -264,6 +282,16 @@ def with_config(config, default="yes") arg_config(config, default) end +def enable_config(config, default=nil) + if arg_config("--enable-"+config, true) + true + elsif arg_config("--disable-"+config, false) + false + else + default + end +end + def create_header() print "creating extconf.h\n" STDOUT.flush |