diff options
Diffstat (limited to 'ext')
-rw-r--r-- | ext/extmk.rb.in | 83 |
1 files changed, 55 insertions, 28 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") |